<template>
  <div class="app-container">
    <el-card shadow="never">
      <div>
        <i class="el-icon-search"></i>
        <span>筛选搜索</span>
      </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="请输入" style="min-width:270px" />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="handleSearchList" size="small">
              查询
            </el-button>
          </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" type="primary">
        添加成果
      </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="title" 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="fieldName"
      ></el-table-column>
      <el-table-column
        label="成熟度"
        align="center"
        prop="maturityName"
      ></el-table-column>
      <el-table-column
        label="合作标签"
        align="center"
        prop="labelName"
      ></el-table-column>
      <el-table-column
        label="成果企业"
        align="center"
        prop="company"
      ></el-table-column>
      <el-table-column
        label="发布日期"
        align="center"
        prop="createTime"
      ></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)" type="text" size="small"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>
<script>
import {
  getScienceResultList,
  handleScienceResult
} from '@/api/technology/achievement';
export default {
  data() {
    return {
      queryParams: {
        pageNum: 1,
        pageSize: 10
      },
      total: 0,
      unscrambleList: [],
      // 归口选项
      attributeOptions: [
        {
          value: 'KJJ',
          label: '科技'
        },
        {
          value: 'JXJ',
          label: '经信'
        },
        {
          value: 'FGW',
          label: '发改'
        },
        {
          value: 'OTHER',
          label: '其他'
        }
      ]
    };
  },
  methods: {
    handleSearchList() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    getList() {
      getScienceResultList(this.queryParams).then(({ data }) => {
        this.unscrambleList = data.list;
        this.total = data.total;
      });
    },
    // 跳转页面
    handlePage(id) {
      this.$router.push({ path: '/technology/addAchievement', query: { id } });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      this.$confirm('确认删除该数据?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(function() {
          row.status = -1;
          return handleScienceResult(row);
        })
        .then(() => {
          this.getList();
          this.msgSuccess('删除成功');
        });
    }
  },
  created() {
    this.getList();
  }
};
</script>
