<!--
  @description: 抽取项目列表--直接指定
  @author: 徐媛媛
  @routerPath:/extractProject/expertProjectList
  @date: 2020-8-24 8:35:58
-->
<template>
  <div>
    <div>
      <el-table
        ref="smallTable"
        v-loading="loading"
        :data="addTableDatas"
        class="tableLimit"
      >
        <el-table-column
          type="index"
          label="序号"
          width="50"
          align="center"
        />
        <el-table-column
          prop="applyCode"
          align="center"
          label="抽取项目编号"
          min-width="160"
        />
        <el-table-column
          label="专家人数"
          prop="expertNum"
          width="70"
          align="center"
        />
        <el-table-column
          header-align="center"
          prop="startTime"
          label="评标开始时间"
          min-width="160"
        />
        <el-table-column
          header-align="center"
          prop="endTime"
          label="评标结束时间"
          width="160"
          align="center"
        />
        <el-table-column
          header-align="center"
          prop="createTime"
          label="创建时间"
          min-width="160"
        />
        <el-table-column label="审核状态" prop="auditStatus" align="center">
          <template slot-scope="{row}">
            {{ row.auditStatus | auditStatusTransform }}
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" min-width="160">
          <template slot-scope="{row}">
            <div style="white-space:nowrap">
              <el-link
                v-if="row.auditStatus===null || row.auditStatus==='02'"
                class="tablebutton"
                type="primary"
                @click="editProject(row)"
              >
                编辑申请
              </el-link>
              <!-- v-if="(row.auditStatus!='00' && row.resultStatus!=null) || (row.auditStatus=='00')" -->
              <el-link
                class="tablebutton"
                type="primary"
                @click="supplyExtract(row)"
              >
                查看申请
              </el-link>
              <!-- <el-link
                v-if="row.auditStatus==='00' && row.resultStatus==null"
                class="tablebutton"
                type="primary"
                @click="withdraw(row)"
              >
                撤回
              </el-link> -->
              <el-link
                v-if="(row.auditStatus===null && row.resultStatus==null) || row.auditStatus=='02'"
                class="tablebutton"
                type="primary"
                @click="delProject(row)"
              >
                删除
              </el-link>
              <el-link
                v-if="row.auditStatus==='01' &&
                  row.resultStatus!==null && row.resultStatus!=='00'"
                class="tablebutton"
                type="primary"
                @click="seeResults(row)"
              >
                查看抽取结果
              </el-link>
            </div>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!--分页组件-->
    <pagination :pagination-data="paginationData" @change="loadData" />
  </div>
</template>

<script>
/* api*/
import { getExtractExpertApplyListByCreateUser
} from '@/api/expert/extractExpert/extractExpert'
import {
  adminDeleteTBExpertExtractApplyInfobyid,
  withdrawTBExpertExtractApplyInfobyid
} from '@/api/expert/expertscloud'
/* 组件*/
import pagination from '@comp/common/pagination/pagination' // 分页组件
/* 混入公共方法*/
import { ListMixin } from '@/mixins/ListMixin'
export default {
  name: 'AddSelfTenderPlanList',
  components: {
    pagination
  },
  filters: {
    auditStatusTransform(val) {
      switch (val) {
        case '00':
          return '待审核'
        case '01':
          return '审核通过'
        case '02':
          return '审核不通过'
        default:
          return '暂存'
      }
    },
    resultStatusTransform(val) {
      switch (val) {
        case null:
          return '待抽取'
        case '00':
          return '待抽取'
        case '01':
          return '抽取中'
        case '02':
          return '抽取完成'
        case '03':
          return '抽取人数不够'
      }
    }
  },
  mixins: [ListMixin],
  props: {
    tableData: {
      type: Object,
      default: function() {
        return {}
      }
    }
  },
  data() {
    return {
      loading: false, // 表格loading
      addTableDatas: [] // 直接指定列表
    }
  },
  watch: {
    // 监听父组件传过来的值
    tableData(val) {
      this.loading = false
      this.addTableDatas = val.records
      this.paginationData.pageNo = val.current
      this.paginationData.pageSize = val.size
      this.paginationData.total = val.total
    }
  },
  created() {
    this.loadData()
  },
  methods: {
    // 查看抽取申请
    supplyExtract(row) {
      this.$router.push({
        path: 'extractApplyDetail',
        query: {
          id: row.id,
          status: row.auditStatus
        }
      })
    },
    // 编辑
    editProject(row) {
      this.$router.push({
        path: 'extractApply',
        query: {
          id: row.id
        }
      })
    },
    seeResults(row) {
      this.$router.push({
        path: 'extractDesigner',
        query: {
          id: row.id
        }
      })
    },
    // 删除
    delProject(row) {
      this.$confirm('确认删除该条数据?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        confirmButtonClass: 'confirmBtn',
        cancelButtonClass: 'cancelBtn',
        type: 'warning'
      })
        .then(() => {
          adminDeleteTBExpertExtractApplyInfobyid({ id: row.id }).then(res => {
            this.$message({
              type: 'success',
              message: '删除成功!'
            })
            this.loadData()
          })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '取消删除'
          })
        })
    },

    withdraw(row) {
      this.$confirm('确认撤回?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          withdrawTBExpertExtractApplyInfobyid({ id: row.id }).then(res => {
            this.$message({
              type: 'success',
              message: '撤回成功!'
            })
            this.loadData()
          })
        })
    },
    loadData() {
      const data = {
        // page: 1,
        // pageSize: 10,
        rakeType: '01'
      }
      getExtractExpertApplyListByCreateUser({ ...data, ...this.paginationData }).then(res => {
        this.loading = false
        this.addTableDatas = res.data.records
        this.paginationData.pageNo = res.data.current
        this.paginationData.pageSize = res.data.size
        this.paginationData.total = res.data.total
      }).catch(res => {
        this.loading = true
      })
    }
  }
}
</script>

<style lang="less" scoped>
</style>
