<!--
  @description: 立项-相关机构信息-代理机构/招标人公用
  @Modifier：肖文龙
  @routerPath: /bidding/bidProjectStep/bidProjectDepart
  @date：  2019-12-19 09:54:13
-->

<template>
  <div>
    <div class="page-title">
      招标人信息
      <!--多招标人新增招标人信息 hn && 委托招标显示-->
      <el-button
        v-if="bidProjectSystemSourceType && isShowAgencyInfo"
        type="primary"
        style="margin-left: 20px"
        @click="addBuyersInfo"
      >
        添加
      </el-button>
    </div>
    <!--主招标人-->
    <section class="mb16">
      <el-form
        ref="buyersForm"
        :model="formData"
        :rules="rules"
        :inline-message="true"
      >
        <table class="from_table">
          <tr>
            <td>
              <!-- 招标人登录不显示选择清空按钮 -->
              <el-form-item
                ref="buyersName"
                :label="buyersNameLabel"
                prop="buyersName"
              />
            </td>
            <td>
              <!--招标人名称-->
              <!-- 招标人登录显示选择清空按钮 -->
              <template v-if="isShowAgencyInfo">
                <gx-input
                  v-model.trim="formData.buyersName"
                  placeholder="请选择招标人"
                  style="width: calc(100% - 160px)"
                  disabled
                  gx-maxlength="varchar100"
                />
                <el-button type="primary" class="ml10" @click="showDialogBtn('10')">
                  选择
                </el-button>
                <el-button @click="clearAgency('10')">
                  清空
                </el-button>
              </template>
              <!-- 无选择清空按钮 v-else -->
              <gx-input
                v-else
                v-model.trim="formData.buyersName"
                gx-maxlength="varchar100"
                placeholder="请输入招标人"
                disabled
              />
            </td>
            <td>
              <!--招标人联系人名称-->
              <el-form-item
                ref="buyersLinkerName"
                label="联系人"
                prop="buyersLinkerName"
              />
            </td>
            <td>
              <gx-input
                v-model.trim="formData.buyersLinkerName"
                gx-maxlength="varchar20"
                placeholder="请输入联系人名称"
              />
            </td>
          </tr>
          <tr>
            <td>
              <!--招标人联系方式-->
              <el-form-item
                ref="buyersLinkerTel"
                label="电话"
                prop="buyersLinkerTel"
              />
            </td>
            <td>
              <gx-input v-model.trim="formData.buyersLinkerTel" gx-maxlength="varchar20" placeholder="请输入联系方式" />
            </td>
            <td>
              <!--招标人邮箱-->
              <el-form-item
                ref="buyersLinkerEmail"
                label="邮箱"
                prop="buyersLinkerEmail"
              />
            </td>
            <td>
              <gx-input v-model.trim="formData.buyersLinkerEmail" gx-maxlength="varchar100" placeholder="请输入邮箱" />
            </td>
          </tr>
          <!--华能显示-Start-->
          <tr v-if="bidProjectSystemSourceType">
            <td>
              <!--所属公司-->
              <el-form-item
                ref="belongCompany"
                label="所属公司"
                prop="belongCompany"
              />
            </td>
            <td>
              <gx-input
                v-model.trim="formData.belongCompany"
                placeholder="请选择所属公司"
                gx-maxlength="varchar200"
                style="width: calc(100% - 160px)"
                disabled
              />
              <el-button type="primary" class="ml10" @click="selectBelongCompanyDialogBtn('',false)">
                选择
              </el-button>
              <el-button @click="clearBelongCompany('',false)">
                清空
              </el-button>
            </td>
            <td>
              <!--传真-->
              <el-form-item
                ref="fax"
                label="传真"
                prop="fax"
              />
            </td>
            <td><gx-input v-model.trim="formData.fax" gx-maxlength="varchar200" placeholder="请输入传真" /></td>
          </tr>
          <!--华能显示-End-->
          <tr>
            <td>
              <!--招标人联系地址-->
              <el-form-item
                ref="buyersLinkerAddress"
                label="地址"
                prop="buyersLinkerAddress"
              />
            </td>
            <td colspan="3">
              <gx-input
                v-model.trim="formData.buyersLinkerAddress"
                gx-maxlength="varchar200"
                placeholder="请输入地址"
                style="width: 96%"
              />
            </td>
          </tr>
        </table>
      </el-form>
    </section>
    <section v-for="(item,index) in projectBuyersList" :key="index" class="mb16 buyers-wrap">
      <i class="delete-buyers el-icon-error" @click="deleteBuyers(index)" />
      <el-form
        :ref="'buyersForm' + index"
        :model="item"
        :rules="rules"
        :inline-message="true"
      >
        <table class="from_table">
          <tr>
            <td>
              <!-- 招标人登录不显示选择清空按钮 -->
              <el-form-item ref="buyersName" label="招标人" prop="buyersName" />
            </td>
            <td>
              <!--招标人名称-->
              <template v-if="roleCode==='11'">
                <!-- 招标人登录显示选择清空按钮 -->
                <gx-input
                  v-model.trim="item.buyersName"
                  gx-maxlength="varchar100"
                  placeholder="请选择招标人"
                  style="width:calc(100% - 160px)"
                  disabled
                />
                <el-button type="primary" class="ml10" @click="selectBuyersShowDialogBtn('10',index)">
                  选择
                </el-button>
                <el-button @click="clearBuyers(index)">
                  清空
                </el-button>
              </template>
              <!-- 无选择清空按钮 -->
              <gx-input v-else v-model.trim="item.buyersName" gx-maxlength="varchar100" placeholder="请输入招标人" disabled />
            </td>
            <td>
              <!--招标人联系人名称-->
              <el-form-item ref="buyersLinkerName" label="联系人" prop="buyersLinkerName" />
            </td>
            <td>
              <gx-input v-model.trim="item.buyersLinkerName" gx-maxlength="varchar20" placeholder="请输入联系人" />
            </td>
          </tr>
          <tr>
            <td>
              <!--招标人联系方式-->
              <el-form-item ref="buyersLinkerTel" label="电话" prop="buyersLinkerTel" />
            </td>
            <td>
              <gx-input
                v-model.trim="item.buyersLinkerTel"
                gx-maxlength="varchar20"
                placeholder="请输入联系方式"
              />
            </td>
            <td>
              <!--招标人邮箱-->
              <el-form-item ref="buyersLinkerEmail" label="邮箱" prop="buyersLinkerEmail" />
            </td>
            <td>
              <gx-input
                v-model.trim="item.buyersLinkerEmail"
                gx-maxlength="varchar100"
                placeholder="请输入邮箱"
              />
            </td>
          </tr>
          <tr>
            <td>
              <!--所属公司-->
              <el-form-item ref="belongCompany" label="所属公司" prop="belongCompany" />
            </td>
            <td>
              <gx-input
                v-model.trim="item.belongCompany"
                gx-maxlength="varchar200"
                placeholder="请选择所属公司"
                style="width:calc(100% - 160px)"
                disabled
              />
              <el-button type="primary" class="ml10" @click="selectBelongCompanyDialogBtn(index,true)">
                选择
              </el-button>
              <el-button @click="clearBelongCompany(index,true)">
                清空
              </el-button>
            </td>
            <td>
              <!--传真-->
              <el-form-item ref="fax" label="传真" prop="fax" />
            </td>
            <td><gx-input v-model.trim="item.fax" gx-maxlength="varchar200" placeholder="请输入传真" /></td>
          </tr>
          <tr>
            <td>
              <!--招标人联系地址-->
              <el-form-item ref="buyersLinkerAddress" label="地址" prop="buyersLinkerAddress" />
            </td>
            <td colspan="3">
              <gx-input
                v-model.trim="item.buyersLinkerAddress"
                gx-maxlength="varchar200"
                placeholder="请输入地址"
                style="width: 96%"
              />
            </td>
          </tr>
        </table>
      </el-form>
    </section>
    <!-----------------招标代理机构信息-------------------->
    <section v-if="isShowAgencyInfo">
      <div class="page-title">
        代理机构信息
      </div>
      <el-form
        ref="agencyForm"
        :model="formData"
        :rules="rules"
        :inline-message="true"
      >
        <table class="from_table">
          <tr>
            <!--代理机构名称-->
            <td>
              <el-form-item
                ref="agentName"
                label="代理机构"
                prop="agentName"
              />
            </td>
            <td>
              <!-- 有选择清空 roleCode==='10' 采购人   按钮 -->
              <!-- <template v-if="roleCode==='10'">
                <gx-input
                  v-model.trim="formData.agentName"
                  placeholder="请选择代理机构"
                  gx-maxlength="varchar200"
                  style="width: calc(100% - 160px)"
                  disabled
                />
                <el-button type="primary" class="ml10" @click="showDialogBtn('11')">
                  选择
                </el-button>
                <el-button @click="clearAgency('11')">
                  清空
                </el-button>
              </template> -->
              <gx-input
                v-model.trim="formData.agentName"
                disabled
                style="width: calc(100% - 160px)"
                placeholder="请输入代理机构"
                gx-maxlength="varchar200"
              />
              <el-button type="primary" class="ml10" @click="showDialogBtn('11')">
                选择
              </el-button>
              <el-button @click="clearAgency('11')">
                清空
              </el-button>
            </td>
            <td>
              <!-- 代理机构联系人 -->
              <el-form-item
                ref="agentLinkerName"
                label="联系人"
                prop="agentLinkerName"
              />
            </td>
            <td>
              <gx-input
                v-model.trim="formData.agentLinkerName"
                gx-maxlength="varchar20"
                placeholder="请输入联系人"
              />
            </td>
          </tr>
          <tr>
            <td>
              <!-- 招标代理机构联系电话 -->
              <el-form-item
                ref="agentLinkerTel"
                label="电话"
                prop="agentLinkerTel"
              />
            </td>
            <td>
              <gx-input
                v-model.trim="formData.agentLinkerTel"
                gx-maxlength="varchar20"
                placeholder="请输入电话"
              />
            </td>
            <td>
              <!--  招标代理电子邮箱 -->
              <el-form-item
                ref="agentLinkerEmail"
                label="邮箱"
                prop="agentLinkerEmail"
              />
            </td>
            <td>
              <gx-input
                v-model.trim="formData.agentLinkerEmail"
                gx-maxlength="varchar100"
                placeholder="请输入邮箱"
              />
            </td>
          </tr>
          <!--          <tr>
            <td>
              &lt;!&ndash;招标人联系电话&ndash;&gt;
              <el-form-item
                      ref="projectManagerNotePhone"
                      label="项目经理发短信手机号"
                      prop="projectManagerNotePhone"
              />
            </td>
            <td colspan="3">
              <gx-input v-model.trim="formData.projectManagerNotePhone" gx-maxlength="varchar20" placeholder="请输入项目经理发短信手机号" />
            </td>
          </tr>-->
          <tr>
            <td>
              <!-- 代理联系地址 -->
              <el-form-item
                ref="agentLinkerAddress"
                label="地址"
                prop="agentLinkerAddress"
              />
            </td>
            <td colspan="3">
              <gx-input
                v-model.trim="formData.agentLinkerAddress"
                gx-maxlength="varchar200"
                placeholder="请输入地址"
                style="width:96%"
              />
            </td>
          </tr>
        </table>
      </el-form>
    </section>
    <!--保存按钮-->
    <div class="but_footer">
      <div class="but_footer-h" />
      <div class="but_footer-but">
        <el-button @click="prevStep">
          上一步
        </el-button>
        <el-button :loading="confirmLoading" type="primary" @click="nextStep()">
          暂存，进入下一步
        </el-button>
      </div>
    </div>
    <!-- 招标人/代理机构-选择弹框 -->
    <bidProjectDepartDialog
      ref="projectDepartInfo"
      @dialogDataBuyersInfo="dialogDataBuyersInfo"
      @dialogDataInfo="dialogDataInfo"
    />
    <!--所属公司选择弹框-->
    <subsidiaryOrganDialog
      ref="subsidiaryOrgan"
      @subsidiaryOrganDataInfo="subsidiaryOrganDataInfo"
    />
  </div>
