<!--
  @description: 项目规则之公开竟价组件
  @author: gmy
  @date: 2020-7-3 9:23:58
-->
<template>
  <div>
    <table class="from_table">
      <!--    收取标书费  收取保证金   集团内用户禁用   -->
      <!-- <tr>
        <td><el-form-item ref="isReceiveTenderDocumentPrice" :rules="rules.isReceiveTenderDocumentPrice" label="收取标书费" prop="isReceiveTenderDocumentPrice"/></td>
        <td>
          <el-radio-group v-model="dataRule.isReceiveTenderDocumentPrice" :disabled="raidioType" >
            <el-radio
              v-for="(item) in documentPrice"
              :key="item.id"
              :label="item.typecode">
              {{ item.typename }}
        </el-radio></el-radio-group></td>
        <td>
        <el-form-item ref="isReceiveTenderBailPrice" :rules="rules.isReceiveTenderBailPrice" label="收取保证金" prop="isReceiveTenderBailPrice"/></td>
        <td>
          <el-radio-group v-model="dataRule.isReceiveTenderBailPrice" :disabled="raidioType">
            <el-radio
              v-for="(item) in bailPrice"
              :key="item.id"
              :label="item.typecode">
              {{ item.typename }}
            </el-radio>
          </el-radio-group>
        </td>
      </tr> -->
      <!--    标书费金额 保证金金额   -->
      <!-- <tr v-if="dataRule.isReceiveTenderDocumentPrice==='01'|| dataRule.isReceiveTenderBailPrice==='01'">
        <td v-if="dataRule.isReceiveTenderDocumentPrice==='01'">
          <el-form-item v-for="(item, index) in dataRule.protProjectDocumentPriceList " :key="index" :prop="'protProjectDocumentPriceList.' + index + '.documentPrice'" :rules="rules.documentPrice" :inline-message="true" label="标书费金额(元)"/>
        </td>
        <td v-if="dataRule.isReceiveTenderDocumentPrice==='01'"> -->
      <!--金额组件-->
      <!-- <money :thousands="true" :money-value="dataRule.protProjectDocumentPriceList[0]" name="documentPrice"/>
        </td>
        <td v-if="dataRule.isReceiveTenderDocumentPrice==='00'"/>
        <td v-if="dataRule.isReceiveTenderDocumentPrice==='00'"/>
        <td v-if="dataRule.isReceiveTenderBailPrice==='01'">
          <el-form-item v-for="(item, index) in dataRule.protProjectBailPriceList " :key="index" :prop="'protProjectBailPriceList.' + index + '.bailPrice'" :rules="rules.bailPrice" :inline-message="true" label="保证金金额(元)"/>
        </td>
        <td v-if="dataRule.isReceiveTenderBailPrice==='01'"> -->
      <!--金额组件-->
      <!-- <money :thousands="true" :money-value="dataRule.protProjectBailPriceList[0]" name="bailPrice"/>
        </td>
        <td v-if="dataRule.isReceiveTenderBailPrice==='00'"/>
        <td v-if="dataRule.isReceiveTenderBailPrice==='00'"/>
      </tr> -->
      <!--    币种- 付款方式-是否含运费       -->
      <tr>
        <td>
          <el-form-item ref=" currency" label="币种" prop="currency" />
        </td>
        <td>
          <el-select v-model="dataRule.currency">
            <el-option
              v-for="(item) in currencyList"
              :key="item.id"
              :label="item.typename"
              :value="item.typecode"
            />
          </el-select>
        </td>
        <td>
          <el-form-item ref="payType" :rules="rules.payType" label="付款方式" prop="payType" />
        </td>
        <td>
          <el-select
            v-model="dataRule.payType"
            filterable
            clearable
            style="width:100%"
          >
            <el-option
              v-for="(item) in payTypelist"
              :key="item.id"
              :label="item.typename"
              :value="item.typecode"
            />
          </el-select>
        </td>
      </tr>
      <!--    强制上传文件 是否含运费      -->
      <tr style="height: 50px">
