
<!--
  @description: 新增审核规则
  @Modifier: Joel
  @routerPath: /tenderPlan/bidInvitationPlanAudit-add
  @date: 2020-6-2
-->
<template>
  <div>
    <div class="title p0-16 clearfix">
      <div class="title-back pointer" @click="back">
        <i class="iconfont icon-fanhui mr10" />新增审核规则
      </div>
    </div>
    <div class="p0-16">
      <el-form
        ref="form"
        :model="formData"
        :inline-message="true"
      >
        <table class="from_table">
          <tr>
            <td>招标人</td>
            <td colspan="3">
              <el-input
                v-model="formData.buysersName"
                placeholder="请选择"
                style="width: calc(100% - 180px)"
                disabled
              />
              <el-button type="primary" @click="buysersDialog.dialog=true">
                选择
              </el-button>
              <el-button @click="buysersDialogInfo('clear')">
                清空
              </el-button>
            </td>
          </tr>
          <tr>
            <td>采购品类</td>
            <td colspan="3">
              <el-input
                v-model="formData.purchaseClassName"
                placeholder="请选择"
                style="width: calc(100% - 180px)"
                disabled
              />
              <el-button type="primary" @click="dialogData.dialog=true">
                选择
              </el-button>
              <el-button @click="categoryTreeInfo('clear')">
                清空
              </el-button>
            </td>
          </tr>
          <tr>
            <td>概算金额（元）</td>
            <td>
              <money :money-value="formData" :thousands="true" :unit-fixed="0" style="display: inline" width="calc((100% - 60px) / 2)" name="budgetAmountLower" />
              -
              <money :money-value="formData" :thousands="true" :unit-fixed="0" style="display: inline" width="calc((100% - 60px) / 2)" name="budgetAmountUpper" />
            </td>
            <td>采购级别</td>
            <td>
              <!-- 采购级别-->
              <el-select v-model="formData.purchaseLevel" style="width:100%" placeholder="请选择">
                <el-option
                  v-for="item in purchaseSchemeLevelList"
                  :key="item.value"
                  :label="item.typename"
                  :value="item.typecode"
                />
              </el-select>
            </td>
          </tr>
          <tr>
            <td>评标办法</td>
            <td>
              <el-select v-model="formData.bidEvaluationMethod" style="width:100%" placeholder="请选择">
                <el-option
                  v-for="(item,index) in purchasesSchemeProEvalMethodList"
                  :key="index"
                  :label="item.typename"
                  :value="item.typecode"
                />
              </el-select>
            </td>
            <td>采购类别</td>
            <td>
              <!-- 采购类别-->
              <el-select v-model="formData.purchaseCategory" style="width:100%" placeholder="请选择">
                <el-option
                  v-for="item in purchaseSchemeProjectTypeList"
                  :key="item.value"
                  :label="item.typename"
                  :value="item.typecode"
                />
              </el-select>
            </td>
          </tr>
          <tr>
            <td>采购类型</td>
            <td>
              <el-select v-model="formData.purchaseType" style="width:100%" placeholder="请选择">
                <el-option
                  v-for="item in purchaseSchemeTypeList"
                  :key="item.value"
                  :label="item.typename"
                  :value="item.typecode"
                />
              </el-select>
            </td>
            <td>默认审核状态</td>
            <td>审核不通过</td>
          </tr>
        </table>
      </el-form>
      <p style="color: red" class="mt10">
        提示：在审核规则范围的招标方案将自动审核不通过，需要手动审核
      </p>
    </div>
    <!-- 保存按钮 -->
    <div class="but_footer">
      <div class="but_footer-h">
        <div class="but_footer-but">
          <el-button type="primary" @click="submit('form')">
            生效
          </el-button>
        </div>
      </div>
    </div>
    <!-- 招标人 -->
    <subsidiaryOrganDialog :dialog-data="buysersDialog" @buyersInfo="buysersDialogInfo" />
    <!-- 采购品类 -->
    <category-tree-dialog :dialog-data="dialogData" @categoryTreeInfo="categoryTreeInfo" />
  </div>
