<template>
  <div>
    <el-form ref="queryFormRef" :model="queryParams" :inline="true" @keyup.enter.native="queryList">
      <el-form-item label="设备SN:">
        <el-input v-model="queryParams.deviceSn" placeholder="设备SN" size="small" style="max-width:180px;"
          show-word-limit clearable maxlength="11" />
      </el-form-item>
      <!-- <el-form-item label="遥测站编码:" style="margin-left: 10px;">
        <el-input v-model="queryParams.stationCode" placeholder="遥测站编码" size="small" style="max-width:120px;" clearable
          maxlength="10" />
      </el-form-item> -->
      <el-form-item label="任务状态:" style="margin-left: 10px;">
        <el-select v-model="queryParams.finishedFlag" class="filter-item" placeholder="任务状态" size="small" clearable
          style="max-width: 150px;">
          <el-option v-for="(key, value) in finishedFlagMap" :key="key" :label="key" :value="value" />
        </el-select>
      </el-form-item>

      <el-form-item label="设备类型:" style="margin-left: 10px;">
        <el-select v-model="queryParams.deviceType" class="filter-item" placeholder="设备类型" style="max-width: 120px;"
          size="small" clearable>
          <el-option v-for="(key, value) in Dic.deviceTypeMap" :key="key" :label="key" :value="value" />
        </el-select>
      </el-form-item>

      <el-form-item label="创建日期:" style="margin-left: 10px;">
        <el-config-provider :locale="locale">
          <el-date-picker v-model="queryParams.createTimeStart" type="date" placeholder="选择开始日期" :shortcuts="shortcuts"
            value-format="YYYY-MM-DD 00:00:00" size="small" style="max-width: 150px;" />
        </el-config-provider>
      </el-form-item>

      <el-form-item>
        <el-config-provider :locale="locale">
          <el-date-picker v-model="queryParams.createTimeEnd" type="date" placeholder="选择结束日期" :shortcuts="shortcuts"
            value-format="YYYY-MM-DD 23:59:59" size="small" style="max-width: 150px;" />
        </el-config-provider>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" class="button" :disabled="state.search_disabled" @click="queryList">
          查询计划
        </el-button>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" class="button" @click="handleAdd">新增计划</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="state.tableData" border stripe style="width: 100%;margin-top: -10px;"
      :height="tableHeight" highlight-current-row @current-change="handleCurrentRowChange" ref="my_table"
      :header-cell-style="{ background: '#606266', color: '#FFFFFF', outerHeight: '30px' }">

      <!-- 折叠区开始 -->
      <el-table-column type="expand">
        <template #default="props">
          <div m="4">
            <p m="t-0 b-2" v-if="props.row.stationCode != null">遥测站编码: {{ props.row.stationCode }}</p>
            <p m="t-0 b-2" v-if="props.row.ip1Port1 != null">通道1地址: {{ props.row.ip1Port1 }}</p>
            <p m="t-0 b-2" v-if="props.row.ip2Port2 != null">通道2地址: {{ props.row.ip2Port2 }}</p>
            <p m="t-0 b-2" v-if="props.row.ip3Port3 != null">通道3地址: {{ props.row.ip3Port3 }}</p>
            <p m="t-0 b-2" v-if="props.row.ip4Port4 != null">通道4地址: {{ props.row.ip4Port4 }}</p>
            <p m="t-0 b-2" v-if="props.row.domainNamePort != null">域名地址: {{ props.row.domainNamePort }}</p>
            <p m="t-0 b-2" v-if="props.row.sampleInterval != null">采样间隔: {{ props.row.sampleInterval }} 分钟</p>
            <p m="t-0 b-2" v-if="props.row.upInterval != null">上传服务器间隔: {{ props.row.upInterval }} 分钟</p>
            <p m="t-0 b-2" v-if="props.row.ltSampleInterval != null">低温采样间隔: {{ props.row.ltSampleInterval }} 小时</p>
            <p m="t-0 b-2" v-if="props.row.digitNum != null">数字个数: {{ props.row.digitNum }}</p>
            <p m="t-0 b-2" v-if="props.row.wheelNum != null">字轮个数: {{ props.row.wheelNum }}</p>
            <p m="t-0 b-2" v-if="props.row.uintType != null">尾数单位: {{ getUnitType(props.row.uintType) }}m³</p>

            <!-- 压力表专用配置 -->
            <p m="t-0 b-2" v-if="props.row.pgRangeMax != null">量程范围: {{ props.row.pgRangeMin }}-- {{
              props.row.pgRangeMax
            }}</p>
            <p m="t-0 b-2" v-if="props.row.pgPrecisionType != null">精度类型: {{
              getpgPrecisionType(props.row.pgPrecisionType)
            }}</p>
            <p m="t-0 b-2" v-if="props.row.pgCorrectvalue != null">校正参数: {{ props.row.pgCorrectvalue }}</p>
            <p m="t-0 b-2" v-if="!tool.stringIsNullOrEmpty(props.row.pgManualConfig)">坐标点赋值: {{
              props.row.pgManualConfigCol
            }}</p>
            <p m="t-0 b-2" v-if="props.row.pgManualConfigLevel != null">配置坐标点优先级: {{
              Dic.PGManualConfigLevel[props.row.pgManualConfigLevel]
            }}</p>
            <p m="t-0 b-2" v-if="props.row.pgIsDebug != null">图片是否描点: {{ props.row.pgIsDebug == '1' ? '是' : '否' }}</p>
            <p m="t-0 b-2" v-if="props.row.pgInitTargetRegion != null">目标历史初始化: {{
              props.row.pgInitTargetRegion == '1' ?
                '是' : '否'
            }}</p>
            <!-- 压力表专用配置 -->

            <p m="t-0 b-2" v-if="props.row.networkRegTimeout != null">入网超时时间(秒): {{ props.row.networkRegTimeout }} 秒</p>
            <p m="t-0 b-2" v-if="props.row.tongxunWay != null">数传类型: {{ props.row.tongxunWay == '2' ? 'NB' : 'CAT1' }}
            </p>
            <p m="t-0 b-2" v-if="props.row.tianxianType != null">天线类型: {{ Dic.tianxianType[props.row.tianxianType] }}
            </p>
            <p m="t-0 b-2" v-if="props.row.lastVal != null">当前读数: {{ props.row.lastVal }}</p>
            <p m="t-0 b-2" v-if="props.row.dnType != null">设备口径: {{ getDnType(props.row.dnType) }} </p>
            <p m="t-0 b-2" v-if="props.row.setupDir != null">安装方向: {{ Dic.setupDirMap[props.row.setupDir].label }}</p>
            <p m="t-0 b-2" v-if="props.row.setupYear != null">安装年份: {{ props.row.setupYear }} 年</p>
            <p m="t-0 b-2" v-if="props.row.workLt != null">工作温度范围: {{ props.row.workLt }} -- {{ props.row.workHt }}</p>
            <p m="t-0 b-2" v-if="props.row.batAlarmVt != null">低电压报警值: {{ props.row.batAlarmVt }} V</p>
            <p m="t-0 b-2" v-if="props.row.batAlarmSoc != null">余电报警电量: {{ props.row.batAlarmSoc }} %</p>
            <p m="t-0 b-2" v-if="props.row.aiPullBack != null">强制拉回概率: {{ props.row.aiPullBack }}</p>
            <p m="t-0 b-2" v-if="props.row.aiPass != null">识别概率阈值: {{ props.row.aiPass }}</p>
            <p m="t-0 b-2" v-if="props.row.aiSinglePass != null">位概率阀值: {{ props.row.aiSinglePass }}</p>
            <p m="t-0 b-2" v-if="props.row.pwmHz != null">背光频率: {{ props.row.pwmHz }} HZ</p>
            <p m="t-0 b-2" v-if="props.row.pwmDuty != null">背光占空比: {{ props.row.pwmDuty }}</p>
            <p m="t-0 b-2" v-if="props.row.flashBrightMin != null">补光灯亮度范围: {{ props.row.flashBrightMin }} --
              {{ props.row.flashBrightMax }}</p>
            <p m="t-0 b-2" v-if="props.row.cpuVersion != null">CPU版本: {{ props.row.cpuVersion }}</p>
            <p m="t-0 b-2" v-if="props.row.tongxunVersion != null">通讯版本: {{ props.row.tongxunVersion }}</p>
            <p m="t-0 b-2" v-if="props.row.upWholeImgWeekRule != null">大图上传周规则: {{
              jxweekString(props.row.upWholeImgWeekRule)
            }}</p>
            <p m="t-0 b-2" v-if="props.row.wiTaskManwakeupFlag != null">手动触发传大图: {{
              props.row.wiTaskManwakeupFlag == '1'
                ? '是' : '否'
            }}</p>
            <p m="t-0 b-2" v-if="props.row.wiTaskMonthFlag != null">月初月末传大图: {{
              props.row.wiTaskMonthFlag == '1' ? '是' :
                '否'
            }}</p>
            <p m="t-0 b-2" v-if="props.row.wiTaskSpecdateFlag != null">
              指定日期发大图:{{ global.getWiTaskSpecdateTip(props.row, 0) }}</p>
            <p m="t-0 b-2" v-if="props.row.logUploadRules != null">日志上传规则: {{
              global.getLogUploadRulesTip(props.row, 0)
            }}
            </p>
            <p m="t-0 b-2" v-if="props.row.isprintcomlog != null">输出串口日志: {{
              props.row.isprintcomlog == '1' ? '是' : '否'
            }}</p>
            <p m="t-0 b-2" v-if="props.row.uploadLastFailLogFlag != null">上传上一次MCU通讯错误的日志: {{
              props.row.uploadLastFailLogFlag == '1' ? '是' : '否'
            }}</p>
            <p m="t-0 b-2" v-if="props.row.logTaskManwakeupFlag != null">手动触发发送本次工作日志: {{
              props.row.logTaskManwakeupFlag
                == '1' ? '是' : '否'
            }}</p>
            <p m="t-0 b-2" v-if="props.row.isresetbat === '1'">电池使用时长清零: 是</p>
            <p m="t-0 b-2" v-if="props.row.isrestmcu === '1'">MCU运行次数清零: 是</p>
            <p m="t-0 b-2" v-if="props.row.isresetwdt === '1'">WDT读数清零: 是</p>

            <p m="t-0 b-2" v-if="props.row.imageType != null">上传图片类型: {{ props.row.imageType }} </p>
            <p m="t-0 b-2" v-if="props.row.imageMargin != null">图片外扩像素: {{ props.row.imageMargin }} </p>
            <p m="t-0 b-2" v-if="props.row.imageConfig != null">指定数字区域: {{
              global.getImageConfigip(props.row)
            }}</p>
            <p m="t-0 b-2" v-if="props.row.uploadCnnFlag != null">上传模型输出结果: {{
              props.row.uploadCnnFlag == '1' ? '是' :
                '否'
            }}</p>
            <p m="t-0 b-2" v-if="props.row.networkRegTimeout != null">NMS阈值: {{ props.row.nmsThreshold }} </p>
            <p m="t-0 b-2" v-if="props.row.isUseDetectedNum != null">使用大框去除野数字: {{
              props.row.isUseDetectedNum == '1' ?
                '是'
                : '否'
            }} </p>
            <p m="t-0 b-2" v-if="props.row.regionImageType != null">区域上报图片类型: {{
              props.row.regionImageType == '1' ?
                'JPG'
                : 'BMP'
            }} </p>
            <p m="t-0 b-2" v-if="props.row.jpgCompressType != null">JPG的压缩类型: {{ props.row.jpgCompressType }} </p>
          </div>
        </template>
      </el-table-column>
      <!-- 折叠区结束 -->
      <el-table-column type="index" width="50" align="center" />
      <!-- <el-table-column prop="deviceSn" label="设备SN" header-align="center" width="110"/> -->

      <el-table-column prop="deviceSn" label="设备SN" header-align="center" width="110">
        <template #default="scope">
          <span style="color:blue;cursor:pointer;text-decoration: underline;" title="点击快速创建任务"
            @click="deviceSnClick(scope.row.deviceSn)">{{ scope.row.deviceSn }}</span>
        </template>
      </el-table-column>

      <el-table-column prop="stationName" label="遥测站名称" header-align="center" width="260" show-overflow-tooltip />
      <el-table-column prop="stationName" label="设备类型" header-align="center" width="80" align="center">
        <template #default="scope">
          <span> {{ Dic.deviceTypeMap[scope.row.deviceType] }}</span>
        </template>

      </el-table-column>
      <!-- <el-table-column prop="stationCode" label="遥测站编码" header-align="center" width="100" /> -->
      <!-- <el-table-column prop="finishedFlag" label="执行状态" header-align="center" min-width="80" /> -->

      <el-table-column prop="createMan" label="创建人" header-align="center" width="100" align="center" />
      <el-table-column prop="createTime" label="创建时间" header-align="center" width="160" align="center" />
      <el-table-column label="执行状态" header-align="center" align="center" width="100">
        <template #default="scope">
          <span v-if="scope.row.finishedFlag === '0'">未执行</span>
          <span v-if="scope.row.finishedFlag === '1'">已完成</span>
        </template>
      </el-table-column>

      <el-table-column prop="finishedTime" label="完成时间" header-align="center" width="160" align="center" />

      <el-table-column label="" align="left" width="95">
        <template #default="scope">
          <el-button type="text" @click="handleEdit(scope.row)"
            :disabled="scope.row.finishedFlag === '1' || scope.row.createMan === '批量任务'">编辑
          </el-button>
          <el-button type="text" @click="submitDeleteForm(scope.row)"
            :disabled="scope.row.finishedFlag === '1' || scope.row.createMan === '批量任务'">删除
          </el-button>
        </template>
      </el-table-column>
      <el-table-column fixed="right" />
    </el-table>

    <!-- 分页开始 -->
    <el-config-provider :locale="locale">
      <el-pagination v-model:currentPage="queryParams.page" v-model:page-size="queryParams.rows"
        :page-sizes="[10, 15, 20, 25, 100]" :small="state.small" :disabled="state.disabled"
        :background="state.background" layout="total, sizes, prev, pager, next, jumper" :total="state.total"
        style="text-align: center; margin-top: 10px; height: 30px" @size-change="handleSizeChange"
        @current-change="handleCurrentChange" />
    </el-config-provider>
    <!-- 分页结束 -->

    <!-- 新增面板开始 -->
    <el-dialog :title="adddialog.title" v-model="adddialog.visible" width="1300px" draggable center
      @close="dialogClose">
      <el-form v-if="state.isAdd" v-model="aiCbqCfgQueryParams" ref="loadFormRef" :inline="true">
        <el-form-item label="设备SN:" prop="deviceSn">
          <el-input v-model="aiCbqCfgQueryParams.deviceSn" placeholder="设备SN" maxlength="11" show-word-limit
            style="width:160px" onkeyup="value=value.replace(/[^\-\d.]/g, '')" />
        </el-form-item>

        <el-form-item label="遥测站编码:" label-width="110px">
          <el-input placeholder="核对遥测站编码" v-model="formAddData.stationCode" style="width:150px" disabled />
        </el-form-item>

        <el-form-item>
          <el-button type="primary" class="button" @click="loadConfig" style="margin-left:10px"
            :disabled="state.loadDisanbled">加载配置</el-button>
        </el-form-item>
      </el-form>
      <el-divider style="margin-top: -10px;" />

      <el-tabs style="margin-top: -15px;height: 500px;margin-bottom: -20px;" type="border-card">
        <el-tab-pane label="基础配置">
          <el-form ref="addFormRef" :model="formAddData" :rules="state.rules">
            <el-row style="height: 45px;margin-top: 0px;">
              <el-col :span="7">
                <el-form-item label="遥测站编码:" label-width="150px">
                  <el-input v-model="formAddData.stationCode" placeholder="10位编码" :disabled="!stationCode"
                    size="small" />
                </el-form-item>
              </el-col>
              <el-col :span="1">
                <el-form-item>
                  <el-switch class="switch_style" v-model="stationCode" />
                </el-form-item>
              </el-col>

              <el-col :span="7">
                <el-form-item label="通道1地址:" label-width="150px">
                  <el-input v-model="formAddData.ip1Port1" placeholder="IP址址:端口" :disabled="!ip1Port1" maxlength="21"
                    size="small" />
                </el-form-item>
              </el-col>
              <el-col :span="1">
                <el-form-item>
                  <el-switch class="switch_style" v-model="ip1Port1" />
                </el-form-item>
              </el-col>

              <el-col :span="7">
                <el-form-item label="域名地址:" label-width="150px">
                  <el-input v-model="formAddData.domainNamePort" placeholder="例:www.web.com:6090"
                    :disabled="!domainNamePort" maxlength="50" size="small" />
                </el-form-item>
              </el-col>
              <el-col :span="1" :offset="0">
                <el-form-item>
                  <el-switch class="switch_style" v-model="domainNamePort" />
                </el-form-item>
              </el-col>
            </el-row>

            <el-divider style="margin-top: 0;" />

            <el-row style="height: 45px;margin-top: -17px;">
              <el-col :span="7">
                <el-form-item label="采样间隔:" label-width="150px">
                  <el-input v-model.number="formAddData.sampleInterval" placeholder="采样时间间隔(分钟)" maxlength="4"
                    :disabled="!sampleInterval" size="small"
                    onkeyup="value=value.replace(/[^\-\d.]/g, '').replace(/\b(0+){2,}/g, '0').replace(/\-{2,}/g, '-').replace(/^\./g, '').replace(/\.{2,}/g, '.').replace('.', '$#$').replace(/\./g, '').replace('$#$', '.')" />
                </el-form-item>
              </el-col>
              <el-col :span="1" :offset="0">
                <el-form-item>
                  <el-switch class="switch_style" v-model="sampleInterval" />
                </el-form-item>
              </el-col>

              <el-col :span="7">
                <el-form-item label="上报间隔:" label-width="150px">
                  <el-input v-model.number="formAddData.sampleInterval" placeholder="定时报时间间隔(分钟)"
                    :disabled="!sampleInterval" maxlength="4" size="small"
                    onkeyup="value=value.replace(/[^\-\d.]/g, '').replace(/\b(0+){2,}/g, '0').replace(/\-{2,}/g, '-').replace(/^\./g, '').replace(/\.{2,}/g, '.').replace('.', '$#$').replace(/\./g, '').replace('$#$', '.')" />
                </el-form-item>
              </el-col>
              <el-col :span="1">
                <el-form-item>
                  <el-switch class="switch_style" v-model="sampleInterval" />
                </el-form-item>
              </el-col>

              <el-col :span="7">
                <el-form-item label="低温采样间隔:" label-width="150px">
                  <el-input v-model.number="formAddData.ltSampleInterval" placeholder="低温采样时间间隔(小时)" type="number"
                    maxlength="3" :disabled="!ltSampleInterval" size="small"
                    onkeyup="value=value.replace(/[^\-\d.]/g, '').replace(/\b(0+){2,}/g, '0').replace(/\-{2,}/g, '-').replace(/^\./g, '').replace(/\.{2,}/g, '.').replace('.', '$#$').replace(/\./g, '').replace('$#$', '.')" />
                </el-form-item>
              </el-col>
              <el-col :span="1">
                <el-form-item>
                  <el-switch class="switch_style" v-model="ltSampleInterval" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-divider style="margin-top: 0;" />

            <!-- 水表专用配置 -->
            <el-row v-if="state.deviceType !== '2'" style="height: 45px;margin-top: -17px;">
              <el-col :span="7">
                <el-form-item label="数字个数:" label-width="150px">
                  <el-input v-model.number="formAddData.digitNum" placeholder="数字个数" type="number" maxlength="2"
                    :disabled="!digitNum" size="small" />
                </el-form-item>
              </el-col>
              <el-col :span="1" :offset="0">
                <el-form-item>
                  <el-switch class="switch_style" v-model="digitNum" />
                </el-form-item>
              </el-col>

              <el-col :span="7">
                <el-form-item label="字轮个数:" label-width="150px">
                  <el-input v-model.number="formAddData.wheelNum" placeholder="字轮个数" type="number" maxlength="2"
                    :disabled="!digitNum" size="small" />
                </el-form-item>
              </el-col>
              <el-col :span="1">
                <el-form-item>
                  <el-switch class="switch_style" v-model="digitNum" />
                </el-form-item>
              </el-col>

              <el-col :span="7">
                <el-form-item label="尾数单位:" label-width="150px">
                  <el-select v-model="formAddData.uintType" class="filter-item" placeholder="尾数单位(m³)"
                    :disabled="!uintType" size="small">
                    <el-option v-for="item in Dic.unitTypeMap" :key="item.value" :label="item.label"
                      :value="item.value" />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="1">
                <el-form-item>
                  <el-switch class="switch_style" v-model="uintType" />
                </el-form-item>
              </el-col>
            </el-row>
            <!-- 水表专用配置 -->

            <el-divider style="margin-top: 0;" v-if="state.deviceType !== '2'" />
            <el-row style="height: 45px;margin-top: -17px;">
              <el-col :span="7" v-if="state.deviceType == '1'">
                <el-form-item label="设备口径:" label-width="150px">
                  <el-select v-model="formAddData.dnType" class="filter-item" placeholder="水表口径" :disabled="!dnType"
                    size="small">
                    <el-option v-for="item in Dic.dnTypeMap" :key="item.value" :label="item.label"
                      :value="item.value" />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="1" :offset="0" v-if="state.deviceType == '1'">
                <el-form-item>
                  <el-switch class="switch_style" v-model="dnType" />
                </el-form-item>
              </el-col>

              <el-col :span="7">
                <el-form-item label="安装方向:" label-width="150px">
                  <el-radio-group v-model="formAddData.setupDir" :disabled="!setupDir" size="small">
                    <el-radio label="0" style="height: 25px;">正向</el-radio>
                    <el-radio label="1">反向</el-radio>
                    <el-radio label="2">左90</el-radio>
                    <el-radio label="3">右90</el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-col>
              <el-col :span="1">
                <el-form-item>
                  <el-switch class="switch_style" v-model="setupDir" />
                </el-form-item>
              </el-col>

              <el-col :span="7" v-if="state.deviceType !== '2'">
                <el-form-item label="当前读数:" label-width="150px">
                  <el-input v-model.number="formAddData.lastVal" placeholder="水表当前读数" type="number" maxlength="10"
                    :disabled="!lastVal" size="small" />
                </el-form-item>
              </el-col>
              <el-col :span="1" v-if="state.deviceType !== '2'">
                <el-form-item>
                  <el-switch class="switch_style" v-model="lastVal" />
                </el-form-item>
              </el-col>
            </el-row>

            <el-row style="height: 45px;">
              <el-col :span="7">
                <el-form-item label="天线类型:" label-width="150px">
                  <el-select v-model="formAddData.tianxianType" class="filter-item" placeholder="内置/外置"
                    :disabled="!tianxianType" size="small">
                    <el-option v-for="(key, value) in Dic.tianxianType" :key="key" :label="key" :value="value" />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="1">
                <el-form-item>
                  <el-switch class="switch_style" v-model="tianxianType" />
                </el-form-item>
              </el-col>

              <el-col :span="7">
                <el-form-item label="数传类型:" label-width="150px">
                  <el-radio-group v-model="formAddData.tongxunWay" :disabled="!tongxunWay" size="small">
                    <el-radio label='2'>NB</el-radio>
                    <el-radio label="1">CAT1</el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-col>
              <el-col :span="1">
                <el-form-item>
                  <el-switch class="switch_style" v-model="tongxunWay" />
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </el-tab-pane>

        <el-tab-pane label="运维配置">
          <el-form>
            <el-row style="height: 45px;margin-top: 0px;">
              <el-col :span="5">
                <el-form-item label="工作温度范围:" label-width="150px">
                  <el-input v-model.number="formAddData.workLt" placeholder="最低温度" :disabled="!workLt" maxlength="4"
                    size="small" />
                </el-form-item>
              </el-col>

              <el-col :span="2">
                <el-form-item label-width="0px">
                  <el-input v-model.number="formAddData.workHt" placeholder="最高温度" :disabled="!workLt" maxlength="4"
                    size="small" />
                </el-form-item>
              </el-col>

              <el-col :span="1">
                <el-form-item>
                  <el-switch class="switch_style" v-model="workLt" />
                </el-form-item>
              </el-col>

              <el-col :span="7">
                <el-form-item label="低电压报警值:" label-width="150px">
                  <el-input v-model="formAddData.batAlarmVt" placeholder="工作电压下限报警值" maxlength="4" type="number"
                    :disabled="!batAlarmVt" size="small" />
                </el-form-item>
              </el-col>
              <el-col :span="1">
                <el-form-item>
                  <el-switch class="switch_style" v-model="batAlarmVt" />
                </el-form-item>
              </el-col>

              <el-col :span="7">
                <el-form-item label="余电报警值:" label-width="150px">
                  <el-input v-model.number="formAddData.batAlarmSoc" placeholder="剩余电量报警值(百分比)" :disabled="!batAlarmSoc"
                    maxlength="2" size="small" />
                </el-form-item>
              </el-col>
              <el-col :span="1" :offset="0">
                <el-form-item>
                  <el-switch class="switch_style" v-model="batAlarmSoc" />
                </el-form-item>
              </el-col>
            </el-row>

            <el-divider style="margin-top: 0;" />
            <el-row style="height: 45px;margin-top: -17px;">
              <el-col :span="7">
                <el-form-item label="背光频率:" label-width="150px">
                  <el-input v-model.number="formAddData.pwmHz" placeholder="摄像头背光屏闪频率(HZ)" :disabled="!pwmHz"
                    maxlength="4" size="small" />
                </el-form-item>
              </el-col>

              <el-col :span="1">
                <el-form-item>
                  <el-switch class="switch_style" v-model="pwmHz" />
                </el-form-item>
              </el-col>

              <el-col :span="7">
                <el-form-item label="背光占空比:" label-width="150px">
                  <el-input v-model.number="formAddData.pwmDuty" placeholder="背光占空比(%)" type="number" maxlength="3"
                    :disabled="!pwmDuty" size="small" />
                </el-form-item>
              </el-col>
              <el-col :span="1">
                <el-form-item>
                  <el-switch class="switch_style" v-model="pwmDuty" />
                </el-form-item>
              </el-col>

              <el-col :span="5">
                <el-form-item label="补光灯亮度:" label-width="150px">
                  <el-input v-model.number="formAddData.flashBrightMin" placeholder="最小亮度" :disabled="!flashBrightMin"
                    maxlength="3" size="small" />
                </el-form-item>
              </el-col>

              <el-col :span="2">
                <el-form-item label-width="0px">
                  <el-input v-model.number="formAddData.flashBrightMax" placeholder="最大亮度" :disabled="!flashBrightMin"
                    maxlength="3" size="small" />
                </el-form-item>
              </el-col>
              <el-col :span="1" :offset="0">
                <el-form-item>
                  <el-switch class="switch_style" v-model="flashBrightMin" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-divider style="margin-top: 0;" />
            <el-row style="height: 45px;margin-top: -17px;">
              <el-col :span="7">
                <el-form-item label="入网超时时间:" label-width="150px">
                  <el-input v-model.number="formAddData.networkRegTimeout" placeholder="注册入网超时时间(秒)" type="number"
                    maxlength="2" :disabled="!networkRegTimeout" size="small" />
                </el-form-item>
              </el-col>
              <el-col :span="1" :offset="0">
                <el-form-item>
                  <el-switch class="switch_style" v-model="networkRegTimeout" />
                </el-form-item>
              </el-col>

              <el-col :span="7">
                <el-form-item label="CPU版本号:" label-width="150px">
                  <el-input v-model="formAddData.cpuVersion" placeholder="4位CPU版本号" :disabled="!cpuVersion"
                    maxlength="4" size="small" />
                </el-form-item>
              </el-col>

              <el-col :span="1">
                <el-form-item>
                  <el-switch class="switch_style" v-model="cpuVersion" />
                </el-form-item>
              </el-col>

              <el-col :span="7">
                <el-form-item label="通信板版本号:" label-width="150px">
                  <el-input v-model="formAddData.tongxunVersion" placeholder="4位通信板版本号" type="number" maxlength="4"
                    :disabled="!tongxunVersion" size="small" />
                </el-form-item>
              </el-col>
              <el-col :span="1">
                <el-form-item>
                  <el-switch class="switch_style" v-model="tongxunVersion" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-divider style="margin-top: 0;" />
            <el-row v-if="state.deviceType !== '2'" style="height: 45px;margin-top: -17px;">
              <el-col :span="15">
                <el-form-item label="整图上报周规则:" label-width="150px">
                  <el-checkbox label="一" size="small" v-model="week1" :disabled="!upWholeImgWeekRule" />
                  <el-checkbox label="二" size="small" v-model="week2" :disabled="!upWholeImgWeekRule" />
                  <el-checkbox label="三" size="small" v-model="week3" :disabled="!upWholeImgWeekRule" />
                  <el-checkbox label="四" size="small" v-model="week4" :disabled="!upWholeImgWeekRule" />
                  <el-checkbox label="五" size="small" v-model="week5" :disabled="!upWholeImgWeekRule" />
                  <el-checkbox label="六" size="small" v-model="week6" :disabled="!upWholeImgWeekRule" />
                  <el-checkbox label="日" size="small" v-model="week7" :disabled="!upWholeImgWeekRule" />
                  <el-tag style="float: right;margin-top: 5px;" @click="weekRuleInvert" v-if="upWholeImgWeekRule">反选
                  </el-tag>
                </el-form-item>
              </el-col>

              <el-col :span="1">
                <el-form-item>
                  <el-switch class="switch_style" v-model="upWholeImgWeekRule" />
                </el-form-item>
              </el-col>
              <el-col :span="7">
                <el-form-item label="手动触发传大图:" label-width="150px">
                  <el-radio-group v-model="formAddData.wiTaskManwakeupFlag" :disabled="!wiTaskManwakeupFlag"
                    size="small">
                    <el-radio label=1>是</el-radio>
                    <el-radio label=0>否</el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-col>

              <el-col :span="1">
                <el-form-item>
                  <el-switch class="switch_style" v-model="wiTaskManwakeupFlag" />
                </el-form-item>
              </el-col>
            </el-row>

            <el-row v-if="state.deviceType !== '2'" style="height: 45px;">
              <el-col :span="6">
                <el-form-item label="月初月末传大图:" label-width="150px">
                  <el-radio-group v-model="formAddData.wiTaskMonthFlag" :disabled="!wiTaskMonthFlag">
                    <el-radio label=1>是</el-radio>
                    <el-radio label=0>否</el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-col>
              <el-col :span="1">
                <el-form-item>
                  <el-switch class="switch_style" v-model="wiTaskMonthFlag" />
                </el-form-item>
              </el-col>
              <el-col :span="5">
                <el-form-item label="指定日期发大图:" label-width="140px">
                  <el-radio-group v-model="formAddData.wiTaskSpecdateEnable" :disabled="!wiTaskSpecdateFlag">
                    <el-radio label='1'>是</el-radio>
                    <el-radio label='0'>否</el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-col>

              <el-col :span="1">
                <el-form-item>
                  <el-switch class="switch_style" v-model="wiTaskSpecdateFlag"
                    @change="wiTaskSpecdateFlagSwitchChange" />
                </el-form-item>
              </el-col>

              <el-col :span="5">
                <el-form-item label="开始日期:" label-width="100px">
                  <el-date-picker v-model="formAddData.wiTaskSpecdateDate" type="date" placeholder="开始日期"
                    :shortcuts="shortcuts" value-format="YYYYMMDD" size="small" style="max-width: 130px;"
                    :disabled="!wiTaskSpecdateFlag" />
                </el-form-item>
              </el-col>

              <el-col :span="4">
                <el-form-item label="天数/次数:" label-width="100px">
                  <el-input v-model="formAddData.wiTaskSpecdateDays" style="width:110px" placeholder="持续天数"
                    :disabled="!wiTaskSpecdateFlag" maxlength="2" size="small"
                    onkeyup="value=value.replace(/[^\d]/g, '')" />
                </el-form-item>
              </el-col>

              <el-col :span="2">
                <el-form-item label-width="0px">
                  <el-input v-model="formAddData.wiTaskSpecdateTimes" placeholder="每天次数" :disabled="!wiTaskSpecdateFlag"
                    maxlength="2" style="width:100px" size="small" onkeyup="value=value.replace(/[^\d]/g, '')" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-divider style="margin-top: 0;" v-if="state.deviceType !== '2'" />
            <el-row style="height: 45px;margin-top: -17px;">
              <el-col :span="6">
                <el-form-item label="日志上传规则:" label-width="150px">
                  <el-radio-group v-model="formAddData.logUploadEnable" :disabled="!logUploadRules">
                    <el-radio label='1'>是</el-radio>
                    <el-radio label='0'>否</el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-col>

              <el-col :span="1">
                <el-form-item>
                  <el-switch class="switch_style" v-model="logUploadRules" @change="logUploadRulesSwitchChange" />
                </el-form-item>
              </el-col>

              <el-col :span="4">
                <el-form-item label="开始日期:" label-width="100px">
                  <el-date-picker v-model="formAddData.logUploadDate" type="date" placeholder="开始日期"
                    :shortcuts="shortcuts" value-format="YYYYMMDD" size="small" style="max-width: 130px;"
                    :disabled="!logUploadRules" />
                </el-form-item>
              </el-col>

              <el-col :span="4">
                <el-form-item label="天数/次数:" label-width="120px">
                  <el-input v-model="formAddData.logUploadDays" placeholder="持续天数" :disabled="!logUploadRules"
                    maxlength="2" size="small" onkeyup="value=value.replace(/[^\d]/g, '')" />
                </el-form-item>
              </el-col>

              <el-col :span="2">
                <el-form-item label-width="0px">
                  <el-input v-model="formAddData.logUploadTimes" placeholder="每天次数" :disabled="!logUploadRules"
                    maxlength="2" size="small" onkeyup="value=value.replace(/[^\d]/g, '')" />
                </el-form-item>
              </el-col>

              <el-col :span="5">
                <el-form-item label="日志等级(MCU/AI):" label-width="150px">
                  <el-select v-model="formAddData.logUploadMcuLevel" class="filter-item" placeholder="MCU等级"
                    :disabled="!logUploadRules" size="small">
                    <el-option v-for="item in Dic.logUploadLevel" :key="item.value" :label="item.label"
                      :value="item.value" />
                  </el-select>
                  <!-- <el-input v-model.number="formAddData.logUploadMcuLevel" placeholder="MCU等级" :disabled="!logUploadRules" maxlength="4" /> -->
                </el-form-item>
              </el-col>

              <el-col :span="2">
                <el-form-item label-width="0px">
                  <el-select v-model="formAddData.logUploadAiLevel" class="filter-item" placeholder="AI等级"
                    :disabled="!logUploadRules" size="small">
                    <el-option v-for="item in Dic.logUploadLevel" :key="item.value" :label="item.label"
                      :value="item.value" />
                  </el-select>
                  <!-- <el-input v-model.number="formAddData.logUploadAiLevel" placeholder="AI等级" :disabled="!logUploadRules" maxlength="2" /> -->
                </el-form-item>
              </el-col>
            </el-row>

            <el-row style="height: 45px;">
              <el-col :span="6">
                <el-form-item label="输出串口日志:" label-width="150px">
                  <el-radio-group v-model="formAddData.isprintcomlog" :disabled="!isprintcomlog">
                    <el-radio label='1'>是</el-radio>
                    <el-radio label='0'>否</el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-col>
              <el-col :span="1">
                <el-form-item>
                  <el-switch class="switch_style" v-model="isprintcomlog" @change="comlogSwitchChange" />
                </el-form-item>
              </el-col>
              <el-col :span="7">
                <el-form-item label="上传错误的日志:" label-width="140px">
                  <el-radio-group v-model="formAddData.uploadLastFailLogFlag" :disabled="!uploadLastFailLogFlag">
                    <el-radio label='1'>是</el-radio>
                    <el-radio label='0'>否</el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-col>
              <el-col :span="1">
                <el-form-item>
                  <el-switch class="switch_style" v-model="uploadLastFailLogFlag"
                    @change="uploadLastFailLogFlagSwitchChange" />
                </el-form-item>
              </el-col>

              <el-col :span="8">
                <el-form-item label="手动触发传日志:" label-width="150px">
                  <el-radio-group v-model="formAddData.logTaskManwakeupFlag" :disabled="!logTaskManwakeupFlag">
                    <el-radio label='1'>是</el-radio>
                    <el-radio label='0'>否</el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-col>
              <el-col :span="1">
                <el-form-item>
                  <el-switch class="switch_style" v-model="logTaskManwakeupFlag" />
                </el-form-item>
              </el-col>
            </el-row>

            <el-divider style="margin-top: 0;margin-bottom: 5px;" />
            <el-row style="height: 45px;margin-top: -5px;">
              <el-col :span="6">
                <el-form-item label="电池时长清零:" label-width="140px">
                  <el-switch class="switch_style" v-model="formAddData.isresetbat" active-value="1"
                    inactive-value="0" />
                </el-form-item>
              </el-col>

              <el-col :span="5">
                <el-form-item label="MCU运行次数清零:" label-width="150px">
                  <el-switch class="switch_style" v-model="formAddData.isrestmcu" active-value="1" inactive-value="0" />
                </el-form-item>
              </el-col>

              <el-col :span="5">
                <el-form-item label="WDT读数清零:" label-width="150px">
                  <el-switch class="switch_style" v-model="formAddData.isresetwdt" active-value="1"
                    inactive-value="0" />
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </el-tab-pane>

        <el-tab-pane label="AI配置" v-if="state.deviceType !== '2'">
          <el-form>
            <el-row style="height: 45px;margin-top: 0px;">
              <el-col :span="7">
                <el-form-item label="强制拉回概率:" label-width="150px">
                  <el-input v-model.number="formAddData.aiPullBack" placeholder="强制拉回概率值(%)" :disabled="!aiPullBack"
                    maxlength="3" size="small"
                    oninput="value=value.replace(/[^\d]/g, '');if(value>100) value=100;if(value<0) value=0" />
                </el-form-item>
              </el-col>

              <el-col :span="1">
                <el-form-item>
                  <el-switch class="switch_style" v-model="aiPullBack" />
                </el-form-item>
              </el-col>

              <el-col :span="7">
                <el-form-item label="识别概率阈值:" label-width="150px">
                  <el-input v-model.number="formAddData.aiPass" placeholder="识别可信度的概率阈值" type="number" maxlength="3"
                    :disabled="!aiPass" size="small"
                    oninput="value=value.replace(/[^\d]/g, '');if(value>100) value=100;if(value<0) value=0" />/>
                </el-form-item>
              </el-col>
              <el-col :span="1">
                <el-form-item>
                  <el-switch class="switch_style" v-model="aiPass" />
                </el-form-item>
              </el-col>

              <el-col :span="7">
                <el-form-item label="位概率阈值:" label-width="150px">
                  <el-input v-model.number="formAddData.aiSinglePass" placeholder="位概率阈值" :disabled="!aiSinglePass"
                    maxlength="3" size="small"
                    oninput="value=value.replace(/[^\d]/g, '');if(value>100) value=100;if(value<0) value=0" />
                </el-form-item>
              </el-col>
              <el-col :span="1" :offset="0">
                <el-form-item>
                  <el-switch class="switch_style" v-model="aiSinglePass" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-divider style="margin-top: 0;margin-bottom: 5px;" />
            <el-row style="height: 45px;margin-top: 0px;">
              <el-col :span="7">
                <el-form-item label="上传图片类型:" label-width="150px">
                  <el-input v-model.number="formAddData.imageType" placeholder="1:BMP;其它值:JPG的质量" :disabled="!imageType"
                    maxlength="5" size="small"
                    oninput="value=value.replace(/[^\d]/g, '');if(value>20000) value=20000;if(value<0) value=1" />
                </el-form-item>
              </el-col>

              <el-col :span="1">
                <el-form-item>
                  <el-switch class="switch_style" v-model="imageType" />
                </el-form-item>
              </el-col>

              <el-col :span="7">
                <el-form-item label="图片外扩像素:" label-width="150px">
                  <el-input v-model.number="formAddData.imageMargin" placeholder="外扩像素(0-30)" type="number"
                    maxlength="2" min="0" max="30" :disabled="!imageMargin" size="small"
                    oninput="value=value.replace(/[^\d]/g, '');if(value>30) value=30;if(value<0) value=0" />
                </el-form-item>
              </el-col>
              <el-col :span="1">
                <el-form-item>
                  <el-switch class="switch_style" v-model="imageMargin" />
                </el-form-item>
              </el-col>

              <el-col :span="7">
                <el-form-item label="上传模型输出结果:" label-width="150px">
                  <el-radio-group v-model="formAddData.uploadCnnFlag" :disabled="!uploadCnnFlag" size="small">
                    <el-radio label='1'>是</el-radio>
                    <el-radio label='0'>否</el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-col>
              <el-col :span="1" :offset="0">
                <el-form-item>
                  <el-switch class="switch_style" v-model="uploadCnnFlag" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-divider style="margin-top: 0;margin-bottom: 5px;" />
            <el-row style="height: 45px;margin-top: 0px;">
              <el-col :span="7">
                <el-form-item label="指定数字区域:" label-width="150px">
                  <el-radio-group v-model="formAddData.imageConfigFlag" :disabled="!imageConfig">
                    <el-radio label='1'>是</el-radio>
                    <el-radio label='0'>否</el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-col>

              <el-col :span="1">
                <el-form-item>
                  <el-switch class="switch_style" v-model="imageConfig" />
                </el-form-item>
              </el-col>

              <el-col :span="5">
                <el-form-item label="旋转角度:" label-width="120px">
                  <el-input v-model="formAddData.imageLeanAngle" placeholder="旋转角度" :disabled="!imageConfig"
                    maxlength="4" size="small"
                    oninput="value=value.replace(/[^0-9-]+/,'');if(value>360) value=360;if(value<-360) value=-360" />
                </el-form-item>
              </el-col>

              <el-col :span="11">
                <el-form-item label="区域坐标(xMin,yMin xMax,yMax):" label-width="250px">
                  <div>
                    <el-input v-model="formAddData.imageNumRegionXMin" placeholder="X-Min" :disabled="!imageConfig"
                      style="width: 70px;" maxlength="3" size="small"
                      oninput="value=value.replace(/[^\d]/g, '');if(value>319) value=333" />
                    <el-input v-model="formAddData.imageNumRegionYMin" placeholder="Y-Min" :disabled="!imageConfig"
                      style="width: 70px;" maxlength="3" size="small"
                      oninput="value=value.replace(/[^\d]/g, '');if(value>239) value=333" />
                    <span> -- </span>
                    <el-input v-model="formAddData.imageNumRegionXMax" placeholder="X-Max" :disabled="!imageConfig"
                      style="width: 70px;" maxlength="3" size="small"
                      oninput="value=value.replace(/[^\d]/g, '');if(value>319) value=333" />
                    <el-input v-model="formAddData.imageNumRegionYMax" placeholder="Y-Max" :disabled="!imageConfig"
                      style="width: 70px;" maxlength="3" size="small"
                      oninput="value=value.replace(/[^\d]/g, '');if(value>239) value=333" />
                  </div>
                </el-form-item>
              </el-col>
            </el-row>
            <el-divider style="margin-top: 0;margin-bottom: 5px;" />
            <el-row style="height: 45px;margin-top: 0px;">
              <el-col :span="7">
                <el-form-item label="NMS阈值:" label-width="150px">
                  <el-input v-model="formAddData.nmsThreshold" placeholder="NMS阈值(1-99)" :disabled="!nmsThreshold"
                    maxlength="2" size="small" oninput="value=value.replace(/[^\d]/g, '')" />
                </el-form-item>
              </el-col>

              <el-col :span="1">
                <el-form-item>
                  <el-switch class="switch_style" v-model="nmsThreshold" />
                </el-form-item>
              </el-col>

              <el-col :span="7">
                <el-form-item label="大框去野数字:" label-width="150px">
                  <el-radio-group v-model="formAddData.isUseDetectedNum" :disabled="!isUseDetectedNum">
                    <el-radio label='1'>是</el-radio>
                    <el-radio label='0'>否</el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-col>

              <el-col :span="1">
                <el-form-item>
                  <el-switch class="switch_style" v-model="isUseDetectedNum" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-divider style="margin-top: 0;margin-bottom: 5px;" />
            <el-row style="height: 45px;margin-top: 0px;">
              <el-col :span="7">
                <el-form-item label="区域上报图片类型:" label-width="150px">
                  <el-radio-group v-model="formAddData.regionImageType" :disabled="!regionImageType">
                    <el-radio label='1'>JPG</el-radio>
                    <el-radio label='2'>BMP</el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-col>

              <el-col :span="1">
                <el-form-item>
                  <el-switch class="switch_style" v-model="regionImageType" />
                </el-form-item>
              </el-col>

              <el-col :span="7">
                <el-form-item label="JPG的压缩类型:" label-width="150px">
                  <el-input v-model="formAddData.jpgCompressType" placeholder="0-9" :disabled="!jpgCompressType"
                    style="width: 100px;" maxlength="1" size="small"
                    oninput="value=value.replace(/[^\d]/g, '');if(value>9) value=9" />
                </el-form-item>
              </el-col>

              <el-col :span="1">
                <el-form-item>
                  <el-switch class="switch_style" v-model="jpgCompressType" />
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </el-tab-pane>

        <el-tab-pane label="压力表" v-if="state.deviceType === '2'">
          <el-form>
            <!-- 压力表专用配置 -->
            <el-row style="height: 45px;margin-top:0px;">
              <el-col :span="5">
                <el-form-item label="量程范围:" label-width="150px">
                  <el-input v-model="formAddData.pgRangeMin" placeholder="量程下限" :disabled="!pgRange" maxlength="10"
                    onkeyup="value=value.replace(/[^\-\d.]/g, '').replace(/\b(0+){2,}/g, '0').replace(/\-{2,}/g, '-').replace(/^\./g, '').replace(/\.{2,}/g, '.').replace('.', '$#$').replace(/\./g, '').replace('$#$', '.')" />
                </el-form-item>
              </el-col>

              <el-col :span="2">
                <el-form-item label-width="0px">
                  <el-input v-model="formAddData.pgRangeMax" placeholder="量程上限" :disabled="!pgRange" maxlength="10"
                    onkeyup="value=value.replace(/[^\-\d.]/g, '').replace(/\b(0+){2,}/g, '0').replace(/\-{2,}/g, '-').replace(/^\./g, '').replace(/\.{2,}/g, '.').replace('.', '$#$').replace(/\./g, '').replace('$#$', '.')" />
                </el-form-item>
              </el-col>

              <el-col :span="1" :offset="0">
                <el-form-item>
                  <el-switch class="switch_style" v-model="pgRange" />
                </el-form-item>
              </el-col>

              <el-col :span="7">
                <el-form-item label="数据精度:" label-width="150px">
                  <el-select v-model="formAddData.pgPrecisionType" class="filter-item" placeholder="数据精度类型"
                    :disabled="!pgPrecisionType">
                    <el-option v-for="item in Dic.pgPrecisionTypeMap" :key="item.value" :label="item.label"
                      :value="item.value" />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="1">
                <el-form-item>
                  <el-switch class="switch_style" v-model="pgPrecisionType" />
                </el-form-item>
              </el-col>

              <el-col :span="7">
                <el-form-item label="校正参数:" label-width="150px">
                  <el-input v-model="formAddData.pgCorrectvalue" placeholder="压力表系统校正参数" :disabled="!pgCorrectvalue"
                    maxlength="10"
                    onkeyup="value=value.replace(/[^\-\d.]/g, '').replace(/\b(0+){2,}/g, '0').replace(/\-{2,}/g, '-').replace(/^\./g, '').replace(/\.{2,}/g, '.').replace('.', '$#$').replace(/\./g, '').replace('$#$', '.')" />
                </el-form-item>
              </el-col>
              <el-col :span="1">
                <el-form-item>
                  <el-switch class="switch_style" v-model="pgCorrectvalue" />
                </el-form-item>
              </el-col>
            </el-row>

            <el-row v-if="state.deviceType === '2'" style="margin-bottom: -10px;">
              <el-col :span="7">
                <el-form-item label="图片是否描点:" label-width="150px">
                  <el-radio-group v-model="formAddData.pgIsDebug" :disabled="!pgIsDebug">
                    <el-radio label='1'>是</el-radio>
                    <el-radio label='0'>否</el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-col>
              <el-col :span="1">
                <el-form-item>
                  <el-switch class="switch_style" v-model="pgIsDebug" @change="isDebugSwitchChange" />
                </el-form-item>
              </el-col>

              <el-col :span="7">
                <el-form-item label="目标历史初始化:" label-width="150px">
                  <el-radio-group v-model="formAddData.pgInitTargetRegion" :disabled="!pgInitTargetRegion">
                    <el-radio label=1>是</el-radio>
                    <el-radio label=0>否</el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-col>
              <el-col :span="1">
                <el-form-item>
                  <el-switch class="switch_style" v-model="pgInitTargetRegion" @change="pgInitSwitchChange" />
                </el-form-item>
              </el-col>

              <el-col :span="7">
                <el-form-item label="坐标点的优先级:" label-width="150px">
                  <el-select v-model="formAddData.pgManualConfigLevel" class="filter-item" placeholder="坐标点的优先级"
                    :disabled="!pgManualConfigLevel">
                    <el-option v-for="(key, value) in Dic.PGManualConfigLevel" :key="key" :label="key" :value="value" />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="1">
                <el-form-item>
                  <el-switch class="switch_style" v-model="pgManualConfigLevel" />
                </el-form-item>
              </el-col>
            </el-row>

            <el-row v-if="state.deviceType === '2'" style="margin-bottom: -10px;">
              <el-col :span="7">
                <el-form-item label="坐标点赋值:" label-width="150px">
                  <el-input v-model="formAddData.originx" placeholder="origin-x" :disabled="!pgManualConfig"
                    maxlength="4" onkeyup="value=value.replace(/[^\d]/g, '')" style="width: 100px;" />
                  <el-input v-model="formAddData.originy" placeholder="origin-y" :disabled="!pgManualConfig"
                    maxlength="4" onkeyup="value=value.replace(/[^\d]/g, '')" style="width: 100px;" />
                  <el-input v-model="formAddData.endx" placeholder="end-x" :disabled="!pgManualConfig"
                    v-if="pgManualConfig" maxlength="4" onkeyup="value=value.replace(/[^\d]/g, '')"
                    style="width: 100px;" />
                  <el-input v-model="formAddData.endy" placeholder="end-y" :disabled="!pgManualConfig"
                    v-if="pgManualConfig" maxlength="4" onkeyup="value=value.replace(/[^\d]/g, '')"
                    style="width: 100px;" />
                  <el-input v-model="formAddData.centerx" placeholder="center-x" :disabled="!pgManualConfig"
                    v-if="pgManualConfig" maxlength="4" onkeyup="value=value.replace(/[^\d]/g, '')"
                    style="width: 100px;" />
                  <el-input v-model="formAddData.centery" placeholder="center-y" :disabled="!pgManualConfig"
                    v-if="pgManualConfig" maxlength="4" onkeyup="value=value.replace(/[^\d]/g, '')"
                    style="width: 100px;" />
                </el-form-item>
              </el-col>
              <el-col :span="1">
                <el-form-item>
                  <el-switch class="switch_style" v-model="pgManualConfig" />
                </el-form-item>
              </el-col>
            </el-row>
            <!-- 压力表专用配置 -->
          </el-form>
        </el-tab-pane>
      </el-tabs>

      <template #footer style="margin-top: -10px;">
        <span class="dialog-footer">
          <el-button @click="cancel()">取消</el-button>
          <el-button type="primary" @click="submitAddForm" :disabled="!state.loadDisanbled">保存</el-button>
        </span>
      </template>
    </el-dialog>
    <!-- 新增面板结束 -->
  </div>
