<template>
  <div class="customer-edit">
    <edit-content ref="editCont" :details-info="detailsData"></edit-content>
    <div class="submit-btn">
      <el-button style="width: 150px;" @click="() => { $router.go(-1) }">取消</el-button>
      <el-button type="primary" style="width: 150px;" @click="onSubmit('temp')">暂存</el-button>
      <el-button type="primary" style="width: 150px;" @click="onSubmit('submit')">提交</el-button>
    </div>
  </div>
</template>

<script>
import { getCustomerInfoEditDetails, customerInfoSubmit } from '@/api/capitalManage/customerInfo/index'
import EditContent from './components/EditContent.vue'

export default {
  components: {
    EditContent
  },
  props: {},
  data() {
    return {
      detailsData: {}
    }
  },
  computed: {},
  watch: {},
  created() {
    this.getDetails()
  },
  methods: {
    getDetails() {
      const { id } = this.$route.query
      if (id) {
        getCustomerInfoEditDetails({ id }).then(({ data }) => {
          this.detailsData = data
        })
      }
    },
    // 提交
    onSubmit(type) {
      this.$refs.editCont.getParams().then((params) => {
        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
        customerInfoSubmit(params).then(() => {
          if (type === 'submit') {
            this.$message.success('客户信息编辑成功')
            this.$router.push({ path: '/capitalManage/customerInfo' })
          } else {
            this.$message.success('客户信息暂存成功')
            this.$router.push({ path: '/capitalManage/customerInfo' })
          }
        })
      })
    }
  }
}
</script>
<style scoped lang="scss"></style>
