<template>
  <div class="topicList">
    <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="addTopic">新增</el-button>
      </div>
    </div>
    <div class="content">
      <div style="display: flex;flex-direction: row;align-items: center">
        <div class="block">
          <span>是否显示</span>
          <el-select class="w100" @change="getList()" style="margin-left: 10px;" v-model="msg.IsOpen" 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="dataList" header-cell-class-name="headClass" style="width: 100%" border>
        <el-table-column prop="Id" label="ID" width="100">
          <template slot-scope="scope">
            <span @click="goRecruit(scope.row.Id)">{{scope.row.Id}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="Content" label="话题">
        </el-table-column>
        <el-table-column prop="CoverPhoto" label="图片">
          <template slot-scope="scope">
            <img v-if="scope.row.CoverPhoto" :src="scope.row.CoverPhoto" style="width:40px;height:40px;" alt="" />
          </template>
        </el-table-column>
        <el-table-column prop="IsOpen" label="是否显示">
          <template slot-scope="scope">
            <el-switch @change="changeSwitch(scope.row)" v-model="scope.row.IsOpen" active-color="#409EFF"
              :active-value="1" :inactive-value="2">
            </el-switch>
          </template>
        </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="pageCount">
      </el-pagination>
    </div>
  </div>
</template>
<script>
  export default {
    name: "topicList",
    data() {
      return {
        msg: {
          pageIndex: 1,
          pageSize: 20,
          IsOpen: 0,
        },
        dataList: [],
        pageCount: 0,
        loading: false
      }
    },
    created() {
      this.getList();
    },
    methods: {
      getList() {
        this.apipost(
          "/api/Education/GetEducationTalkPageList", this.msg,
          res => {
            if (res.data.resultCode == 1) {
              this.dataList = res.data.data.pageData;
              this.pageCount = res.data.data.pageCount;
            } else {
              this.Error(res.data.message);
            }
          },
        );
      },
      handleCurrentChange(val) {
        this.msg.pageIndex = val;
        this.getList();
      },
      //新增话题
      addTopic() {
        this.$router.push('/editTopic');
      },
      //删除话题
      delete_b(row) {
        let that = this;
        that.Confirm("是否删除?", function () {
          that.apipost(
            "/api/Education/DelEducationTalk", {
              Id: row.Id
            },
            res => {
              if (res.data.resultCode == 1) {
                that.Success(res.data.message);
                that.getList();
              } else {
                that.Error(res.data.message);
              }
            },
          );
        });
      },
      //编辑数据
      Edit(row) {
        this.$router.push({
          name: 'editTopic',
          query: {
            Id: row.Id,
            blank: "y"
          }
        });
      },
      //切换
      changeSwitch(item) {
        let msg = {
          Id: item.Id,
          IsOpen: item.IsOpen
        }
        this.apipost("/api/Education/UpdateEducationTalkShow", msg, res => {
          if (res.data.resultCode == 1) {
            this.Success(res.data.message);
            this.getList();
          }
        })
      }
    },
  }

</script>

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

  }

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

</style>
