<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="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="typeName"
      ></el-table-column>
      <el-table-column
        label="需求企业"
        align="center"
        prop="company"
      ></el-table-column>
      <el-table-column
        label="价格"
        align="center"
        prop="price"
      ></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>
  </div>
</template>
<script>
import {
  getEnterpriseNeedList,
  handleEnterpriseNeed
} from '@/api/technology/demand';
export default {
  data() {
    return {
      queryParams: {
        pageNum: 1,
        pageSize: 100
      },
      unscrambleList: []
    };
  },
  methods: {
    handleSearchList() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    getList() {
      getEnterpriseNeedList(this.queryParams).then(({ data }) => {
        this.unscrambleList = data.list;
      });
    },
    // 跳转页面
    handlePage(id) {
      this.$router.push({ path: '/technology/addDemand', query: { id } });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      this.$confirm('确认删除该数据?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(function() {
          row.status = -1;
          return handleEnterpriseNeed(row);
        })
        .then(() => {
          this.getList();
          this.msgSuccess('删除成功');
        });
    }
  },
  created() {
    this.getList();
  }
};
</script>