<!--        <td>
          <el-form-item label="强制上传应答文件" prop="autoExtension" />
        </td>
        <td>
          <el-radio-group v-model="dataRule.isUploadReplyFile">
            <el-radio
              v-for="(item) in uploadReplyFileList"
              :key="item.typecode"
              :label="item.typecode"
            >
              {{ item.typename }}
            </el-radio>
          </el-radio-group>
        </td>-->
        <td>
          <el-form-item ref="isContainsFreight" label="是否含运费" prop="isContainsFreight" />
        </td>
        <td colspan="3">
          <el-radio-group v-model="dataRule.isContainsFreight">
            <el-radio
              v-for="(item) in containsFreightList"
              :key="item.id"
              :label="item.typecode"
            >
              {{ item.typename }}
            </el-radio>
          </el-radio-group>
        </td>
      </tr>
      <!-- 审核报名 -->
      <!-- <tr>
        <td>
          <el-form-item ref="isFile" :rule="rules.signupAudit" label="审核报名" prop="signupAudit" />
        </td>
        <td colspan="3">
          <el-radio-group v-model="dataRule.signupAudit">
            <el-radio
              v-for="(item) in signupAudit"
              :key="item.id"
              :label="item.typecode"
              :disabled="fileFlag"
            >
              {{ item.typename }}
            </el-radio>
          </el-radio-group>
        </td>
      </tr> -->
    </table>
    <div class="page-title">
      2.竞价规则
    </div>
    <table class="from_table">
      <!--    竞价开始时间-竞价时长        -->
      <tr>
        <td>
          <el-form-item ref="quoteStartTime" :rules="rules.quoteStartTime" label="竞价开始时间" prop="quoteStartTime" />
        </td>
        <td>
          <el-date-picker
            v-model="dataRule.quoteStartTime"
            :picker-options="disabledPickerOptions"
            :value-format="elValueSaveFormat"
            :default-time="defaultTimeDateTime"
            type="datetime"
            placeholder="选择日期时间"
            style="width:100%"
          />
        </td>
        <td>
          <el-form-item ref="quoteTime" :rules="rules.quoteTime" label="竞价时长" prop="quoteTime" />
        </td>
        <td>
          <div style="display: flex">
            <el-input v-model="dataRule.quoteTime" placeholder="只允许输入正整数" onkeyup="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}" onafterpaste="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}" clearable />
            <el-select v-model="dataRule.quoteTimeUnit" :placeholder="language.Pleasechoose">
              <el-option
                v-for="item in quoteTimeUnit"
                :key="item.id"
                :label="item.typename"
                :value="item.typecode"
              />
            </el-select>
          </div>
        </td>
      </tr>
      <!--    竞价类型-控制价格（元）       -->
      <tr>
        <td>
          <el-form-item ref="comparePriceType" :rules="rules.comparePriceType" label="竞价类型" prop="comparePriceType" />
        </td>
        <td>
          <el-radio-group v-model="dataRule.comparePriceType">
            <el-radio
              v-for="(item) in comparePriceType"
              :key="item.id"
              :label="item.typecode"
            >
              {{ item.typename }}
            </el-radio>
          </el-radio-group>
        </td>
        <td>
          <el-form-item ref="comparePrice" :label="title+text" inline-message="true" prop="comparePrice" />
        </td>
        <td>
          <el-input
            v-model="dataRule.comparePrice"
            placeholder="只允许输入数值"
            style="width:80%"
            onkeyup="this.value= this.value.match(/([1-9]\d*|0)+(\.\d{0,2})?/)?this.value.match(/([1-9]\d*|0)+(\.\d{0,2})?/)[0]:''"
            clearable
          />
        </td>
      </tr>
      <!--    报价次数-报价最小幅度       -->
      <tr>
        <td>
          <el-form-item ref="quoteCountType" :rules="rules.quoteCountType" label="报价次数(次)" prop="quoteCountType" />
        </td>
        <td>
          <el-radio-group v-model="dataRule.quoteCountType">
            <el-radio
              v-for="(item) in quoteCountType"
              :key="item.id"
              :label="item.typecode"
            >
              {{ item.typename }}
            </el-radio>
          </el-radio-group>
          <el-input v-model.trim="dataRule.quoteCount" :rules="rules.quoteCount" :disabled="disflags" maxlength="3" placeholder="正整数" style="width:49%;" onkeyup="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}" onafterpaste="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}" clearable />
        </td>
        <td>
          <el-form-item ref="quoteRangeType" :rules="rules.quoteRangeType" :label="titleTab" prop="quoteRangeType" />
        </td>
        <td>
          <el-radio-group v-model="dataRule.quoteRangeType">
            <el-radio
              v-for="(item) in quoteRangeType"
              :key="item.id"
              :label="item.typecode"
            >
              {{ item.typename }}
            </el-radio>
          </el-radio-group>
          <el-input
            v-model="dataRule.quoteRangePrice"
            :disabled="flag"
            placeholder="最多8位正整数2位小数"
            maxlength="11"
            style="width:43%;margin-left:40px;"
            onkeyup="this.value= this.value.match(/\d{1,8}.{0,1}\d{0,2}/) ? this.value.match(/\d{1,8}.{0,1}\d{0,2}/)[0] : ''"
            clearable
          />
        </td>
      </tr>
      <!--     超时竞价-超时竞价延长       -->
      <tr>
        <td>
          <el-form-item ref="quoteOutTime" :rules="rules.quoteOutTime" label="超时竞价"	prop="quoteOutTime" />
        </td>
        <td colspan="3" class="clearfix">
          <el-row>
            <el-col :md="12" :lg="12" class="fl" style="width:437px">
              <span style="font-size:12px;">竞价倒计时</span>
              <el-input v-model="dataRule.quoteOutTime" placeholder="1-4位正整数" style="width:118px" maxlength="4" onkeyup="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}" onafterpaste="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}" clearable />
              <el-select v-model="dataRule.quoteOutTimeUnit" :placeholder="language.Pleasechoose" style="width:25%">
                <el-option
                  v-for="item in quoteOutTimeUnit"
                  :key="item.id"
                  :label="item.typename"
                  :value="item.typecode"
                />
              </el-select>
              <span style="font-size:12px;">内,有人报价进入超时竞价</span>
            </el-col>
            <el-col :md="12" :lg="12" class="fl">
              <el-form-item ref="quoteOutTimeAddTime" :rules="rules.quoteOutTimeAddTime" label="超时竞价延长" label-width="160px" style="font-size:12px;" prop="quoteOutTimeAddTime">
                <el-input v-model.trim="dataRule.quoteOutTimeAddTime" maxlength="6" placeholder="正整数" style="width:49%;" onkeyup="if(this.value.length==1){this.value=this.value.replace(/[^1-9]{1-4}/g,'')}else{this.value=this.value.replace(/\D/g,'')}" onafterpaste="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}" clearable />
                <el-select v-model="dataRule.quoteOutTimeAddTimeUnit" :placeholder="language.Pleasechoose" style="width:25%">
                  <el-option
                    v-for="item in quoteOutTimeAddTimeUnit"
                    :key="item.id"
                    :label="item.typename"
                    :value="item.typecode"
                  />
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
        </td>
      </tr>
      <!--     是否公开参与的竞价家数-是否公开排名      -->
      <tr>
        <td>
          <el-form-item ref="isPublicSupplierCount" :rules="rules.isPublicSupplierCount" label="是否公开参与的竞价家数" label-width="180px" prop="isPublicSupplierCount" />
        </td>
        <td>
          <el-radio-group v-model="dataRule.isPublicSupplierCount">
            <el-radio
              v-for="(item) in isPublicSupplierCount"
              :key="item.id"
              :label="item.typecode"
            >
              {{ item.typename }}
            </el-radio>
          </el-radio-group>
        </td>
        <td>
          <el-form-item ref="isPublicSupplierRanking" :rules="rules.isPublicSupplierRanking" label="是否公开竞价排名" prop="isPublicSupplierRanking" />
        </td>
        <td>
          <el-radio-group v-model="dataRule.isPublicSupplierRanking">
            <el-radio
              v-for="(item) in isPublicSupplierRanking"
              :key="item.id"
              :label="item.typecode"
            >
              {{ item.typename }}
            </el-radio>
          </el-radio-group>
        </td>
      </tr>
      <!--   是否公开竞价方名称-是否公开报价金额      -->
      <tr v-if="dataRule.isPublicSupplierCount === '01'">
        <td>
          <el-form-item ref="isPublicSupplierName" :rules="rules.isPublicSupplierName" label="是否公开竞价方名称" prop="isPublicSupplierName" />
        </td>
        <td>
          <el-radio-group v-model="dataRule.isPublicSupplierName">
            <el-radio
              v-for="(item) in isPublicSupplierName"
              :key="item.id"
              :label="item.typecode"
            >
              {{ item.typename }}
            </el-radio>
          </el-radio-group>
        </td>
        <td>
          <el-form-item ref="isPublicSupplierPrice" :rules="rules.isPublicSupplierPrice" label="是否公开报价金额" prop="isPublicSupplierPrice" />
        </td>
        <td>
          <el-radio-group v-model="dataRule.isPublicSupplierPrice">
            <el-radio
              v-for="(item) in isPublicSupplierPrice"
              :key="item.id"
              :label="item.typecode"
            >
              {{ item.typename }}
            </el-radio>
          </el-radio-group>
        </td>
      </tr>
      <tr>
        <td>
          <el-form-item ref="comparePriceMethod" :rules="rules.comparePriceMethod" label="竞价方式" prop="comparePriceMethod" />
        </td>
        <td colspan="3">
          <el-radio-group v-model="dataRule.comparePriceMethod">
            <el-radio
              v-for="(item) in comparePriceMethod"
              :key="item.id"
              :label="item.typecode"
            >
              {{ item.typename }}
            </el-radio>
          </el-radio-group>
        </td>
      </tr>
    </table>
  </div>