</template>

<script lang="ts" setup>
import { reactive, toRefs, toRef, ref, onMounted, onUnmounted } from "vue";
import { ElForm, ElMessage, ElMessageBox } from "element-plus";
import TaskRemoteCfgAction from "@/api/downlinktask/taskremotecfg";
import TAicbqCfgAction from "@/api/taicbqcfg";
import { TaskRemoteCfgQueryParam, TaskRemoteCfg, TAicbqCfg, TAicbqCfgQueryParam, Dialog, PageResult, DeviceAccModel } from "@/types";
import zhCn from "element-plus/lib/locale/lang/zh-cn";
import Dic from "@/dictionary/aicbqcfg";
import DeviceAccAction from "@/api/deviceacc";
import tool from '@/until/tool';
import global from '@/until/global';
import Moment from "moment";

let locale = ref(zhCn);
const loading = ref(false);
const addFormRef = ref(ElForm); // 属性名必须和元素的ref属性值一致
const loadFormRef = ref(ElForm);
let pageSize = (localStorage.getItem("PageSize") == null ? 10 : localStorage.getItem("PageSize") as unknown as number) * 1;
const finishedFlagMap = {
  9: "全部",
  0: "未执行",
  1: "已完成",
};
const my_table = ref();
const state = reactive({
  queryParams: { page: 1, rows: pageSize, deviceSn: '', stationCode: '', finishedFlag: '' } as TaskRemoteCfgQueryParam,
  aiCbqCfgQueryParams: { deviceSn: '', stationCode: '', useFlag: '1' } as TAicbqCfgQueryParam,
  total: 0,
  small: false,
  background: true,
  disabled: false,
  search_disabled: false,
  adddialog: {} as Dialog,
  formAddData: {} as TaskRemoteCfg,
  tableData: [] as TaskRemoteCfg[],
  formAddCfgData: {} as TAicbqCfg,
  submitData: {} as TaskRemoteCfg,
  deviceAccModel: {} as DeviceAccModel,
  deviceType: '1',                                     //设备类型(1:水表,2压力表..)
  isAdd: true,
  loadDisanbled: false,
  rules: {
    deviceSn: [
      { required: true, message: "设备SN不能为空", trigger: "blur" }
    ],
  },
});

