<template>
  <el-dialog v-dialogDrag :title="title" :visible.sync="dialogVisible" width="60%" :before-close="handleClose" center :close-on-click-modal="false">
    <data-form ref="dataTop" :form="formTop" :inline="inline" :form-model="formModel" :rules="topRules" />
    <el-collapse v-model="activeNames">
      <el-collapse-item title="IBP盘AFC闸机配置对象" name="1">
        <el-row :gutter="20">
          <el-col :span="12">
            <el-card class="box-card">
              <div slot="header" class="clearfix">
                <span>输入配置:</span>
              </div>
              <div style="margin-top: 20px">
                <data-form ref="dataAfcLeft" :form="formAfc.left" :form-model="formModel.afczjConfig" />
              </div>
            </el-card>
          </el-col>
          <el-col :span="12">
            <el-card class="box-card">
              <div slot="header" class="clearfix">
                <span>输出配置:</span>
              </div>
              <div style="margin-top: 20px">
                <data-form ref="dataAfcRight" :form="formAfc.right" :form-model="formModel.afczjConfig" />
              </div>
            </el-card>
          </el-col>
        </el-row>
      </el-collapse-item>
      <el-collapse-item title="IBP盘电梯和扶梯配置对象" name="2">
        <el-row :gutter="20">
          <el-col :span="12">
            <el-card class="box-card">
              <div slot="header" class="clearfix">
                <span>输入配置:</span>
              </div>
              <div style="margin-top: 20px">
                <data-form ref="dataElevatorLeft" :form="formElevator.left" :form-model="formModel.dftConfig" />
              </div>
            </el-card>
          </el-col>
          <el-col :span="12">
            <el-card class="box-card">
              <div slot="header" class="clearfix">
                <span>输出配置:</span>
              </div>
              <div style="margin-top: 20px">
                <data-form ref="dataElevatorRight" :form="formElevator.right" :form-model="formModel.dftConfig" />
              </div>
            </el-card>
          </el-col>
        </el-row>
      </el-collapse-item>
      <el-collapse-item title="IBP盘环境与设备监控配置对象" name="3">
        <el-row :gutter="20">
          <el-col :span="12">
            <el-card class="box-card">
              <div slot="header" class="clearfix">
                <span>输入配置:</span>
              </div>
              <div style="margin-top: 20px">
                <data-form ref="dataMonitorLeft" :form="formMonitor.left" :form-model="formModel.hjsbjkConfig" />
              </div>
            </el-card>
          </el-col>
          <el-col :span="12">
            <el-card class="box-card">
              <div slot="header" class="clearfix">
                <span>输出配置:</span>
              </div>
              <div style="margin-top: 20px">
                <data-form ref="dataMonitorRight" :form="formMonitor.right" :form-model="formModel.hjsbjkConfig" />
              </div>
            </el-card>
          </el-col>
        </el-row>
      </el-collapse-item>
      <el-collapse-item title="IBP盘门禁配置对象" name="4">
        <el-row :gutter="20">
          <el-col :span="12">
            <el-card class="box-card">
              <div slot="header" class="clearfix">
                <span>输入配置:</span>
              </div>
              <div style="margin-top: 20px">
                <data-form ref="dataEgLeft" :form="formEg.left" :form-model="formModel.mjConfig" />
              </div>
            </el-card>
          </el-col>
          <el-col :span="12">
            <el-card class="box-card">
              <div slot="header" class="clearfix">
                <span>输出配置:</span>
              </div>
              <div style="margin-top: 20px">
                <data-form ref="dataEgRight" :form="formEg.right" :form-model="formModel.mjConfig" />
              </div>
            </el-card>
          </el-col>
        </el-row>
      </el-collapse-item>
      <el-collapse-item title="IBP盘屏蔽门配置对象" name="5">
        <el-row :gutter="20">
          <el-col :span="12">
            <el-card class="box-card">
              <div slot="header" class="clearfix">
                <span>输入配置:</span>
              </div>
              <div style="margin-top: 20px">
                <data-form ref="dataPsdLeft" :form="formPsd.left" :form-model="formModel.pbmConfig" />
              </div>
            </el-card>
          </el-col>
          <el-col :span="12">
            <el-card class="box-card">
              <div slot="header" class="clearfix">
                <span>输出配置:</span>
              </div>
              <div style="margin-top: 20px">
                <data-form ref="dataPsdRight" :form="formPsd.right" :form-model="formModel.pbmConfig" />
              </div>
            </el-card>
          </el-col>
        </el-row>
      </el-collapse-item>
      <el-collapse-item title="IBP盘隧道通风配置对象" name="6">
        <el-row :gutter="20">
          <el-col :span="12">
            <el-card class="box-card">
              <div slot="header" class="clearfix">
                <span>输入配置:</span>
              </div>
              <div style="margin-top: 20px">
                <data-form ref="dataTunnelLeft" :form="formTunnel.left" :form-model="formModel.sdtfConfig" />
              </div>
            </el-card>
          </el-col>
          <el-col :span="12">
            <el-card class="box-card">
              <div slot="header" class="clearfix">
                <span>输出配置:</span>
              </div>
              <div style="margin-top: 20px">
                <data-form ref="dataTunnelRight" :form="formTunnel.right" :form-model="formModel.sdtfConfig" />
              </div>
            </el-card>
          </el-col>
        </el-row>
      </el-collapse-item>
      <el-collapse-item title="IBP盘信号配置对象" name="7">
        <el-row :gutter="20">
          <el-col :span="12">
            <el-card class="box-card">
              <div slot="header" class="clearfix">
                <span>输入配置:</span>
              </div>
              <div style="margin-top: 20px">
                <data-form ref="dataTunnelLeft" :form="formTunnel.left" :form-model="formModel.xhConfig" />
              </div>
            </el-card>
          </el-col>
          <el-col :span="12">
            <el-card class="box-card">
              <div slot="header" class="clearfix">
                <span>输出配置:</span>
              </div>
              <div style="margin-top: 20px">
                <data-form ref="dataTunnelRight" :form="formTunnel.right" :form-model="formModel.xhConfig" />
              </div>
            </el-card>
          </el-col>
        </el-row>
      </el-collapse-item>
      <el-collapse-item title="IBP盘消火栓泵配置对象" name="8">
        <el-row :gutter="20">
          <el-col :span="12">
            <el-card class="box-card">
              <div slot="header" class="clearfix">
                <span>输入配置:</span>
              </div>
              <div style="margin-top: 20px">
                <data-form ref="dataFhLeft" :form="formFh.left" :form-model="formModel.xhsbConfig" />
              </div>
            </el-card>
          </el-col>
          <el-col :span="12">
            <el-card class="box-card">
              <div slot="header" class="clearfix">
                <span>输出配置:</span>
              </div>
              <div style="margin-top: 20px">
                <data-form ref="dataFhRight" :form="formFh.right" :form-model="formModel.xhsbConfig" />
              </div>
            </el-card>
          </el-col>
        </el-row>
      </el-collapse-item>
      <el-collapse-item title="IBP盘环境与设备监控——站台层配置对象" name="9">
        <el-row :gutter="20">
          <el-col :span="12">
            <el-card class="box-card">
              <div slot="header" class="clearfix">
                <span>输入配置:</span>
              </div>
              <div style="margin-top: 20px">
                <data-form ref="dataEemPlatformLeft" :form="formEemPlatform.left" :form-model="formModel.hjsbjkConfig.pfConfig" />
              </div>
            </el-card>
          </el-col>
          <el-col :span="12">
            <el-card class="box-card">
              <div slot="header" class="clearfix">
                <span>输出配置:</span>
              </div>
              <div style="margin-top: 20px">
                <data-form ref="dataEemPlatformRight" :form="formEemPlatform.right" :form-model="formModel.hjsbjkConfig.pfConfig" />
              </div>
            </el-card>
          </el-col>
        </el-row>
      </el-collapse-item>
      <el-collapse-item title="IBP盘环境与设备监控——站厅层配置对象" name="10">
        <el-row :gutter="20">
          <el-col :span="12">
            <el-card class="box-card">
              <div slot="header" class="clearfix">
                <span>输入配置:</span>
              </div>
              <div style="margin-top: 20px">
                <data-form ref="dataEemHallLeft" :form="formEemHall.left" :form-model="formModel.hjsbjkConfig.shfConfig" />
              </div>
            </el-card>
          </el-col>
          <el-col :span="12">
            <el-card class="box-card">
              <div slot="header" class="clearfix">
                <span>输出配置:</span>
              </div>
              <div style="margin-top: 20px">
                <data-form ref="dataEemHallRight" :form="formEemHall.right" :form-model="formModel.hjsbjkConfig.shfConfig" />
              </div>
            </el-card>
          </el-col>
        </el-row>
      </el-collapse-item>
    </el-collapse>
    <span slot="footer" class="dialog-footer">
      <el-button type="primary" @click="doSave">{{ $t('global.confirm') }}</el-button>
      <el-button @click="handleClose">{{ $t('global.cancel') }}</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { getDeviceDetail, setIbpConfig} from '@/api/project';
