<template>
  <div class="contract-preparation">
    <cy-up-down-drag>
      <div slot="top">
        <financing-view-content />
      </div>
      <div slot="bar">
        <div>
          合同制作
        </div>
      </div>
      <div slot="bottom">
        <contract-preparation-content ref="contractPreparationContent" :details-info="detailsInfo" />
        <div class="submit-btn">
          <el-button @click="() => { $router.go(-1) }">取消</el-button>
          <el-button type="primary" @click="onSubmit('temp')">暂存</el-button>
          <el-button type="primary" @click="onSubmit('submit')">提交</el-button>
        </div>
      </div>
    </cy-up-down-drag>
  </div>
</template>

<script>
import { contractMakingDetails, contractMakingSubmit } from '@/api/financingManage'
export default {
  name: 'ContractPreparation',
  components: {
    ContractPreparationContent: () => import('./components/ContractPreparationContent'),
    FinancingViewContent: () => import('./components/FinancingViewContent.vue')
  },
  data() {
    return {
      detailsInfo: {}
    }
  },
  created() {
    this.getDetails()
  },
  methods: {
    getDetails() {
      const { id } = this.$route.params
      contractMakingDetails({ id }).then(({ data }) => {
        this.detailsInfo = data
      })
    },
    async onSubmit(type) {
      const { taskId } = this.$route.query
      const { id, reviewQuotaDisburseId, businessNo } = this.detailsInfo
      const data = await this.$refs.contractPreparationContent.getParams(type)
      const params = {
        Loading: true,
        ...data, 
        taskId: taskId, 
        visible: type === 'submit', 
        id, 
        reviewQuotaDisburseId, 
        businessNo 
      }
      contractMakingSubmit(params).then(() => {
        if (type === 'submit') {
          this.$message.success('合同制作成功')
        } else {
          this.$message.success('暂存合同制作成功')
        }

        this.$router.go(-1)
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.contract-preparation {
  height: calc(100vh - 250px);
}
</style>
