<!--
  @description: 录入委员会信息-基本信息
  @author:肖文龙
  @date: 2020年3月9日22:07:37
-->
<template>
  <div>
    <el-form ref="formData" :model="data" :rules="rules" label-width="140px" :disabled="judgesStatus==='02'">
      <el-row :gutter="40">
        <el-col :md="24" :lg="12">
          <!--批次号-->
          <el-form-item label="批次号">
            <el-input
              v-model="data.batchNumber"
              disabled
              show-word-limit
              maxlength="200"
              placeholder="批次号"
            />
          </el-form-item>
        </el-col>
        <el-col :md="24" :lg="12">
          <!--评标委员会名称-->
          <el-form-item ref="juryName" label="评标委员会名称" prop="juryName">
            <el-input v-model="data.juryName" show-word-limit maxlength="600" placeholder="最多允许输入300个汉字(600字符)" />
          </el-form-item>
        </el-col>
        <el-col>
          <!--标段（包）-->
          <el-form-item label="标段（包）">
            <el-button type="text" @click="dialogData.dialog=true">
              查看标段（包）列表
            </el-button>
          </el-form-item>
        </el-col>
        <el-col :md="24" :lg="12">
          <!--抽取类型-->
          <el-form-item
            ref="extractionType"
            label="抽取类型"
            prop="extractionType"
          >
            <el-radio-group v-model="data.extractionType">
              <el-radio v-for="(item,index) in extractionTypeList" :key="index" :label="item.typecode">
                {{ item.typename }}
              </el-radio>
            </el-radio-group>
          </el-form-item>
          <!--通知方式-->
          <el-form-item
            ref="notificationMode"
            label="通知方式"
            prop="notificationMode"
          >
            <el-radio-group v-model="data.notificationMode">
              <el-radio v-for="(item,index) in informWayList" :key="index" :label="item.typecode" disabled>
                {{ item.typename }}
              </el-radio>
            </el-radio-group>
          </el-form-item>
          <!--评委会总人数-->
          <el-form-item ref="juryPeopleNumber" label="评委会总人数" prop="juryPeopleNumber">
            <el-input
              v-model="data.juryPeopleNumber"
              type="number"
              show-word-limit
              disabled
              maxlength="20"
              placeholder="评委会总人数"
            />
          </el-form-item>
          <!--招标代表人数-->
          <el-form-item ref="representNumber" label="招标代表人数" prop="representNumber">
            <el-input
              v-model="data.representNumber"
              disabled
              type="number"
              show-word-limit
              maxlength="15"
              placeholder="招标代表人数"
            />
          </el-form-item>
          <!--
          技术组人数
          分组情况下展示
          -->
          <el-form-item
            v-if="data.judgesGroupedStatus==='01'"
            ref="technicalExpertsSelectedNumber"
            label="技术组人数"
            prop="technicalExpertsSelectedNumber"
          >
            <el-input
              v-model="data.technicalExpertsSelectedNumber"
              disabled
              type="number"
              show-word-limit
              maxlength="15"
              placeholder="技术组人数"
            />
          </el-form-item>
          <!--联系电话-->
          <el-form-item ref="contactTel" label="联系电话" prop="contactTel">
            <el-input v-model="data.contactTel" maxlength="30" placeholder="联系电话" />
          </el-form-item>
          <!--监抽人-->
          <el-form-item ref="superintendent" label="监抽人" prop="superintendent">
            <el-input v-model="data.superintendent" show-word-limit maxlength="20" placeholder="监抽人" />
          </el-form-item>
          <!--评标结束时间-->
          <el-form-item ref="evaluationEndTime" label="评标结束时间" prop="evaluationEndTime">
            <el-date-picker
              v-model="data.evaluationEndTime"
              :picker-options="disabledPickerOptions"
              :format="elValueFormat"
              :value-format="elValueSaveFormat"
              type="datetime"
              placeholder="选择日期时间"
            />
          </el-form-item>
        </el-col>
        <el-col :md="24" :lg="12">
          <!--评委会组建方式-->
          <el-form-item ref="juryBuildType" label="评委会组建方式" prop="juryBuildType">
            <el-radio-group v-model="data.juryBuildType" disabled>
              <el-radio v-for="(item,index) in juryOrganizeWayList" v-if="item.typecode" :key="index" :label="item.typecode">
                {{
                  item.typename }}
              </el-radio>
            </el-radio-group>
          </el-form-item>
          <!--限制65岁以上专家-->
          <el-form-item ref="isLimitOverAge" label="限制65岁以上专家" prop="isLimitOverAge">
            <el-radio-group v-model="data.isLimitOverAge">
              <el-radio v-for="(item,index) in limitTheExpertList" :key="index" :label="item.typecode">
                {{ item.typename }}
              </el-radio>
            </el-radio-group>
          </el-form-item>
          <!--评标专家人数-->
          <el-form-item ref="juryExpertsNumber" label="评标专家人数" prop="juryExpertsNumber">
            <el-input
              v-model="data.juryExpertsNumber"
              disabled
              type="number"
              show-word-limit
              maxlength="15"
              placeholder="评标专家人数"
            />
          </el-form-item>

          <!--商务组人数
            分组情况下展示
          -->
          <el-form-item
            v-if="data.judgesGroupedStatus==='01'"
            ref="businessExpertsSelectedNumber"
            label="商务组人数"
            prop="businessExpertsSelectedNumber"
          >
            <el-input
              v-model="data.businessExpertsSelectedNumber"
              disabled
              type="number"
              show-word-limit
              maxlength="15"
              placeholder="商务组人数"
            />
          </el-form-item>
          <!--联系人-->
          <el-form-item ref="extractApplicationContact" label="联系人" prop="extractApplicationContact">
            <el-input v-model="data.extractApplicationContact" show-word-limit maxlength="20" placeholder="联系人" />
          </el-form-item>
          <!--联系人所在单位-->
          <el-form-item ref="company" label="联系人所在单位" prop="company">
            <el-input
              v-model="data.company"
              disabled
              show-word-limit
              maxlength="600"
              placeholder="最多允许输入300个汉字(600字符)"
            />
          </el-form-item>
          <!--评标开始时间-->
          <el-form-item ref="evaluationStartTime" label="评标开始时间" prop="evaluationStartTime">
            <el-date-picker
              v-model="data.evaluationStartTime"
              :picker-options="disabledPickerOptions"
              :format="elValueFormat"
              :value-format="elValueSaveFormat"
              type="datetime"
              placeholder="选择日期时间"
            />
          </el-form-item>
          <!--评标地点-->
          <!--evaluationPlace -->
          <el-form-item ref="evaluationPlaceCode" label="评标地点" prop="evaluationPlaceCode">
            <el-select v-model="data.evaluationPlaceCode" @change="handleEvaluationPlace">
              <el-option
                v-for="item in evaluationPlaceList"
                :key="item.typecode"
                :label="item.typename"
                :value="item.typecode"
              />
            </el-select>
            <el-input v-if="data.evaluationPlaceCode==='3'" v-model="data.evaluationPlace" show-word-limit maxlength="1000" placeholder="最多允许输入500个汉字(1000字符)" style="margin-left:10px;width: calc(100% - 225px)" />
          </el-form-item>
        </el-col>
        <el-col>
          <!--备注-->
          <el-form-item
            ref="remarks"
            label="备注"
            prop="remarks"
          >
            <el-input
              v-model="data.remarks"
              :autosize="{ minRows: 8, maxRows: 8 }"
              type="textarea"
              show-word-limit
              maxlength="4000"
              placeholder="最多允许输入4000个汉字(8000字符)"
            />
          </el-form-item>
          <!--附件-->
          <div style="margin-left: 95px;">
            <upload
              ref="upload"
              :data="upLoadData"
              :auto-delete="true"
              :auto-upload="true"
              title="附件"
              file-ref="fileRef"
            />
          </div>
        </el-col>
      </el-row>
    </el-form>
    <!--查看标段（包）列表弹框-->
    <packageInfoDialog :dialog-data="dialogData" />
  </div>