const {
  queryParams,
  total,
  adddialog,
  formAddData,
  tableData,
  aiCbqCfgQueryParams,
  formAddCfgData,
  submitData,
  isAdd,
  loadDisanbled,
  deviceType
} = toRefs(state);

const handleAdd = () => {
  state.loadDisanbled = false;
  state.isAdd = true;
  state.adddialog = {
    title: "新增远程配置计划",
    visible: true,
    disabled: false,
  };
};

const handleEdit = (row: any) => {
  state.loadDisanbled = true;
  state.isAdd = false;
  //state.formAddData = row;
  state.formAddData = { ...row }    //深复制 ？

  loadDateByEdit();
  state.deviceType = state.formAddData.deviceType;
  state.adddialog = {
    title: "修改远程配置计划",
    visible: true,
    disabled: false,
  };
};

const queryList = () => {
  loading.value = true;
  state.search_disabled = true;

  TaskRemoteCfgAction.QueryTaskRemoteCfgList(state.queryParams)
    .then((result) => {
      if (result.status === 200) {
        const { res, flag, error } = result.data;
        if (flag != undefined && flag == 1) {
          const pageData = res as PageResult<TaskRemoteCfg[]>;
          state.tableData = pageData.list;

          state.total = pageData.total;
        } else {
        }
        loading.value = false;
        state.search_disabled = false;
      }
    })
    .catch((error) => {
      //请求失败时的操作
      ElMessage.error(error);
      loading.value = false;
      state.search_disabled = false;
    });
};

