<!--
  @description:选择资格要求弹框
                招标-招标公告-投标资格要求
  @Modifier: 肖文龙
  @routerPath:
  @date: 2020/1/2-10:26
-->
<template>
  <el-dialog
    v-dialogDrag
    :visible.sync="dialogData.bidQualificationVisible"
    :close-on-click-modal="false"
    title="资格库列表"
    width="840px"
    custom-class="el-dialog__body-p8 el-dialog_table"
  >
    <div class="mb10">
      <!--父级-->
      <el-select
        v-model="qualificationData.qualificationTemplateType"
        style="width: 220px;"
        placeholder="请选择"
        @change="qualificationTemplateTypeChange"
      >
        <el-option
          v-for="(item,index) in projectClassificationList"
          :key="index"
          :label="item.typename"
          :value="item.typecode"
        />
      </el-select>
      <!--子级-->
      <el-select
        v-for="(item,index) in projectClassificationList"
        v-if="qualificationData.qualificationTemplateType===item.typecode"
        :key="index"
        v-model="qualificationData.qualificationTemplateTypeChild"
        clearable
        filterable
        style="width: calc(100% - 223px);margin-left: 3px"
        placeholder="请选择"
        @change="qualificationTemplateTypeChange(item.typecode,item.child)"
      >
        <el-option
          v-for="(child,childIndex) in item.child"
          :key="childIndex"
          :label="child.typename"
          :value="child.typecode"
        />
      </el-select>
    </div>
    <!--查询列表-->
    <section>
      <el-table
        ref="singleTable"
        :data="list"
        class="pointer"
        size="mini"
        @selection-change="selectionChange"
      >
        <el-table-column type="selection" align="center" width="45" />
        <el-table-column type="index" label="序号" align="center" width="60" />
        <el-table-column label="资格要求" prop="qualificationRequirement" header-align="center" />
        <el-table-column label="资质类型" width="140px" align="center" prop="qualificationType">
          <template slot-scope="scope">
            <span
              v-for="(item,index) in qualificationTypeList"
              v-if="scope.row.qualificationType===item.typecode"
              :key="index"
            >{{ item.typename }}</span>
          </template>
        </el-table-column>
      </el-table>
    </section>
    <!--底部操作按钮-->
    <span slot="footer" class="dialog-footer">
      <el-button type="primary" @click="referenceSample">引用范本</el-button>
      <el-button :loading="confirmLoading" type="primary" @click="ensure">部分引用</el-button>
      <el-button :loading="confirmLoading" @click="dialogData.bidQualificationVisible = false">取 消</el-button>
    </span>
  </el-dialog>
</template>

<script>
/* api*/
import { listQuoteBidderQualificationTemplate } from '@/api/bidding/bidBulletin'// 资格库列表
/* 公用方法*/
import { cloneObject } from '@assets/js/utils'// 常用方法
/* 混合开发方法-参数字段*/
import { tenderBulletinInitGroupMixin } from './../mixins/tenderBulletinInitGroupMixin'// 字典信息
export default {
  name: 'TenderQualificationDialog',
  mixins: [tenderBulletinInitGroupMixin],
  props: {
    // 弹框展示状态
    dialogData: {
      type: Object,
      default: function() {
      }
    }
  },
  data() {
    return {
      // 资格要求类型
      qualificationData: {
        qualificationTemplateType: '', // 资格要求类型
        qualificationTemplateTypeChild: '', // 资格要求二级类型
        typeId: '' // 类型id
      },
      confirmLoading: false, // 确定Loding
      list: [], // 列表数据
      selectionData: []// 当前选择的信息
    }
  },
  watch: {
    'dialogData.bidQualificationVisible'(val) {
      if (val) {
        this.$nextTick(() => {
          this.$refs.singleTable.clearSelection()
        })
        // 加载数据
        this.loadData()
      }
    }
  },
  created() {
    this.getTenderQualificationInitInfo()// 字典信息
  },
  methods: {
    // 当前选择的信息
    selectionChange(val) {
      this.selectionData = val
    },
    // 加载数据
    loadData() {
      listQuoteBidderQualificationTemplate(this.qualificationData.typeId).then(response => {
        this.list = response.data
      }).catch(() => {
      })
    },
    // 部分引用
    ensure() {
      if (this.selectionData.length > 0) {
        this.confirmLoading = true // 确定Loding
        this.$emit('tenderQualificationInfo', cloneObject(this.selectionData), '01')
        this.dialogData.bidQualificationVisible = false
        this.$message({
          message: '添加成功',
          type: 'success'
        })
        this.confirmLoading = false // 确定Lodinglist
      } else {
        this.$message({
          message: `请选择资格要求`,
          type: 'warning'
        })
      }
    },
    // 引用范本
    referenceSample() {
      this.list.map(row => {
        this.$refs.singleTable.toggleRowSelection(row, true)
      })
      this.$emit('tenderQualificationInfo', cloneObject(this.list), '00')
      this.dialogData.bidQualificationVisible = false
    },
    // 资格要求类型
    qualificationTemplateTypeChange(val, child) {
      if (!child) {
        // 当改变父级状态时将子级数据清空
        this.qualificationData.qualificationTemplateTypeChild = ''
      } else { // 当子集项目分类变化的时候
        child.forEach((item) => {
          // 循环遍历 编号 取得相对应的 å名称
          if (this.qualificationData.qualificationTemplateTypeChild === item.typecode) {
            this.qualificationData.typeId = item.id
            // 加载数据
            this.loadData()
          }
        })
      }
    }
  }
}
</script>

<style scoped lang="less">

</style>
