<!--
  @description: 项目驱动-组建评标委员会-招标人代理--查看
  @author:肖文龙
  @date: 2020年3月30日09:31:27
  @routerPath:/bidding/projectDrive/formEvalCommittee
  isCanOperate: true可以操作 false不可以查看只有查看权限
-->
<template>
  <div>
    <div v-if="tenderBase && tenderBase.isCanOperate" class="mb16">
      <!--临时时展示 00 临时 01 正式--->
      <el-button v-if="useStatus!=='01'" type="primary" @click="add">
        新增招标人代表
      </el-button>
    </div>
    <div>
      <el-table
        ref="smallTable"
        v-loading="loading"
        :data="tableData"
        width="100%"
      >
        <el-table-column type="index" label="序号" width="45" align="center" />
        <el-table-column
          prop="name"
          label="姓名"
          min-width="140"
        />
        <el-table-column
          header-align="center"
          prop="userName"
          label="用户名"
          min-width="140"
        />
        <el-table-column
          header-align="center"
          prop="workCompany"
          label="工作单位"
          min-width="300"
        />
        <el-table-column
          header-align="center"
          prop="mobilePhone"
          label="手机"
          min-width="120"
          align="center"
        />
        <el-table-column
          header-align="center"
          prop="technicalTitle"
          label="职称"
          min-width="80"
          align="center"
        >
          <template slot-scope="scope">
            <span
              v-for="(item,index) in titleList"
              v-if="scope.row.technicalTitle===item.typecode"
              :key="index"
            >{{ item.typename }}</span>
          </template>
        </el-table-column>
        <el-table-column
          header-align="center"
          prop="cardType"
          label="证件类型"
          min-width="100"
          align="center"
        >
          <template slot-scope="scope">
            <span
              v-for="(item,index) in cardTypeList"
              v-if="scope.row.cardType===item.typecode"
              :key="index"
            >{{ item.typename }}</span>
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          prop="idCard"
          label="证件号"
          min-width="160"
        />
        <!--临时时展示 00 临时 01 正式-->
        <el-table-column
          v-if="useStatus!=='01' && tenderBase.isCanOperate"
          header-align="center"
          label="操作"
          align="center"
          width="80"
        >
          <template slot-scope="scope">
            <el-link
              type="primary"
              @click="deleteRow(scope.row,scope.$index)"
            >
              删除
            </el-link>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <template>
      <!--保存按钮-->
      <div v-if="tenderBase && tenderBase.isCanOperate" class="but_footer">
        <div class="but_footer-h" />
        <div class="but_footer-but">
          <!--临时时展示 00 临时 01 正式-->
          <el-button v-if="useStatus==='00'" type="primary" @click="submit()">
            生效
          </el-button>
          <!--正式时展示 00 临时 01 正式-->
          <el-button v-if="useStatus!=='00'" type="primary" @click="changeAgentTenderer()">
            变更
          </el-button>
        </div>
      </div>
    </template>
    <!--组建评标委员会-选择招标人代表列表-弹框-->
    <agentTendererSelectDalog :dialog-data="dialogData" @agentTendererSelectInfo="agentTendererSelectInfo" />
  </div>
</template>

<script>
/* api*/
import { queryRepresentsByPackId, queryJuryStatusByStageId, saveOrUpdateRepresentInfo,
  deleteRepresentInfoBypackIdAndRepresentId, checkIsAddRepresentInfo } from '@/api/intensiveeval/intensiveeval'