const handleSizeChange = (val: number) => {
  queryParams.value.rows = val;
  queryList();
  localStorage.setItem("PageSize", val.toString());
};

const handleCurrentChange = (val: number) => {
  queryParams.value.page = val;
  queryList();
  if (Object.keys(my_table).length > 0) { if (my_table.value != null) { (my_table.value as any).$refs.bodyWrapper.scrollTop = 0; } }
};

const submitDeleteForm = (row: any) => {
  ElMessageBox.confirm(" 是否删除设备SN：[" + row.deviceSn + "]的远程配置任务? ", "提示", {
    cancelButtonText: "取消",
    confirmButtonText: "确认",
    type: "warning",
    center: true,
  })
    .then(() => {
      TaskRemoteCfgAction.DeleteTaskRemoteCfg(row.id).then((result) => {
        ElMessage.success("删除成功");
        queryList();
      });
    })
    .catch(() => {
      ElMessage({
        type: "info",
        message: "取消删除成功!",
      });
    });
};

const submitAddForm = () => {
  addFormRef.value.validate((valid: any) => {
    if (valid) {
      // 角度的正负值,用正则没控制上,暂用逻辑控制
      if (imageConfig.value && state.formAddData.imageLeanAngle) {
        let angle = state.formAddData.imageLeanAngle.toString();
        let index = angle.lastIndexOf('-');
        if (index > -1 && index !== 0) {
          ElMessage.warning("指定数字区域的[转换角度]不合法");
          return;
        }
      }
      state.loadDisanbled = true;
      let isCfg = false;
      //根据勾选情况,给提交对象赋值     
      state.submitData.deviceSn = state.formAddData.deviceSn;
      if (!state.submitData.deviceSn || state.submitData.deviceSn.length != 11) {
        ElMessage.warning("请检查录入的设备SN");
        return;
      }
      if (ip1Port1.value) { state.submitData.ip1Port1 = state.formAddData.ip1Port1; isCfg = true; }
      if (ip2Port2.value) { state.submitData.ip2Port2 = state.formAddData.ip2Port2; isCfg = true; }
      if (ip3Port3.value) { state.submitData.ip3Port3 = state.formAddData.ip3Port3; isCfg = true; }
      if (ip4Port4.value) { state.submitData.ip4Port4 = state.formAddData.ip4Port4; isCfg = true; }
      if (stationCode.value) { state.submitData.stationCode = state.formAddData.stationCode; isCfg = true; };
      if (domainNamePort.value) { state.submitData.domainNamePort = state.formAddData.domainNamePort; isCfg = true; }
      if (dnType.value) { state.submitData.dnType = state.formAddData.dnType; isCfg = true; }
      if (digitNum.value) {
        state.submitData.digitNum = state.formAddData.digitNum;
        state.submitData.wheelNum = state.formAddData.wheelNum;
        isCfg = true;
      }
      if (uintType.value) { state.submitData.uintType = state.formAddData.uintType; isCfg = true; }
      if (setupDir.value) { state.submitData.setupDir = state.formAddData.setupDir; isCfg = true; }
      if (sampleInterval.value) {
        state.submitData.sampleInterval = state.formAddData.sampleInterval;
        state.submitData.upInterval = state.formAddData.sampleInterval;//两个值现阶段都是一致的
        isCfg = true;
      }
      if (networkRegTimeout.value) { state.submitData.networkRegTimeout = state.formAddData.networkRegTimeout; isCfg = true; }
      if (setupYear.value) { state.submitData.setupYear = state.formAddData.setupYear; isCfg = true; }
      if (aiPullBack.value) { state.submitData.aiPullBack = state.formAddData.aiPullBack; isCfg = true; }
      if (aiPass.value) { state.submitData.aiPass = state.formAddData.aiPass; isCfg = true; }
      if (aiSinglePass.value) { state.submitData.aiSinglePass = state.formAddData.aiSinglePass; isCfg = true; }
      if (pwmHz.value) { state.submitData.pwmHz = state.formAddData.pwmHz; isCfg = true; }
      if (pwmDuty.value) { state.submitData.pwmDuty = state.formAddData.pwmDuty; isCfg = true; }
      if (flashBrightMin.value) {
        state.submitData.flashBrightMin = state.formAddData.flashBrightMin;
        state.submitData.flashBrightMax = state.formAddData.flashBrightMax;
        isCfg = true;
      }
      // if (upWholeImgWeekRule.value) { state.submitData.upWholeImgWeekRule = state.formAddData.upWholeImgWeekRule }
      if (ip1ExpandOn.value) { state.submitData.ip1ExpandOn = state.formAddData.ip1ExpandOn; isCfg = true; }
      if (upInterval.value) { state.submitData.upInterval = state.formAddData.upInterval; isCfg = true; }
      if (ltSampleInterval.value) { state.submitData.ltSampleInterval = state.formAddData.ltSampleInterval; isCfg = true; }
      if (workLt.value) {
        state.submitData.workLt = state.formAddData.workLt;
        state.submitData.workHt = state.formAddData.workHt;
        isCfg = true;
      }
      if (batAlarmSoc.value) { state.submitData.batAlarmSoc = state.formAddData.batAlarmSoc; isCfg = true; }
      // if (workHt.value) { state.submitData.workHt = state.formAddData.workHt }
      if (batAlarmVt.value) { state.submitData.batAlarmVt = state.formAddData.batAlarmVt; isCfg = true; }
      if (cpuVersion.value) { state.submitData.cpuVersion = state.formAddData.cpuVersion; isCfg = true; }
      if (tongxunVersion.value) { state.submitData.tongxunVersion = state.formAddData.tongxunVersion; isCfg = true; }
      if (tianxianType.value) { state.submitData.tianxianType = state.formAddData.tianxianType; isCfg = true; }
      if (tongxunWay.value) { state.submitData.tongxunWay = state.formAddData.tongxunWay; isCfg = true; }
      // if (wheelNum.value) { state.submitData.wheelNum = state.formAddData.wheelNum }
      if (lastVal.value) { state.submitData.lastVal = state.formAddData.lastVal; isCfg = true; }
      if (meterFontStyle.value) { state.submitData.meterFontStyle = state.formAddData.meterFontStyle; isCfg = true; }

      //压力表添加
      if (pgRange.value) {
        state.submitData.pgRangeMin = state.formAddData.pgRangeMin;
        state.submitData.pgRangeMax = state.formAddData.pgRangeMax;
        isCfg = true;
      }
      if (pgPrecisionType.value) { state.submitData.pgPrecisionType = state.formAddData.pgPrecisionType; isCfg = true; }
      if (pgManualConfig.value) {
        state.submitData.originx = state.formAddData.originx;
        state.submitData.originy = state.formAddData.originy;
        state.submitData.endx = state.formAddData.endx;
        state.submitData.endy = state.formAddData.endy;
        state.submitData.centerx = state.formAddData.centerx;
        state.submitData.centery = state.formAddData.centery;
        isCfg = true;
      }
      if (pgCorrectvalue.value) { state.submitData.pgCorrectvalue = state.formAddData.pgCorrectvalue; isCfg = true; }
      if (pgIsDebug.value) { state.submitData.pgIsDebug = state.formAddData.pgIsDebug; isCfg = true; }
      if (pgInitTargetRegion.value) { state.submitData.pgInitTargetRegion = state.formAddData.pgInitTargetRegion; isCfg = true; }

      if (isprintcomlog.value) { state.submitData.isprintcomlog = state.formAddData.isprintcomlog; isCfg = true; }
      if (isresetwdt.value) { state.submitData.isresetwdt = state.formAddData.isresetwdt; isCfg = true; }
      if (state.formAddData.isresetbat === '1') {
        state.submitData.isresetbat = state.formAddData.isresetbat; isCfg = true;
      }
      if (state.formAddData.isrestmcu === '1') {
        state.submitData.isrestmcu = state.formAddData.isrestmcu; isCfg = true;
      }

      if (wiTaskManwakeupFlag.value) {
        state.submitData.wiTaskManwakeupFlag = state.formAddData.wiTaskManwakeupFlag; isCfg = true;
      }
      if (wiTaskMonthFlag.value) {
        state.submitData.wiTaskMonthFlag = state.formAddData.wiTaskMonthFlag; isCfg = true;
      }
      if (wiTaskSpecdateFlag.value) {
        state.submitData.wiTaskSpecdateEnable = state.formAddData.wiTaskSpecdateEnable;
        state.submitData.wiTaskSpecdateDate = state.formAddData.wiTaskSpecdateDate;
        state.submitData.wiTaskSpecdateDays = state.formAddData.wiTaskSpecdateDays;
        state.submitData.wiTaskSpecdateTimes = state.formAddData.wiTaskSpecdateTimes;
        isCfg = true;
      }
      if (logUploadRules.value) {
        state.submitData.logUploadEnable = state.formAddData.logUploadEnable;
        state.submitData.logUploadDate = state.formAddData.logUploadDate;
        state.submitData.logUploadDays = state.formAddData.logUploadDays;
        state.submitData.logUploadTimes = state.formAddData.logUploadTimes;
        state.submitData.logUploadMcuLevel = state.formAddData.logUploadMcuLevel;
        state.submitData.logUploadAiLevel = state.formAddData.logUploadAiLevel;
        isCfg = true;
      }
      if (uploadLastFailLogFlag.value) {
        state.submitData.uploadLastFailLogFlag = state.formAddData.uploadLastFailLogFlag; isCfg = true;
      }
      if (logTaskManwakeupFlag.value) {
        state.submitData.logTaskManwakeupFlag = state.formAddData.logTaskManwakeupFlag; isCfg = true;
      }
      if (pgManualConfigLevel.value) {
        state.submitData.pgManualConfigLevel = state.formAddData.pgManualConfigLevel; isCfg = true;
      }

      if (imageType.value) {
        state.submitData.imageType = state.formAddData.imageType; isCfg = true;
      }
      if (imageMargin.value) {
        state.submitData.imageMargin = state.formAddData.imageMargin; isCfg = true;
      }
      if (imageConfig.value) {
        state.submitData.imageConfigFlag = state.formAddData.imageConfigFlag;
        state.submitData.imageLeanAngle = state.formAddData.imageLeanAngle;
        state.submitData.imageNumRegionXMin = state.formAddData.imageNumRegionXMin;
        state.submitData.imageNumRegionYMin = state.formAddData.imageNumRegionYMin;
        state.submitData.imageNumRegionXMax = state.formAddData.imageNumRegionXMax;
        state.submitData.imageNumRegionYMax = state.formAddData.imageNumRegionYMax;
        isCfg = true;
      }
      if (uploadCnnFlag.value) {
        state.submitData.uploadCnnFlag = state.formAddData.uploadCnnFlag; isCfg = true;
      }
      if (nmsThreshold.value) {
        state.submitData.nmsThreshold = state.formAddData.nmsThreshold; isCfg = true;
      }
      if (isUseDetectedNum.value) {
        state.submitData.isUseDetectedNum = state.formAddData.isUseDetectedNum; isCfg = true;
      }

      if (regionImageType.value) {
        state.submitData.regionImageType = state.formAddData.regionImageType; isCfg = true;
      }
      if (jpgCompressType.value) {
        state.submitData.jpgCompressType = state.formAddData.jpgCompressType; isCfg = true;
      }

      //处理周规则
      if (upWholeImgWeekRule.value) {
        let weeks = "";
        weeks += week1.value ? "1" : "0";
        weeks += week2.value ? "1" : "0";
        weeks += week3.value ? "1" : "0";
        weeks += week4.value ? "1" : "0";
        weeks += week5.value ? "1" : "0";
        weeks += week6.value ? "1" : "0";
        weeks += week7.value ? "1" : "0";
        state.submitData.upWholeImgWeekRule = weeks;
        isCfg = true;
      }
      state.submitData.deviceType = state.deviceType;

      if (!isCfg) {
        ElMessage.warning("您未修改任何配置");
        return;
      }

      if (state.isAdd) {
        state.submitData.finishedFlag = "0";
        state.submitData.createMan = localStorage.getItem("UserName") + "";
        TaskRemoteCfgAction.AddTaskRemoteCfg(state.submitData).then((result) => {
          const { res, flag, error } = result.data;
          if (flag === "1") {
            ElMessage.success("新增成功");
            cancel();
            queryList();
          }
          else {
            ElMessage.warning(error);
          }
        });
      }
      else {
        state.submitData.id = state.formAddData.id;
        state.submitData.taskId = state.formAddData.taskId;
        state.submitData.createMan = state.formAddData.createMan;
        state.submitData.createTime = state.formAddData.createTime;
        state.submitData.finishedFlag = state.formAddData.finishedFlag;
        state.submitData.finishedTime = state.formAddData.finishedTime;
        state.submitData.batchFlag = state.formAddData.batchFlag;

        TaskRemoteCfgAction.EditTaskRemoteCfg(state.submitData).then((result) => {
          const { res, flag, error } = result.data;
          if (flag === "1") {
            ElMessage.success("修改成功");
            cancel();
            queryList();
          }
          else {
            ElMessage.warning(error);
          }
        });
      }
    }
  });
};