</template>

<script>
/* api */
import { savePretPurchaseschemePretenderingSystemRule, getPretPurchaseschemePretenderingSystemRuleById } from '@/api/purchasePlan/pretcloudPurchasescheme'
/* 混入 */
import { tenderPlan } from '../../../mixins/tenderPlan'
import { tenderPlanAllotMixin } from '../../../mixins/tenderPlanAllotMixin'
/* 组件*/
import money from '@comp/common/money/money'
import subsidiaryOrganDialog from '@/views/purchasePlan/tenderPlan/tenderPlanInfo/baseInfo/subsidiaryOrgan-dialog'// 招标人-弹框
import categoryTreeDialog from '@/views/common/tools/categoryTree-dialog'// 采购品类-弹框
export default {
  name: 'BidInvitationPlanAuditRuleAdd',
  components: {
    money,
    subsidiaryOrganDialog,
    'category-tree-dialog': categoryTreeDialog // 采购品类-弹框
  },
  mixins: [tenderPlan, tenderPlanAllotMixin],
  data() {
    return {
      // 招标人
      buysersDialog: {
        dialog: false
      },
      // 弹窗-展示/隐藏状态 true 展示/false 隐藏
      dialogData: {
        title: '采购品类',
        dialog: false, // 采购品类
        selectCodes: [] // 当前选中的采购品类Code
      },
      formData: {
        budgetAmountUpper: '', // 概算金额（元）最大值
        budgetAmountLower: '', // 概算金额（元） 最小值
        buysersName: '', // 招标人
        buysersId: '', // 招标人Code
        purchaseClassName: '', // 采购品类
        purchaseClass: '', // 采购品类Code
        purchaseLevel: '', // 采购级别
        bidEvaluationMethod: '', // 评标办法
        purchaseCategory: '', // 采购类别
        purchaseType: '', // 采购类型
        isUsed: '01'// 启用/禁用,00禁用，01启用
      }
    }
  },
  watch: {
    // 采购品类Code
    'formData.purchaseClass'(val) {
      this.dialogData.selectCodes = val ? val.split(',') : []// 前选中的采购品类Code
    }
  },
  created() {
    // 获取字典
    this.initPurchaseSchemeWebTypeGroup()
    // 判断是否有id 如果有则是编辑
    if (this.$route.query.id) {
      this.initData(this.$route.query.id)// 初始化数据
    }
  },
  methods: {
    // 初始化数据
    initData(id) {
      getPretPurchaseschemePretenderingSystemRuleById(id).then(res => {
        this.formData = res.data
      })
    },
    // 保存接口信息
    saveData() {
      const data = {
        ...this.formData
      }
      savePretPurchaseschemePretenderingSystemRule(data).then(res => {
        this.back()// 返回
      })
    },
    // 生效
    submit(formName) {
      this.$refs[formName].validate((valid, field) => {
        if (valid) { // 校验通过
          const verify = this.verify()// 校验-mixins
          if (!verify) return verify// 不满足校验条件
          this.$confirm('确认生效本条分配规则吗？', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            confirmButtonClass: 'confirmBtn',
            cancelButtonClass: 'cancelBtn',
            type: 'warning'
          }).then(() => {
            this.saveData()
          }).catch(() => {
          })
        }
      })
    },
    // 招标人
    buysersDialogInfo(data) {
      if (data === 'clear') { // 清空
        this.formData.buysersName = ''
        this.formData.buysersId = ''
      } else { // 选择
        this.formData.buysersName = data.departName
        this.formData.buysersId = data.id
      }
    },
    // 采购品类选择/清空
    categoryTreeInfo(data) {
      if (data === 'clear') { // 清空
        this.formData.purchaseClassName = ''
        this.formData.purchaseClass = ''
      } else { // 选择
        this.formData.purchaseClassName = data.labels
        this.formData.purchaseClass = data.keys
      }
    },
    // 返回
    back() {
      this.$router.push({
        path: '/bidInvitation/bidInvitationPlanAuditRule-list'
      })
    }
  }
}
</script>

<style scoped>

</style>
