<!--
  @description:集约化评标-抽取条件
  @Modifier: 肖文龙
  @routerPath:
  @date: 2020-3-6-9:43
-->
<template>
  <div>
    <div class="page-title">
      2. 抽取条件
      <el-button v-if="isEdit && judgesStatus!=='02'" type="primary" @click="addRow()">
        添加抽取条件
      </el-button>
    </div>
    <div>
      <el-table :data="tableData">
        <el-table-column
          type="index"
          label="序号"
          width="45"
          align="center"
        />
        <el-table-column
          header-align="center"
          label="专家专业"
          min-width="200px"
          prop="specialName"
        />
        <!--分组情况下展示-->
        <el-table-column
          v-if="data.judgesGroupedStatus==='01'"
          :formatter="formatterExpertGroupList"
          align="center"
          label="分组"
          min-width="60px"
          prop="groupType"
        />
        <el-table-column
          :formatter="formatterSystemSourceList"
          align="center"
          label="集团内/外"
          min-width="80px"
          prop="groupStatus"
        />
        <el-table-column
          header-align="center"
          label="所属地区"
          min-width="200px"
          prop="cityName"
        />
        <el-table-column
          :formatter="formatterTechnicalTitle"
          align="center"
          label="技术职称"
          min-width="80px"
          prop="technicalTitle"
        />
        <el-table-column
          :formatter="formatExpertLevel"
          align="center"
          label="专家星级"
          min-width="80px"
          prop="expertLevel"
        />
        <el-table-column
          header-align="center"
          align="right"
          min-width="80px"
          label="抽取人数"
          prop="expertNum"
        />
        <el-table-column
          v-if="isEdit"
          header-align="center"
          label="操作"
          align="center"
          width="120"
        >
          <template slot-scope="scope">
            <template v-if="judgesStatus==='02' && scope.row.useStatus==='02'">
              <el-link type="primary" @click="editRow(scope.row,scope.$index)">
                [编辑]
              </el-link>
              <el-link type="danger" :underline="false">
                失败
              </el-link>
            </template>
            <template v-if="judgesStatus!=='02'&& scope.row.useStatus!=='02'">
              <el-link type="primary" @click="editRow(scope.row,scope.$index)">
                [编辑]
              </el-link>
              <el-link type="primary" @click="deleteRow(scope.row,scope.$index)">
                [删除]
              </el-link>
            </template>
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination :pagination-data="paginationData" @change="initData" />
    </div>
    <!--添加/编辑抽取条件-->
    <extractConditionDialog
      :dialog-data="dialogData"
      :data="formData"
      @extractConditionInfo="extractConditionInfo"
    />
  </div>
</template>

<script>
/* api*/
import { queryExtractConditionBybatchNumber, deleteExpertExtractConditionInfo } from '@/api/intensiveeval/intensiveeval'
/* 公共方法*/
import { cloneObject } from '@/assets/js/utils'// 深拷贝,生成随机Id,清空value值
/* 混合开发方法-参数字段*/
import { groupMixin } from '@/views/intensiveeval/mixins/intensiveevalGroupMixin'// 字典信息
import { ListMixin } from '@/mixins/ListMixin'// 分页
/* 组件*/
import pagination from '@comp/common/pagination/pagination'// 分页
import extractConditionDialog from './extractCondition-dialog'// 添加/编辑抽取条件-弹框
export default {
  name: 'ExtractConditionEditView',
  components: {
    extractConditionDialog,
    pagination
  },
  mixins: [groupMixin, ListMixin],
  props: {
    data: {
      type: Object,
      default: function() {
        return {
        }
      }
    }
  },
  data() {
    return {
      judgesStatus: this.$route.query.judgesStatus, // 评委会状态02为抽取失败 禁用添加抽取条件按钮
      isEdit: this.$route.meta.isEdit, // 是否可编辑 布尔值
      formData: {}, // 新增的信息参数
      tableData: [], // 列表信息
      // 弹窗展示状态
      dialogData: {
        dialog: false, // 是否展开 布尔值
        submitType: '', // 编辑状态 01 新增 00 编辑
        index: '', // 下标-编辑时会用到
        judgesGroupedStatus: '' // 评委会是否分组(00不分组 01分组)
      }
    }
  },
  created() {
    this.initData()// 初始化抽取条件列表
  },
  methods: {
    // 初始化抽取条件列表
    initData() {
      const stageId = this.$route.query.juryId ? '' : this.$store.getters.groupId.stageId
      const data = {
        batchNumber: this.$route.query.batchNumber, // 批次号-组建评标委员会时用的
        stageId: stageId, // 阶段Id>在项目驱动里用的
        pageNo: this.paginationData.pageNo,
        pageSize: this.paginationData.pageSize
      }
      queryExtractConditionBybatchNumber(data).then(res => {
        this.tableData = res.data.records
        this.paginationData.total = res.data.total
      })
    },
    // 新增
    addRow() {
      this.dialogData = {
        dialog: true,
        submitType: '01',
        judgesGroupedStatus: this.data.judgesGroupedStatus
      }
    },
    // 编辑
    editRow(row, index) {
      this.dialogData = {
        dialog: true,
        submitType: '00',
        index: index,
        judgesGroupedStatus: this.data.judgesGroupedStatus
      }
      this.formData = cloneObject(row)
    },
    // 新增/编辑返回的信息
    extractConditionInfo() {
      this.paginationData.pageNo = 1
      this.paginationData.pageSize = 10
      this.initData()// 初始化抽取条件列表
    },
    //  删除
    deleteRow(row) {
      this.$confirm('此操作将永久删除该记录, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        confirmButtonClass: 'confirmBtn',
        cancelButtonClass: 'cancelBtn',
        type: 'warning'
      }).then(() => {
        deleteExpertExtractConditionInfo(row.id).then(() => {
          this.$message({
            type: 'success',
            message: '删除成功!'
          })
          this.paginationData.pageNo = 1
          this.paginationData.pageSize = 10
          this.initData()// 初始化抽取条件列表
        })
      })
    }
  }
}
</script>

<style lang="less" scoped>

</style>
