<template>
  <div class="customer-info-edit">
    <ol class="breadcrumb">
      <i class="icon-chevron-sign-left newBackBtn" @click="() => { $router.go(-1) }"></i>
      <li>客户支用管理</li>
      <li>编辑</li>
    </ol>   
     <div class="tempalte-content" >
      <p class="details-title">编辑</p>
      <edit-content ref="editContent" :deatails-info="deatailsInfo"></edit-content>
      <div class="submit-btn">
        <el-button type="primary" @click="onSubmit('temp')" style="width: 100px;">暂存</el-button>
        <el-button type="primary" @click="onSubmit('submit')" style="width: 100px;">确定</el-button>
        <el-button @click="() => { $router.go(-1) }" style="width: 100px;">取消</el-button>
      </div>
     </div>
  </div>
</template>
<script>
module.exports = {
  components: {
    EditContent: httpVueLoader('./components/EditContent.vue')
  },
  data() {
    return {
      deatailsInfo: {
        downstreamDetailList: [],
        upstreamDetailList: [],
        loanDateList: [],
      }
    }
  },
  created() {
    this.getDetails()
  },
  methods: {
    getDetails() {
      const { id } = this.$route.query
      this.$api.capitalManage.getcustomerDisburseInfoEditDetails({ id }).then(({ data }) => {
        this.deatailsInfo = data
      })
    },
    onSubmit(type) {
      let params = this.$refs.editContent.getParams()
      const {upstreamDetailList, downstreamDetailList, attachmentFileIds } = params
      if(type === 'submit') {
        for (let i = 0; i < upstreamDetailList.length; i++) {
          const { upstreamPurchContractFileIds,upstreamSettlementFileIds,upstreamInvoiceFileIds } = upstreamDetailList[i];
          if(!upstreamPurchContractFileIds.length) {
            this.$message.warning('请上传上游采购合同后提交')
            return
          }
          if(!upstreamSettlementFileIds.length) {
            this.$message.warning('请上传上游结算单后提交')
            return
          }
          // if(!upstreamInvoiceFileIds.length) {
          //   this.$message.warning('请上传上游发票后提交')
          //   return
          // }
        }
        for (let j = 0; j < downstreamDetailList.length; j++) {
          const { downstreamSalesContractFileIds,downstreamSettlementFileIds,downstreamInvoiceFileIds } = downstreamDetailList[j];
          if(!downstreamSalesContractFileIds.length) {
            this.$message.warning('请上传下游销售合同后提交')
            return
          }
          if(!downstreamSettlementFileIds.length) {
            this.$message.warning('请上传下游结算单后提交')
            return
          }
          // if(!downstreamInvoiceFileIds.length) {
          //   this.$message.warning('请上传下游发票后提交')
          //   return
          // }
        }
        if(!attachmentFileIds.length){
          this.$message.warning('请上传合同及附件后提交')
          return
        }
      }
      params.submit = type === 'submit' ? 1 : 0
      params.Loading = true
      this.$api.capitalManage.customerDisburseInfoSubmit(params).then(() => {
        if(type === 'submit') {
          this.$message.success('客户支用信息编辑成功')
          this.$router.push({ path: '/customerDisburseInfo' })
        }else {
          this.$message.success('客户支用信息暂存成功')
        }

      })
    },
  },
}
</script>

<style  scoped>

</style>