<template>
  <div class="sales-contract-add">
    <sales-contract-add-content ref="salesContractAddContent" :deatils-info="deatilsInfo" />
    <div class="submit-btn">
      <el-button @click="() => { $router.push({ name: 'MyTrade', query: {type: 'SalesContractManagement'} })}">关闭</el-button>
      <el-button type="primary" @click="onSubmit('temp')">暂存</el-button>
      <el-button type="primary" @click="onSubmit('submit')">提交</el-button>
    </div>
  </div>
</template>

<script>
import { salesContractManagementDoEnter, salesContractManagementgetDetail } from '@/api/myTrade/salesContractManagement/salesContractManagement'
export default {
  name: 'SalesContractManagementSalesContractAdd',
  components: {
    SalesContractAddContent: () => import('./components/SalesContractAddContent.vue')
  },
  data() {
    return {
      deatilsInfo: {}
    }
  },
  created() {
    this.getDetails()
  },
  methods: {
    getDetails() {
      const { id, type } = this.$route.query
      if (type === 'edit') {
        salesContractManagementgetDetail({ id }).then(({ data }) => {
          this.deatilsInfo = data
        })
      }
    },
    onSubmit(type) {
      let tipword = ''
      if (type === 'temp') {
        this.$refs.salesContractAddContent.getParamsTemp().then((data) => {
          const params = {
            Loading: true,
            ...data
          }
          params.commit = 0
          tipword = '暂存'
          salesContractManagementDoEnter(params).then(() => {
            this.$message.success(tipword + '成功')
            this.$router.push({
              name: 'MyTrade',
              query: {
                type: 'SalesContractManagement'
              }
            })
          })
        })
      } else {
        this.$refs.salesContractAddContent.getParams().then((data) => {
          const params = {
            Loading: true,
            ...data
          }
          params.commit = 1
          tipword = '提交'
          salesContractManagementDoEnter(params).then(() => {
            this.$message.success(tipword + '成功')
            this.$router.push({
              name: 'MyTrade',
              query: {
                type: 'SalesContractManagement'
              }
            })
          })
        })
      }
    }
  }
}
</script>

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

}
</style>