import { deepAssign } from '@/utils/index';
export default {
    name: 'EditConfigIbp',
    data() {
        var validateDevice = (rule, value, callback) => {
            const list = [];
            rule.list.forEach(item=> {
                if (item.value !== rule.field && this.formModel[item.value] && this.formModel[item.value] === value) {
                    list.push(item.label);
                } else if (item.value === rule.field) {
                    list.push(item.label);
                }
            });
            if (!this.formModel.quantity) {
                this.$refs.datatop.validateField('quantity');
            }
            if (list.length > 1) {
                let repeatedValue = '';
                list.forEach((item, index) => {
                    repeatedValue += item;
                    if (index !== list.length - 1) {
                        repeatedValue += '与';
                    }
                });
                callback(new Error(repeatedValue + '位置重复，请调整！'));
            } else if (this.formModel.quantity && value >= this.formModel.quantity) {
                callback(new Error('网关位应小于位数量！'));
            } else {
                callback();
            }
        };
        return {
            title: '编辑IBP盘配置',
            activeNames: '',
            checkCount: 0,
            data: null,
            formModel: {
                afczjConfig: {},
                dftConfig: {},
                hjsbjkConfig: {
                    pfConfig: {},
                    shfConfig: {}
                },
                mjConfig: {},
                pbmConfig: {},
                sdtfConfig: {},
                xhConfig: {},
                xhsbConfig: {}
            },
            topRules: {
                addr: [
                    { required: true, message: '请填写网关位地址', trigger: 'blur' }
                ],
                quantity: [
                    { required: true, message: '请填写位数量', trigger: 'blur'}
                ],
                ribpsd: [
                    { required: true, message: '请填写IBP盘试灯按钮位', trigger: 'blur'}
                ],
                wibpsdand: [
                    { required: true, message: '请填写IBP盘试灯指示灯位', trigger: 'blur'}
                ]
            },
            dialogVisible: false,
            inline: true,
            formAfc:{
                left: {
                    labelWidth: '220px',
                    items: [
                        { prop:'rjjsf', label: '紧急释放按钮:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'ryskg', label: '钥匙开关:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0}
                    ]
                },
                right: {
                    labelWidth: '220px',
                    items: [
                        { prop:'wjjsfand', label: '紧急释放按钮灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wjjsfztzsd', label: '紧急释放状态指示灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wxfldzsd', label: '消防联动指示灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wyxwzsd', label: '有效位指示灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0}
                    ]
                }
            },
            formElevator: {
                left: {
                    labelWidth: '220px',
                    items: [
                        { prop:'rdt01tt', label: '电梯01停梯按钮:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'rft01tt', label: '扶梯01停梯按钮:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'rft02tt', label: '扶梯02停梯按钮:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'rft03tt', label: '扶梯03停梯按钮:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'rft04tt', label: '扶梯04停梯按钮:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'ryskg', label: '钥匙开关:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0}
                    ]
                },
                right: {
                    labelWidth: '220px',
                    items: [
                        { prop:'wdt01sxzsd', label: '电梯01上行指示灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wdt01ttand', label: '电梯01停梯按钮灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wdt01xxzsd', label: '电梯01下行指示灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wdt01zsd', label: '电梯01指示灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wft01sxzsd', label: '扶梯01上行指示灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wft01ttand', label: '扶梯01停梯按钮灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wft01xxzsd', label: '扶梯01下行指示灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wft01zsd', label: '扶梯01指示灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wft02sxzsd', label: '扶梯02上行指示灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wft02ttand', label: '扶梯02停梯按钮灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wft02xxzsd', label: '扶梯02下行指示灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wft02zsd', label: '扶梯02指示灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wft03sxzsd', label: '扶梯03上行指示灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wft03ttand', label: '扶梯03停梯按钮灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wft03xxzsd', label: '扶梯03下行指示灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wft03zsd', label: '扶梯03指示灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wft04sxzsd', label: '扶梯04上行指示灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wft04ttand', label: '扶梯04停梯按钮灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wft04xxzsd', label: '扶梯04下行指示灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wft04zsd', label: '扶梯04指示灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wyskgzsd', label: '开关指示灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0}
                    ]
                }

            },
            formMonitor: {
                left: {
                    labelWidth: '220px',
                    items: [
                        { prop:'rfw', label: '复位按钮:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'rzhkg', label: '自动/手动钥匙转换开关:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0}
                    ]
                },
                right: {
                    labelWidth: '220px',
                    items: [
                        { prop:'wfwand', label: '复位按钮灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wsdztzsd', label: '手动状态指示灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wzdztzsd', label: '自动状态指示灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wzhkgzsd', label: '自动/手动钥匙转换开关手动位指示灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0}
                    ]
                }
            },
            formEg: {
                left: {
                    labelWidth: '220px',
                    items: [
                        { prop:'radjjsf', label: 'A端紧急释放按钮:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'rbdjjsf', label: 'B端紧急释放按钮:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0}
                    ]
                },
                right: {
                    labelWidth: '220px',
                    items: [
                        { prop:'wadjjsfand', label: 'A端紧急释放按钮灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wadjjsfzsdg', label: 'A端紧急释放绿色指示灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wadjjsfzsdr', label: 'A端紧急释放红色指示灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wadjjsfzsdy', label: 'A端紧急释放黄色指示灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wbdjjsfand', label: 'B端紧急释放按钮灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wbdjjsfzsdg', label: 'B端紧急释放绿色指示灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wbdjjsfzsdr', label: 'B端紧急释放红色指示灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wbdjjsfzsdy', label: 'B端紧急释放黄色指示灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0}
                    ]
                }

            },
            formPsd: {
                left: {
                    labelWidth: '220px',
                    items: [
                        { prop:'rsxczyx', label: '上行操作允许钥匙开关:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'rsxgm', label: '上行关门按钮:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'rsxkm', label: '上行开门按钮:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'rxxczyx', label: '下行操作允许钥匙开关:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'rxxgm', label: '下行关门按钮:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'rxxkm', label: '下行开门按钮:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0}
                    ]
                },
                right: {
                    labelWidth: '220px',
                    items: [
                        { prop:'wsxczyxzsd', label: '上行操作允许指示灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wsxgmand', label: '上行关门按钮灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wsxgmsbzsd', label: '上行关门锁闭指示灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wsxkmand', label: '上行开门按钮灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wsxkmdwzsd', label: '上行开门到位指示灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wxxczyxzsd', label: '下行操作允许指示灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wxxgmand', label: '下行关门按钮灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wxxgmsbzsd', label: '下行关门锁闭指示灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wxxkmand', label: '下行开门按钮灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wxxkmdwzsd', label: '下行开门到位指示灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0}
                    ]
                }
            },
            formTunnel: {
                left: {
                    labelWidth: '220px',
                    items: [
                        { prop:'rsxcrdx', label: '上行出入段线按钮:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'rsxczsdhz', label: '上行车站隧道火灾按钮:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'rsxhz1y', label: '上行火灾1右按钮:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'rsxhz2y', label: '上行火灾2右按钮:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'rsxzc1y', label: '上行阻塞1右按钮:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'rsxzc2y', label: '上行阻塞2右按钮 :', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'rsxzthz', label: '上行站台火灾按钮:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'rxxcrdx', label: '下行出入段线按钮:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'rxxczsdhz', label: '下行车站隧道火灾按钮:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'rxxhz1y', label: '下行火灾1右按钮:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'rxxhz2y', label: '下行火灾2右按钮:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'rxxzc1y', label: '下行阻塞1右按钮:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'rxxzc2y', label: '下行阻塞2右按钮:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'rxxzthz', label: '下行站台火灾按钮:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0}
                    ]
                },
                right: {
                    labelWidth: '220px',
                    items: [
                        { prop:'wsxcrdxand', label: '上行出入段线按钮灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wsxczsdhzand', label: '上行车站隧道火灾按钮灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wsxhz1yand', label: '上行火灾1右按钮灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wsxhz2yand', label: '上行火灾2右按钮灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wsxzc1yand', label: '上行阻塞1右按钮灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wsxzc2yand', label: '上行阻塞2右按钮灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wsxzthzand', label: '上行站台火灾按钮灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wxxcrdxand', label: '下行出入段线按钮灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wxxczsdhzand', label: '下行车站隧道火灾按钮灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wxxhz1yand', label: '下行火灾1右按钮灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wxxhz2yand', label: '下行火灾2右按钮灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wxxzc1yand', label: '下行阻塞1右按钮灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wxxzc2yand', label: '下行阻塞2右按钮灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wxxzthzand', label: '下行站台火灾按钮灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0}
                    ]
                }
            },
            formSign: {
                left: {
                    labelWidth: '220px',
                    items:[
                        { prop:'rsxjjtc', label: '上行紧急停车按钮:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'rsxjljc', label: '上行警铃解除按钮:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'rsxkc', label: '上行扣车按钮:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'rsxqxjjtc', label: '上行取消紧急停车按钮:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'rsxqxkc', label: '上行取消扣车按钮:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'rsxsd', label: '上行试灯按钮:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'rxxjjtc', label: '下行紧急停车按钮:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'rxxjljc', label: '下行警铃解除按钮:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'rxxkc', label: '下行扣车按钮:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'rxxqxjjtc', label: '下行取消紧急停车按钮:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'rxxqxkc', label: '下行取消扣车按钮:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'rxxsd', label: '下行试灯按钮:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0}
                    ]
                },
                right: {
                    labelWidth: '220px',
                    items:[
                        { prop:'wfmq', label: '蜂鸣器:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wsxjjtccand', label: '上行紧急停车按钮灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wsxjjtczsd', label: '上行取消紧急停车按钮灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wsxjljcand', label: '上行警铃解除按钮灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wsxkcand', label: '上行扣车按钮灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wsxkczsd', label: '上行扣车指示灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wsxqxjjtcand', label: '上行取消紧急停车按钮灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wsxqxkcand', label: '上行取消扣车按钮灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wsxqxkczsd', label: '上行取消扣车指示灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wsxsdand', label: '上行试灯按钮灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wxxjjtccand', label: '下行紧急停车按钮灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wxxjjtczsd', label: '下行取消紧急停车按钮灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wxxjljcand', label: '下行警铃解除按钮灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wxxkcand', label: '下行扣车按钮灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wxxkczsd', label: '下行扣车指示灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wxxqxjjtcand', label: '下行取消紧急停车按钮灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wxxqxkcand', label: '下行取消扣车按钮灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wxxqxkczsd', label: '下行取消扣车指示灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wxxsdand', label: '下行试灯按钮灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0}
                    ]
                }
            },
            formFh: {
                left: {
                    labelWidth: '220px',
                    items:[
                        { prop:'rqb', label: '启泵按钮:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'rtb', label: '停泵按钮:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'rxy', label: '消音按钮:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'ryskg', label: '钥匙开关:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0}
                    ]
                },
                right: {
                    labelWidth: '220px',
                    items:[
                        { prop:'wgzbjzsd', label: '故障报警指示灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wqband', label: '启泵按钮灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wqbjl', label: '启泵警铃蜂鸣器:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wtband', label: '停泵按钮灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wxyand', label: '消音按钮灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wyxwzsd', label: '有效位指示灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wzdztzsd', label: '自动状态指示灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0}
                    ]
                }
            },
            formEemPlatform: {
                left: {
                    labelWidth: '220px',
                    items: [
                        { prop:'r04kvdykggs', label: '0.4KV低压开关柜室按钮:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'r35kvkggs', label: '35KV开关柜室按钮:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'rggqhz', label: '公共区火灾按钮:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'rkzs', label: '控制室按钮:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'rsytxsbshz', label: '商用通信设备室火灾按钮:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'rzlbyqs1', label: '整流变压器室一按钮:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'rzlbyqs2', label: '整流变压器室二按钮:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'rzlkggshz', label: '直流开关柜室火灾按钮:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'rzszddzshz', label: '再生制动电阻室火灾按钮:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'rzszdkzshz', label: '再生制动控制室火灾按钮:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0}
                    ]
                },
                right: {
                    labelWidth: '220px',
                    items: [
                        { prop:'w35kvkggsand', label: '35KV开关柜室按钮灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wggqhzand', label: '公共区火灾按钮灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wkzsand', label: '控制室按钮灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wr04kvdykggsand', label: '0.4KV低压开关柜室按钮灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wsytxsbshzand', label: '商用通信设备室火灾按钮灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wzlbyqs1and', label: '整流变压器室一按钮灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wzlbyqs2and', label: '整流变压器室二按钮灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wzlkggshzand', label: '直流开关柜室火灾按钮灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wzszddzshzand', label: '再生制动电阻室火灾按钮灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wzszdkzshzand', label: '再生制动控制室火灾按钮灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0}
                    ]
                }

            },
            formEemHall: {
                left: {
                    labelWidth: '220px',
                    items: [
                        { prop:'rczkzshz', label: '车站控制室火灾按钮:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'rggqhz', label: '公共区火灾按钮:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'rydhkdkshz', label: '右端环控电控室火灾按钮:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'rydjfkthz', label: '右端机房空调火灾按钮:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'rydlsjfhz', label: '右端冷水机房火灾按钮:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'rydqyfjhz', label: '右端其余房间火灾按钮:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'rydzlhz', label: '右端走廊火灾按钮:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'rzdhkdkshz', label: '左端环控电控室火灾按钮:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'rzdktjfhz', label: '左端空调机房火灾按钮:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'rzdqyfjhz', label: '左端其余房间火灾按钮:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0}
                    ]
                },
                right: {
                    labelWidth: '220px',
                    items: [
                        { prop:'wczkzshzand', label: '车站控制室火灾按钮灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wggqhzand', label: '公共区火灾按钮灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wydhkdkshzand', label: '右端环控电控室火灾按钮灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wydjfkthzand', label: '右端机房空调火灾按钮灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wydlsjfhzand', label: '右端冷水机房火灾按钮灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wydqyfjhzand', label: '右端其余房间火灾按钮灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wydzlhzand', label: '右端走廊火灾按钮灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wzdhkdkshzand', label: '左端环控电控室火灾按钮灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wzdktjfhzand', label: '左端空调机房火灾按钮灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                        { prop:'wzdqyfjhzand', label: '左端其余房间火灾按钮灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0}
                    ]
                }
            }
        };
    },
    computed: {
        formTop() {
            return {
                labelWidth: '220px',
                items: [
                    { prop:'addr', label: '网关位地址:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                    { prop:'quantity', label: '位数量:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0},
                    { prop: 'ribpsd', label: 'IBP盘试灯按钮:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0 },
                    { prop: 'wibpsdand', label: 'IBP盘试灯指示灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0 }
                ]
            };
        }

    },
    watch: {
        'checkCount'() {
            if (this.checkCount === 19) {
                const model = deepAssign({}, this.formModel);
                if (JSON.stringify(model.afczjConfig) === '{}') {
                    model.afczjConfig = null;
                }
                if (JSON.stringify(model.dftConfig) === '{}') {
                    model.dftConfig = null;
                }
                if (JSON.stringify(model.hjsbjkConfig.pfConfig) === '{}' && JSON.stringify(model.hjsbjkConfig.shfConfig) === '{}') {
                    model.hjsbjkConfig = null;
                } else if (JSON.stringify(model.hjsbjkConfig.pfConfig) === '{}') {
                    model.hjsbjkConfig.pfConfig = null;
                } else if (JSON.stringify(model.hjsbjkConfig.shfConfig) === '{}') {
                    model.hjsbjkConfig.shfConfig = null;
                }
                if (JSON.stringify(model.mjConfig) === '{}') {
                    model.mjConfig = null;
                }
                if (JSON.stringify(model.pbmConfig) === '{}') {
                    model.pbmConfig = null;
                }
                if (JSON.stringify(model.sdtfConfig) === '{}') {
                    model.sdtfConfig = null;
                }
                if (JSON.stringify(model.xhConfig) === '{}') {
                    model.xhConfig = null;
                }
                if (JSON.stringify(model.xhsbConfig) === '{}') {
                    model.xhsbConfig = null;
                }
                setIbpConfig(this.data.id, model).then(resp => {
                    this.$message.success('设置IBP网关映射配置成功');
                    this.handleClose();
                    this.$emit('reloadTable');
                }).catch(error => {
                    this.$message.error(this.$t('tip.modifyTheFailure') + error.message);
                });
            }
        }
    },
    methods: {
        doShow(row) {
            this.initData(row);
            this.data = row;
            this.dialogVisible = true;
        },
        initData(row) {
            getDeviceDetail(row.id).then(resp => {
                if (resp.data.config) {
                    const model = JSON.parse(resp.data.config) || {};
                    if (!model.afczjConfig) {
                        model.afczjConfig = {};
                    }
                    if (!model.dftConfig) {
                        model.dftConfig = {};
                    }
                    if (!model.hjsbjkConfig) {
                        model.hjsbjkConfig = {
                            pfConfig: {},
                            shfConfig: {}
                        };
                        if (!model.hjsbjkConfig.pfConfig) {
                            model.hjsbjkConfig.pfConfig = {};
                        }
                        if (!model.hjsbjkConfig.shfConfig) {
                            model.hjsbjkConfig.shfConfig = {};
                        }
                    }
                    if (!model.mjConfig) {
                        model.mjConfig = {};
                    }
                    if (!model.pbmConfig) {
                        model.pbmConfig = {};
                    }
                    if (!model.sdtfConfig) {
                        model.sdtfConfig = {};
                    }
                    if (!model.xhConfig) {
                        model.xhConfig = {};
                    }
                    if (!model.xhsbConfig) {
                        model.xhsbConfig = {};
                    }
                    this.formModel = model;
                }
            }).catch(()=> {
                this.$message.error('获取项目设备详情失败！');
            });
        },
        doSave() {
            this.checkCount = 0;
            const that = this;
            this.$refs.dataTop.validateForm(() => { that.checkCount++; });
            this.$refs.dataAfcLeft.validateForm(() => { that.checkCount++; });
            this.$refs.dataAfcRight.validateForm(() => { that.checkCount++; });
            this.$refs.dataElevatorLeft.validateForm(() => { that.checkCount++; });
            this.$refs.dataElevatorRight.validateForm(() => { that.checkCount++; });
            this.$refs.dataMonitorLeft.validateForm(() => { that.checkCount++; });
            this.$refs.dataMonitorRight.validateForm(() => { that.checkCount++; });
            this.$refs.dataEgLeft.validateForm(() => { that.checkCount++; });
            this.$refs.dataEgRight.validateForm(() => { that.checkCount++; });
            this.$refs.dataPsdLeft.validateForm(() => { that.checkCount++; });
            this.$refs.dataPsdRight.validateForm(() => { that.checkCount++; });
            this.$refs.dataTunnelLeft.validateForm(() => { that.checkCount++; });
            this.$refs.dataTunnelRight.validateForm(() => { that.checkCount++; });
            this.$refs.dataFhLeft.validateForm(() => { that.checkCount++; });
            this.$refs.dataFhRight.validateForm(() => { that.checkCount++; });
            this.$refs.dataEemPlatformLeft.validateForm(() => { that.checkCount++; });
            this.$refs.dataEemPlatformRight.validateForm(() => { that.checkCount++; });
            this.$refs.dataEemHallLeft.validateForm(() => { that.checkCount++; });
            this.$refs.dataEemHallRight.validateForm(() => { that.checkCount++; });
        },
        handleClose() {
            this.formModel = {
                afczjConfig: {},
                dftConfig: {},
                hjsbjkConfig: {
                    pfConfig: {},
                    shfConfig: {}
                },
                mjConfig: {},
                pbmConfig: {},
                sdtfConfig: {},
                xhConfig: {},
                xhsbConfig: {}
            };
            this.data = null;
            this.dialogVisible = false;
        }
    }
};
</script>

<style scoped>

</style>