//修改时回填数据
const loadDateByEdit = () => {
  if (state.formAddData != null && state.formAddData.upWholeImgWeekRule != null && state.formAddData.upWholeImgWeekRule.length == 7) {
    week1.value = state.formAddData.upWholeImgWeekRule[0] == "1";
    week2.value = state.formAddData.upWholeImgWeekRule[1] == "1";
    week3.value = state.formAddData.upWholeImgWeekRule[2] == "1";
    week4.value = state.formAddData.upWholeImgWeekRule[3] == "1";
    week5.value = state.formAddData.upWholeImgWeekRule[4] == "1";
    week6.value = state.formAddData.upWholeImgWeekRule[5] == "1";
    week7.value = state.formAddData.upWholeImgWeekRule[6] == "1";
    upWholeImgWeekRule.value = true;
  }

  stationCode.value = state.formAddData.stationCode != null;
  ip1Port1.value = state.formAddData.ip1Port1 != null;
  ip2Port2.value = state.formAddData.ip2Port2 != null;
  ip3Port3.value = state.formAddData.ip3Port3 != null;
  ip4Port4.value = state.formAddData.ip4Port4 != null;
  domainNamePort.value = state.formAddData.domainNamePort != null;
  dnType.value = state.formAddData.dnType != null;
  digitNum.value = state.formAddData.digitNum != null;
  uintType.value = state.formAddData.uintType != null;
  setupDir.value = state.formAddData.setupDir != null;
  sampleInterval.value = state.formAddData.sampleInterval != null;
  networkRegTimeout.value = state.formAddData.networkRegTimeout != null;
  setupYear.value = state.formAddData.setupYear != null;
  aiPullBack.value = state.formAddData.aiPullBack != null;
  aiPass.value = state.formAddData.aiPass != null;
  aiSinglePass.value = state.formAddData.aiSinglePass != null;
  pwmHz.value = state.formAddData.pwmHz != null;
  pwmDuty.value = state.formAddData.pwmDuty != null;
  flashBrightMin.value = state.formAddData.flashBrightMin != null;
  ip1ExpandOn.value = state.formAddData.ip1ExpandOn != null;
  upInterval.value = state.formAddData.upInterval != null;
  ltSampleInterval.value = state.formAddData.ltSampleInterval != null;
  workLt.value = state.formAddData.workLt != null;
  batAlarmSoc.value = state.formAddData.batAlarmSoc != null;
  workHt.value = state.formAddData.workHt != null;
  batAlarmVt.value = state.formAddData.batAlarmVt != null;
  cpuVersion.value = state.formAddData.cpuVersion != null;
  tongxunVersion.value = state.formAddData.tongxunVersion != null;
  tianxianType.value = state.formAddData.tianxianType != null;
  tongxunWay.value = state.formAddData.tongxunWay != null;
  //wheelNum.value = state.formAddData.wheelNum != null;
  lastVal.value = state.formAddData.lastVal != null;
  meterFontStyle.value = state.formAddData.meterFontStyle != null;
  state.aiCbqCfgQueryParams.deviceSn = state.formAddData.deviceSn;

  //压力表添加 2022-09-13 guozhao
  pgRange.value = state.formAddData.pgRangeMin != null || state.formAddData.pgRangeMax != null;
  pgPrecisionType.value = state.formAddData.pgPrecisionType != null;
  pgCorrectvalue.value = state.formAddData.pgCorrectvalue != null;
  pgManualConfig.value = state.formAddData.pgManualConfig != null;
  pgIsDebug.value = state.formAddData.pgIsDebug != null;
  pgInitTargetRegion.value = state.formAddData.pgInitTargetRegion != null;

  isprintcomlog.value = state.formAddData.isprintcomlog != null;
  isresetwdt.value = state.formAddData.isresetwdt != null;

  wiTaskManwakeupFlag.value = state.formAddData.wiTaskManwakeupFlag != null;
  wiTaskMonthFlag.value = state.formAddData.wiTaskMonthFlag != null;
  wiTaskSpecdateFlag.value = state.formAddData.wiTaskSpecdateFlag != null;
  logUploadRules.value = state.formAddData.logUploadRules != null;
  uploadLastFailLogFlag.value = state.formAddData.uploadLastFailLogFlag != null;
  logTaskManwakeupFlag.value = state.formAddData.logTaskManwakeupFlag != null;
  pgManualConfigLevel.value = state.formAddData.pgManualConfigLevel != null;

  //因BMP 添加的 2022-11-08
  imageType.value = state.formAddData.imageType != null;
  imageMargin.value = state.formAddData.imageMargin != null;
  imageConfig.value = state.formAddData.imageConfig != null;
  uploadCnnFlag.value = state.formAddData.uploadCnnFlag != null;
  nmsThreshold.value = state.formAddData.nmsThreshold != null;

  //2022-11-15 guozhao
  isUseDetectedNum.value = state.formAddData.isUseDetectedNum != null;

  //服务侧识别水表添加 2023-01-18 guozhao
  regionImageType.value = state.formAddData.regionImageType != null;
  jpgCompressType.value = state.formAddData.jpgCompressType != null;
};

