<!--
  @description: 抽取项目列表--随机抽取
  @author: 徐媛媛
  @routerPath:/extractProject/expertProjectList
  @date: 2020-8-24 8:35:58
-->
<template>
  <div>
    <div>
      <el-table
        ref="smallTable"
        v-loading="loading"
        :data="alldata"
        class="tableLimit"
      >
        <el-table-column
          type="index"
          label="序号"
          width="50"
          align="center"
        />
        <el-table-column
          prop="tenderNo"
          align="center"
          min-width="160"
        >
          <template slot="header">
            <span>抽取申请编号</span>
          </template>
          <template slot-scope="scope">
            <span>{{ scope.row.applyCode }}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="expertNum"
          width="70"
          align="center"
        >
          <template slot="header">
            <span>专家人数</span>
          </template>
          <template slot-scope="scope">
            <span>{{ scope.row.expertNum }}</span>
          </template>
        </el-table-column>
        <el-table-column
          header-align="center"
          prop="startTime"
          min-width="160"
          align="center"
        >
          <template slot="header">
            <span>评标开始时间</span>
          </template>
          <template slot-scope="scope">
            <span>{{ scope.row.startTime }}</span>
          </template>
        </el-table-column>
        <el-table-column
          header-align="center"
          prop="endTime"
          min-width="160"
          align="center"
        >
          <template slot="header">
            <span>评标结束时间</span>
          </template>
          <template slot-scope="scope">
            <span>{{ scope.row.endTime }}</span>
          </template>
        </el-table-column>
        <el-table-column
          header-align="center"
          prop="createTime"
          min-width="160"
          align="center"
        >
          <template slot="header">
            <span>创建时间</span>
          </template>
          <template slot-scope="scope">
            <span>{{ scope.row.createTime }}</span>
          </template>
        </el-table-column>
        <el-table-column label="审核状态" prop="auditStatus" align="center">
          <template slot-scope="{row}">
            {{ row.auditStatus | auditStatusTransform }}
          </template>
        </el-table-column>
        <el-table-column label="抽取状态" prop="resultStatus" align="center">
          <template slot-scope="{row}">
            <!-- <span v-if="row.rakeType=='00'">{{ row.resultStatus | resultStatusTransform }}</span> -->
            <span>{{ row.resultStatus | resultStatusTransform }}</span>
            <!-- <span v-else/> -->
          </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>
              <el-link
                v-if="(row.auditStatus!='00' && row.resultStatus!=null) || (row.auditStatus=='00')"
                class="tablebutton"
                type="primary"
                @click="supplyExtract(row)"
              >
                查看申请
              </el-link>
              <!-- <el-link
                v-if="(row.auditStatus==='01' && row.resultStatus==='02') || (row.auditStatus==='01' && row.resultStatus==='03')"
                class="tablebutton"
                type="primary"
                @click="lookProjectDetail(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' &&
                  row.resultStatus==null"
                class="tablebutton"
                type="primary"
                @click="delProject(row)"
              >
                删除
              </el-link>
              <!-- <el-link
                v-if="row.auditStatus===null && row.resultStatus==null || row.auditStatus==='01' &&
                row.resultStatus==null"
                class="tablebutton"
                type="primary"
                @click="seeResults(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 { filterDictText } from '@/assets/js/utils'// 常用方法
import {
  adminDeleteTBExpertExtractApplyInfobyid,
  withdrawTBExpertExtractApplyInfobyid
} from '@/api/expert/expertscloud'
/* 组件*/
import pagination from '@comp/common/pagination/pagination' // 分页组件

/* 混入公共方法*/
import { ListMixin } from '@/mixins/ListMixin'
// import { tenderPlan } from './mixins/tenderPlan'
export default {
  name: 'AllocationTenderPlanList',
  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: {
    alldata: {
      type: Array,
      required: true
    }
  },
  data() {
    return {
      loading: true, // 表格loading
      allTableDatas: []
    }
  },
  created() {
    this.loadData()
  },
  methods: {
    filterDictText,
    // 查看抽取申请
    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()
          })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '取消撤回'
          })
        })
    },
    loadData() {
      const data = {
        rakeType: '00'
      }
      getExtractExpertApplyListByCreateUser({ ...data, ...this.paginationData }).then(res => {
        this.loading = false
        this.allTableDatas = 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 scoped>

</style>
