<template>
  <div class="app-container">
    <el-card shadow="never">
      <div>
        <i class="el-icon-search"></i>
        <span>筛选搜索</span>
        <div style="float:right">
          <el-button type="primary" @click="handleSearchList" size="small">
            查询
          </el-button>
        </div>
      </div>
      <div style="margin-top: 15px">
        <el-form
          size="small"
          :model="queryParams"
          ref="queryForm"
          :inline="true"
          @submit.native.prevent
        >
          <el-form-item label="解读标题">
            <el-input v-model="queryParams.title" placeholder="请输入" />
          </el-form-item>
        </el-form>
      </div>
    </el-card>
    <el-card class="operate-container" shadow="never">
      <i class="el-icon-tickets"></i>
      <span>数据列表</span>
      <el-button class="btn-add" @click="handlePage(null)" size="mini">
        添加解读
      </el-button>
    </el-card>
    <el-table
      style="width: 100%"
      class="table-container"
      :data="unscrambleList"
    >
      <el-table-column
        label="序号"
        align="center"
        type="index"
      ></el-table-column>
      <el-table-column label="解读标题" prop="name" align="center">
        <template slot-scope="scope">
          <el-link type="primary" :underline="false">{{
            scope.row.title
          }}</el-link>
        </template>
      </el-table-column>
      <el-table-column label="归口" align="center" prop="attribute">
        <template slot-scope="scope">
          {{
            attributeOptions.filter(
              item => item.value == scope.row.attribute
            )[0].label
          }}
        </template>
      </el-table-column>
      <el-table-column
        label="发布日期"
        align="center"
        prop="listDate"
      ></el-table-column>
      <el-table-column
        label="来源"
        align="center"
        prop="source"
      ></el-table-column>
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button @click="handlePage(scope.row.id)" type="text" size="small"
            >编辑</el-button
          >
          <el-button
            @click="handleDelete(scope.row.id)"
            type="text"
            size="small"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script>
import { getPolicyRead, delRead } from '@/api/front/unscramble';
export default {
  data() {
    return {
      queryParams: {
        pageNum: 1,
        pageSize: 100
      },
      unscrambleList: [],
      // 归口选项
      attributeOptions: [
        {
          value: 'KJJ',
          label: '科技'
        },
        {
          value: 'JXJ',
          label: '经信'
        },
        {
          value: 'FGW',
          label: '发改'
        },
        {
          value: 'OTHER',
          label: '其他'
        }
      ]
    };
  },
  methods: {
    handleSearchList() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    getList() {
      getPolicyRead(this.queryParams).then(({ data }) => {
        this.unscrambleList = data.list;
      });
    },
    // 跳转页面
    handlePage(id) {
      this.$router.push({ path: '/front/addUnscramble', query: { id } });
    },
    /** 删除按钮操作 */
    handleDelete(id) {
      this.$confirm('确认删除该数据?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(function() {
          return delRead({ id });
        })
        .then(() => {
          this.getList();
          this.msgSuccess('删除成功');
        });
    }
  },
  created() {
    this.getList();
  }
};
</script>