</template>

<script>
/* api*/
import { queryJuryInformationById } from '@/api/intensiveeval/intensiveeval'
/* 公共方法*/
import { checkLinktel, linkerName, checkRate, validateInput, characters1_auto } from '@/assets/js/validate'// 校验
import { validFn } from '@assets/js/utils'// 生成随机Id//校验//总数计算
import { intensiveEvaluationMixin } from '@/views/intensiveeval/mixins/intensiveevalMixin.js'// 集约化评标-公共参数
/* 混合开发*/
import { ListMixin } from '@/mixins/ListMixin'// 分页搜索
import { groupMixin } from '@/views/intensiveeval/mixins/intensiveevalGroupMixin'// 字典信息
/* 组件*/
import upload from '@comp/common/updownload/upload'// 文件上传
import packageInfoDialog from './packageInfo-dialog'// 查看标段（包）列表弹框
import { formatTimeSecond } from '@/assets/js/utils' // 保存时间初始化00秒
import { setInterval, clearInterval } from 'timers'
export default {
  name: 'BasicInformationAdd',
  components: {
    upload,
    packageInfoDialog
  },
  mixins: [ListMixin, groupMixin, intensiveEvaluationMixin],
  props: {
    data: {
      type: Object,
      default: function() {
        return {
        }
      }
    }
  },

  data() {
    return {
      setinterval: null, // 定时器
      /* 字典信息-start */
      evaluationPlaceList: [], // 评标地点
      /* 字典信息-end */
      judgesStatus: this.$route.query.judgesStatus, // 评委会状态02为抽取失败 禁用基本信息表单项
      // 查看标段（包）列表  弹框展示状态
      dialogData: {
        dialog: false,
        groupId: '' // 分组id
      },
      // 校验
      rules: {
        juryName: [{ required: true, validator: validateInput, trigger: 'blur' }], // 评标委员会名称
        extractionType: [{ required: true, message: '请选择', trigger: 'change' }], // 抽取类型
        notificationMode: [{ required: true, message: '请选择', trigger: 'change' }], // 通知方式
        juryPeopleNumber: [{ required: true, validator: checkRate, trigger: 'change' }], // 评委会总人数
        representNumber: [{ required: true, validator: checkRate, trigger: 'blur' }], // 招标代表人数
        contactTel: [{ required: true, validator: checkLinktel, trigger: 'blur' }], // 联系电话
        superintendent: [{ required: true, validator: linkerName, trigger: 'blur' }], // 监抽人
        evaluationEndTime: [{ required: true, message: '请选择', trigger: 'change' }], // 评标结束时间
        juryBuildType: [{ required: true, message: '请选择', trigger: 'change' }], // 评委会组件方式
        isLimitOverAge: [{ required: true, message: '请选择', trigger: 'change' }], // 限制65岁以上专家
        juryExpertsNumber: [{ required: true, validator: checkRate, trigger: 'blur' }], // 评标专家人数
        businessExpertsSelectedNumber: [{ required: true, validator: checkRate, trigger: 'blur' }], // 商务组人数
        technicalExpertsSelectedNumber: [{ required: true, validator: checkRate, trigger: 'blur' }], // 技术组人数
        extractApplicationContact: [{ required: true, validator: linkerName, trigger: 'blur' }], // 联系人
        evaluationStartTime: [{ required: true, message: '请选择', trigger: 'change' }], // 评标开始时间
        evaluationPlaceCode: [{ required: true, validator: characters1_auto, trigger: 'change' }] // 评标地点
      }
    }
  },
  watch: {
    // 评标开始时间
    'data.evaluationStartTime'(val) {
      this.checkTime()// 校验时间
    },
    // 评标结束时间
    'data.evaluationEndTime'(val) {
      this.checkTime()// 校验时间
    }
  },
  beforeDestroy() {
    // 清除定时
    clearInterval(this.setinterval)
  },
  created() {
    this.initData()// 初始化基本信息
    // 定时刷新
    const _this = this
    this.setinterval = setInterval(function() {
      Promise.resolve().then(() => {
        _this.initData()
      })
    }, 5000)
    this.initGroup() // 获取字典方法
  },
  methods: {
    // 获取字典方法
    initGroup() {
      const data = [
        'evaluationPlace' // 评标地点字典信息
      ]
      this.$store.dispatch('getGroupType', data).then(res => {
        Object.keys(res.bidTypeData).forEach((key) => {
          this[key] = res.bidTypeData[key]
        })
      })
    },
    // 评标地点
    handleEvaluationPlace() {
      this.$forceUpdate()
    },
    // 初始化基本信息
    initData() {
      const data = {
        juryId: this.$route.query.juryId, // 评委会id
        groupId: this.$route.query.groupId // 分组id
      }
      queryJuryInformationById(data).then(res => {
        this.dialogData.groupId = res.data.groupingstatisticsId
        for (const key in res.data) {
          this.data[key] = res.data[key]
        }
        //  初始化数据
        if (!this.data.evaluationPlaceCode) this.data.evaluationPlaceCode = ''
        if (!this.data.extractionType) this.data.extractionType = '00'// 抽取类型（00资格审查委员会 01评标委员会）
        if (!this.data.juryBuildType) this.data.juryBuildType = '00'// 评委会会组建方式 00随机抽取 01直接指定
        if (!this.data.isLimitOverAge) this.data.isLimitOverAge = '01'// 是否限制65岁以上专家 00不限制 01限制
        /* 若为随机抽取，此处默认为语音通知
        若为直接指定，此处默认为人工通知*/
        if (this.data.juryBuildType === '00') {
          this.data.notificationMode = '00'// 通知方式（00语音通知 01人工通知）
        } else {
          this.data.notificationMode = '01'// 通知方式（00语音通知 01人工通知）
        }
        /* 自动带出用户信息*/
        const info = this.$store.state.user.info// 账号基本信息
        this.data.company = info.companyName// 联系人所在单位
        this.data.extractApplicationContact = this.data.extractApplicationContact || info.realName // 联系人
        this.data.contactTel = this.data.contactTel || info.mobilePhone // 联系电话
        this.$router.push({ query: {
          ...this.$route.query,
          juryId: this.data.id// 评委会Id
        }})
        // 附件
        this.upLoadData.bizId = this.data.id // 业务主键Id
      })
    },
    // 转化时间
    transformTime(startTime, endTime) {
      return this.$Moment(endTime).diff(this.$Moment(startTime), 'days')
    },
    // 校验时间
    checkTime() {
      /*
        * 计算相差天数
        * 评标开始时间 ,评标结束时间
        * */
      // 接收答疑截止时间
      const dataTime = {
        evaluationStartTime: '', // 评标开始时间
        evaluationEndTime: '' // 评标结束时间
      }
      if (this.data.evaluationStartTime) dataTime.evaluationStartTime = formatTimeSecond(this.data.evaluationStartTime)
      if (this.data.evaluationEndTime) dataTime.evaluationEndTime = formatTimeSecond(this.data.evaluationEndTime)
      const days = this.transformTime(dataTime.evaluationStartTime, dataTime.evaluationEndTime)
      if (days < 0) {
        this.$message({
          message: '【评标结束时间】应不小于【评标开始时间】',
          type: 'warning'
        })
        return days > 0
      } else {
        this.handleCheckTime(dataTime)
      }
    },
    // 触发评标时间传递给兄弟组件
    handleCheckTime(dataTime) {
      // 评标时间
      const evaluationTime = {
        evaluationStartTime: dataTime.evaluationStartTime,
        evaluationEndTime: dataTime.evaluationEndTime
      }
      this.$bus.$emit('on-checkTime', evaluationTime)
    },
    // 保存组装数据
    assemblyData(status) {
      const data = {
        ...this.data,
        status// 提交状态
      }
      // 评标开始时间
      if (data.evaluationStartTime) {
        data.evaluationStartTime = formatTimeSecond(data.evaluationStartTime)
      }
      // 评标结束时间
      if (data.evaluationEndTime) {
        this.data.evaluationEndTime = formatTimeSecond(this.data.evaluationEndTime)
      }
      return data
    },
    /*
  * 校验
  * formName 校验的form表单
  * */
    submit() {
      let isValid = false // 是否通过校验
      const checkTime = this.checkTime()// 校验时间 布尔值
      if (checkTime) return
      this.$forceUpdate()
      this.$refs.formData.validate((valid, field) => {
        if (valid) {
          isValid = true
        } else {
          validFn(field, this)// 校验》跳转到为通过的参数地点
          isValid = false
        }
      })
      return isValid
    }
  }
}
</script>

<style lang="less" scoped>

</style>

