<template>
  <!-- <a-spin :spinning="confirmLoading"> -->
    <j-form-container>
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-divider orientation="left"> <span>基本信息</span> </a-divider>
          <a-col :span="24">
            <a-form-model-item label="联锁条件" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="interlockConditionData">
              <a-cascader
                v-model="model.interlockConditionData"
                :options="tagDataOptions"
                :fieldNames="customFieldNames"
                :show-search="true"
                :filter-option="filter"
                expand-trigger="hover"
                placeholder="请选择点位"
                @change="changeCascaderCondition"
                />
                <!-- :display-render="displayRender" -->
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="联锁设定值" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="interlockSetValue">
              <a-input v-model="model.interlockSetValue" placeholder="请输入联锁设定值"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="单位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="interlockSetUnit">
              <a-input v-model="model.interlockSetUnit" placeholder="请输入单位"></a-input>
            </a-form-model-item>
          </a-col>
          <!-- <a-col :span="24">
            <a-form-model-item label="当前值" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="currentValueData">
              <a-cascader
                v-model="model.currentValueData"
                :options="tagDataOptions"
                :fieldNames="customFieldNames"
                expand-trigger="hover"
                placeholder="请选择当前值"/>
            </a-form-model-item>
          </a-col> -->
          <a-col :span="24">
            <a-form-model-item label="输入卡件状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="inputStatusData">
              <a-radio-group name="radioGroup" v-model="model.inputStatusRadio" @change="statusRadioChange">
                <a-radio :value="'0'"> 默认正常 </a-radio>
                <a-radio :value="'1'"> 位号读取 </a-radio>
              </a-radio-group>
              <template v-if="model.inputStatusRadio === '0'">
                <a-input v-model="model.inputStatusDefault" disabled></a-input>
              </template>
              <template v-if="model.inputStatusRadio === '1'">
                <a-cascader
                  v-model="model.inputStatusData"
                  :options="tagDataOptions"
                  :fieldNames="customFieldNames"
                  :show-search="true"
                  :filter-option="filter"
                  expand-trigger="hover"
                  placeholder="请选择输入卡件状态"
                  @change="changeCascaderInput"
                  />
              </template>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="输出卡件状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="outputStatusData">
              <a-radio-group name="radioGroup" v-model="model.outputStatusRadio" @change="statusRadioChange">
                <a-radio :value="'0'"> 默认正常 </a-radio>
                <a-radio :value="'1'"> 位号读取 </a-radio>
              </a-radio-group>
              <template v-if="model.outputStatusRadio === '0'">
                <a-input v-model="model.outputStatusDefault" disabled></a-input>
              </template>
              <template v-if="model.outputStatusRadio === '1'">
                <a-cascader
                  v-model="model.outputStatusData"
                  :options="tagDataOptions"
                  :fieldNames="customFieldNames"
                  :show-search="true"
                  :filter-option="filter"
                  expand-trigger="hover"
                  placeholder="请选择输出卡件状态"
                  @change="changeCascaderOutput"
                />
              </template>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="MP状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="mpStatusData">
              <a-radio-group name="radioGroup" v-model="model.mpStatusRadio" @change="statusRadioChange">
                <a-radio :value="'0'"> 默认正常 </a-radio>
                <a-radio :value="'1'"> 位号读取 </a-radio>
              </a-radio-group>
              <template v-if="model.mpStatusRadio === '0'">
                <a-input v-model="model.mpStatusDefault" disabled></a-input>
              </template>
              <template v-if="model.mpStatusRadio === '1'">
                <a-cascader
                  v-model="model.mpStatusData"
                  :options="tagDataOptions"
                  :fieldNames="customFieldNames"
                  :show-search="true"
                  :filter-option="filter"
                  expand-trigger="hover"
                  placeholder="请选择MP状态"
                  @change="changeCascaderMp"
                />
              </template>
            </a-form-model-item>
          </a-col>
          <!-- 仪表状态开始 -->
          <a-divider orientation="left"> <span>仪表状态</span> </a-divider>
          <a-col :span="24">
            <!-- 0819修改需求为高低限判断和突变的默认值只为系统配置中的类别有关，此处无需修改类别但能自定义输入，若需要查看上一版代码见同级别的--choose或上一版git -->
            <a-form-model-item label="仪表状态判定依据" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="instrumentStatusJuge">
              <a-radio-group name="radioGroup" v-model="model.instrumentStatusJuge">
                <!-- @change="instrumentStatusJugeChange" -->
                <a-radio :value="'3'"> 默认正常 </a-radio>
                <a-radio :value="'0'"> 位号读取 </a-radio>
                <a-radio :value="'1'"> 高低限判断 </a-radio>
                <a-radio :value="'2'"> 突变超限判断 </a-radio>
              </a-radio-group>
              <template v-if="model.instrumentStatusJuge === '3'">
                <a-input v-model="model.instrumentStatusDefault" disabled></a-input>
                <!-- <a-col :span="24">
                </a-col> -->
              </template>
            </a-form-model-item>
          </a-col>
          <template v-if="model.instrumentStatusJuge === '0'">
            <a-col :span="24">
              <a-form-model-item label="仪表位号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="instrumentStatusData">
                <a-cascader
                  v-model="model.instrumentStatusData"
                  :options="tagDataOptions"
                  :fieldNames="customFieldNames"
                  :show-search="true"
                  :filter-option="filter"
                  expand-trigger="hover"
                  placeholder="请选择仪表位号"
                  @change="changeCascaderInstrument"
                />
              </a-form-model-item>
            </a-col>
          </template>
          <template v-if="model.instrumentStatusJuge === '1'">
            <a-col :span="24">
              <a-form-model-item label="原始模拟量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ysmnlData">
                <a-cascader
                  v-model="model.ysmnlData"
                  :options="tagDataOptions"
                  :fieldNames="customFieldNames"
                  :show-search="true"
                  :filter-option="filter"
                  expand-trigger="hover"
                  placeholder="请选择原始模拟量"
                  @change="changeCascaderYsmnl"
                />
              </a-form-model-item>
            </a-col>
            <a-col :span="24">
              <a-form-model-item label="高限值" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="upperLimitGd">
                <a-auto-complete :data-source="upperLimitGdDefault" v-model="model.upperLimitGd" :filter-option="filterOption" placeholder="请输入高限" @change="instrumentStatusChange"></a-auto-complete>
                <!-- <a-input v-model="model.upperLimitGd" placeholder="请输入高限"></a-input> -->
              </a-form-model-item>
            </a-col>
            <a-col :span="24">
              <a-form-model-item label="低限值" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="lowerLimitGd">
                <a-auto-complete :data-source="lowerLimitGdDefault" v-model="model.lowerLimitGd" :filter-option="filterOption" placeholder="请输入低限" @change="instrumentStatusChange"></a-auto-complete>
                <!-- <a-input v-model="model.lowerLimitGd" placeholder="请输入低限"></a-input> -->
              </a-form-model-item>
            </a-col>
          </template>
          <template v-if="model.instrumentStatusJuge === '2'">
            <a-col :span="24">
              <a-form-model-item label="原始模拟量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ysmnlData">
                <a-cascader
                  v-model="model.ysmnlData"
                  :options="tagDataOptions"
                  :fieldNames="customFieldNames"
                  :show-search="true"
                  :filter-option="filter"
                  expand-trigger="hover"
                  placeholder="请选择原始模拟量"
                  @change="changeCascaderYsmnl"
                />
              </a-form-model-item>
            </a-col>
            <a-col :span="24">
              <a-form-model-item label="突变判断公式" :labelCol="labelCol" :wrapperCol="wrapperCol" class="red-star-form-item">
                <div style="display: flex;">
                  <div style="width: 30px;text-align: center;">( </div>
                  <a-form-model-item prop="upperLimitTb">
                    <a-auto-complete :data-source="upperLimitTbDefault" v-model="model.upperLimitTb" :filter-option="filterOption" placeholder="请输入高限" @change="instrumentStatusChange"></a-auto-complete>
                    <!-- <a-input v-model="model.upperLimitTb" placeholder="请输入高限"></a-input> -->
                  </a-form-model-item>
                  <div style="width: 30px;text-align: center;"> - </div>
                  <a-form-model-item prop="lowerLimitTb">
                    <a-auto-complete :data-source="lowerLimitTbDefault" v-model="model.lowerLimitTb" :filter-option="filterOption" placeholder="请输入低限" @change="instrumentStatusChange"></a-auto-complete>
                    <!-- <a-input v-model="model.lowerLimitTb" placeholder="请输入低限"></a-input> -->
                  </a-form-model-item>
                  <div style="width: 60px;text-align: center;">）* </div>
                  <a-form-model-item prop="thresholdValueN">
                    <a-auto-complete :data-source="['1']" v-model="model.thresholdValueN" :filter-option="filterOption" placeholder="请输入阈值" @change="instrumentStatusChange"></a-auto-complete>
                    <!-- <a-input v-model="model.thresholdValueN" placeholder="请输入阈值"></a-input> -->
                  </a-form-model-item>
                  <div style="width: 30px;text-align: center;"> % </div>
                </div>
              </a-form-model-item>
            </a-col>
            <a-col :span="24">
              <a-form-model-item label="突变判断时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="thresholdTime">
                <a-input v-model="model.thresholdTime" suffix="S" placeholder="请输入时间"></a-input>
                <!-- suffix="S" -->
              </a-form-model-item>
            </a-col>
          </template>
          <a-col :span="24">
            <a-form-model-item label="描述" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="description">
              <a-input v-model="model.description" placeholder="请输入描述"></a-input>
            </a-form-model-item>
          </a-col>
          <!-- 仪表状态结束 -->

          <!-- 是否旁路 -->
          <a-divider orientation="left"> <span>旁路状态</span> </a-divider>
          <a-col :span="24">
            <a-form-model-item label="是否有旁路" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ifBypass">
              <a-radio-group name="radioGroup" v-model="model.ifBypass">
                <!--  :default-value="model.ifBypass" -->
                <a-radio :value="'0'"> 否 </a-radio>
                <a-radio :value="'1'"> 是 </a-radio>
                <a-radio :value="'2'"> 现场旁路 </a-radio>
              </a-radio-group>
              <template v-if="model.ifBypass === '0'">
                <a-input v-model="model.bypassDefault" disabled></a-input>
              </template>
            </a-form-model-item>
          </a-col>
          <template v-if="model.ifBypass === '1'">
            <a-col :span="24">
              <a-form-model-item label="旁路" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bypassData">
                <a-cascader
                  v-model="model.bypassData"
                  :options="tagDataOptions"
                  :fieldNames="customFieldNames"
                  :show-search="true"
                  :filter-option="filter"
                  expand-trigger="hover"
                  placeholder="请选择旁路"
                  @change="changeCascaderBypass"
                />
              </a-form-model-item>
            </a-col>
          </template>
          <template v-if="model.ifBypass === '2'">
            <a-col :span="24">
              <a-form-model-item label="旁路状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bypassNo">
                <a-select v-model="model.bypassNo" @change="bypassChange">
                  <a-select-option :value="item.value" v-for="item in byPassOptions" :key="item.value"> {{ item.title }} </a-select-option>
                </a-select>
              </a-form-model-item>
            </a-col>
          </template>
        </a-row>
      </a-form-model>
    </j-form-container>
  <!-- </a-spin> -->
</template>

<script>
  import { httpAction, getAction, postAction } from '@/api/manage'

  export default {
    name: 'InterlockConditionForm',
    props: {
      // 该系统设置的默认值
      itSystemDefaultValue: {
        type: Object,
        default: function(){
          return {} // 使用工厂函数返回默认值
        }
      },
      // 所有位号
      tagDataOptions: {
        type: Array,
        default: function(){
          return [] // 使用工厂函数返回默认值
        }
      },
    },
    data () {
      return {
        model:{
          inputStatusRadio: '0', // 输入卡件状态单选默认-默认值
          inputStatusDefault: null, // 输入卡件状态默认值默认参数
          outputStatusRadio: '0', // 输出卡件状态单选默认-默认值
          outputStatusDefault: null, // 输出卡件状态默认值默认参数
          mpStatusRadio: '0', // MP状态单选默认-默认值
          mpStatusDefault: null, // MP状态默认值默认参数
          instrumentStatusJuge: '3', // 仪表判定依据-默认正常
          instrumentStatusDefault: null, // 仪表状态默认值默认参数
          instrumentGDXT: '',
          instrumentTBXT: '',
          upperLimitGd: null,
          lowerLimitGd: null,
          upperLimitTb: null,
          lowerLimitTb: null,
          thresholdValueN: '1',
          ifBypass: '1', // 是否有旁路-是
          bypassDefault: null, // 是否有旁路-否显示的正常状态值
          bypassNo: '0', // 旁路默认值
          bypass: null, // MP状态默认值默认参数
        },
        upperLimitTbDefault: [],
        lowerLimitTbDefault: [],
        upperLimitGdDefault: [],
        lowerLimitGdDefault: [],
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        // confirmLoading: true,
        validatorRules: {
          interlockConditionData: [{
            required: true, message: '请选择联锁条件!',
          }],
          // instrumentStatusJuge: [{
          //   required: true, message: '请选择仪表状态判定依据!',
          // }],
          instrumentStatusData: [{
            required: true, message: '请选择仪表状态!',
          }],
          // 高低限
          ysmnlData: [{
            required: true, message: '请选择原始模拟量!',
          }],
          upperLimitGd: [{
            required: true, message: '请输入高限值!',
          }],
          lowerLimitGd: [{
            required: true, message: '请输入低限值!',
          }],
          upperLimitTb: [{
            required: true, message: '请输入高限值!',
          }],
          lowerLimitTb: [{
            required: true, message: '请输入低限值!',
          }],
          // 突变超限
          tbGongshi: [
            // { required: true, message: '', },
            { required: true, message: '请输入高限值!', },
            { required: true, message: '请输入低限值!', },
            { required: true, message: '请输入阈值!', },
          ],
          thresholdTime: [{
            required: true, message: '请输入时间!',
          }],
          thresholdValueN: [{
            required: true, message: '请输入阈值!',
          }],

          // interlockSetValue: [{
          //   required: true, message: '请输入联锁设定值!',
          // }],
          // currentValueData: [{
          //   required: true, message: '请选择当前值!',
          // }],
          ifBypass: [{
            required: true, message: '请选择是否旁路!',
          }],
          bypassData: [{
            required: true, message: '请选择旁路!',
          }],
          bypassNo: [{
            required: true, message: '请选择旁路状态!',
          }],
          // inputStatusData: [{
          //   required: true, message: '请选择!',
          // }],
          // outputStatusData: [{
          //   required: true, message: '请选择输出卡件状态!',
          // }],
          // mpStatusData: [{
          //   required: true, message: '请选择MP状态!',
          // }],
        },
        url: {
          interLockSelect: '/sys/dict/loadTreeData',
          add: "/summary/interlockSummary/add",
          edit: "/summary/interlockSummary/edit",
          queryById: "/summary/interlockSummary/queryById",
        },
        customFieldNames: {
          label: 'name',
          value: 'info',
          children: 'children'
        },
        // tagDataOptions: [],
      }
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      // 设置状态默认值和初始化值
      setDefaultValue(){
        // this.$set(this.model, 'inputStatusDefault', this.itSystemDefaultValue.controlSystemStatusNormal)
        var controlSystemStatusDefault = this.itSystemDefaultValue.controlSystemStatusNormalName +'('+ this.itSystemDefaultValue.controlSystemStatusNormal+')'
        this.model.inputStatusDefault = controlSystemStatusDefault
        this.model.outputStatusDefault = controlSystemStatusDefault
        this.model.mpStatusDefault = controlSystemStatusDefault
        // 仪表状态
        this.model.instrumentStatusDefault = this.itSystemDefaultValue.instrumentStatusNormalName +'('+ this.itSystemDefaultValue.instrumentStatusNormal+')'
        // 过滤数组
        var upperLimitTbDefault = this.itSystemDefaultValue.systemType === '0' ? '4095' : '59577'
        var lowerLimitTbDefault = this.itSystemDefaultValue.systemType === '0' ? '819' : '11915'
        var upperLimitGdDefault = this.itSystemDefaultValue.systemType === '0' ? '4258' : '61948'
        var lowerLimitGdDefault = this.itSystemDefaultValue.systemType === '0' ? '737' : '10722'
        this.upperLimitTbDefault.push(upperLimitTbDefault)
        this.lowerLimitTbDefault.push(lowerLimitTbDefault)
        this.upperLimitGdDefault.push(upperLimitGdDefault)
        this.lowerLimitGdDefault.push(lowerLimitGdDefault)
        
        // 旁路状态
        this.model.bypassDefault = this.itSystemDefaultValue.bypassYesName +'('+ this.itSystemDefaultValue.bypassYes+')'
        this.byPassOptions = []
        this.byPassOptions.push({
          value: this.itSystemDefaultValue.bypassYes,
          title: this.itSystemDefaultValue.bypassYesName +'('+ this.itSystemDefaultValue.bypassYes +')'
        })
        var noNormal = this.itSystemDefaultValue.bypassYes === '0' ? '1' : '0'
        this.byPassOptions.push({
          value: noNormal,
          title: this.itSystemDefaultValue.bypassNoName +'('+ noNormal +')'
        })
        // this.model.bypassNo = this.itSystemDefaultValue.bypassYesName +'('+ this.itSystemDefaultValue.bypassYes +')'
        // 初始化
        // this.model.thresholdValueN = '1'
      },
      // 过滤
      filterOption(input, option) {
        return (
          option.componentOptions.children[0].text.toUpperCase().indexOf(input.toUpperCase()) >= 0
        );
      },
      // displayRender({ labels }) {
      //   // 设置显示最有一位
      //   return labels[labels.length - 1];
      // },
      // 级联选择点位时赋值
      changeCascaderCondition(value, selectedOptions){
        this.model.interlockConditionDeviceId = value[0]
        this.model.interlockConditionModuleName = value[1]
        this.model.interlockConditionTag = value[2]
        this.model.interlockCondition = selectedOptions[2].value
        this.model = {...this.model}
      },
      changeCascaderInput(value, selectedOptions){
        this.model.inputStatus = selectedOptions[2].value
        this.model = {...this.model}
      },
      changeCascaderOutput(value, selectedOptions){
        this.model.outputStatus = selectedOptions[2].value
        this.model = {...this.model}
      },
      changeCascaderMp(value, selectedOptions){
        this.model.mpStatus = selectedOptions[2].value
        this.model = {...this.model}
      },
      // 仪表状态位号改变时赋值
      changeCascaderInstrument(value, selectedOptions){
        this.model.instrumentStatusDeviceId = value[0]
        this.model.instrumentStatusModuleName = value[1]
        this.model.instrumentStatusTag = value[2]
        this.model.instrumentStatusValue = selectedOptions[2].value
        this.model = {...this.model}
      },
      // 原始模拟量改变时赋值
      changeCascaderYsmnl(value, selectedOptions){
        this.model.ysmnlDeviceId = value[0]
        this.model.ysmnlModuleName = value[1]
        this.model.ysmnlTag = value[2]
        this.model.ysmnlValue = selectedOptions[2].value
        this.model = {...this.model}
      },
      // 旁路位号改变时赋值
      changeCascaderBypass(value, selectedOptions){
        this.model.bypassDeviceId = value[0]
        this.model.bypassModuleName = value[1]
        this.model.bypassTag = value[2]
        this.model.bypass = selectedOptions[2].value
        this.model = {...this.model}
      },
      // 级联选择过滤搜索
      filter(inputValue, path) {
        return path.some(option => (option.label).toLowerCase().indexOf(inputValue.toLowerCase()) > -1);
      },
      statusRadioChange(e){
        // console.log(e)
        // console.log(this.model.inputStatusRadio)
        // this.$set(this.model, 'inputStatusRadio', e.target.value)
        this.model = {...this.model}
      },
      instrumentStatusChange(){
        this.model = {...this.model}
      },
      // 是否旁路改变时 
      bypassChange(){
        this.model = { ...this.model }
      },
      add () {
        this.model.upperLimitGd = this.itSystemDefaultValue.systemType === '0' ? '4258' : '61948'
        this.model.lowerLimitGd = this.itSystemDefaultValue.systemType === '0' ? '737' : '10722'
        this.model.upperLimitTb = this.itSystemDefaultValue.systemType === '0' ? '4095' : '59577'
        this.model.lowerLimitTb = this.itSystemDefaultValue.systemType === '0' ? '819' : '11915'
        this.model.thresholdValueN = '1'
        // 设置状态默认值
        this.setDefaultValue()
      },
      edit (record) {
        // console.log(record)
        this.model = Object.assign({}, record);
        // 联锁条件
        this.model.interlockConditionData = [record.interlockConditionDeviceId, record.interlockConditionModuleName, record.interlockConditionTag]
        // 仪表状态
        if(record.instrumentStatusJuge === '0'){
          // 仪表状态-仪表状态位号
          this.model.instrumentStatusData = [record.instrumentStatusDeviceId, record.instrumentStatusModuleName, record.instrumentStatusTag]
        }
        if(this.model.instrumentStatusJuge === '1' || this.model.instrumentStatusJuge === '2'){
          // 仪表状态-原始模拟量位号
          this.model.ysmnlData = [record.ysmnlDeviceId, record.ysmnlModuleName, record.ysmnlTag]
        }
        if(this.model.instrumentStatusJuge === '1'){
          // 高低限赋值--依据转换后还保持刚刚的选择
          this.model.upperLimitGd = record.upperLimit
          this.model.lowerLimitGd = record.lowerLimit
        }else if(this.model.instrumentStatusJuge === '2'){
          this.model.upperLimitTb = record.upperLimit
          this.model.lowerLimitTb = record.lowerLimit
          // 仪表状态-阈值Math.round解决相乘会出现很多小数的情况
          this.model.thresholdValueN = Math.round(parseInt(record.thresholdValue)*100)
          // this.model.thresholdValueN = (parseInt(record.thresholdValue)*100).toFixed(0)
        } else {
          // 当前为默认状态或者位号读取时，赋默认值
          this.model.upperLimitGd = this.itSystemDefaultValue.systemType === '0' ? '4258' : '61948'
          this.model.lowerLimitGd = this.itSystemDefaultValue.systemType === '0' ? '737' : '10722'
          this.model.upperLimitTb = this.itSystemDefaultValue.systemType === '0' ? '4095' : '59577'
          this.model.lowerLimitTb = this.itSystemDefaultValue.systemType === '0' ? '819' : '11915'
          this.model.thresholdValueN = '1'
        }
        // 当前值
        // this.model.currentValueData = [record.currentValueDeviceId, record.currentValueModuleName, record.currentValueTag+'&'+record.currentValue]
        // 旁路
        if(record.ifBypass === '0'){
          this.model.bypassNo = '0'
          this.model.bypassNo = record.bypass
        }
        if(record.ifBypass === '1'){
          this.model.bypassNo = '0'
          this.model.bypassData = [record.bypassDeviceId, record.bypassModuleName, record.bypassTag]
        }
        if(record.ifBypass === '2'){
          this.model.bypassNo = record.bypass
        }
        // 输入卡件状态
        this.model.inputStatusRadio = record.inputStatusTag ? '1' : '0'
        if(record.inputStatusTag){
          this.model.inputStatusData = [record.inputStatusDeviceId, record.inputStatusModuleName, record.inputStatusTag]
        }
        // 输出卡件状态
        this.model.outputStatusRadio = record.outputStatusTag ? '1' : '0'
        if(record.outputStatusTag){
          this.model.outputStatusData = [record.outputStatusDeviceId, record.outputStatusModuleName, record.outputStatusTag]
        }
        // MP状态
        this.model.mpStatusRadio = record.mpStatusTag ? '1' : '0'
        if(record.mpStatusTag){
          this.model.mpStatusRadio = '1'
          this.model.mpStatusData = [record.mpStatusDeviceId, record.mpStatusModuleName, record.mpStatusTag]
        }
        this.setDefaultValue()
      },
      submitForm () {
        // const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            // 拆分级联选择器的数据传递后端使用-设备id、模块名称、点位、值
            // 改变了方式，有些赋值在级联选择时就赋值了
            
            // 仪表状态
            if(this.model.instrumentStatusJuge === '3'){
              // 默认正常
              this.model.instrumentStatusDeviceId = null
              this.model.instrumentStatusModuleName = null
              this.model.instrumentStatusTag = null
              this.model.instrumentStatusValue = this.itSystemDefaultValue.instrumentStatusNormal
            }

            if(this.model.instrumentStatusJuge === '1'){
              // 根据状态给后端高低限赋值
              this.model.upperLimit = this.model.upperLimitGd
              this.model.lowerLimit = this.model.lowerLimitGd
            }
            if(this.model.instrumentStatusJuge === '2'){
              this.model.upperLimit = this.model.upperLimitTb
              this.model.lowerLimit = this.model.lowerLimitTb
              // 仪表状态-阈值--设置thresholdValueN是防止自身转换出现问题
              this.model.thresholdValue = parseInt(this.model.thresholdValueN)/100
            }
            
            // 当前值-去掉了
            // this.model.currentValueDeviceId = this.model.currentValueData[0]
            // this.model.currentValueModuleName = this.model.currentValueData[1]
            // this.model.currentValueTag = (this.model.currentValueData[2].split('&'))[0]
            // this.model.currentValue = (this.model.currentValueData[2].split('&'))[1]

            // 旁路位号
            if(this.model.ifBypass === '0'){
              // 否
              this.model.bypass = this.itSystemDefaultValue.bypassYes
            }
            // if(this.model.ifBypass === '1'){
            //   // 是
            //   this.model.bypassDeviceId = this.model.bypassData[0]
            //   this.model.bypassModuleName = this.model.bypassData[1]
            //   this.model.bypassTag = (this.model.bypassData[2].split('&'))[0]
            //   this.model.bypass = (this.model.bypassData[2].split('&'))[1]
            // }
            if(this.model.ifBypass === '2'){
              // 现场旁路
              this.model.bypass = this.model.bypassNo
              // this.model.bypass = this.itSystemDefaultValue.bypassYes
            }
            
            // 输入卡件状态
            if(this.model.inputStatusRadio === '1' && this.model.inputStatusData && this.model.inputStatusData.length  > 0){
              // 传位号
              this.model.inputStatusDeviceId = this.model.inputStatusData[0]
              this.model.inputStatusModuleName = this.model.inputStatusData[1]
              this.model.inputStatusTag = this.model.inputStatusData[2]
            } else {
              this.model.inputStatusDeviceId = null
              this.model.inputStatusModuleName = null
              this.model.inputStatusTag = null
              // 由于需要变成正常(0)的状态，且默认是正常，所以直接用系统的正常状态赋值
              // 如果需要改成下拉选择，就得换个方式写了
              // this.model.inputStatus = this.model.inputStatusDefault
              this.model.inputStatus = this.itSystemDefaultValue.controlSystemStatusNormal
            }
            
            // 输出卡件状态
            if(this.model.outputStatusRadio === '1' && this.model.outputStatusData && this.model.outputStatusData.length  > 0){
              this.model.outputStatusDeviceId = this.model.outputStatusData[0]
              this.model.outputStatusModuleName = this.model.outputStatusData[1]
              this.model.outputStatusTag = this.model.outputStatusData[2]
            } else {
              this.model.outputStatusDeviceId = null
              this.model.outputStatusModuleName = null
              this.model.outputStatusTag = null
              this.model.outputStatus = this.itSystemDefaultValue.controlSystemStatusNormal
            }

            // MP状态
            if(this.model.mpStatusRadio === '1' && this.model.mpStatusData && this.model.mpStatusData.length  > 0){
              this.model.mpStatusDeviceId = this.model.mpStatusData[0]
              this.model.mpStatusModuleName = this.model.mpStatusData[1]
              this.model.mpStatusTag = this.model.mpStatusData[2]
            } else {
              this.model.mpStatusDeviceId = null
              this.model.mpStatusModuleName = null
              this.model.mpStatusTag = null
              this.model.mpStatus = this.itSystemDefaultValue.controlSystemStatusNormal
            }
            console.log(this.model)
            this.$emit('ok', this.model)
          }
         
        })
      },
    }
  }
</script>
<style lang="less">
  .red-star-form-item{
    margin-bottom: 0;
    .ant-form-item-label {
      ::before {
        display: inline-block;
        margin-right: 4px;
        color: #ff4d4f;
        font-size: 14px;
        font-family: SimSun, sans-serif;
        line-height: 1;
        content: '*';
      }
    }
  }
</style>