const cancel = () => {
  state.queryParams = { page: 1, rows: 10, deviceSn: '', stationCode: '', finishedFlag: '' } as TaskRemoteCfgQueryParam;
  state.aiCbqCfgQueryParams = { deviceSn: '', stationCode: '', useFlag: '1' } as TAicbqCfgQueryParam;
  state.formAddData = {} as TaskRemoteCfg;
  state.formAddCfgData = {} as TAicbqCfg;
  state.submitData = {} as TaskRemoteCfg;
  state.adddialog.visible = false;
  state.deviceType = '1';
  state.deviceAccModel = {} as DeviceAccModel;
  initData();
  addFormRef.value.resetFields();
};

//解析周规则字符串11111101
const jxweekString = (weeks: string) => {
  let reString = "";
  reString += weeks[0] == "1" ? "一" : "";
  reString += weeks[1] == "1" ? "二" : "";
  reString += weeks[2] == "1" ? "三" : "";
  reString += weeks[3] == "1" ? "四" : "";
  reString += weeks[4] == "1" ? "五" : "";
  reString += weeks[5] == "1" ? "六" : "";
  reString += weeks[6] == "1" ? "日" : "";

  return reString === '' ? '不上传' : reString;
};

//根据尾数单位的 value获取label
const getUnitType = (type: number) => {
  /*  没找到这两种匹配不到的原因  
    let model = unitTypeMap.findIndex((s)=>{s.value==type});
    let test=unitTypeMap.find((s)=>{s.value.toString()=='5'}); */

  for (let index = 0; index < Dic.unitTypeMap.length; index++) {
    if (Dic.unitTypeMap[index].value == type) {
      return Dic.unitTypeMap[index].label;
    }
  }
  return "";
};

