<template>
  <div class="create-sales-contract">
    <create-sales-contract-content ref="createSalesContract" :sales-contract="salesContract" :disabled="disabled" />
    <div class="submit-btn">
      <el-button @click="() => { $router.push({ name: 'MyTrade', query: {type: 'SalesContractManagement'} })}">关闭</el-button>
      <el-button type="primary" @click="onSubmit">提交</el-button>
    </div>
  </div>
</template>

<script>
import { doAddSalesContractManagement, getDeatail } from '@/api/myTrade/salesContractManagement/salesContractManagement'
export default {
  name: 'SalesContractManagementCreateSalesContract',
  components: {
    CreateSalesContractContent: () => import('./components/CreateSalesContractContent.vue')
  },
  data() {
    return {
      salesContract: {},
      disabled: false,
      loading: false
    }
  },
  created() {
    this.getDetails()
  },
  methods: {
    getDetails() {
      const { id, type } = this.$route.query
      if (type === 'see') {
        this.disabled = true
      }
      if (id || type) {
        getDeatail({ id }).then(({ data }) => {
          this.salesContract = data
        })
      }
    },
    onSubmit() {
      this.$refs.createSalesContract.getParams().then((data) => {
        const params = {
          ...data,
          Loading: true
        }
        doAddSalesContractManagement(params).then(() => {
          this.$message.success('提交成功')
          this.$router.push({
            name: 'MyTrade',
            query: {
              type: 'SalesContractManagement'
            }
          })
        })
      })
    }
  }
}
</script>

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

}
</style>
