<!--
  @description: 专家-专家成果
  @Modifier: 徐媛媛
  @routerPath:/expert/expertAchievements
  @date: 2020/8/12-13:27
-->
<template>
  <div>
    <el-form ref="forms" :model="formData" :rules="rules" :inline-message="true">
      <table class="from_table">
        <!--开始时间--->
        <tr>
          <td>
            <el-form-item label="开始时间" prop="researchResult" />
          </td>
          <td>
            <el-date-picker
              v-model="formData.startDate"
              :value-format="elValueFormatDate"
              type="date"
              placeholder="选择日期"
            />
          </td>
        </tr>
        <!--主要业绩-->
        <tr>
          <td>
            <el-form-item label="结束时间 " prop="mainAchievement" />
          </td>
          <td>
            <el-date-picker
              v-model="formData.endDate"
              :value-format="elValueFormatDate"
              type="date"
              placeholder="选择日期"
            />
          </td>
        </tr>
        <!--请假原因-->
        <tr>
          <td>
            <el-form-item label="请假原因" prop="leaveDescription" />
          </td>
          <td>
            <el-input
              v-model.trim="formData.leaveDescription"
              type="textarea"
              maxlength="50"
              style="width: 100%;"
              placeholder="请假原因"
              class="show-word-limit-padding"
            />
          </td>
        </tr>
      </table>
    </el-form>
    <!--保存按钮-->
    <div class="but_footer">
      <div class="but_footer-h">
        <div class="but_footer-but">
          <el-button :loading="allSubmitLoading" @click="allSubmit">
            提交
          </el-button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
/* 接口*/
import { saveExpertLeave } from '@/api/expert/expertscloud' //  专家成果接口
import { queryExpertAchievementByApplyId } from '@/api/expert/expertChange' // 变更获取专家成果
// import upload from '@comp/common/updownload/upload'
import { mapGetters } from 'vuex'

export default {
  name: 'BidWorkExperienceDialog',
  components: {
  },
  props: {
    projectData: {
      type: Object,
      default: function() {
        return {
          id: '',
          applyId: '',
          type: ''
        }
      }
    }
  },
  data() {
    return {
      formData: {
        endDate: '', // 结束时间
        startDate: '', // 结束时间
        leaveDescription: '' // 请假原因
      },
      rules: {
        otherDesc: [{ required: true, message: '请填写证书编号' }], // 开始时间
        startDate: [
          { required: true, message: '开始时间不能为空', trigger: 'blur' }
        ], // 结束时间
        leaveDescription: [{ required: true, message: '结束时间' }] // // 请假原因
      }
    }
  },
  computed: {
    ...mapGetters(['info'])
  },
  created() {
    if (this.projectData.type === 'declarationChange') {
      this.loadData()
    }
  },
  methods: {
    loadData() {
      queryExpertAchievementByApplyId(this.projectData.applyId).then(res => {
        this.formData = res.data
      })
    },
    //  提交所有页面信息
    allSubmit() {
      const userId = this.info.id
      this.formData.userId = userId
      const data = { ...this.formData }
      saveExpertLeave(data).then(res => {
        this.formData.id = res.data.id
        this.formData = res.data
      }).catch(() => {})
    }
  }
}
</script>

<style scoped lang="less">
.el-dialog__body {
  height: 55vh;
}
</style>
