<!--
  @description:招标项目/采购项目-合同付款条款（多买）
  @Modifier:郝定康
  @routerPath:
  @date:2021-10-18 14:30:49
-->
<template>
  <div>
    <!-- 单买单买 -->
    <contractPaymentProvisionSingleAdd v-if="formData.contractSupplyType === '01'" ref="contractPaymentProvisionSingleAdd" :form-data="formData" />
    <!-- 多买 -->
    <contractPaymentProvisionBuyMoreAdd v-if="formData.contractSupplyType === '02'" ref="contractPaymentProvisionBuyMoreAdd" :form-data="formData" />
    <!-- 多卖 -->
    <contractPaymentProvisionSellMoreAdd v-if="formData.contractSupplyType === '03'" ref="contractPaymentProvisionSellMoreAdd" :form-data="formData" />
    <!--保存按钮-->
    <div class="but_footer">
      <div class="but_footer-h" />
      <div class="but_footer-but">
        <el-button @click="save('prev')">
          上一步
        </el-button>
        <el-button type="primary" @click="save('save')">
          保存
        </el-button>
        <el-button @click="save('next')">
          下一步
        </el-button>
      </div>
    </div>
  </div>
</template>

<script>
/* api */
import { listContractPayStage, saveContractPayStageData } from '@/api/contractManagement/index'
/* 组件*/
import contractPaymentProvisionSingleAdd from './contractPaymentProvisionSingle-add' // 单买单买
import contractPaymentProvisionBuyMoreAdd from './contractPaymentProvisionBuyMore-add' // 多买
import contractPaymentProvisionSellMoreAdd from './contractPaymentProvisionSellMore-add' // 多卖
export default {
  name: 'ContractPaymentProvisionAdd',
  components: {
    contractPaymentProvisionSingleAdd,
    contractPaymentProvisionBuyMoreAdd,
    contractPaymentProvisionSellMoreAdd
  },
  data() {
    return {
      formData: {
        contractId: '',
        stageDetailDtoList: [
          {
            contractPayStageDetailItemDtoList: [ // 多买 多卖详细信息
              {
                buyerSeller: '', // 买方卖方
                contractPayStageId: '', // 合同付款阶段id
                departId: '', // 卖方买方单位id
                departName: '', // 卖方买方名称
                paymentMoney: '', // 付款金额
                paymentProportion: '' // 比例
              }
            ],
            isUnified: '', // 是否统一付款
            paymentCurrency: '', // 付款币种
            paymentCurrencyCode: '', // 付款币种编码
            paymentMoney: '0', // 付款金额
            paymentName: '', // 付款阶段名称
            paymentProportion: '0', // 付款比例
            paymentRemarks: '', // 付款备注
            paymentStage: '1', // 付款阶段编号
            paymentTime: '' // 付款时间
          }
        ]
      }
    }
  },
  created() {
    this.loadData()
  },
  methods: {
    // 获取详情
    loadData() {
      const params = {
        contractId: this.$route.query.id
      }
      listContractPayStage(params).then(res => {
        this.formData = res.data
      })
    },
    save(type) {
      this.saveContractPayStageData(type)
    },
    saveContractPayStageData(type) {
      if (this.formData.contractSupplyType === '01' && !this.$refs.contractPaymentProvisionSingleAdd.save() && type !== 'save' && type !== 'prev') {
        return false
      }
      if (this.formData.contractSupplyType === '02' && !this.$refs.contractPaymentProvisionBuyMoreAdd.save() && type !== 'save' && type !== 'prev') {
        return false
      }
      if (this.formData.contractSupplyType === '03' && !this.$refs.contractPaymentProvisionSellMoreAdd.save() && type !== 'save' && type !== 'prev') {
        return false
      }
      saveContractPayStageData(this.formData).then(res => {
        const pathData = {
          ...this.$route.query
        }
        if (type === 'save') {
          this.$message({
            type: 'success',
            message: '保存成功'
          })
        } else if (type === 'prev') {
          this.$emit('stepPage', 'prev', pathData)// 步骤条切换方法 prev 上一步
        } else if (type === 'next') {
          this.$emit('stepPage', 'next', pathData)// 步骤条切换方法 next 下一步
        }
      })
    }
  }
}
</script>

<style>
</style>
