<template>
  <div class="customer-info-edit">
    <ol class="breadcrumb">
      <i class="icon-chevron-sign-left newBackBtn" @click="() => { $router.go(-1) }"></i>
      <li>客户管理</li>
      <li>编辑</li>
    </ol>
     <div class="tempalte-content" >
      <p class="details-title">编辑</p>
      <edit-content ref="editContent"  :deatails-info="deatailsInfo"></edit-content>
      <div class="submit-btn">
        <el-button type="primary" @click="onSubmit('temp')" style="width: 100px;">暂存</el-button>
        <el-button type="primary" @click="onSubmit('submit')" style="width: 100px;">确定</el-button>
        <el-button @click="() => { $router.go(-1) }" style="width: 100px;">取消</el-button>
      </div>
     </div>
  </div>
</template>

<script>
module.exports = {
  components: {
    EditContent: httpVueLoader('./components/EditContent.vue')
  },
  data() {
    return {
      deatailsInfo: {}
    }
  },
  created() {
    this.getDetails()
  },
  methods: {
    getDetails() {
      const { id } = this.$route.query
      this.$api.capitalManage.getCustomerInfoEditDetails({ id }).then(({ data }) => {
        this.deatailsInfo = data
      })
    },
    onSubmit(type) {
      let params = this.$refs.editContent.getParams()
      const { basicFiles } = params
      if(type === 'submit') {
        for (let i = 0; i < basicFiles.length; i++) {
          const { fileStorageIdList } = basicFiles[i];
          if(i < basicFiles.length - 3) {
            if(!fileStorageIdList.length) {
              this.$message.warning('请完善客户资料后提交')
              return
            }
          }
        }
      }
      params.submit = type === 'submit' ? 1 : 0
      params.Loading = true
      this.$api.capitalManage.customerInfoSubmit(params).then(() => {
        if(type === 'submit') {
          this.$message.success('客户信息编辑成功')
          this.$router.push({ path: '/customerInfo' })
        }else {
          this.$message.success('客户信息暂存成功')
        }

      })
    }
  },
}
</script>

<style  scoped>
.customer-info-edit .submit-btn {
  margin-top: 60px;
}
</style>
