<!--
  @description: 立项-选择关联招标计划弹框列表
  @author: 肖文龙
  @routerPath:
  @date:2020/04/10 14:44
-->
<template>
  <el-dialog
    v-dialogDrag
    :visible.sync="dialogData.dialog"
    :close-on-click-modal="false"
    title="招标计划选择"
    width="840px"
    custom-class="el-dialog__body-p8 el-dialog_table"
  >
    <!--搜索-->
    <section class="clearfix mb10">
      <el-form ref="searchForm" :model="searchForm" inline>
        <el-form-item label="招标汇总号" prop="schemeNo">
          <el-input
            v-model.trim="searchForm.schemeNo"
            placeholder="招标汇总号"
            style="width: 160px"
          />
        </el-form-item>
        <el-form-item label="招标汇总名称" prop="schemeName">
          <el-input
            v-model.trim="searchForm.schemeName"
            placeholder="招标汇总名称"
            style="width: 160px"
          />
        </el-form-item>
        <el-form-item class="fr">
          <el-button type="primary" @click="search('searchForm')">
            搜索
          </el-button>
          <el-button plain type="info" @click="resetForm('searchForm')">
            重置
          </el-button>
        </el-form-item>
      </el-form>
    </section>
    <!--查询列表-->
    <section>
      <el-table
        ref="singleTable"
        v-loading="loading"
        :data="list"
        size="mini"
        class="pointer"
        highlight-current-row
        @current-change="currentChange"
      >
        <el-table-column
          type="index"
          label="序号"
          align="center"
          width="80"
          fixed
        />
        <el-table-column
          fixed
          prop="schemeNo"
          label="招标汇总号"
          min-width="160"
        />
        <el-table-column
          fixed

          prop="schemeName"
          label="招标汇总名称"
          min-width="230"
        />
        <el-table-column

          prop="projectName"
          label="工程项目名称"
          min-width="230"
        />
        <el-table-column

          prop="schemeDeptname"
          label="招标组织单位名称"
          min-width="230"
        />
        <el-table-column
          :formatter="formatBiddingPlanType"
          prop="biddingPlanType"
          label="招标计划类型"
          width="100"
        />
        <el-table-column
          :formatter="formatPurchasLevel"
          header-align="center"
          prop="purchasLevel"
          label="采购级别"
          align="center"
          width="100"
        /> <el-table-column
          :formatter="formatBiddingOrganizationForm"
          prop="biddingOrganizationForm"
          label="招标组织形式"
          width="100"
        />
        <el-table-column

          prop="biddingAgencyName"
          label="招标代理机构"
          min-width="230"
        />
        <el-table-column
          :formatter="formatBiddingMethod"
          prop="biddingMethod"
          label="招标方式"
          align="center"
          width="100"
        />
        <el-table-column
          :formatter="formatQualificationCheckWay"
          prop="qualificationCheckWay"
          label="资格审查方式"
          width="100"
        />
        <el-table-column
          :formatter="formatBiddingSchemeType"
          prop="biddingSchemeType"
          label="招标项目类型"
          align="center"
          width="100"
        />
        <el-table-column
          :formatter="formatSchemeClass"

          prop="schemeClass"
          label="工程分类"
          width="120"
        />
      </el-table>
      <!--分页组件-->
      <pagination :pagination-data="paginationData" @change="loadData" />
    </section>
    <!--底部操作按钮-->
    <span slot="footer" class="dialog-footer">
      <el-button type="primary" @click="ensure">确 定</el-button>
      <el-button @click="dialogData.dialog = false">取 消</el-button>
    </span>
  </el-dialog>
</template>

<script>
/* 接口*/
import { getUnrelatedPurchasesSchemePages } from '@/api/purchasePlan/pretcloudPurchasescheme'// 招标计划
/* 公用方法*/
import { filterObj, cloneObject } from '@/assets/js/utils'// 过滤空的key
/* 混合开发方法-参数字段*/
import { ListMixin } from '@/mixins/ListMixin'// 分页
import { tenderPlan } from '../mixins/tenderPlan'
/* 组件*/
import pagination from '@comp/common/pagination/pagination'// 分页
export default {
  name: 'RelevanceTenderPlanSelectDialog',
  components: {
    pagination// 分页
  },
  mixins: [ListMixin, tenderPlan],
  props: {
    // 弹框展示状态
    dialogData: {
      type: Object,
      default: function() {
        return {
          dialog: false, // 展示状态
          materialId: [], // 招标计划Id去重列表
          packIndex: '' // 标段索引
        }
      }
    }
  },
  data() {
    return {
      loading: true,
      // 搜索信息
      searchForm: {
        schemeIdList: [], // 计划id集合-前端传值,用于去重
        schemeNo: '', // 编号
        schemeName: ''// 名称
      },
      list: [], // 列表数据
      currentData: {}// 当前选择的信息
    }
  },
  watch: {
    // 监听-弹框展示状态
    'dialogData.dialog'(val) {
      if (val) {
        // 弹框已打开
        this.searchForm.schemeNo = ''
        this.searchForm.schemeName = ''
        // 加载数据
        this.loadData()
      }
    }
  },
  created() {
    // 招标计划-字典信息
    this.initPurchaseSchemeWebTypeGroup()
  },
  methods: {
    // 当前选择的信息
    currentChange(val) {
      this.currentData = val
    },
    // 加载数据
    loadData() {
      this.searchForm.schemeIdList = this.dialogData.schemeIdList// 去重物料Id
      const params = this.getParams()// 查询条件
      getUnrelatedPurchasesSchemePages(params).then(response => {
        this.loading = false
        this.list = response.data.records
        this.paginationData.total = response.data.total
      }).catch(() => {
        this.loading = false
      })
    },
    // 查询条件
    getParams() {
      const param = Object.assign({}, this.searchForm)
      param.pageNo = this.paginationData.pageNo
      param.pageSize = this.paginationData.pageSize
      return filterObj(param)// 过滤空的key
    },
    // 选择信息-确定
    ensure() {
      if (this.currentData) {
        // 招标计划信息
        this.$emit('relevanceTenderPlanSelect', cloneObject(this.currentData), this.dialogData.packIndex, '01')
        this.dialogData.dialog = false
      } else {
        this.$message({
          message: '请选择招标计划',
          type: 'warning'
        })
      }
    },
    // 搜索重置
    resetForm(formName) {
      this.paginationData.pageNo = 1
      this.paginationData.pageSize = 10
      this.$refs[formName].resetFields()
      this.loadData()
    },
    // 搜索
    search() {
      this.paginationData.pageNo = 1
      this.paginationData.pageSize = 10
      this.loadData()
    }
  }
}
</script>

<style scoped lang="less">

</style>
