<template>
  <div class="plateList">
    <div class="el-card__header">
      <span>版块管理</span>
      <div style="display: flex;flex-direction: row;align-items: center">
        <el-button type="primary" class="el-button--small" @click="addRecharge">新增</el-button>
      </div>
    </div>
    <div class="content">
      <div style="display: flex;flex-direction: row;align-items: center">
        <div class="block">
          <div class="searchInput" style="width:200px">
            <el-input style="display:inline-block;width:170px;height:30px" placeholder="请输入板块名称搜索" v-model="msg.Name"
              size="small" @clear="getList" @keyup.enter.native="getList" clearable>
            </el-input>
            <span @click="getList" class="el-icon-search"
              style="color:#979dad;font-size:14px;position:relative;top:1px"></span>
          </div>
          <span>是否显示</span>
          <el-select class="w100" @change="getList()" style="margin-right: 10px;" v-model="msg.PrizeType" size="small"
            placeholder="请选择">
            <el-option label="不限" :value="0"></el-option>
            <el-option label="是" :value="1"></el-option>
            <el-option label="否" :value="2"></el-option>
          </el-select>
        </div>
      </div>
    </div>
    <div style="padding: 20px;background: #fff;">
      <el-table :data="tableData" header-cell-class-name="headClass" style="width: 100%" border>
        <el-table-column prop="Id" label="ID" width="100">
          <template slot-scope="scope">
            <span class="plateGoId" @click="goRecruit(scope.row.Id)">{{scope.row.Id}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="Name" label="信息">
          <template slot-scope="scope">
            <div class="app-image" :style="{backgroundImage:'url(' + scope.row.Icon + ')',backgroundSize:'cover'}">
            </div>
            <div flex="dir:left cross:center">
              {{scope.row.Name}}
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="Sort" label="排序">
        </el-table-column>
        <el-table-column prop="IsShow" label="是否显示">
          <template slot-scope="scope">
            <!--            <div flex="dir:left cross:center">-->
            <!--              {{scope.row.IsShow==1?'是':'否'}}-->
            <!--            </div>-->
            <el-switch v-model="scope.row.IsShow" :active-value="1" :inactive-value="2" @change="setshow(scope.row)">
            </el-switch>
          </template>
        </el-table-column>
        <el-table-column prop="CreateDate" label="创建时间">
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="180">
          <template slot-scope="scope">
            <el-tooltip class="item" effect="dark" content="编辑" placement="top">
              <img src="../../assets/img/setup/edit.png" alt="" class="imgstyle" @click="Edit(scope.row)">
            </el-tooltip>
            <el-tooltip class="item" effect="dark" content="删除" placement="top">
              <img src="../../assets/img/setup/del.png" alt="" class="imgstyle" @click="delete_b(scope.row)">
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination style="text-align:right" background @current-change="handleCurrentChange" :page-size="msg.pageSize"
        layout="prev, pager, next" :current-page.sync="msg.pageIndex" :total="count">
      </el-pagination>
    </div>
  </div>
</template>
<script>
  export default {
    name: "plateList",
    data() {
      return {
        msg: {
          pageIndex: 1,
          pageSize: 20,
          Name: '',
          IsShow: 0,
        },
        changeState: false,
        dateList: [],
        tableData: [],
        count: 0,
        loading: false,
        EnableMsg: {
          Ids: '',
          TeacherStatus: 0,
        },
      }
    },
    created() {
      this.getDateList();
    },
    methods: {
      getDateList() {
        let msg = JSON.parse(JSON.stringify(this.msg))
        this.loading = true;
        this.apipost("/api/Miai/GetForumPageList", msg, res => {
          this.loading = false;
          if (res.data.resultCode == 1) {
            this.tableData = res.data.data.pageData;
            this.count = res.data.data.count;
          } else {
            this.Info(res.data.message);
          }
        })
      },
      addRecharge() {
        this.$router.push('/addplate');

      },
      setshow(row) {
        this.apipost(
          "/api/Miai/SetForumState", {
            ForumId: row.Id,
            Type: 1
          },
          res => {
            if (res.data.resultCode == 1) {
              this.Success(res.data.message);
            } else {
              this.Error(res.data.message);
            }
          },
        );
      },
      Edit(row) {
        let arr = encodeURIComponent(JSON.stringify(row))
        this.$router.push({
          name: 'addplate',
          query: {
            arr: arr,
            blank: "y"
          }
        });
      },
      delete_b(row) {
        let that = this;
        that.Confirm("是否删除?", function () {
          that.apipost(
            "/api/Miai/SetForumState", {
              ForumId: row.Id,
              Type: 2
            },
            res => {
              if (res.data.resultCode == 1) {
                that.Success(res.data.message);
                that.getDateList();
              } else {
                that.Error(res.data.message);
              }
            },
          );
        });
      },

      //勾选导游
      handleSelectionChange(val) {
        var selectRow = JSON.parse(JSON.stringify(val));
        let array = [];
        selectRow.forEach(x => {
          let obj = {}
          obj = x.ID;
          array.push(obj)
        });
        this.EnableMsg.Ids = array
      },


      getList() {
        this.msg.pageIndex = 1
        this.getDateList()
      },

      handleCurrentChange(val) {
        this.msg.pageIndex = val;
        this.getDateList();
      },
      goRecruit(Id){
        this.$router.push({
            name: 'recruitStick',
            query: {
              Id:Id,
              blank: "y"
            }
        });
      },
    },
  }

</script>

<style>
  .plateList .el-card__header {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    background: #fff;

  }

  .plateList .el-button--small {
    padding: 9px 15px;
  }

  .plateList .content .searchInput {
    border: 1px solid #DCDFE6;
    border-radius: 4px;
    /*margin-left: 10px;*/
  }

  .plateList .content .searchInput .el-input__inner {
    border: none;
    outline: none;
    height: 30px;
    line-height: 30px;
  }

  .plateList .content .searchInput {
    line-height: normal;
    display: inline-table;
    border-collapse: separate;
    border-spacing: 0;
    width: 250px;
  }

  .plateList .content {
    background: #fff;
    margin-top: 10px;
    padding: 15px;
    box-sizing: border-box;
  }

  .plateList .el-tag {
    margin-right: 5px;
  }

  .plateList .app-image {
    background-position: center center;
    width: 50px;
    height: 50px;
    border-radius: 0%;
    float: left;
    margin-right: 8px;
  }
  .plateList .plateGoId{
    color:#409EFF;
    cursor: pointer;
  }
</style>
