<!--
  @description:  专家-完善基本信息
  @Modifier: 徐媛媛
  @routerPath: /expertInfo/expertEssentialInfo
  @date: 2020/8/11-12:56
-->
<template>
  <div>
    <!-- 完善基本信息-->
    <essentialInfoForm ref="bidProjectBase" :project-data="projectData" />
    <div class="but_footer">
      <div class="but_footer-h">
        <div class="but_footer-but">
          <el-button @click="lastStep">
            保存
          </el-button>
          <el-button :loading="confirmLoading" type="primary" @click="saveNextStep">
            下一步
          </el-button>
          <el-button type="primary" @click="allSubmit">
            提交
          </el-button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
/* 组件*/
import essentialInfoForm from './essentialInfoForm'
/* 接口*/
import { submitExpertApply } from '@/api/expert/expertInfo'//  完善基本信息提交接口
import { submitExpertChangeApply } from '@/api/expert/expertChange'//  完善基本信息提交接口
export default {
  name: 'ExpertEssentialInfo',
  components: {
    essentialInfoForm //  完善基本信息form表单
  },
  props: {
    projectData: {
      type: Object,
      default: function() {
        return {
          id: '',
          applyId: '',
          type: ''
        }
      }
    }
  },
  data() {
    return {
      confirmLoading: false // 下一步Loding
    }
  },
  methods: {
    // 保存
    lastStep() {
      this.$nextTick(function() {
        this.$refs.bidProjectBase.lastStep()
      })
    },
    // 暂存，进入下一步
    saveNextStep() {
      this.$nextTick(function() {
        this.$refs.bidProjectBase.nextStep()
      })
    },
    //  提交
    allSubmit() {
      this.$refs.bidProjectBase.$refs['form'].validate((valid, field) => {
        if (valid) {
          this.$confirm('确认提交审核吗?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            if (this.projectData.type === 'declarationChange') {
              submitExpertChangeApply(this.projectData.applyId).then(res => {
                this.$message({
                  message: '提交成功',
                  type: 'success'
                })
                this.$nextTick(function() {
                  this.$refs.bidProjectBase.queryExpertBaseInfo()
                })
                // this.$router.push({
                //   path: '/expert/perfectInfo',
                //   query: {
                //     metaData: this.$route.meta.type
                //   }
                // })
                // this.$refs.bidProjectBase.loadData()
              }).catch(() => {})
            } else {
              submitExpertApply().then(res => {
                this.$message({
                  message: '提交成功',
                  type: 'success'
                })
                this.$router.push({
                  path: '/expert/perfectInfo',
                  query: {
                    type: this.$route.meta.type, // 类型
                    expertId: this.$refs.bidProjectBase.formData.expertId // 专家id
                  }
                })
              }).catch(() => {})
            }
          }).catch(() => {})
        }
      })
    }
  }
}
</script>

<style lang="less" scoped>
  /deep/.show-word-limit-padding {
    .el-input__inner {
      padding-right: 70px;
    }
  }
</style>
