<!--
  @description: 发起评审费报销-报销申请
  @Modifier: sunxinman/肖文龙
  @routerPath:/fee/evalfeeApplyStep/evalfeeApplyInfo-add
  @date: 2020/04/14-13:20
-->
<template>
  <div>
    <el-form
      ref="fromData"
      :rules="rules"
      :model="formData"
      :inline-message="true"
    >
      <table class="from_table">
        <tr>
          <td>
            <el-form-item label="表单编号" />
          </td>
          <td>
            {{ formData.formNumber?formData.formNumber:'保存后自动生成' }}
          </td>
          <td>
            <el-form-item label="表单名称" />
          </td>
          <td>
            {{ formData.name }}
          </td>
        </tr>
        <tr>
          <td>
            <el-form-item ref="batchNumber" label="会议信息表" prop="batchNumber" />
          </td>
          <td>
            <el-input v-model="formData.batchNumber" disabled style="width:calc(100% - 140px)" />
            <el-button :loading="dialogLoding" type="primary" @click="dialogData.dialog=true">
              选择
            </el-button>
            <el-button :loading="dialogLoding" @click="conferenceInfo('clear')">
              清空
            </el-button>
          </td>
          <td>
            <el-form-item label="标段（包）信息" />
          </td>
          <td>
            <el-button v-show="formData.meetingId" type="text" @click="viewPack">
              查看标段（包）列表
            </el-button>
            <el-button v-show="!formData.meetingId" type="text" @click="dialogData.dialog=true">
              请选择会议信息表
            </el-button>
          </td>
        </tr>
        <tr>
          <td>
            <el-form-item label="评标开始时间" />
          </td>
          <td>{{ formData.evalStartTime }}</td>
          <td>
            <el-form-item label="评标结束时间" />
          </td>
          <td>{{ formData.evalStopTime }}</td>
        </tr>
        <tr>
          <td>
            <el-form-item label="评审地点" />
          </td>
          <td>{{ formData.auditAddress }}</td>
          <td>
            <el-form-item label="评委会人数" />
          </td>
          <td>{{ formData.auditNumber }}</td>
        </tr>
        <tr>
          <td>
            <el-form-item label="评标专家人数" />
          </td>
          <td>{{ formData.evalExpertNumber }}</td>
          <td>
            <el-form-item label="招标代表人数" />
          </td>
          <td>{{ formData.bidiReprNumber }}</td>
        </tr>
        <tr>
          <td>
            <el-form-item label="牵头部门" />
          </td>
          <td>{{ formData.leadDepart }}</td>
          <td>
            <el-form-item label="费用类别" />
          </td>
          <td>
            {{ formData.expenType }}
          </td>
        </tr>
        <tr>
          <td>
            <el-form-item ref="purpose" prop="purpose" label="用途" />
          </td>
          <td colspan="3">
            <el-input
              v-model="formData.purpose"
              :autosize="{ minRows: 4, maxRows: 4 }"
              type="textarea"
              maxlength="4000"
              show-word-limit
              style="width: 100%"
            />
          </td>
        </tr>
        <tr>
          <td>
            <el-form-item ref="brief" prop="brief" label="摘要" />
          </td>
          <td colspan="3">
            <el-input
              v-model="formData.brief"
              :autosize="{ minRows: 4, maxRows: 4 }"
              type="textarea"
              maxlength="4000"
              show-word-limit
              style="width: 100%"
            />
          </td>
        </tr>
        <tr>
          <td>
            <el-form-item label="专家签到表扫描件" prop="title" />
          </td>
          <td colspan="3">
            <downloadFile :data="evaluationSignInScanningCopyBase" />
          </td>
        </tr>
      </table>
    </el-form>
    <!--操作按钮-->
    <div class="but_footer">
      <div class="but_footer-h" />
      <div class="but_footer-but">
        <el-button :loading="confirmLoading" @click="saveData('save')">
          保存
        </el-button>
        <el-button :loading="confirmLoading" type="primary" @click="next('fromData')">
          下一步
        </el-button>
      </div>
    </div>
    <!-- 选择会议表信息弹框 -->
    <conferenceTable :dialog-data="dialogData" ident="0" @conferenceInfo="conferenceInfo" />
    <!-- 查看标段（包）列表 -->
    <packageDetail :dialog-data="dialogDataPack" />
  </div>
</template>

