<!--
  @description:  招标-招标公告-招标条件
  @Modifier: 肖文龙
  @routerPath:/bidding/projectDrive/bulletin/tabs/tenderBulletIinInfo-add
  @date: 2019/12/30-19:20
-->
<template>
  <div>
    <div style="width: 90%;margin-left: 4%;">
      <el-form
        ref="form"
        :model="formData"
        :rules="rules"
        label-width="140px"
      >
        <el-row>
          <el-col>
            <!--招标项目名称/项目名称-->
            <el-form-item
              ref="tenderName"
              :label="dict.tenderNameLabel"
              prop="tenderName"
            >
              <span>{{ formData.tenderName }}</span>
            </el-form-item>
            <!--发标方式-->
            <!-- <el-form-item ref="bidingType" label="发标方式" prop="bidingType">
              <el-radio-group v-model="formData.bidingType">
                <el-radio v-for="(item,index) in bidingTypeList" :key="index" :label="item.typecode">
                  {{ item.typename }}
                </el-radio>
              </el-radio-group>
            </el-form-item> -->
            <!--公告标题-->
            <el-form-item
              ref="title"
              placeholder="最多允许输入200个字符"
              show-word-limit
              label="公告标题"
              prop="title"
            >
              <gx-input v-model.trim="formData.title" gx-maxlength="varchar200" placeholder="公告标题" />
            </el-form-item>
            <!--项目资金-->
            <el-form-item
              ref="projectMoney"
              label="项目资金"
              prop="projectMoney"
            >
              <money :thousands="true" :unit-stust="true" :great="true" :money-value="formData" name="projectMoney" />
            </el-form-item>
            <!--招标人·-->
            <el-form-item ref="buyersName" label="招标人" prop="buyersName">
              <span>{{ formData.buyersName }}</span>
            </el-form-item>
            <!--招标方式/公开方式-->
            <el-form-item ref="tenderMethod" :label="dict.tenderMethodLabel" prop="tenderMethod">
              <span
                v-for="(item,index) in allTenderMethodTypeList"
                v-if="formData.tenderMethod===item.typecode"
                :key="index"
              >{{ item.typename }}</span>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <!--保存按钮-->
    <div class="but_footer">
      <div class="but_footer-h" />
      <div class="but_footer-but">
        <el-button :loading="confirmLoading" type="primary" @click="nextStep('form')">
          暂存，进入下一步
        </el-button>
      </div>
    </div>
  </div>
</template>

<script>
/* api*/
import { queryBaseTenderBulletinInfo, saveBaseTenderBulletinInfo } from '@/api/bidding/bidBulletin'// 查询是否公告提交 保存接口
/* 公用方法*/
import { characters1_auto, validateInput } from '@/assets/js/validate'// 校验输入内容
/* 组件*/
import money from '@comp/common/money/money'
import { tenderBulletinInitGroupMixin } from '../mixins/tenderBulletinInitGroupMixin'
import { tenderProjectMixin } from './../mixins/tenderProjectMixin'// 字典信息
export default {
  name: 'TenderBulletIinInfoAdd',
  components: {
    money
  },
  mixins: [tenderBulletinInitGroupMixin, tenderProjectMixin],
  data() {
    return {
      /* 字典信息-start */
      allTenderMethodTypeList: [], // 招标方式字典根据配置展示
      /* 字典信息-end */
      confirmLoading: false,
      tenderBase: this.$store.getters.tenderBase, // 项目信息
      tenderId: this.$route.query.id, // 项目Id
      bulletinId: this.$route.query.bulletinId, // 公告Id
      formData: {
        isSwitchTable: '', // 是否可以切换项目概况已后的tab页 00 不可以切换 01可以切换
        bulletinType: '', // 招标公告
        bidingType: '', // 发标方式
        bulletinId: '', // 公告Id
        title: '', // 公告标题
        tenderName: '', // 项目名称
        projectMoney: '', // 项目资金
        buyersName: '', // 招标人
        tenderMethod: ''// 招标方式
      },

      // 校验输入内容
      rules: {
        title: [{ required: true, validator: validateInput, trigger: 'blur' }], // 公告标题
        bidingType: [{ required: true, validator: characters1_auto, trigger: 'blur' }], // 发标方式
        projectMoney: [{ required: true, validator: characters1_auto, trigger: 'blur' }] // 项目资金
      }
    }
  },
  created() {
    this.initBulletin()// 获取公告信息
    this.initGroup() // 获取字典方法
  },
  methods: {
    // 获取字典方法
    initGroup() {
      const data = [
        'allTenderMethodType'
      ]
      this.$store.dispatch('getGroupType', data).then(res => {
        Object.keys(res.bidTypeData).forEach((key) => {
          this[key] = res.bidTypeData[key]
        })
      })
    },
    // 获取公告信息
    initBulletin() {
      const data = {
        tenderId: this.tenderId, // 项目Id
        bulletinId: this.bulletinId// 公告Id
      }
      queryBaseTenderBulletinInfo(data).then(res => {
        this.formData = res.data
        // 当项目ID为空时
        if (!data.bulletinId) {
          // 招标采购配置bidProcurementConfig 00招标 后审
          if (this.tenderBase.bulletinType === '01' && this.tenderBase.bidProcurementConfig === '00') {
            this.formData.title = `【${this.formData.tenderName}】招标公告`// 公告标题
          }
          // 招标采购配置bidProcurementConfig 01采购 后审
          if (this.tenderBase.bulletinType === '01' && this.tenderBase.bidProcurementConfig === '01') {
            this.formData.title = `【${this.formData.tenderName}】采购公告`// 公告标题
          }
          // 资审
          if (this.tenderBase.bulletinType === '21') {
            this.formData.title = `【${this.formData.tenderName}】资审公告`// 公告标题
          }
        }
        this.$router.push({ query: {
          ...this.$route.query,
          isSwitchTable: this.formData.isSwitchTable// 是否可以切换项目概况已后的tab页 00 不可以切换 01可以切换
        }})
      })
    },
    // 保存数据接口 暂存，下一步
    saveData(type) {
      this.confirmLoading = true// btnLoding
      this.formData.tenderId = this.tenderId// 项目Id
      this.formData.bulletinType = this.tenderBase.bulletinType// 21资审公告 01招标公告
      saveBaseTenderBulletinInfo(this.formData).then(response => {
        this.formData.bulletinId = response.data.id// 招标公告Id
        // route携带参数
        const pathData = {
          ...this.$route.query,
          bulletinId: this.formData.bulletinId
        }
        this.confirmLoading = false// btnLoding
        // 判断是否-点击步骤条切换-如果是则不执行next下一步
        if (type === 'draft') {
          this.$router.push({
            query: {
              ...pathData
            }
          })
        } else {
          this.$emit('stepPage', 'next', pathData)// 步骤条切换方法 next 下一步
        }
      }).catch(() => {
        this.confirmLoading = false// btnLoding
      })
    },
    // 下一步
    nextStep(formName) {
      // 校验个人信息是否已完善
      this.$store.dispatch('findUserRule').then(() => {
      // 校验输入内容
        this.$refs[formName].validate((valid, field) => {
          if (valid) { // 校验通过
            this.saveData()
          }
        })
      })
    }
  }
}
</script>

<style lang="less" scoped>

</style>