</template>

<script>
/* 接口*/
import { queryTenderProjectDepartInfo, saveTenderProjectDepartInfo } from '@/api/bidding/biddingProject'
/* 公用方法*/
import { characters1_50, checkLinktel, linkerName, email, validateInput } from '@/assets/js/validate'// 校验输入内容
import { cloneObject } from '@assets/js/utils'// 常用方法
/* 组件*/
import bidProjectDepartDialog from './bidProjectDepart-dialog'// 招标人/代理机构-选择弹框
import subsidiaryOrganDialog from './subsidiaryOrgan-dialog'

import { bidProjectCommon } from '../mixins/bidProjectCommon' // mixins混入公共方法
export default {
  name: 'BidProjectDepartAdd',
  components: {
    bidProjectDepartDialog, // 招标人/代理机构-选择弹框
    subsidiaryOrganDialog // 所属公司-选择弹框
  },
  mixins: [bidProjectCommon],
  data() {
    return {
      confirmLoading: false, // 暂存Loding
      // 相关机构信息
      formData: {
        agentCode: '', // 招标代理机构代码
        agentId: '', // 代理机构Id
        agentLinkerAddress: '', // 代理机构联系地址
        agentLinkerEmail: '', // 代理机构联系邮箱
        agentLinkerName: '', // 代理机构联系人
        agentLinkerTel: '', // 代理机构联系电话
        agentName: '', // 代理机构名称
        buyersCode: '', // 招标人代码
        buyersId: '', // 招标人Id
        buyersLinkerAddress: '', // 招标人联系地址
        buyersLinkerEmail: '', // 招标人联系邮箱
        buyersLinkerName: '', // 招标人联系人
        buyersLinkerTel: '', // 招标人联系人
        buyersName: '', // 招标人名称
        tenderId: '', // 项目id
        tenderMonitorDepCode: '', // 监管部门编码
        tenderMonitorDepName: '', // 监管部门编码
        belongCompany: '', // 所属公司
        belongCompanyId: '', // 所属公司id
        fax: '', // 传真
        projectManagerNotePhone: '' // 项目经理发短信手机号
      },

      // 校验输入内容
      rules: {
        buyersName: [{ required: true, validator: characters1_50, trigger: 'blur' }], // 招标人名称
        buyersLinkerName: [{ required: true, validator: linkerName, trigger: 'blur' }], // 招标人-联系人
        buyersLinkerTel: [{ required: true, validator: checkLinktel, trigger: 'blur' }], // 招标人联系电话
        buyersLinkerEmail: [{ required: false, validator: email, trigger: 'blur' }], // 招标人邮箱
        buyersLinkerAddress: [{ required: false, validator: validateInput, trigger: 'blur' }], // 招标人地址
        agentName: [{ required: true, validator: characters1_50, trigger: 'blur' }], // 招标代理机构名称
        agentLinkerName: [{ required: true, validator: linkerName, trigger: 'blur' }], // 招标代理机构-联系人
        agentLinkerTel: [{ required: true, validator: checkLinktel, trigger: 'blur' }], // 招标代理机构联系电话
        agentLinkerEmail: [{ required: false, validator: email, trigger: 'blur' }], // 招标代理机构邮箱
        projectManagerNotePhone: [{ required: true, validator: validateInput, trigger: 'blur' }], // 项目经理发短信电话
        contractCode: [{ required: true, validator: characters1_50, trigger: 'blur' }], // 委托合同编码
        agentLinkerAddress: [{ required: false, validator: validateInput, trigger: 'blur' }] // 代理机构地址
      },
      // 招标人信息（多招标人使用）
      buyersData: {
        buyersCode: '', // 招标人代码
        buyersId: '', // 招标人Id
        buyersLinkerAddress: '', // 招标人联系地址
        buyersLinkerEmail: '', // 招标人联系邮箱
        buyersLinkerName: '', // 招标人联系人
        buyersLinkerTel: '', // 招标人联系人
        buyersName: '', // 招标人名称
        belongCompany: '', // 所属公司
        belongCompanyId: '', // 所属公司id
        fax: '', // 传真
        tenderId: ''// 项目Id
      },
      projectBuyersList: [] // 多招标人(不包含主招标人)集合
    }
  },
  created() {
    this.initData()// 加载数据/初始化
  },
  methods: {
    // 加载数据
    initData() {
      queryTenderProjectDepartInfo(this.projectData.id).then((response) => {
        this.formData = response.data
        if (this.formData.projectBuyersList) {
          this.projectBuyersList = this.formData.projectBuyersList // 多招标人信息
        }
        this.isTenderOrgMethod()// 根据组织形式判断代理机构招标人模块的显示
      })
    },
    // 根据组织形式判断代理机构招标人模块的显示
    isTenderOrgMethod() {
      const currentDepart = this.$store.state.user.info.currentDepart
      const info = this.$store.state.user.info
      // 委托招标
      if (this.isShowAgencyInfo) {
        // 代理机构登录 && 代理机构信息为空时 从用户信息带出
        if (!this.formData.agentId) {
          this.formData.agentCode = currentDepart.orgCode // 招标人代码
          this.formData.agentName = info.companyName// 代理机构名称
          this.formData.agentId = info.companyId
          this.formData.agentLinkerName = info.realName// 代理机构联系人
          this.formData.agentLinkerTel = info.mobilePhone// 代理机构联系电话
          this.formData.agentLinkerEmail = info.email// 代理机构联系邮箱
          this.formData.agentLinkerAddress = info.address// 代理机构地址
        }
      } else { // 自行招标
        // 招标人登录 && 招标人为空时 从用户信息带出
        if (!this.formData.buyersId) {
          this.formData.buyersCode = currentDepart.orgCode // 招标人代码
          this.formData.buyersName = info.companyName// 招标人名称
          this.formData.buyersId = info.companyId
          this.formData.buyersLinkerName = info.realName// 招标人联系人
          this.formData.buyersLinkerTel = info.mobilePhone// 招标人联系电话
          this.formData.buyersLinkerEmail = info.email// 招标人联系邮箱
          this.formData.buyersLinkerAddress = info.address// 招标人地址
        }
      }
    },
    /* ----------------多招标人信息Start-------------*/
    // 添加招标人
    addBuyersInfo() {
      this.buyersData.tenderId = this.projectData.id // 多招标人保存项目id
      const data = cloneObject(this.buyersData)// 深层拷贝
      this.projectBuyersList.push(data)
    },
    // 删除招标人
    deleteBuyers(index) {
      this.$confirm('确认删除?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        confirmButtonClass: 'confirmBtn',
        cancelButtonClass: 'cancelBtn',
        type: 'warning'
      }).then(() => {
        this.projectBuyersList.splice(index, 1)
      }).catch(() => {
      })
    },
    // 打开弹框挑选招标人
    selectBuyersShowDialogBtn(departRoleName, index) {
      // 10招标人 11代理机构
      this.$refs.projectDepartInfo.openOrganizationDialog(departRoleName, index, true)
    },
    // 多招标人清空
    clearBuyers(index) {
      this.projectBuyersList[index].buyersName = ''
      this.projectBuyersList[index].buyersId = ''
      this.projectBuyersList[index].buyersLinkerName = ''
      this.projectBuyersList[index].buyersLinkerTel = ''
      this.projectBuyersList[index].buyersLinkerEmail = ''
      this.projectBuyersList[index].buyersLinkerAddress = ''
    },
    // 某一招标人已选信息
    dialogDataBuyersInfo(data, index) {
      this.projectBuyersList[index].buyersName = data.departName// 招标人名称
      this.projectBuyersList[index].buyersCode = data.orgCode// 招标人代码
      this.projectBuyersList[index].buyersId = data.id
      this.projectBuyersList[index].buyersLinkerName = data.linkerName// 招标人联系人
      this.projectBuyersList[index].buyersLinkerTel = data.mobilePhone// 招标人联系电话
      this.projectBuyersList[index].buyersLinkerEmail = data.email// 招标人联系邮箱
      this.projectBuyersList[index].buyersLinkerAddress = data.address// 招标人地址
    },
    /* ----------------多招标人信息End-------------*/
    /* -----------------所属公司信息 start----------------*/
    // 挑选所属公司
    selectBelongCompanyDialogBtn(index, type) {
      // true 表示为添加多招标人挑选所属公司
      this.$refs.subsidiaryOrgan.openShowDialog(index, type)
    },
    // 清除所属公司
    clearBelongCompany(index, type) {
      // type 为真表示多招标人选择所谓公司 否则为主招标人
      if (type) {
        this.projectBuyersList[index].belongCompany = ''// 所属公司
        this.projectBuyersList[index].belongCompanyId = '' // 所属公司id
      } else {
        this.formData.belongCompany = ''//  所属公司
        this.formData.belongCompanyId = ''// 所属公司id
      }
    },
    // 所属公司已选信息
    subsidiaryOrganDataInfo(data, index, type) {
      // type 为真表示多招标人选择所谓公司 否则为主招标人
      if (type) {
        this.projectBuyersList[index].belongCompany = data.departName// 所属公司
        this.projectBuyersList[index].belongCompanyId = data.id // 所属公司id
      } else {
        this.formData.belongCompany = data.departName//  所属公司
        this.formData.belongCompanyId = data.id // 所属公司id
      }
    },
    /* -----------------所属公司信息 end----------------*/
    /* ----------------主招标人信息 代理机构信息Start-------------*/
    // 选择招标人列表弹框获取数据
    showDialogBtn(departRoleName) {
      this.$refs.projectDepartInfo.openOrganizationDialog(departRoleName, '', false)
    },
    dialogDataInfo(data, n) {
      // 10 招标人 11代理机构
      if (n === '10') {
        this.formData.buyersCode = data.orgCode// 招标人代码
        this.formData.buyersName = data.departName// 招标人名称
        this.formData.buyersId = data.id
        this.formData.buyersLinkerName = data.linkerName// 招标人联系人
        this.formData.buyersLinkerTel = data.mobilePhone// 招标人联系电话
        this.formData.buyersLinkerEmail = data.email// 招标人联系邮箱
        this.formData.buyersLinkerAddress = data.address// 招标人地址
      } else if (n === '11') {
        this.formData.agentCode = data.orgCode// 招标人代码
        this.formData.agentName = data.departName// 代理机构名称
        this.formData.agentId = data.id
        this.formData.agentLinkerName = data.linkerName// 代理机构联系人
        this.formData.agentLinkerTel = data.mobilePhone// 代理机构联系电话
        this.formData.agentLinkerEmail = data.email// 代理机构联系邮箱
        this.formData.agentLinkerAddress = data.address// 代理机构地址
      }
    },
    // 清空按钮
    clearAgency(n) {
      if (n === '10') {
        this.formData.buyersName = ''// 招标人名称
        this.formData.buyersId = ''
        this.formData.buyersLinkerName = ''// 招标人联系人
        this.formData.buyersLinkerTel = ''// 招标人联系电话
        this.formData.buyersLinkerEmail = ''// 招标人联系邮箱
        this.formData.buyersLinkerAddress = ''// 招标人联系地址
      } else if (n === '11') {
        this.formData.agentName = ''// 代理机构名称
        this.formData.agentId = ''
        this.formData.agentLinkerName = ''// 代理机构联系人
        this.formData.agentLinkerTel = ''// 代理机构联系电话
        this.formData.agentLinkerEmail = ''// 代理机构联系邮箱
        this.formData.agentLinkerAddress = ''// 代理机构地址
      }
    },
    /* ----------------招标人信息 代理机构信息 弹框End-------------*/
    /*
    * 保存数据接口 暂存，下一步
    * type参数 draft 点击步骤条切换-进行保存草稿
    * */
    saveData(type) {
      this.confirmLoading = true// btnLoding
      this.formData.projectBuyersList = this.projectBuyersList // 保存多招标人信息
      const data = {
        ...this.formData,
        tenderId: this.projectData.id
      }
      saveTenderProjectDepartInfo(data).then(() => {
        this.confirmLoading = false// btnLoding
        if (type === 'draft') return false// 判断是否-点击步骤条切换-如果是则不执行next下一步
        this.$emit('stepPage', 'next')// 步骤条切换方法 next 下一步
      }).catch(() => {
        this.confirmLoading = false// btnLoding
      })
    },
    // 上一步
    prevStep() {
      this.$emit('stepPage', 'prev')// 步骤条切换方法 prev 上一步
    },
    // 下一步
    nextStep() {
      const newArr = [] // 承接promise的返回结果
      const _self = this
      /* ==========================多招标人校验===================*/
      // 显示多招标人 && 添加了招标人projectBuyersList长度大于0
      if (this.bidProjectSystemSourceType && this.projectBuyersList.length > 0) {
        this.projectBuyersList.forEach((item, index) => {
          projectBuyers('buyersForm' + index)
        })
      }
      function projectBuyers(arrName) { // 根据form表单的ref，动态生成promise，再对其做表单校验，都通过了再去做处理
        var result = new Promise(function(resolve, reject) {
          _self.$refs[arrName][0].validate((valid) => {
            if (valid) {
              resolve()
            } else {
              reject()
            }
          })
        })
        newArr.push(result) // push 得到promise的结果
      }
      /* ==========================主招标人、代理机构校验===================*/
      // 采购人 && 委托招标 或者代理机构登录 显示代理机构模块则校验
      if (this.isShowAgencyInfo) {
        checkForm('agencyForm') // 代理机构校验
      }
      checkForm('buyersForm') // 采购人校验
      function checkForm(arrName) { // 根据form表单的ref，动态生成promise，再对其做表单校验，都通过了再去做处理
        var result = new Promise(function(resolve, reject) {
          _self.$refs[arrName].validate((valid) => {
            if (valid) {
              resolve()
            } else {
              reject()
            }
          })
        })
        newArr.push(result) // push 得到promise的结果
      }
      Promise.all(newArr).then(() => {
        this.saveData()
      })
    }
  }
}
</script>

<style lang="less" scoped>
  .buyers-wrap{
    position: relative;
    .delete-buyers{
      position: absolute;
      right: -10px;
      top:-10px;
      font-size: 24px;
      color: #007CCC;
      cursor: pointer;
    }
  }
</style>