const getDnType = (type: number) => {
  for (let index = 0; index < Dic.dnTypeMap.length; index++) {
    if (Dic.dnTypeMap[index].value == type) {
      return Dic.dnTypeMap[index].label;
    }
  }
  return "";
};

//翻译压力表精度范围
const getpgPrecisionType = (type: number) => {
  /*  没找到这两种匹配不到的原因  
    let model = unitTypeMap.findIndex((s)=>{s.value==type});
    let test=unitTypeMap.find((s)=>{s.value.toString()=='5'}); */

  for (let index = 0; index < Dic.pgPrecisionTypeMap.length; index++) {
    if (Dic.pgPrecisionTypeMap[index].value == type) {
      return Dic.pgPrecisionTypeMap[index].label;
    }
  }
  return "";
};

// const convertToNumber=(parm:any)=>{
//   const result=ref(0);
//   parm as 
// }

/* 新增面板开始 */
//根据遥测代码加载配置
const loadConfig = () => {
  if (!state.aiCbqCfgQueryParams.deviceSn || state.aiCbqCfgQueryParams.deviceSn.length !== 11) {
    ElMessage.warning("请检查设备SN");
    return;
  }

  TAicbqCfgAction.QueryTAicbqCfg(state.aiCbqCfgQueryParams.deviceSn).then((result) => {
    if (result.status == 200) {
      const { res, flag, error } = result.data;
      if (flag != undefined && flag == 1) {
        const cfgs = res as TAicbqCfg[];
        if (cfgs != null && cfgs.length > 0) {
          state.loadDisanbled = true;
          state.formAddCfgData = cfgs[0];
          state.formAddData.deviceSn = state.formAddCfgData.deviceSn;
          if (state.formAddCfgData.serverIp1 != null && state.formAddCfgData.serverPort1 != null) {
            state.formAddData.ip1Port1 = state.formAddCfgData.serverIp1 + ':' + state.formAddCfgData.serverPort1;
          }
          if (state.formAddCfgData.serverIp2 != null && state.formAddCfgData.serverPort2 != null) {
            state.formAddData.ip2Port2 = state.formAddCfgData.serverIp2 + ':' + state.formAddCfgData.serverPort2;
          }
          if (state.formAddCfgData.serverIp3 != null && state.formAddCfgData.serverPort3 != null) {
            state.formAddData.ip3Port3 = state.formAddCfgData.serverIp3 + ':' + state.formAddCfgData.serverPort3;
          }
          if (state.formAddCfgData.serverIp4 != null && state.formAddCfgData.serverPort4 != null) {
            state.formAddData.ip4Port4 = state.formAddCfgData.serverIp4 + ':' + state.formAddCfgData.serverPort4;
          }
          state.formAddData.stationCode = state.formAddCfgData.stationCode;
          if (state.formAddCfgData.domainName != null && state.formAddCfgData.domainPort != null) {
            state.formAddData.domainNamePort = state.formAddCfgData.domainName + ':' + state.formAddCfgData.domainPort;
          }
          state.formAddData.dnType = state.formAddCfgData.dnType;
          state.formAddData.digitNum = state.formAddCfgData.digitNum;
          state.formAddData.uintType = state.formAddCfgData.uintType;
          state.formAddData.setupDir = state.formAddCfgData.setupDir;
          state.formAddData.sampleInterval = state.formAddCfgData.sampleInterval;
          state.formAddData.networkRegTimeout = state.formAddCfgData.networkRegTimeout;
          state.formAddData.setupYear = state.formAddCfgData.setupYear;
          state.formAddData.aiPullBack = state.formAddCfgData.aiPullBack;
          state.formAddData.aiPass = state.formAddCfgData.aiPass;
          state.formAddData.aiSinglePass = state.formAddCfgData.aiSinglePass;
          state.formAddData.pwmHz = state.formAddCfgData.pwmHz;
          state.formAddData.pwmDuty = state.formAddCfgData.pwmDuty;
          state.formAddData.flashBrightMin = state.formAddCfgData.flashBrightMin;
          state.formAddData.flashBrightMax = state.formAddCfgData.flashBrightMax;
          //state.formAddData.upWholeImgWeekRule=state.formAddCfgData.upWholeImgWeekRule;
          state.formAddData.ip1ExpandOn = state.formAddCfgData.ip1ExpandOn;
          state.formAddData.upInterval = state.formAddCfgData.upInterval;
          state.formAddData.ltSampleInterval = state.formAddCfgData.ltSampleInterval;
          state.formAddData.workLt = state.formAddCfgData.workLt;
          state.formAddData.batAlarmVt = state.formAddCfgData.batAlarmVt;
          state.formAddData.workHt = state.formAddCfgData.workHt;
          state.formAddData.batAlarmSoc = state.formAddCfgData.batAlarmSoc;
          state.formAddData.cpuVersion = state.formAddCfgData.cpuVersion;             //CPU版本也没有
          state.formAddData.tongxunVersion = state.formAddCfgData.tongxunVersion;     //通讯版本也没有
          state.formAddData.tianxianType = state.formAddCfgData.tianxianType;         //天线类型在配置表中没有
          state.formAddData.tongxunWay = state.formAddCfgData.tongxunWay;
          state.formAddData.wheelNum = state.formAddCfgData.wheelNum;
          state.formAddData.lastVal = state.formAddCfgData.lastVal;
          state.formAddData.meterFontStyle = state.formAddCfgData.meterFontStyle;

          //转换周规则
          week1.value = state.formAddCfgData.upWholeImgWeek1 == '1';
          week2.value = state.formAddCfgData.upWholeImgWeek2 == '1';
          week3.value = state.formAddCfgData.upWholeImgWeek3 == '1';
          week4.value = state.formAddCfgData.upWholeImgWeek4 == '1';
          week5.value = state.formAddCfgData.upWholeImgWeek5 == '1';
          week6.value = state.formAddCfgData.upWholeImgWeek6 == '1';
          week7.value = state.formAddCfgData.upWholeImgWeek7 == '1';

          state.deviceType = state.formAddCfgData.deviceType;

          //压力表添加 2022-09-13 guozhao
          state.formAddData.pgRangeMin = state.formAddCfgData.pgRangeMin;
          state.formAddData.pgRangeMax = state.formAddCfgData.pgRangeMax;
          state.formAddData.pgPrecisionType = state.formAddCfgData.pgPrecisionType;
          state.formAddData.pgCorrectvalue = state.formAddCfgData.pgCorrectvalue;
          state.formAddData.pgManualConfig = state.formAddCfgData.pgManualConfig;
          state.formAddData.pgIsDebug = state.formAddCfgData.pgIsDebug;
          state.formAddData.pgInitTargetRegion = state.formAddCfgData.pgInitTargetRegion;
          state.formAddData.pgManualConfigCol = state.formAddCfgData.pgManualConfigCol;
          state.formAddData.originx = state.formAddCfgData.originx;
          state.formAddData.originy = state.formAddCfgData.originy;
          state.formAddData.endx = state.formAddCfgData.endx;
          state.formAddData.endy = state.formAddCfgData.endy;
          state.formAddData.centerx = state.formAddCfgData.centerx;
          state.formAddData.centery = state.formAddCfgData.centery;
          state.formAddData.isprintcomlog = state.formAddCfgData.isprintcomlog;
          state.formAddData.isresetwdt = state.formAddCfgData.isresetwdt;
          state.formAddData.pgManualConfigLevel = state.formAddCfgData.pgManualConfigLevel;

          //大图和日志规则 2022.10.04 guozhao
          state.formAddData.wiTaskManwakeupFlag = state.formAddCfgData.wiTaskManwakeupFlag;
          state.formAddData.wiTaskMonthFlag = state.formAddCfgData.wiTaskMonthFlag;
          state.formAddData.wiTaskSpecdateFlag = state.formAddCfgData.wiTaskSpecdateFlag;
          state.formAddData.logUploadRules = state.formAddCfgData.logUploadRules;
          state.formAddData.wiTaskSpecdateEnable = state.formAddCfgData.wiTaskSpecdateEnable;
          state.formAddData.wiTaskSpecdateDate = state.formAddCfgData.wiTaskSpecdateDate;
          state.formAddData.wiTaskSpecdateDays = state.formAddCfgData.wiTaskSpecdateDays;
          state.formAddData.wiTaskSpecdateTimes = state.formAddCfgData.wiTaskSpecdateTimes;
          state.formAddData.logUploadEnable = state.formAddCfgData.logUploadEnable;
          state.formAddData.logUploadDate = state.formAddCfgData.logUploadDate;
          state.formAddData.logUploadDays = state.formAddCfgData.logUploadDays;
          state.formAddData.logUploadTimes = state.formAddCfgData.logUploadTimes;
          state.formAddData.logUploadMcuLevel = state.formAddCfgData.logUploadMcuLevel;
          state.formAddData.logUploadAiLevel = state.formAddCfgData.logUploadAiLevel;
          state.formAddData.uploadLastFailLogFlag = state.formAddCfgData.uploadLastFailLogFlag;
          state.formAddData.logTaskManwakeupFlag = state.formAddCfgData.logTaskManwakeupFlag;

          //BMP添加的 2022-11-08
          state.formAddData.imageType = state.formAddCfgData.imageType;
          state.formAddData.imageMargin = state.formAddCfgData.imageMargin;
          state.formAddData.imageConfig = state.formAddCfgData.imageConfig;
          state.formAddData.uploadCnnFlag = state.formAddCfgData.uploadCnnFlag;
          state.formAddData.nmsThreshold = state.formAddCfgData.nmsThreshold;
          state.formAddData.imageConfigFlag = state.formAddCfgData.imageConfigFlag;
          state.formAddData.imageLeanAngle = state.formAddCfgData.imageLeanAngle;
          state.formAddData.imageNumRegionXMin = state.formAddCfgData.imageNumRegionXMin;
          state.formAddData.imageNumRegionYMin = state.formAddCfgData.imageNumRegionYMin;
          state.formAddData.imageNumRegionXMax = state.formAddCfgData.imageNumRegionXMax;
          state.formAddData.imageNumRegionYMax = state.formAddCfgData.imageNumRegionYMax;

          //2022-11-15 guozhao
          state.formAddData.isUseDetectedNum = state.formAddCfgData.isUseDetectedNum;

          //2023-01-18 guozhao
          state.formAddData.regionImageType = state.formAddCfgData.regionImageType;
          state.formAddData.jpgCompressType = state.formAddCfgData.jpgCompressType;
        }
        else {
          //此处的情况是,数据库中没有该设备的有效配置
          if (isAdd) {
            ElMessageBox.confirm("未查询到设备[" + state.aiCbqCfgQueryParams.deviceSn + "]的配置,是否继续添加? ", "提示", {
              cancelButtonText: "取消",
              confirmButtonText: "确认",
              type: "warning",
              center: true,
            })
              .then(() => {
                queryDeviceAcc(state.aiCbqCfgQueryParams.deviceSn);
                state.formAddData.deviceSn = state.aiCbqCfgQueryParams.deviceSn;
                state.loadDisanbled = true;
              })
              .catch(() => {
                ElMessage({
                  type: "info",
                  message: "取消添加设备[" + state.aiCbqCfgQueryParams.deviceSn + "]的远程配置任务!",
                });
              });
          }
        }
      }
    }
  })
    .catch((error) => {
      //请求失败时的操作
      ElMessage.error(error);
    });
}
/* 新增面板结束 */

