<template>
  <div class="business-manage-create">
    <ol class="breadcrumb">
      <i class="icon-chevron-sign-left newBackBtn" @click="() => { $router.go(-1) }"></i>
      <li>业务管理</li>
      <li>{{ $route.query.id ?  $route.query.type === 'history' ? '查看历史数据' : '修改业务' : '新建业务' }} </li>
    </ol>
     <div class="tempalte-content" >
      <p class="details-title">{{ $route.query.id ? $route.query.type === 'history' ? '查看历史数据' : '修改业务' : '新建业务' }}</p>
      <div class="business-create-content-box">
        <business-create-content ref="businessCreateContent" :deatails-info="deatailsInfo" :disabled="$route.query.type === 'history'"></business-create-content>
      </div>

      <div class="submit-btn" v-if="$route.query.type !== 'history'">
        <!-- <el-button type="primary" @click="onSubmit('temp')" style="width: 100px;">暂存</el-button> -->
        <el-button type="primary" @click="onSubmit('submit')" style="width: 150px;">确定</el-button>
        <el-button @click="() => { $router.go(-1) }" style="width: 150px;">取消</el-button>
      </div>
     </div>
  </div>
</template>

<script>
module.exports = {
  components: {
    BusinessCreateContent: httpVueLoader('./components/BusinessCreateContent.vue')
  },
  data() {
    return {
      deatailsInfo: {}
    }
  },
  created() {
    const { id } = this.$route.query
    if(id) {
      this.getDetails(id)
    }

  },
  methods: {
    getDetails(id) {
      console.log(id, 888)
      this.$api.businessManage.getbusinessManageEditDetails({ businessBasicInfoId: id }).then(({ data }) => {
        this.deatailsInfo = data
      })
    },
    onSubmit() {
      this.$refs.businessCreateContent.getParams().then(( data ) => {
        const { id } = this.$route.query
        if(id) {
          this.$api.businessManage.businessManageUpdateSubmit(data).then(() => {
            this.$message.success('修改业务成功')
            this.$router.push({ path: '/businessManage' })
          })
        }else {
          this.$api.businessManage.businessManageCreateSubmit(data).then(() => {
            this.$message.success('新建业务成功')
            this.$router.push({ path: '/businessManage' })
          })
        }

      })
    }
  },
}
</script>

<style  scoped>
.business-manage-create .business-create-content-box {
  overflow-y: auto;
  margin-right: -20px;
  padding-right: 20px;
  height: calc(100vh - 0.85rem - 160px);
}
.business-manage-create .tempalte-content {
  min-height: calc(100vh - 0.85rem - 46px);
}
</style>
