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

<script>
import { getContractApprovalDetails, contractApprovalSubmit } from '@/api/financingManage'
export default {
  components: {
    ContractApprovalContent: () => import('./components/ContractApprovalContent'),
    FinancingViewContent: () => import('./components/FinancingViewContent.vue')
  },
  data() {
    return {
      detailsInfo: {}
    }
  },
  created() {
    this.getDetails()
  },
  methods: {
    getDetails() {
      const { id } = this.$route.params
      getContractApprovalDetails({ id }).then(({ data }) => {
        this.detailsInfo = data
      })
    },
    onSubmit() {
      this.$refs.contractApproval.$refs.ruleForm.validate(valid => {
        if (valid) {
          const { taskId } = this.$route.query
          // const { id } = this.$route.params
          const params = {
            ...this.$refs.contractApproval.ruleForm,
            visible: true,
            taskId,
            contractInfoId: this.detailsInfo.contractInfoId
          }
          contractApprovalSubmit(params).then(() => {
            this.$message.success('提交成功')
            this.$router.go(-1)
          })
        } else {
          return false
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.contract-approval {

}
</style>