const queryDeviceAcc = (devicesn: string) => {
  DeviceAccAction.FindDeviceAccBysn(devicesn).then((result) => {
    const { res, flag, error } = result.data;
    if (flag != undefined && flag == 1) {
      state.deviceAccModel = res as DeviceAccModel;
      state.deviceType = state.deviceAccModel.deviceType;
    }
  });
}

/* 日期控件开始 */
const size = ref<'' | 'large' | 'small'>('')
const shortcuts = [
  {
    text: '今天',
    value: new Date(),
  },
  {
    text: '昨天',
    value: () => {
      const date = new Date()
      date.setTime(date.getTime() - 3600 * 1000 * 24)
      return date
    },
  },
  {
    text: '前一周',
    value: () => {
      const date = new Date()
      date.setTime(date.getTime() - 3600 * 1000 * 24 * 7)
      return date
    },
  },
]
/* 日期控件结束 */

onMounted(() => {
  queryList()
  window.onresize = function () {
    tableHeight.value = document.documentElement.clientHeight - 180;
  };
});

// onUnmounted(()=>{});

const dialogClose = () => {
  addFormRef.value.resetFields();
  cancel();
}
/* 开始 ---- 记录打开了那一项的配置开关,简单写法,应该可优化 */
const stationCode = ref(false);
const ip1Port1 = ref(false);
const ip2Port2 = ref(false);
const ip3Port3 = ref(false);
const ip4Port4 = ref(false);
const domainNamePort = ref(false);
const dnType = ref(false);
const digitNum = ref(false);
const uintType = ref(false);
const setupDir = ref(false);
const sampleInterval = ref(false);
const networkRegTimeout = ref(false);
const setupYear = ref(false);
const aiPullBack = ref(false);
const aiPass = ref(false);
const aiSinglePass = ref(false);
const pwmHz = ref(false);
const pwmDuty = ref(false);
const flashBrightMin = ref(false);
const upWholeImgWeekRule = ref(false);
const ip1ExpandOn = ref(false);
const upInterval = ref(false);
const ltSampleInterval = ref(false);
const workLt = ref(false);
const batAlarmSoc = ref(false);
const workHt = ref(false);
const batAlarmVt = ref(false);
const cpuVersion = ref(false);
const tongxunVersion = ref(false);
const tongxunWay = ref(false);
const tianxianType = ref(false);
//const wheelNum = ref(false);
const lastVal = ref(false);
const meterFontStyle = ref(false);
const pgRange = ref(false);
const pgPrecisionType = ref(false);
const pgCorrectvalue = ref(false);
const pgManualConfig = ref(false);
const pgIsDebug = ref(false);
const pgInitTargetRegion = ref(false);
const isprintcomlog = ref(false);
const isresetwdt = ref(false);
const wiTaskManwakeupFlag = ref(false);
const wiTaskMonthFlag = ref(false);
const wiTaskSpecdateFlag = ref(false);
const logUploadRules = ref(false);
const uploadLastFailLogFlag = ref(false);
const logTaskManwakeupFlag = ref(false);
const pgManualConfigLevel = ref(false);
const imageType = ref(false);
const imageMargin = ref(false);
const imageConfig = ref(false);
const uploadCnnFlag = ref(false);
const nmsThreshold = ref(false);
const isUseDetectedNum = ref(false);
const regionImageType = ref(false);
const jpgCompressType = ref(false);
/* 结束 ---- 记录打开了那一项的配置开关,简单写法,应该可优化 */

const initData = () => {
  stationCode.value = false;
  ip1Port1.value = false;
  ip2Port2.value = false;
  ip3Port3.value = false;
  ip4Port4.value = false;
  domainNamePort.value = false;
  dnType.value = false;
  digitNum.value = false;
  uintType.value = false;
  setupDir.value = false;
  sampleInterval.value = false;
  networkRegTimeout.value = false;
  setupYear.value = false;
  aiPullBack.value = false;
  aiPass.value = false;
  aiSinglePass.value = false;
  pwmHz.value = false;
  pwmDuty.value = false;
  flashBrightMin.value = false;
  upWholeImgWeekRule.value = false;
  ip1ExpandOn.value = false;
  upInterval.value = false;
  ltSampleInterval.value = false;
  workLt.value = false;
  batAlarmSoc.value = false;
  workHt.value = false;
  batAlarmVt.value = false;
  cpuVersion.value = false;
  tongxunVersion.value = false;
  tianxianType.value = false;
  tongxunWay.value = false;
  //wheelNum.value = false;         //按协议约定,要和数字个数一起配置
  lastVal.value = false;

  week1.value = false;
  week2.value = false;
  week3.value = false;
  week4.value = false;
  week5.value = false;
  week6.value = false;
  week7.value = false;

  meterFontStyle.value = false;
  pgRange.value = false;
  pgPrecisionType.value = false;
  pgCorrectvalue.value = false;
  pgManualConfig.value = false;
  pgIsDebug.value = false;
  pgInitTargetRegion.value = false;

  isprintcomlog.value = false;
  isresetwdt.value = false;
  wiTaskManwakeupFlag.value = false;
  wiTaskMonthFlag.value = false;
  wiTaskSpecdateFlag.value = false;
  logUploadRules.value = false;
  uploadLastFailLogFlag.value = false;
  logTaskManwakeupFlag.value = false;
  pgManualConfigLevel.value = false;
  imageType.value = false;
  imageMargin.value = false;
  imageConfig.value = false;
  uploadCnnFlag.value = false;
  nmsThreshold.value = false;
  isUseDetectedNum.value = false;

  regionImageType.value = false;
  jpgCompressType.value = false;
}

/* 开始 ---- 记录星期的勾选 */
const week1 = ref(false);
const week2 = ref(false);
const week3 = ref(false);
const week4 = ref(false);
const week5 = ref(false);
const week6 = ref(false);
const week7 = ref(false);
/* 结束 ---- 记录星期的勾选 */

const tableHeight = ref(document.documentElement.clientHeight - 180);

const currentRow = ref();

const handleCurrentRowChange = (val: TaskRemoteCfg | undefined) => {
  currentRow.value = val;
};

const isDebugSwitchChange = () => {
  if (state.isAdd) {
    state.formAddData.pgIsDebug = pgIsDebug.value ? '1' : '0';
  }
}

const pgInitSwitchChange = () => {
  if (state.isAdd) {
    state.formAddData.pgInitTargetRegion = pgInitTargetRegion.value ? '1' : '0';
  }
}

const comlogSwitchChange = () => {
  if (state.isAdd) {
    state.formAddData.isprintcomlog = isprintcomlog.value ? '1' : '0';
  }
}

const isresetwdtSwitchChange = () => {
  if (state.isAdd) {
    state.formAddData.isresetwdt = isresetwdt.value ? '1' : '0';
  }
}

const uploadLastFailLogFlagSwitchChange = () => {
  if (state.isAdd) {
    state.formAddData.uploadLastFailLogFlag = uploadLastFailLogFlag.value ? '1' : '0';
  }
}

const wiTaskSpecdateFlagSwitchChange = () => {
  if (wiTaskSpecdateFlag.value) {
    state.formAddData.wiTaskSpecdateDate = Moment((new Date())).format("YYYYMMDD");
  }
}

const logUploadRulesSwitchChange = () => {
  if (logUploadRules.value) {
    state.formAddData.logUploadDate = Moment((new Date())).format("YYYYMMDD");
  }
}

const deviceSnClick = (val: string) => {
  state.aiCbqCfgQueryParams.deviceSn = val;
  handleAdd();
}

//周上传规则反选
const weekRuleInvert = () => {
  week1.value = !week1.value;
  week2.value = !week2.value;
  week3.value = !week3.value;
  week4.value = !week4.value;
  week5.value = !week5.value;
  week6.value = !week6.value;
  week7.value = !week7.value;
}
</script>

<style lang="scss" scoped>
.title {
  font-size: 30px;
}

.switch_style {
  margin-left: 5px;
}
</style>