<!--
  @description:新增招标失败
  @Modifier: haofengxian/肖文龙
  @routerPath:/bidding/projectDrive/biddingFailure/biddingFailureAdd
  @date: 2020-5-13-10:42
-->
<template>
  <div class="main">
    <el-form
      ref="fromData"
      :model="formData"
      :rules="rules"
      :inline-message="true"
    >
      <table class="from_table">
        <tr class="singleRow">
          <td>
            <el-form-item label="标段（包）" required prop="stopBiddingPackId" />
          </td>
          <td colspan="3">
            <stopbiddingRecord-pack-component
              ref="packComp"
              :is-radio="true"
              :select-pack-list="packInfoList"
            />
          </td>
        </tr>
        <tr class="singleRow">
          <td>
            <el-form-item label="异常原因" prop="unusualReasonText" />
          </td>
          <td colspan="3">
            <el-select
              v-model="formData.unusualReasonText"
              placeholder="请选择"
              @change="unusualReasonTypeChange"
            >
              <el-option
                v-for="(item,index) in unusualReasonTypeList"
                :key="index"
                :label="item.typename"
                :value="{value:item.typecode,label:item.typename}"
              />
            </el-select>
          </td>
        </tr>
      </table>
    </el-form>
    <!--保存按钮-->
    <div class="but_footer">
      <div class="but_footer-h" />
      <div class="but_footer-but">
        <el-button :loading="confirmLoading" type="primary" @click="saveData('fromData')">
          提交
        </el-button>
        <el-button
          :loading="confirmLoading"
          @click="back"
        >
          返 回
        </el-button>
      </div>
    </div>
  </div>
</template>

<script>
/* 接口*/
import { pushBiddingFails } from '@api/huanengwuzids/index'
/* 选择标包组件*/
import stopbiddingRecordPackComponent from '../stopbiddingRecord/tenderStopbidding/stopbiddingRecordPackComponent.vue'
export default {
  name: 'RebiddingRecordAdd',
  components: {
    'stopbiddingRecord-pack-component': stopbiddingRecordPackComponent
  },
  data() {
    return {
      confirmLoading: false, // 暂存、下一步Loding
      tenderBase: this.$store.getters.tenderBase, // 项目信息
      tenderId: this.$route.query.id, // 项目id
      packInfoList: [], // 选择的标段（包）
      formData: {
        tenderId: this.$route.query.id, // 项目id
        stopBiddingPackId: '', // 标段id
        stopBiddingPackNo: '', // 标段编号
        stopBiddingPackName: '', // 标段名称
        stopBiddingBulletinName: '', // 公告名称
        unusualReasonText: '', // 异常原因记录
        unusualReasonType: '' // 异常原因类型 :00购标人不足,01投标人不足,02解密成功不足,03评审合格不足,04资审合格不足,05不认可,06撤项,07单一来源,08询价,09谈判,10其他
      },
      // 校验
      rules: {
        stopBiddingPackId: [{ required: true, message: '请选择', trigger: 'blur' }], // 标段
        unusualReasonType: [{ required: true, message: '请选择', trigger: 'blur' }] // 异常原因
      },
      /* 字典信息-start */
      unusualReasonTypeList: [] // 异常原因
      /* 字典信息-end */
    }
  },
  watch: {
    // 监听是否选择了标段
    packInfoList: {
      deep: true,
      handler: function(val) {
        if (val.length > 0) {
          this.formData.stopBiddingPackId = val[0].packId // 标段id
          this.formData.stopBiddingPackNo = val[0].packNo // 标段id
          this.formData.stopBiddingPackName = val[0].packName// 标段名称
          this.formData.stopBiddingBulletinName = '【' + val[0].packName + '】终止公告'// 公告名称
        }
      }

    }
  },
  created() {
    this.initGroup()// 获取字典方法
  },
  methods: {
    // 异常原因
    unusualReasonTypeChange(params) {
      const { value, label } = params
      this.formData.unusualReasonType = value
      this.formData.unusualReasonText = label
    },
    // 获取字典方法
    initGroup() {
      const data = [
        'unusualReasonType' // 招标方式
      ]
      this.$store.dispatch('getGroupType', data).then(res => {
        Object.keys(res.bidTypeData).forEach((key) => {
          this[key] = res.bidTypeData[key]
        })
      })
    },
    // 提交
    saveData(formName) {
      this.$confirm('确认提交吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        confirmButtonClass: 'confirmBtn',
        cancelButtonClass: 'cancelBtn',
        type: 'warning'
      }).then(() => {
        // 校验输入内容
        this.$refs[formName].validate((valid) => {
          if (valid) { // 校验通过
            pushBiddingFails(this.formData).then(response => {
              this.back()
              this.confirmLoading = false// btnLoding
            }).catch(() => {
              this.confirmLoading = false// btnLoding
            })
          }
        })
      }).catch(() => {
      })
    },
    // 返回
    back() {
      this.$router.push({
        path: '/bidding/projectDrive/biddingFailure/biddingFailureList',
        query: {
          ...this.$route.query
        }
      })
    }
  }
}
</script>

<style scoped lang="less">
  /deep/.file-list {
    .fileBtn,
    li {
      margin-bottom: 0 !important;
    }
    .name {
      margin-right: 0 !important;
    }
  }
</style>
