<!--
  @description:招标项目/采购项目-合同签订
  @Modifier:zyy
  @routerPath:
  @date:2021/4/21-17:52
-->
<template>
  <div>
    <el-form
      ref="form"
      :model="formData"
      :rules="rules"
      :inline-message="true"
    >
      <table class="from_table">
        <tr>
          <td colspan="4" style="background: #fff;border:none">
            <div class="page-title" style="display: inline-block">
              1.{{ contractSource== '00' ? '采购' : '招标' }}信息
            </div>
            <el-button style="margin-left:16px;" @click="addProjectInfo">
              添加
            </el-button>
          </td>
        </tr>
      </table>
      <div>
        <el-table
          ref="singleTable"
          :data="formData.orderSaveDtoList"
          class="pointer"
          size="mini"
        >
          <el-table-column
            type="index"
            label="序号"
            width="60px"
            align="center"
          />
          <el-table-column
            align="center"
            prop="orderNo"
            label="订单编号"
            min-width="50px"
          />
          <el-table-column
            align="center"
            prop="tenderNo"
            label="采购单编号"
            min-width="50px"
          />
          <el-table-column
            align="center"
            prop="tenderName"
            label="采购单名称"
            min-width="50px"
          />
          <el-table-column
            align="center"
            prop="tenderMethod"
            label="采购方式"
            min-width="50px"
          >
            <template slot-scope="scope">
              {{ filterDictText(tender_methodList, scope.row.tenderMethod) }}
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            prop="orderTotalTaxMoney"
            label="订单含税总额"
            min-width="50px"
          />
          <el-table-column
            align="center"
            label="操作"
            width="100"
          >
            <template slot-scope="scope">
              <el-link
                type="primary"
                @click.stop="del(scope.$index,formData.orderSaveDtoList,scope.row)"
              >
                [移除]
              </el-link>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div class="page-title">
        2.合同基本信息
      </div>
      <table class="from_table">
        <tr>
          <td>
            <el-form-item
              ref="contractNo"
              show-word-limit
              label="合同编号"
              prop="contractNo"
            />
          </td>
          <td>
            <gx-input v-model.trim="formData.contractNo" gx-maxlength="varchar100" placeholder="合同编号" />
          </td>
          <td>
            <el-form-item
              ref="contractName"
              show-word-limit
              label="合同名称"
              prop="contractName"
            />
          </td>
          <td>
            <gx-input v-model.trim="formData.contractName" gx-maxlength="varchar100" placeholder="合同名称" />
          </td>
        </tr>
        <tr>
          <td>
            <el-form-item
              ref="isFocus"
              show-word-limit
              label="合同类型"
              prop="isFocus"
            />
          </td>
          <td>
            <!--00采购合同，01框架合同-->
            <gx-input :value="formData.isFocus == '01' ? '框架合同' : '采购合同'" gx-maxlength="varchar100" placeholder="请选择" disabled />
          </td>
          <td>
            <el-form-item
              v-if="formData.isFocus!='01'"
              ref="contractTotalMoney"
              show-word-limit
              label="合同金额(元)"
              prop="contractTotalMoney"
            />
          </td>
          <td>
            <!--金额组件-->
            <money
              v-if="formData.isFocus!='01'"
              :thousands="true"
              :money-value="formData"
              :unit-stust="true"
              :great="true"
              name="contractTotalMoney"
              :disabled="true"
            />
          </td>
        </tr>
        <!--集采框架合同-->
        <tr v-if="formData.isFocus=='01'">
          <td>
            <el-form-item
              ref="contractStartTime"
              show-word-limit
              label="供货期限"
              prop="contractStartTime"
            />
          </td>
          <td>
            <el-date-picker
              v-model="formData.contractStartTime"
              :clearable="false"
              :format="elValueFormatDate"
              :default-time="defaultTimeDateTime"
              :value-format="elValueFormatDate"
              type="date"
              placeholder="开始日期"
              style="width: 220px"
              @change="handleTime"
            />
            至
            <el-date-picker
              v-model="formData.contractEndTime"
              :clearable="false"
              :format="elValueFormatDate"
              :default-time="defaultTimeDateTime"
              :value-format="elValueFormatDate"
              type="date"
              placeholder="结束日期"
              style="width: 220px"
              @change="handleTime"
            />
          </td>
          <td>
            <el-form-item
              ref="deliveryAddress"
              show-word-limit
              label="交货地址"
              prop="deliveryAddress"
            />
          </td>
          <td>
            <gx-input v-model.trim="formData.deliveryAddress" gx-maxlength="varchar200" placeholder="交货地址" />
          </td>
        </tr>
      </table>
      <template v-if="formData.orderSaveDtoList.length > 0">
        <div class="page-title">
          3.合同供方
          <!--            <el-button v-if="formData.demandContractPartyVo.length === 1" type="primary" style="margin-left:16px;" @click="supplyContractAdd">-->
          <!--              新增卖方单位-->
          <!--            </el-button>-->
        </div>
        <template v-for="(item, index) in formData.supplyContractPartyVo">
          <table :key="index+'departName'" class="from_table mt10">
            <tr>
              <td>
                <el-form-item
                  show-word-limit
                  label="单位名称"
                  :prop="'supplyContractPartyVo.'+ index +'.departName'"
                  :rules="rules.departName"
                />
                <el-button v-if="formData.supplyContractPartyVo.length > 1" type="primary" style="margin-left:16px;" @click="deleteItem(formData.supplyContractPartyVo,index)">
                  删除
                </el-button>
              </td>
              <td>
                <!-- <gx-input v-model.trim="item.departName" gx-maxlength="varchar200" placeholder="单位名称" disabled /> -->
                <gx-input
                  v-model="item.departName"
                  placeholder="请选择"
                  disabled
                />
                <!--                  <el-button type="primary" @click="contractBuyerUnitCheck">-->
                <!--                    选择-->
                <!--                  </el-button>-->
                <!--                  <el-button @click="buyerUnit('clear')">-->
                <!--                    清空-->
                <!--                  </el-button>-->
              </td>
              <td>
                <el-form-item
                  show-word-limit
                  label="社会统一信用代码"
                  :prop="'supplyContractPartyVo.'+ index +'.unified'"
                  :rules="rules.unified"
                />
              </td>
              <td>
                <gx-input v-model.trim="item.unified" gx-maxlength="varchar200" placeholder="社会统一信用代码" disabled />
              </td>
            </tr>
            <tr :key="index+'corporation'">
              <td>
                <el-form-item
                  show-word-limit
                  label="法定代表人"
                  :prop="'supplyContractPartyVo.'+ index +'.corporation'"
                  :rules="rules.corporation"
                />
              </td>
              <td>
                <gx-input v-model.trim="item.corporation" gx-maxlength="varchar50" placeholder="法定代表人" />
              </td>
              <td>
                <el-form-item
                  show-word-limit
                  label="税号"
                  :prop="'supplyContractPartyVo.'+ index +'.taxNo'"
                  :rules="rules.taxNo"
                />
              </td>
              <td>
                <gx-input v-model.trim="item.taxNo" gx-maxlength="varchar200" placeholder="税号" />
              </td>
            </tr>
            <tr :key="index+'bankName'">
              <td>
                <el-form-item
                  show-word-limit
                  label="开户行"
                  :prop="'supplyContractPartyVo.'+ index +'.bankName'"
                  :rules="rules.bankName"
                />
              </td>
              <td>
                <gx-input v-model.trim="item.bankName" gx-maxlength="varchar200" placeholder="开户行" />
              </td>
              <td>
                <el-form-item
                  show-word-limit
                  label="账号"
                  :prop="'supplyContractPartyVo.'+ index +'.bankNo'"
                  :rules="rules.bankNo"
                />
              </td>
              <td>
                <gx-input v-model.trim="item.bankNo" gx-maxlength="varchar100" placeholder="账号" />
              </td>
            </tr>
            <tr :key="index+'address'">
              <td>
                <el-form-item
                  show-word-limit
                  label="单位地址"
                  :prop="'supplyContractPartyVo.'+ index +'.address'"
                  :rules="rules.address"
                />
              </td>
              <td colspan="3">
                <gx-input v-model.trim="item.address" gx-maxlength="varchar200" placeholder="单位地址" />
              </td>
            </tr>
            <tr :key="index+'agent'">
              <td>
                <el-form-item
                  show-word-limit
                  label="委托代理人"
                  :prop="'supplyContractPartyVo.'+ index +'.agent'"
                  :rules="rules.agent"
                />
              </td>
              <td>
                <gx-input v-model.trim="item.agent" gx-maxlength="varchar200" placeholder="委托代理人" />
              </td>
              <td>
                <el-form-item
                  show-word-limit
                  label="电话"
                  :prop="'supplyContractPartyVo.'+ index +'.tel'"
                  :rules="rules.tel"
                />
              </td>
              <td>
                <gx-input v-model.trim="item.tel" gx-maxlength="varchar20" placeholder="电话" />
              </td>
            </tr>
            <tr :key="index+'bankNo'">
              <td>
                <el-form-item
                  show-word-limit
                  label="传真"
                  :prop="'supplyContractPartyVo.'+ index +'.fax'"
                  :rules="rules.fax"
                />
              </td>
              <td>
                <gx-input v-model.trim="item.fax" gx-maxlength="varchar200" placeholder="传真" />
              </td>
              <td>
                <el-form-item
                  show-word-limit
                  label="邮箱"
                  :prop="'supplyContractPartyVo.'+ index +'.mail'"
                  :rules="rules.mail"
                />
              </td>
              <td>
                <gx-input v-model.trim="item.mail" gx-maxlength="varchar100" placeholder="邮箱" />
              </td>
            </tr>
          </table>
        </template>
        <div class="page-title">
          4.合同需方
          <!--            <el-button v-if="formData.supplyContractPartyVo.length === 1" type="primary" style="margin-left:16px;" @click="demandContractAdd">-->
          <!--              新增买方单位-->
          <!--            </el-button>-->
        </div>
        <template v-for="(item, index) in formData.demandContractPartyVo">
          <table :key="index+'demandDepartName'" class="from_table mt10">
            <tr>
              <td>
                <el-form-item
                  show-word-limit
                  label="单位名称"
                  :prop="'demandContractPartyVo.'+ index +'.departName'"
                  :rules="rules.departName"
                />
                <el-button v-if="formData.demandContractPartyVo.length > 1" type="primary" style="margin-left:16px;" @click="deleteItem(formData.demandContractPartyVo,index)">
                  删除
                </el-button>
              </td>
              <td>
                <gx-input
                  v-model="item.departName"
                  placeholder="请选择"
                  disabled
                />
                <!--                  <el-button type="primary" @click="organSelect(index)">-->
                <!--                    选择-->
                <!--                  </el-button>-->
                <!--                  <el-button @click="organTree('clear')">-->
                <!--                    清空-->
                <!--                  </el-button>-->
              </td>
              <td>
                <el-form-item
                  show-word-limit
                  label="社会统一信用代码"
                  :prop="'demandContractPartyVo.'+ index +'.unified'"
                  :rules="rules.unified"
                />
              </td>
              <td>
                <gx-input v-model.trim="item.unified" gx-maxlength="varchar200" placeholder="社会统一信用代码" />
              </td>
            </tr>
            <tr :key="index+'demandCorporation'">
              <td>
                <el-form-item
                  show-word-limit
                  label="法定代表人"
                  :prop="'demandContractPartyVo.'+ index +'.corporation'"
                  :rules="rules.corporation"
                />
              </td>
              <td>
                <gx-input v-model.trim="item.corporation" gx-maxlength="varchar50" placeholder="法人" />
              </td>
              <td>
                <el-form-item
                  show-word-limit
                  label="税号"
                  :prop="'demandContractPartyVo.'+ index +'.taxNo'"
                  :rules="rules.taxNo"
                />
              </td>
              <td>
                <gx-input v-model.trim="item.taxNo" gx-maxlength="varchar200" placeholder="税号" />
              </td>
            </tr>
            <tr :key="index+'demandBankName'">
              <td>
                <el-form-item
                  show-word-limit
                  label="开户行"
                  :prop="'demandContractPartyVo.'+ index +'.bankName'"
                  :rules="rules.bankName"
                />
              </td>
              <td>
                <gx-input v-model.trim="item.bankName" gx-maxlength="varchar200" placeholder="开户行" />
              </td>
              <td>
                <el-form-item
                  show-word-limit
                  label="账号"
                  :prop="'demandContractPartyVo.'+ index +'.bankNo'"
                  :rules="rules.bankNo"
                />
              </td>
              <td>
                <gx-input v-model.trim="item.bankNo" gx-maxlength="varchar100" placeholder="账号" />
              </td>
            </tr>
            <tr :key="index+'demandAddress'">
              <td>
                <el-form-item
                  show-word-limit
                  label="单位地址"
                  :prop="'demandContractPartyVo.'+ index +'.address'"
                  :rules="rules.address"
                />
              </td>
              <td colspan="3">
                <gx-input v-model.trim="item.address" gx-maxlength="varchar200" placeholder="单位地址" />
              </td>
            </tr>
            <tr :key="index+'demandAgent'">
              <td>
                <el-form-item
                  show-word-limit
                  label="委托代理人"
                  :prop="'demandContractPartyVo.'+ index +'.agent'"
                  :rules="rules.agent"
                />
              </td>
              <td>
                <gx-input v-model.trim="item.agent" gx-maxlength="varchar200" placeholder="委托代理人" />
              </td>
              <td>
                <el-form-item
                  show-word-limit
                  label="电话"
                  :prop="'demandContractPartyVo.'+ index +'.tel'"
                  :rules="rules.tel"
                />
              </td>
              <td>
                <gx-input v-model.trim="item.tel" gx-maxlength="varchar20" placeholder="电话" />
              </td>
            </tr>
            <tr :key="index+'demandBankNo'">
              <td>
                <el-form-item
                  show-word-limit
                  label="传真"
                  :prop="'demandContractPartyVo.'+ index +'.fax'"
                  :rules="rules.fax"
                />
              </td>
              <td>
                <gx-input v-model.trim="item.fax" gx-maxlength="varchar200" placeholder="传真" />
              </td>
              <td>
                <el-form-item
                  ref="contractPartyVo.supplyMail"
                  show-word-limit
                  label="邮箱"
                  :prop="'demandContractPartyVo.'+ index +'.mail'"
                  :rules="rules.mail"
                />
              </td>
              <td>
                <gx-input v-model.trim="item.mail" gx-maxlength="varchar100" placeholder="邮箱" />
              </td>
            </tr>
          </table>
        </template>
      </template>
    </el-form>
    <div class="but_footer">
      <div class="but_footer-h">
        <div class="but_footer-but">
          <el-button :loading="confirmLoading" @click="saveData('save')">
            暂存，进入下一步
          </el-button>
          <!--<el-button type="primary" :loading="confirmLoading" @click="submitData('form')">
              提交
            </el-button>-->
        </div>
      </div>
    </div>
    <contractBuyerUnitDialog
      :dialog-data="contractBuyerUnitData"
      :contract-source="contractSource"
      @callBack="buyerUnit"
    />
    <!-- 项目信息-选择弹框 -->
    <bidProjectInfoDialog
      ref="bidProjectInfoDialog"
      :contract-source="contractSource"
      @dialogDataInfo="dialogDataInfo"
    />
    <!-- 所属机构弹框 -->
    <organTree-dialog
      ref="organTree"
      :single-choice="true"
      @call-back="organTree"
    />
  </div>
