<!--
  @description: 招标-招标公告-投标人资格要求-标段列表
  @Modifier: 肖文龙
  @routerPath:
  @date: 2020/1/2-10:29
-->
<template>
  <el-dialog
    v-dialogDrag
    :visible.sync="dialogData.bidPackagesVisible"
    :close-on-click-modal="false"
    title="将当前标段（包）复制到其他标段（包）"
    width="840px"
    custom-class="el-dialog__body-p8 el-dialog_table"
  >
    <!--查询列表-->
    <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="packNo" width="160px" align="center" />
        <el-table-column label="标段名称" header-align="center" prop="packName" />
      </el-table>
    </section>
    <!--底部操作按钮-->
    <span slot="footer" class="dialog-footer">
      <el-button :loading="confirmLoading" type="primary" @click="ensure">确 定</el-button>
      <el-button :loading="confirmLoading" @click="dialogData.bidPackagesVisible = false">取 消</el-button>
    </span>
  </el-dialog>
</template>

<script>
/* api*/
import { listMarkedBulletinPackage, copyBidderQualification } from '@/api/bidding/bidBulletin'
export default {
  name: 'TenderQualificationCopyPackDialog',
  props: {
    // 弹框展示状态
    dialogData: {
      type: Object,
      default: function() {

      }
    },
    // 要被复制的标段信息
    packInfo: {
      type: Object,
      default: function() {

      }
    }
  },
  data() {
    return {
      confirmLoading: false, // 确定Loding
      tenderId: this.$route.query.id, // 项目Id
      bulletinId: this.$route.query.bulletinId, // 公告Id
      list: [], // 要展示的列表数据
      initList: [], // 所有列表数据
      selectionData: []// 当前选择的信息
    }
  },
  watch: {
    // 监听-弹框展示状态
    'dialogData.bidPackagesVisible'(val) {
      if (val) {
        // 弹框已打开
        this.packFilter()// 公告已制作的标段（包）筛选要展示的数据
      }
    }
  },
  created() {
    // 加载数据
    this.loadData()
  },
  methods: {
    // 当前选择的信息
    selectionChange(val) {
      this.selectionData = val
    },
    // 公告已制作的标段（包）
    loadData() {
      this.list = []// 初始化
      listMarkedBulletinPackage(this.bulletinId).then(res => {
        this.initList = res.data// 所有列表数据
      })
    },
    // 公告已制作的标段（包）筛选要展示的数据
    packFilter() {
      this.list = []// 初始化数据
      this.initList.map(item => {
        // 去除被复制资格要求的标段（包）
        if (this.packInfo.packId !== item.packId && this.packInfo.stageId !== item.stageId) {
          this.list.push({ ...item })
        }
      })
    },
    // 选择信息-确定
    ensure() {
      if (this.selectionData.length > 0) {
        this.confirmLoading = true // 确定Loding
        const data = this.assemblyData()// 数据组装
        copyBidderQualification(data).then(res => {
          this.$message({
            message: '复制成功',
            type: 'success'
          })
          this.dialogData.bidPackagesVisible = false
          this.confirmLoading = false// 确定Loding
        }).catch(() => {
          this.confirmLoading = false// 确定Loding
        })
      } else {
        this.$message({
          message: `请选择标段（包）`,
          type: 'warning'
        })
      }
    },
    //  组装参数
    assemblyData() {
      const data = {
        packId: this.packInfo.packId, // 要被复制资格要求的标段Id,
        stageId: this.packInfo.stageId, // 要被复制资格要求的阶段Id,
        packageStage: []// 要复制资格要求的阶段Id标段（包）Id,
      }
      this.selectionData.map(item => {
        data.packageStage.push({
          packId: item.packId,
          stageId: item.stageId
        })
      })
      return data
    }
  }
}
</script>

<style scoped lang="less">

</style>