<script>
/* 接口*/
import { queryByIdEvalFeeInfo, addOrUpdateAuditFee } from '@api/fee/evalfee'
import { queryByIdMeetingInfo } from '@/api/intensiveeval/intensiveeval'
/* 常用方法 */
import { validateInput, characters1_auto } from '@/assets/js/validate'// 校验输入内容
/* 公用方法*/
import { restoreInitialValue } from '@/assets/js/utils'
/* 混入公共方法 */
import { evalFeeMixin } from '../mixins/evalFeeMixin'
/* 组件*/
import downloadFile from '@comp/common/updownload/downloadFile'// 文件下载组件
import conferenceTable from '@views/fee/components/conferenceTable-dialog'// 会议信息表弹框
import packageDetail from '@views/fee/components/packageDetail-dialog'// 标段包列表
export default {
  name: 'EvalfeeApplyInfoAdd',
  components: {
    downloadFile, // 文件下载组件
    conferenceTable, // 会议信息表弹框
    packageDetail // 标段包列表弹框
  },
  mixins: [evalFeeMixin],
  props: {
    // 接收tab父页面信息
    evalFeeData: {
      type: Object,
      default: function() {
        return {
          evalFeeId: '', // 评审费id
          meetingId: ''// 会议id
        }
      }
    }
  },
  data() {
    return {
      dialogLoding: false, // 选择会议信息按钮Loading
      // 校验
      rules: {
        purpose: [{ required: true, validator: characters1_auto, trigger: 'blur' }], // 用途
        brief: [{ required: true, validator: characters1_auto, trigger: 'blur' }], // 摘要
        batchNumber: [{ required: true, validator: validateInput, trigger: 'blur' }]// 会议信息表批次号
      },
      // 会议信息表-弹框
      dialogData: { // 选择会议信息表弹框
        dialog: false
      },
      // 查看标段信息-弹框
      dialogDataPack: { // 标段包列表弹框
        dialog: false,
        meetingId: ''// 会议信息id
      }
    }
  },
  created() {
    // 判断是否已保存
    if (this.evalFeeData.evalFeeId) {
      this.initData()// 查询初始化
    }
  },
  methods: {
    // 查询初始化
    initData() {
      queryByIdEvalFeeInfo(this.evalFeeData.evalFeeId).then(res => {
        this.formData = res.data
        // 专家签到表扫描件
        this.evaluationSignInScanningCopyBase.bizId = this.formData.meetingId// 业务主键id
        this.evalFeeData.evalFeeId = this.formData.id // 评审费id
        this.evalFeeData.meetingId = this.formData.meetingId // 会议id
      })
    },
    // 查看标段包信息
    viewPack() {
      this.dialogDataPack = { // 标段包列表弹框
        dialog: true,
        meetingId: this.formData.meetingId// 会议信息id
      }
    },
    // 会议信息
    conferenceInfo(data) {
      if (data === 'clear') { // 清空
        const formData = { ...this.formData }
        // 不需要清空的参数
        delete formData.formNumber// 表单编号
        delete formData.expenType// 费用类别
        delete formData.name// 表单名称
        delete formData.purpose// 用途
        delete formData.brief// 摘要
        delete formData.id// 主键id
        restoreInitialValue(formData)// 清空数据
        // 合并清空的数据
        this.formData = {
          ...this.formData,
          ...formData
        }
      } else { // 选择
        this.dialogLoding = true// 打开loding
        this.formData.meetingId = data.id// 会议信息id
        // 专家签到表扫描件
        this.evaluationSignInScanningCopyBase.bizId = this.formData.meetingId// 业务主键id
        this.queryByIdMeetingInfo()// 会议信息详情
      }
    },
    // 会议信息详情
    queryByIdMeetingInfo() {
      const id = this.formData.meetingId// 会议id
      queryByIdMeetingInfo(id).then(res => {
        delete res.data.id
        this.formData = {
          ...this.formData,
          ...res.data
        }
        this.formData.evalStartTime = this.$Moment(this.formData.evalStartTime).format(this.momentDateTime)// 评标开始时间
        this.formData.evalStopTime = this.$Moment(this.formData.evalStopTime).format(this.momentDateTime)// 评标结束时间
        this.dialogLoding = false// 关闭loding
      })
    },
    // 保存存储数据
    saveData(type) {
      this.confirmLoading = true// btnLoding
      addOrUpdateAuditFee(this.formData).then(res => {
        this.formData.id = res.data
        // 修改父组件参数
        this.evalFeeData.evalFeeId = this.formData.id // 评审费id
        this.evalFeeData.meetingId = this.formData.meetingId // 会议id
        // 保存
        if (type === 'save') {
          this.$message({
            type: 'success',
            message: '保存成功'
          })
          this.initData()// 查询初始化
        } else if (type === 'next') {
          this.$emit('stepPage', 'next')// 步骤条切换方法 next 下一步
        }
        this.confirmLoading = false// btnLoding
      }).catch(() => {
        this.confirmLoading = false// btnLoding
      })
    },
    // 保存-下一步
    next(formName) {
      // 校验输入内容
      this.$refs[formName].validate((valid) => {
        if (valid) { // 校验通过
          this.saveData('next')// 保存数据
        }
      })
    }
  }
}
</script>

<style scoped lang="less">

</style>
