<!--
  @description: 招标项目-归档目录管理列表-添加归档目录
  @Modifier: 肖文龙
  @routerPath:/bidArchived/bidArchivedTOC-add
  @date: 2020/12/05
-->
<template>
  <div>
    <section class="title p0-16 clearfix">
      <template>
        <div class="title-back pointer" @click="back">
          <i class="iconfont icon-fanhui mr10" />添加归档目录
        </div>
      </template>
    </section>
    <section class="p0-16">
      <el-form
        ref="fromData"
        :rules="rules"
        :inline-message="true"
        :model="formData"
      >
        <table class="from_table">
          <tr>
            <td>
              <el-form-item label="文件目录名称" prop="isChangeTime" />
            </td>
            <td>
              <gx-input
                v-model="formData.isChangeTime"
                gx-maxlength="varchar200"
                placeholder="文件目录名称"
              />
            </td>
            <td>
              <el-form-item label="文档模板编号" prop="templatesCode" />
            </td>
            <td>
              <gx-input
                v-model="formData.templatesCode"
                placeholder="请选择"
                gx-maxlength="varchar200"
                style="width:calc(100% - 180px)"
                disabled
              />
              <el-button type="primary" @click="templatesCodeOpen">
                选择
              </el-button>
              <el-button @click="templatesCodeChange('clear')">
                清空
              </el-button>
            </td>
          </tr>
          <tr>
            <td>
              <el-form-item label="招标方式" prop="tenderMethod" />
            </td>
            <td>
              <el-select v-model="formData.tenderMethod" style="width: 100%;" placeholder="请选择">
                <el-option
                  v-for="(item,index) in bidTypeList"
                  :key="index"
                  :label="item.typename"
                  :value="item.typecode"
                />
              </el-select>
            </td>
            <td>
              <el-form-item label="保管期（年）" prop="tenderDocumentReceiveEndTime" />
            </td>
            <td>
              <money
                :money-value="formData"
                :thousands="true"
                size="mini"
                name="tenderDocumentReceiveEndTime"
              />
            </td>
          </tr>
          <tr>
            <td>
              <el-form-item label="是否必须归档" prop="qualificationMethod" />
            </td>
            <td>
              <el-radio-group v-model="formData.qualificationMethod">
                <el-radio v-for="(item,index) in isMustArchiveList" :key="index" :label="item.typecode">
                  {{ item.typename }}
                </el-radio>
              </el-radio-group>
            </td>
            <td>
              <el-form-item label="文件来源" prop="tenderDocumentReceiveStartTime" />
            </td>
            <td>
              <gx-input
                v-model="formData.tenderDocumentReceiveStartTime"
                gx-maxlength="varchar200"
                placeholder="文件来源"
              />
            </td>
          </tr>
          <!-- clarificationId 是否有id 如果有则是变更或编辑时 才展示 -->
          <tr v-if="clarificationId">
            <td>
              <el-form-item label="文件目录状态" prop="editFileTOCStauts" />
            </td>
            <td colspan="3">
              <el-radio-group v-model="formData.editFileTOCStauts">
                <el-radio v-for="(item,index) in editFileTOCStautsList" :key="index" :label="item.typecode">
                  {{ item.typename }}
                </el-radio>
              </el-radio-group>
            </td>
          </tr>
        </table>
      </el-form>
    </section>
    <!--保存按钮-->
    <div class="but_footer">
      <div class="but_footer-h" />
      <div class="but_footer-but">
        <el-button :loading="confirmLoading" @click="saveData('00')">
          保存
        </el-button>
        <el-button :loading="confirmLoading" type="primary" @click="submit()">
          生效
        </el-button>
      </div>
    </div>
    <!-- 文件模版选择弹框 -->
    <archivedSelectDialog ref="templatesCode" @call-back="templatesCodeChange" />
  </div>
</template>