</template>
<script>
/* 接口*/
import { getBidtCalibrationTenderContractData, saveBidtCalibrationTenderContractData, delOrderContractDetailInfo, checkContractNoIsExist } from '@/api/contractManagement/index'// 招标项目-编辑初始化数据 招标项目-签订保存
import { selectWinnerSupplierInfo, getPurchaseDepartInfo } from '@/api/procurement/procurementResult'// 获取供应信息
/* 公用方法*/
import { validateInput, characters1_50, linkerName, email, bankCardNumber } from '@/assets/js/validate'// 校验输入内容
import { restoreInitialValue, filterDictText } from '@/assets/js/utils'
// import { validFn } from '@assets/js/utils'// 常用方法
/* 混合开发方法-参数字段*/
// import { initGroupMixin } from '@/mixins/initGroupMixin'
import { procurementGroupMixins } from '@/views/procurement/mixins/procurementGrounpMixins'
/* 组件*/
import bidProjectInfoDialog from './projectInfo-dialog' // 项目信息-选择弹框
import contractBuyerUnitDialog from '../contractComp/contractBuyerUnit-dialog' // 合同买方单位选择
import organTreeDialog from '@/views/common/user/organizationTree/organTree-dialog' // 组织机构选择
import money from '@/components/common/money/money.vue'
export default {
  name: 'ContractSigning',
  components: {
    filterDictText, // 字典值替换文本通用方法
    money,
    bidProjectInfoDialog, // 所属公司-选择弹框
    contractBuyerUnitDialog, // 合同买方单位选择
    'organTree-dialog': organTreeDialog // 组织机构选择
  },
  mixins: [procurementGroupMixins],
  data() {
    return {
      contractData: this.$route.params,
      orderId: [],
      confirmLoading: false,
      contractSource: '', // 合同来源00采购01招标
      id: '', // 合同详情id
      organTreeIndex: 0,
      formData: {
        orderSaveDtoList: [],
        // packId: '',
        isFocus: '00', // 00 采购合同，01框架合同
        deliveryTime: '', // 供货期限
        contractStartTime: '', // 开始时间
        contractEndTime: '', // 结束时间
        deliveryAddress: '', // 交货地址
        // noticeId: '', // 通知书id
        // tenderName: '', // 项目名称
        // purchaseProjectName: '', // 采购下的项目名称
        // tenderNo: '', // 项目编号
        // tenderId: '', // 项目id
        // tenderMethod: '', // 采购方式
        // packNo: '', // 标段编号
        // packName: '', // 标段名称
        contractNo: '', // 合同编号
        contractName: '', // 合同名称
        contractTotalMoney: '', // 合同金额
        orderTotalTaxMoney: '', // 订单含税总额
        // 供方
        supplyContractPartyVo: [
          {
            departName: '', // 中标人名称/供方单位
            departId: '', // 供方人id
            unified: '', // 供方统一社会信用代码
            tel: '', // 供方电话
            corporation: '', // 供方法人
            bankName: '', // 供方开户行
            mail: '', // 供方邮箱
            address: '', // 供方地址
            agent: '', // 供方代理人
            fax: '', // 供方传真
            bankNo: '', // 供方银行账号
            taxNo: '' // 供方税号
          }
        ],
        // 需方
        demandContractPartyVo: [
          {
            departId: '', // 需方机构id
            departName: '', // 需方机构名称
            unified: '', // 需方统一社会信用代码
            corporation: '', // 需方法人
            tel: '', // 需方电话
            bankName: '', // 需方开户行
            mail: '', // 需方邮箱
            address: '', // 需方地址
            agent: '', // 需方代理人
            fax: '', // 需方传真
            bankNo: '', // 需方银行账号
            taxNo: '' // 需方税号
          }
        ]
      },
      contractBuyerUnitData: {
        dialog: false,
        tenderId: '',
        selectedSupplierId: []
      },
      rules: {
        contractStartTime: [{ required: true, message: '不能为空', trigger: 'change' }], // 供货开始期限
        deliveryTime: [{ required: true, message: '不能为空', trigger: 'change' }], // 供货期限
        deliveryAddress: [{ required: true, message: '不能为空', trigger: 'blur' }], // 供货期限
        contractName: [{ required: true, message: '不能为空', trigger: 'blur' }], // 项目编号
        tenderName: [{ required: true, validator: validateInput, trigger: 'blur' }], // 项目名称
        tenderNo: [{ required: true, validator: validateInput, trigger: 'blur' }], // 项目编号
        packNo: [{ required: true, validator: validateInput, trigger: 'blur' }], // 标段编号
        packName: [{ required: true, validator: validateInput, trigger: 'blur' }], // 标段名称
        contractNo: [{ required: true, validator: validateInput, trigger: 'blur' },
          { required: true, validator: this.contractNoApi, trigger: 'blur' }], // 合同编号
        // contractTotalMoney: [{ required: true, message: '请填写金额', trigger: 'blur' }], // 金额
        'departName': [{ required: true, validator: validateInput, trigger: 'blur' }], // 中标人名称
        'unified': [{ required: true, validator: validateInput, trigger: 'blur' }], // 统一社会信用代码
        'tel': [{ required: true, validator: characters1_50, trigger: 'blur' }], // 法人
        'corporation': [{ required: true, validator: linkerName, trigger: 'blur' }], // 法定代表人
        'bankName': [{ required: true, validator: validateInput, trigger: 'blur' }], // 开户行
        'mail': [{ required: true, validator: email, trigger: 'blur' }], // 邮箱
        'address': [{ required: true, validator: validateInput, trigger: 'blur' }], // 地址
        'agent': [{ required: true, validator: validateInput, trigger: 'blur' }], // 代理人
        // 'fax': [{ required: true, validator: validateInput, trigger: 'blur' }], // 传真
        'bankNo': [{ required: true, validator: bankCardNumber, trigger: 'blur' }], // 银行账号
        'taxNo': [{ required: true, validator: validateInput, trigger: 'blur' }], // 税号
        'departId': [{ required: true, validator: validateInput, trigger: 'blur' }] // 机构id
      }
    }
  },
  created() {
    // 字典信息
    // this.initTypeGroup('bidType')// 招标方式
    this.initWebTypeGroup() // 采购方式
    if (this.$route.query.id) { // 编辑
      this.id = this.$route.query.id// 合同Id
      this.initData(this.$route.query.id)
    }
    this.contractSource = this.$route.query.contractSource
  },
  methods: {
    filterDictText, // 字典值替换文本通用方法
    // 编辑初始化数据
    initData(id) {
      const data = {
        id: id
      }
      getBidtCalibrationTenderContractData(data).then(response => {
        this.formData = response.data
        response.data.orderSaveDtoList.forEach((item) => {
          this.orderId.push(item.orderId)
        })
        // this.formData.isFocus = '01'
      }).catch(() => {
        this.confirmLoading = false
      })
    },
    deleteItem(data, index) {
      data.splice(index, 1)
    },
    // 用户名重复校验
    contractNoApi(rule, value, callback) {
      checkContractNoIsExist({ contractNo: value })
        .then(response => {
          if (response.data === '00') {
            callback(new Error('合同编号已存在'))
          } else {
            callback()
          }
        })
        .catch(() => {
        })
    },
    // 选择供方
    contractBuyerUnitCheck() {
      // this.contractBuyerUnitData.packId = this.formData.packId
      // this.contractBuyerUnitData.tenderId = this.formData.tenderId
      // this.contractBuyerUnitData.selectedSupplierId = []
      // this.formData.supplyContractPartyVo.forEach(item => {
      //   this.contractBuyerUnitData.selectedSupplierId.push(item.departId)
      // })
      // this.contractBuyerUnitData.dialog = true
      const selectedSupplierId = []
      this.formData.supplyContractPartyVo.forEach(item => {
        selectedSupplierId.push(item.departId)
      })
      const params = {
        tenderId: this.formData.tenderId,
        selectedSupplierId: selectedSupplierId
      }
      // 招标
      selectWinnerSupplierInfo(params).then(response => {
        const dateList = []
        response.data.forEach((item) => {
          const obj = {}
          obj.departName = item.supplyDepartName
          obj.departId = item.supplyDepartId
          obj.unified = item.supplyUnified
          obj.tel = item.supplyTel
          obj.corporation = item.supplyAgent
          obj.bankName = item.supplyBankName
          obj.mail = item.supplyMail
          obj.address = item.supplyAddress
          obj.agent = item.supplyCorporation
          obj.fax = item.supplyFax
          obj.bankNo = item.supplyBankNo
          obj.taxNo = item.supplyUnified
          dateList.push(obj)
        })
        this.formData.supplyContractPartyVo = dateList
      }).catch(() => {

      })
    },
    getPurchaseDepartInfo() {
      getPurchaseDepartInfo().then(response => {
        const dateList = []
        response.data.forEach((item) => {
          const obj = {}
          obj.departName = item.supplyDepartName
          obj.departId = item.supplyDepartId
          obj.unified = item.supplyUnified
          obj.tel = item.supplyTel
          obj.corporation = item.supplyAgent
          obj.bankName = item.supplyBankName
          obj.mail = item.supplyMail
          obj.address = item.supplyAddress
          obj.agent = item.supplyCorporation
          obj.fax = item.supplyFax
          obj.bankNo = item.supplyBankNo
          obj.taxNo = item.supplyUnified
          dateList.push(obj)
        })
        this.formData.demandContractPartyVo = dateList
      }).catch(() => {

      })
    },
    // 新增供方单位
    // supplyContractAdd() {
    //   const supplyContractData = {
    //     ...this.formData.supplyContractPartyVo[0]
    //   }
    //   restoreInitialValue(supplyContractData)
    //   this.formData.supplyContractPartyVo.push(supplyContractData)
    // },
    // 新增需方单位
    demandContractAdd() {
      const demandContractData = {
        ...this.formData.demandContractPartyVo[0]
      }
      restoreInitialValue(demandContractData)
      this.formData.demandContractPartyVo.push(demandContractData)
    },
    // 处理时间
    handleTime(val) {
    },
    // 返回
    back() {
      this.$router.push({
        path: '/contractManagement/contractSigning-list'
      })
    },
    // 关联项目
    addProjectInfo() {
      this.$refs.bidProjectInfoDialog.openProjectInfoDialog()
    },
    // 关联项目信息
    dialogDataInfo(data) {
      const newArr = []
      let res = 0
      data.forEach((item) => {
        const obj = {}
        obj.packId = item.packId
        obj.isFocus = item.isFocus // 合同类型 01 框架合同，00采购合同
        obj.noticeId = item.noticeId// 通知书id
        obj.tenderName = item.tenderName// 项目名称
        obj.tenderNo = item.tenderNo// 项目编号
        obj.tenderMethod = item.tenderMethod// 采购方式
        obj.tenderId = item.tenderId// 项目id
        obj.packNo = item.packNo// 标段编号
        obj.packName = item.packName// 标段名称
        obj.orderId = item.id// 订单id
        res = res.add(item.orderTotalTaxMoney)// 合同金额
        obj.orderNo = item.orderCode // 合同金额
        obj.orderTotalTaxMoney = item.orderTotalTaxMoney
        newArr.push(obj)
        this.orderId.push(item.id)
      })
      this.formData.orderSaveDtoList = newArr
      this.formData.tenderId = data[0].tenderId// 项目id
      this.formData.contractTotalMoney = res // 合同金额
      this.formData.supplyContractPartyVo[0].departId = data[0].supplyDepartId// 供方机构id
      this.contractBuyerUnitCheck()
      this.getPurchaseDepartInfo()
    },
    // 选择机构
    organSelect(index) {
      this.organTreeIndex = index
      this.$refs.organTree.open({
        title: '选择机构', // 弹框标题
        dialog: true, // 弹窗状态
        selectCodes: this.formData.demandContractPartyVo[index].departId && this.formData.demandContractPartyVo[index].departId.split(',')
      })
    },
    // 选择/清空买方单位
    buyerUnit(data) {
      // 清空
      if (data === 'clear') {
        this.formData.supplyContractPartyVo[0].departId = '' // 供方机构id
        this.formData.supplyContractPartyVo[0].departName = '' // 供方单位/中标人名称
        this.formData.supplyContractPartyVo[0].unified = '' // 供方统一社会信用代码
        this.formData.supplyContractPartyVo[0].corporation = '' // 供方法人
        this.formData.supplyContractPartyVo[0].bankName = '' // 供方开户行
        this.formData.supplyContractPartyVo[0].tel = '' // 供方电话
        this.formData.supplyContractPartyVo[0].mail = '' // 供方邮箱
        this.formData.supplyContractPartyVo[0].address = '' // 供方地址
        this.formData.supplyContractPartyVo[0].agent = '' // 供方代理人
        this.formData.supplyContractPartyVo[0].fax = '' // 供方传真
        this.formData.supplyContractPartyVo[0].bankNo = '' // 供方账号
        this.formData.supplyContractPartyVo[0].taxNo = '' // 供方税号
      } else {
        // 选择
        // this.$set(this.formData.demandContractPartyVo[0], 'departName', data.labels)
        // this.$set(this.formData.demandContractPartyVo[0], 'departId', data.keys)
        // this.$set(this.formData.demandContractPartyVo[0], 'unified', data.orgCodes)
        this.formData.supplyContractPartyVo[0].departId = data.supplyDepartId// 供方机构id
        this.formData.supplyContractPartyVo[0].departName = data.supplyDepartName// 供方单位/中标人名称
        this.formData.supplyContractPartyVo[0].unified = data.supplyUnified // 供方统一社会信用代码
        this.formData.supplyContractPartyVo[0].corporation = data.supplyCorporation // 供方法人
        this.formData.supplyContractPartyVo[0].bankName = data.supplyBankName // 供方开户行
        this.formData.supplyContractPartyVo[0].tel = data.supplyTel // 供方电话
        this.formData.supplyContractPartyVo[0].mail = data.supplyMail // 供方邮箱
        this.formData.supplyContractPartyVo[0].address = data.supplyAddress // 供方地址
        this.formData.supplyContractPartyVo[0].agent = data.supplyAgent // 供方代理人
        this.formData.supplyContractPartyVo[0].fax = data.supplyFax // 供方传真
        this.formData.supplyContractPartyVo[0].bankNo = data.supplyBankNo // 供方账号
        this.formData.supplyContractPartyVo[0].taxNo = data.supplyTaxNo // 供方税号
      }
    },
    // 选择/清空机构
    organTree(data, index) {
      // 清空
      if (data === 'clear') {
        this.formData.demandContractPartyVo[index].departId = '' // 需方机构id
        this.formData.demandContractPartyVo[index].departName = '' // 需方机构名称
      } else {
        // 选择
        this.$set(this.formData.demandContractPartyVo[this.organTreeIndex], 'departName', data.labels)
        this.$set(this.formData.demandContractPartyVo[this.organTreeIndex], 'departId', data.keys)
        this.$set(this.formData.demandContractPartyVo[this.organTreeIndex], 'unified', data.orgCodes)
      }
    },
    // 保存
    saveData(type) {
      this.confirmLoading = true
      if (type === 'save') {
        this.status = '00'
      } else {
        this.status = '01'
      }
      const data = {
        ...this.formData,
        // contractType: this.formData.isFocus, //  00采购合同 01框架合同 02协议采购
        contractSource: this.contractSource, // 合同来源00采购01招标
        useStatus: this.status // 00保存，01提交
      }
      data.contractTypeNo = this.formData.isFocus //  00采购合同 01框架合同 02协议采购
      data.contractTypeName = this.formData.isFocus === '01' ? '框架合同' : '采购合同' //  00采购合同 01框架合同 02协议采购
      if (this.formData.contractStartTime && this.formData.contractEndTime) {
        this.formData.deliveryTime = [this.formData.contractStartTime, this.formData.contractEndTime] // 必填校验
      } else {
        this.formData.deliveryTime = ''
      }
      this.$refs.form.validate(valid => {
        if (valid) {
          if (!this.formData.contractEndTime && this.formData.isFocus === '01') {
            this.$message({
              type: 'warning',
              message: '供货期限为必填项'
            })
            return false
          }
          if (this.formData.orderSaveDtoList.length === 0) {
            this.$confirm('请选择订单信息？', '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              confirmButtonClass: 'confirmBtn',
              cancelButtonClass: 'cancelBtn',
              type: 'warning'
            })
            this.confirmLoading = false
          } else {
            saveBidtCalibrationTenderContractData(data).then(response => {
              this.confirmLoading = false
              this.$message({
                type: 'success',
                message: '保存成功'
              })
              const orderList = []
              this.formData.orderSaveDtoList.forEach((item) => {
                orderList.push(item.orderId)
              })
              const pathData = {
                ...this.$route.query,
                id: response.data,
                order: orderList
              }
              this.$emit('stepPage', 'next', pathData)
            }).catch(() => {
              this.confirmLoading = false
            })
          }
        } else {
          this.confirmLoading = false
          return false
        }
      })
    },
    // 提交
    submitData(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          this.$confirm('确认提交吗？', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            confirmButtonClass: 'confirmBtn',
            cancelButtonClass: 'cancelBtn',
            type: 'warning'
          }).then(() => {
            this.saveData()
          })
        } else {
          return false
        }
      })
    },
    del(index, rows, a) {
      rows.splice(index, 1)
      delOrderContractDetailInfo(a.orderId, a.contractId).then(response => {
        this.$message({
          type: 'success',
          message: '删除成功'
        })
      })
    }
  }
}
</script>
<style lang="less" scoped>

</style>