/* 混合开发*/
import { groupMixin } from '@/views/intensiveeval/mixins/intensiveevalGroupMixin'// 字典信息
import { ListMixin } from '@/mixins/ListMixin'// 分页
/* 组件*/
import agentTendererSelectDalog from './agentTendererSelect-dialog'// 组建评标委员会-选择招标人代表列表-弹框
export default {
  name: 'AgentTendererDetail',
  components: {
    agentTendererSelectDalog
  },
  mixins: [groupMixin, ListMixin],
  data() {
    return {
      tenderBase: this.$store.getters.tenderBase, // 项目信息
      useStatus: '', // 00 临时 01 正式
      loading: false, // 刷新loading
      searchForm: {
        stageId: this.$store.getters.groupId.stageId, // 标段Id>在项目驱动里用的
        pageNo: 1,
        pageSize: 10
      },
      // 评标委员会列表
      tableData: [],
      // 弹窗展示状态
      dialogData: {
        dialog: false // 是否展开 布尔值
      }
    }
  },
  created() {
    this.loadData()// 获取数据
  },
  methods: {
    // 获取数据
    loadData() {
      this.loading = true
      const params = this.getQueryParams()// 查询条件
      queryRepresentsByPackId(params).then(response => {
        this.tableData = response.data.records
        this.tableData.forEach(item => {
          if (item.useStatus === '00') {
            this.useStatus = item.useStatus
          } else {
            this.useStatus = '01'
          }
        })
        this.loading = false
      }).catch(() => {

      })
    },
    // 查询条件
    getQueryParams() {
      const param = Object.assign({}, this.searchForm)
      param.pageNo = 1
      param.pageSize = 9999
      return param
    },
    // 新增招标代表人
    add() {
      this.dialogData.dialog = true
    },
    /*
    * 招标人代表信息回调函数
    * data 招标人代表信息
    * */
    agentTendererSelectInfo(data) {
      this.loadData()// 获取数据
    },
    // 生效
    submit() {
      const stageId = this.$store.getters.groupId.stageId// 阶段Id
      queryJuryStatusByStageId(stageId).then(res => {
        let text = '是否确定生效？'// 弹框提示文字
        /*
        * extractionMode 评委会会组建方式 00随机抽取 01直接指定
        *judgesStatus 评委会状态（00待申请 01抽取中 02抽取失败 03抽取成功 04待指定 05已生效
        * notificationMode 通知方式（00语音通知 01人工通知）
        * */
        const { data: { extractionMode, judgesStatus }} = res

        if (extractionMode === '00' && judgesStatus === '01') { // 随机抽取
          text = '本批次已经发起评标委员会抽取申请，确认继续变更招标人代表？'
        } else if (extractionMode === '01' && judgesStatus === '01') { // 直接指定
          text = '本批次已经完成专家指定，确认继续变更招标人代表？”如果确认，除了将招标人代表生效，还需要将评委会名单推送至专家库。'
        }
        this.$confirm(text, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          confirmButtonClass: 'confirmBtn',
          cancelButtonClass: 'cancelBtn',
          type: 'warning'
        }).then(() => {
          this.saveData('01')// 生效
        })
      })
    },
    // 生效
    saveData(useStatus) {
      if (this.tableData.length > 0) {
        const data = []
        this.tableData.forEach(item => {
          data.push({
            ...this.$store.getters.groupId, // 项目Id 包id 阶段Id
            representId: item.representId, // 招标人代表Id
            id: item.id, // 招标人代表Id-主键
            useStatus: useStatus// 使用状态 00 临时 01 正式
          })
        })
        saveOrUpdateRepresentInfo(data).then(res => {
          this.$message({
            type: 'success',
            message: '提交成功'
          })
          this.loadData()// 获取数据
        })
      } else {
        this.$message({
          message: '请选招标人代表',
          type: 'warning'
        })
      }
    },
    // 变更
    changeAgentTenderer() {
      // 校验是否可以变更招标人代表
      checkIsAddRepresentInfo(this.$store.getters.groupId.stageId).then(res => {
        this.useStatus = '00'
      }).catch(() => {
      })
    },
    /*
  * 删除
  * row 代表人信息
  * */
    deleteRow(row, index) {
      this.$confirm('此操作将永久删除该记录, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        confirmButtonClass: 'confirmBtn',
        cancelButtonClass: 'cancelBtn',
        type: 'warning'
      }).then(() => {
        const data = {
          packId: this.$route.query.packId, // 标段id
          representId: row.id// 招标人代理id
        }
        deleteRepresentInfoBypackIdAndRepresentId(data).then(res => {
          this.$message({
            type: 'success',
            message: '删除成功'
          })
          this.tableData.splice(index, 1)
        })
      })
        .catch(() => {
        })
    }
  }
}
</script>

<style lang="less" scoped>

</style>