</template>

<script>
/* 公用方法*/
import { checkMoney, checkRate, characters1_auto } from '@assets/js/validate.js' // 常用方法
/* 混合开发*/
import { procurementProjectGroupMixin } from '@/views/procurement/procurementProject/mixins/procurementProjectGroupMixin'// 立项采购-字典
// import money from '@comp/common/money/money'
// vuex
import { mapGetters } from 'vuex'
export default {
  name: 'ProcurementProjectAdd',
  components: {
    // money
  },
  mixins: [procurementProjectGroupMixin],
  props: {
    dataRule: {
      type: Object,
      default: () => {
        return {}
      }
    }
  },
  data() {
    return {
      quoteCount: '',
      value: '',
      raidioType: false,
      confirmLoading: false,
      disflags: true,
      flgsaction: true,
      flag: true,
      fileFlag: true, // 审核开关
      labellocaltion: 'left',
      status: '', // 采购方式：10公开询价  11邀请询价  12竞争性谈判  13竞争性磋商   14公开竞价  15邀请竞价  16单一来源采购
      amounttenderfeeflg: false, // 标书费金额显示隐藏
      depositflg: false, // 保证金金额显示隐藏
      title: '控制', // 限价
      text: '价格(元)', // 限价
      titleTab: '报价最小幅度(元)', // 价格幅度
      procurementDocumentsFlg: false, // 标书费收取显示隐藏
      depositflgs: false, // 线下收取
      // 校验输入内容
      rules: {
        payType: [{ required: true, validator: characters1_auto, trigger: 'change' }], // 付款方式
        isReceiveTenderDocumentPrice: [{ required: true, message: '请选择', trigger: 'blur' }], // 收取标书费
        isReceiveTenderBailPrice: [{ required: true, message: '请选择', trigger: 'blur' }], // 收取保证金
        documentPrice: [{ required: true, validator: checkMoney, trigger: 'blur' }], // 标书费金额
        bailPrice: [{ required: true, validator: checkMoney, trigger: 'blur' }], // 保证金金额
        signupAudit: [{ required: true, message: '请选择', trigger: 'blur' }], // 审核报名
        quoteStartTime: [{ required: true, message: '请选择', trigger: 'blur' }], // 竞价开始时间
        quoteTime: [{ required: true, message: '请输入', trigger: 'blur' }], // 竞价时长
        comparePriceType: [{ required: true, message: '请选择', trigger: 'blur' }], // 竞价类型
        quoteCountType: [{ required: true, message: '请选择', trigger: 'blur' }], // 报价次数
        quoteCount: [{ required: true, message: '请输入', trigger: 'blur' }], // 报总价金额
        quoteRangePrice: [{ required: true, message: '请输入', trigger: 'blur' }], // 报价最小幅度金额
        quoteRangeType: [{ required: true, message: '输入', trigger: 'blur' }], // 报价最小幅度
        quoteOutTime: [{ required: true, validator: checkRate, trigger: 'blur' }], //  超时竞价
        quoteOutTimeAddTime: [{ required: true, validator: checkRate, trigger: 'blur' }], // 超时竞价延长单位
        isPublicSupplierCount: [{ required: true, message: '请选择', trigger: 'blur' }], // 是否公开参与的竞价家数
        isPublicSupplierName: [{ required: true, message: '请选择', trigger: 'blur' }], // 是否公开竞价方名称
        isPublicSupplierPrice: [{ required: true, message: '请选择', trigger: 'blur' }], // 是否公开报价金额
        isPublicSupplierRanking: [{ required: true, message: '请选择', trigger: 'blur' }] // 是否公开竞价排名
      }
    }
  },
  computed: {
    /* language 国际化*/
    ...mapGetters(['language'])
  },
  watch: {
    'dataRule.isFile'(val) {
      // 采购文件
      if (val === '00') {
        this.procurementDocumentsFlg = false
      } else {
        this.procurementDocumentsFlg = true
      }
    },
    'dataRule.quotePriceMethod'(val) {
      if (val === '00') {
        this.flgsaction = false
      } else {
        this.flgsaction = true
      }
    },
    // 报总价
    'dataRule.quoteCountType'(val) {
      if (val === '01') {
        this.disflags = false
      } else {
        this.dataRule.quoteCount = ''
        this.disflags = true
      }
    },
    'dataRule.isReceiveTenderDocumentPrice'(val) {
      // 收取标书费隐藏显示
      if (val === '00') {
        this.amounttenderfeeflg = false
      } else {
        this.amounttenderfeeflg = true
        this.dataRule.protProjectDocumentPriceList[0].documentPrice = ''
      }
    },
    'dataRule.isReceiveTenderBailPrice'(val) {
      // 收取保证金隐藏显示
      if (val === '00') {
        this.depositflg = false
        this.depositflgs = false
      } else {
        if (val === '02') {
          this.dataRule.protProjectBailPriceList[0].bailPrice = ''
          this.depositflg = true
          this.depositflgs = false
        } else {
          this.dataRule.protProjectBailPriceList[0].bailPrice = ''
          this.depositflg = true
          this.depositflgs = true
        }
      }
    },
    'dataRule.comparePriceType'(val) {
      // 竞价方式转换字
      if (val === '01') {
        this.text = '折扣率(%)'
        this.titleTab = '报价最小幅度(%)'
      } else {
        this.text = '价格(元)'
        this.titleTab = '报价最小幅度(元)'
      }
    },
    'dataRule.quoteRangeType'(val) {
      // 竞价方式转换字
      if (val === '01') {
        this.flag = false
      } else {
        this.flag = true
        this.dataRule.quoteRangePrice = ''
      }
    }

  },
  created() {
    // 调用项目规则字典方法
    this.initqueryProcurementProjectRuleInitInfo()
    this.fileFlag = this.$route.query.tenderType === '01' ? this.fileFlag : !this.fileFlag
    if (this.$route.query.systemType === '00' && this.$route.query.sourceType.indexOf('01B') !== -1) {
      this.raidioType = true
      this.dataRule.isReceiveTenderBailPrice = '00'
      return
    }
    this.raidioType = false
  },
  methods: {
    // 保存或提交时 组装数据然后返回
    assemblyData() {
      const data = {
        id: this.dataRule.id,
        tenderId: this.$route.query.tenderId, // 项目id
        isReceiveTenderDocumentPrice: this.dataRule.isReceiveTenderDocumentPrice, // 是否收取标书费
        isReceiveTenderBailPrice: this.dataRule.isReceiveTenderBailPrice, // 是否收取保证金
        protProjectDocumentPriceList: this.dataRule.protProjectDocumentPriceList, // 标书费金额
        protProjectBailPriceList: this.dataRule.protProjectBailPriceList, // 保证金金额
        currency: this.dataRule.currency, // 币种
        payType: this.dataRule.payType, // 付费方式
        isUploadReplyFile: this.dataRule.isUploadReplyFile, // 强制上传应答文件
        isContainsFreight: this.dataRule.isContainsFreight, // 是否含运费
        signupAudit: this.dataRule.signupAudit, // 审核报名
        quoteStartTime: this.$Moment(this.dataRule.quoteStartTime).format(this.momentSaveFormat), // 竞价开始时间 保存时间保留至秒 不够补00
        quoteTime: this.dataRule.quoteTime, // 竞价时长
        quoteTimeUnit: this.dataRule.quoteTimeUnit, // 竞价时长单位
        comparePriceType: this.dataRule.comparePriceType, // 竞价类型
        comparePrice: this.dataRule.comparePrice, // 控制价额
        quoteCountType: this.dataRule.quoteCountType, // 报价次数
        quoteCount: this.dataRule.quoteCount, // 报价次数文本框
        quoteRangeType: this.dataRule.quoteRangeType, // 报价最小幅度
        quoteRangePrice: this.dataRule.quoteRangePrice, // 报价最小幅度 最低幅度
        quoteOutTime: this.dataRule.quoteOutTime, // 超时竞价
        quoteOutTimeUnit: this.dataRule.quoteOutTimeUnit, // 超时竞价单位
        quoteOutTimeAddTime: this.dataRule.quoteOutTimeAddTime, // 超时竞价延长
        quoteOutTimeAddTimeUnit: this.dataRule.quoteOutTimeAddTimeUnit, //  超时竞价延长单位
        isPublicSupplierCount: this.dataRule.isPublicSupplierCount, // 是否公开参与的竞价家数
        isPublicSupplierRanking: this.dataRule.isPublicSupplierRanking, // 是否公开竞价排名
        isPublicSupplierName: this.dataRule.isPublicSupplierName, // 是否公开竞价方名称
        isPublicSupplierPrice: this.dataRule.isPublicSupplierPrice, // 是否公开报价金额
        comparePriceMethod: this.dataRule.comparePriceMethod // 竞价方式
      }
      // 返回
      return data
    }
  }
}
</script>

<style lang="less" scoped>

  /deep/.show-word-limit-padding{
    .el-input__inner{
      padding-right: 70px;
    }
  }
</style>