<script>
/* 接口*/
// import { getEditClarificationInfo, saveClarificationInfo } from '@/api/bidding/bidClarification'// 澄清
/* 公用方法*/
import { validateInput, checkRate, characters1_auto } from '@/assets/js/validate'// 校验输入内容
/* 混入-字典信息 */
import { bidArchiveddGroup } from './../mixins/bidArchivedGroupMixin'// 字典信息
/* 组件*/
import money from '@comp/common/money/money' // 金额
import archivedSelectDialog from './archivedSelect-dialog'// 文件模版选择弹框
export default {
  name: 'ClarificationAdd',
  components: {
    money, // 金额组件
    archivedSelectDialog// 文件模版选择弹框
  },
  data() {
    return {
      /* 字典信息-start */
      ...bidArchiveddGroup,
      bidTypeList: [], // 招标类型
      /* 字典信息-end */
      clarificationId: '', // 归档目录Id
      formData: {
        clarificationId: '', // 归档目录Id
        isChangeTime: '', // 文件目录名称
        templatesCode: '', // 文档模板编号
        tenderDocumentReceiveEndTime: '', // 保管期（年）
        tenderDocumentReceiveStartTime: '', // 文件来源
        tenderMethod: '', // 招标方式
        qualificationMethod: '01', // 是否必须归档
        editFileTOCStauts: '01' // 文件目录状态
      },
      // 校验
      rules: {
        templatesCode: [{ required: true, validator: characters1_auto, trigger: 'change' }], // 文档模板编号
        qualificationMethod: [{ required: true, message: '请选择', trigger: 'change' }], // 是否必须归档
        tenderMethod: [{ required: true, message: '请选择', trigger: 'change' }], // 招标方式
        tenderDocumentReceiveStartTime: [{ required: true, validator: validateInput, trigger: 'blur' }], // 文件来源
        tenderDocumentReceiveEndTime: [{ required: true, validator: checkRate, trigger: 'blur' }], // 保管期（年）
        isChangeTime: [{ required: true, validator: validateInput, trigger: 'blur' }] // 文件目录名称
      }
    }
  },
  created() {
    // 获取字典方法
    this.initGroup()
    // 判断是否有澄清Id
    if (this.$route.params.id) { // 编辑
      this.clarificationId = this.$route.params.id// 归档目录Id
      this.initData(this.$route.params.id)// 获取澄清信息
    }
  },
  methods: {
    // 获取字典方法
    initGroup() {
      const data = ['bidType']
      this.$store.dispatch('getGroupType', data).then(res => {
        Object.keys(res.bidTypeData).forEach((key) => {
          this[key] = res.bidTypeData[key]
        })
      })
    },
    // 返回
    back() {
      this.$router.push({
        path: '/bidArchived/bidArchivedTOC-list'
      })
    },
    // 获取澄清信息
    initData(id) {
      // getEditClarificationInfo(id).then(res => {
      //   this.formData = res.data
      // })
    },
    // 文档模版-打开弹框
    templatesCodeOpen() {
      this.$refs.templatesCode.open()
    },
    // 文档模版数据操作
    templatesCodeChange(data) {
      if (data === 'clear') { // 清空
        this.formData.templatesCode = ''// 文件模版编号
      } else { // 选择
        this.formData.templatesCode = data.code// 文件模版编号
      }
    },
    /*
    * 保存接口
    * type 01 生效 00 保存
    * */
    saveData(type) {
      this.confirmLoading = true// btnLoding
      // saveClarificationInfo(this.formData).then(response => {
      //   this.$message.success('操作成功')
      //   this.confirmLoading = false// btnLoding
      // 生效
      if (type === '01') {
        // 生效成功后返回列表
        this.back()
      }
      // }).catch(() => {
      //   this.confirmLoading = false// btnLoding
      // })
    },
    // 提交
    submit() {
      this.$refs.fromData.validate((valid, field) => {
        if (valid) { // 校验通过
          this.$confirm('确定生效吗?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            confirmButtonClass: 'confirmBtn',
            cancelButtonClass: 'cancelBtn',
            type: 'warning'
          }).then(() => {
            this.saveData('01')
          })
        }
      })
    }
  }
}
</script>

<style scoped lang="less">

</style>
