<!-- 配置预览组件 -->
<template>
  <div>
    <el-tabs style="margin-top: -20px;height: 600px;margin-bottom: -10px;" type="border-card">
      <el-tab-pane label="基础配置">
        <el-form label-position="left" label-width="100px" style="margin-left: 40px;margin-top: 10px;">
          <el-row class="el-row">
            <el-col :span="7">
              <el-form-item label="遥测站编码">
                <span>：{{ aicbqCfgData.stationCode }}</span>
              </el-form-item>
            </el-col>

            <el-col :span="8">
              <el-form-item label="通道1地址">
                <span>：{{ aicbqCfgData.serverIp1 }}:{{ aicbqCfgData.serverPort1 }}</span>
              </el-form-item>
            </el-col>

            <el-col :span="9">
              <el-form-item label="域名地址">
                <span>：{{ aicbqCfgData.domainName }}:{{ aicbqCfgData.domainPort }}</span>
              </el-form-item>
            </el-col>
          </el-row>
          <el-divider style="margin-top: 0;margin-bottom: 0;width: 80%;" />

          <el-row class="el-row">
            <el-col :span="7">
              <el-form-item label="采样间隔">
                <span>：{{ aicbqCfgData.sampleInterval }} 分钟</span>
              </el-form-item>
            </el-col>

            <el-col :span="8">
              <el-form-item label="上报间隔">
                <span>：{{ aicbqCfgData.upInterval }} 分钟</span>
              </el-form-item>
            </el-col>

            <el-col :span="6">
              <el-form-item label="低温采样间隔">
                <span>：{{ aicbqCfgData.ltSampleInterval }} 小时</span>
              </el-form-item>
            </el-col>

            <el-col :span="3">
              <vue-qr :text="aicbqCfgData.deviceSn" :size="110" style="margin-top: -10px;"></vue-qr>
            </el-col>
          </el-row>
          <el-divider style="margin-top: 0;margin-bottom: 0;width: 80%;" />

          <el-row class="el-row" v-if="aicbqCfgData.deviceType === '1'">
            <el-col :span="7">
              <el-form-item label="数字个数">
                <span>：{{ aicbqCfgData.digitNum }}</span>
              </el-form-item>
            </el-col>

            <el-col :span="8">
              <el-form-item label="字轮个数">
                ：{{ aicbqCfgData.wheelNum }}
              </el-form-item>
            </el-col>

            <el-col :span="9">
              <el-form-item label="尾数单位">
                <span v-if="aicbqCfgData.uintType === 1">：0.001</span>
                <span v-if="aicbqCfgData.uintType === 2">：0.01</span>
                <span v-if="aicbqCfgData.uintType === 3">：0.1</span>
                <span v-if="aicbqCfgData.uintType === 4">：1</span>
                <span v-if="aicbqCfgData.uintType === 5">：10</span>
                <span v-if="aicbqCfgData.uintType === 6">：100</span>
                <span v-if="aicbqCfgData.uintType === 7">：1000</span>
                <span v-if="aicbqCfgData.uintType === 8">：10000</span>
              </el-form-item>
            </el-col>
          </el-row>
          <el-divider style="margin-top: 0;margin-bottom: 0;width: 97%;" v-if="aicbqCfgData.deviceType === '1'" />
          <el-row class="el-row">
            <el-col :span="7" v-if="aicbqCfgData.deviceType === '1'">
              <el-form-item label="设备口径">
                ：{{ getDnType(aicbqCfgData.dnType) }}
              </el-form-item>
            </el-col>

            <el-col :span="8">
              <el-form-item label="安装方向">
                <span v-if="aicbqCfgData.setupDir === '0'">：正向</span>
                <span v-if="aicbqCfgData.setupDir === '1'">：反向</span>
                <span v-if="aicbqCfgData.setupDir === '2'">：右90</span>
                <span v-if="aicbqCfgData.setupDir === '3'">：右90</span>
              </el-form-item>
            </el-col>

            <el-col :span="9" v-if="aicbqCfgData.deviceType === '1'">
              <el-form-item label="当前读数">
                ：{{ aicbqCfgData.lastVal }}
              </el-form-item>
            </el-col>
          </el-row>
          <el-divider style="margin-top: 0;margin-bottom: 0;width: 97%;" />

          <el-row class="el-row">
            <el-col :span="7">
              <el-form-item label="数传类型">
                <el-radio-group v-model="aicbqCfgData.tongxunWay">
                  <span v-if="aicbqCfgData.tongxunWay === '1'">：CAT1</span>
                  <span v-if="aicbqCfgData.tongxunWay === '2'">：NB</span>
                </el-radio-group>
              </el-form-item>
            </el-col>

            <el-col :span="8">
              <el-form-item label="天线类型">
                <span>：{{ Dic.tianxianType[aicbqCfgData.tianxianType] }}</span>
              </el-form-item>
            </el-col>

            <el-col :span="9">
              <el-form-item label="安装年份">
                ：{{ aicbqCfgData.setupYear }}
              </el-form-item>
            </el-col>
          </el-row>
          <el-divider style="margin-top: 0;margin-bottom: 0;width: 97%;" />
          <el-row class="el-row">
            <el-col :span="7">
              <el-form-item label="生效时间">
                ：{{ tool.dateFormatNoSec(aicbqCfgData.createTime) }}
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </el-tab-pane>
      <el-tab-pane label="运维配置" v-if="userType === '0'">
        <el-form label-position="left" label-width="100px" style="margin-left: 40px;margin-top: 10px;">
          <el-row class="el-row">
            <el-col :span="5">
              <el-form-item label="工作温度范围">
                ：{{ aicbqCfgData.workLt }}- {{ aicbqCfgData.workHt }}
              </el-form-item>
            </el-col>
            <el-col :span="2">
            </el-col>
            <el-col :span="8">
              <el-form-item label="低电压报警值">
                ：{{ aicbqCfgData.batAlarmVt }} V
              </el-form-item>
            </el-col>

            <el-col :span="7">
              <el-form-item label="余电报警值">
                ：{{ aicbqCfgData.batAlarmSoc }} %
              </el-form-item>
            </el-col>
          </el-row>
          <el-divider style="margin-top: 0;margin-bottom: 0;width: 96%;" />
          <el-row class="el-row">
            <el-col :span="7">
              <el-form-item label="背光频率">
                ：{{ aicbqCfgData.pwmHz }} Hz
              </el-form-item>
            </el-col>

            <el-col :span="8">
              <el-form-item label="背光占空比">
                ：{{ aicbqCfgData.pwmDuty }} %
              </el-form-item>
            </el-col>

            <el-col :span="9">
              <el-form-item label="补光灯亮度">
                <span>：{{ aicbqCfgData.flashBrightMin }}-{{ aicbqCfgData.flashBrightMax }}</span>
              </el-form-item>
            </el-col>
          </el-row>
          <el-divider style="margin-top: 0;margin-bottom: 0;width: 96%;" />
          <el-row class="el-row">
            <el-col :span="7">
              <el-form-item label="入网超时时间">
                ：{{ aicbqCfgData.networkRegTimeout }} 秒
              </el-form-item>
            </el-col>

            <el-col :span="8">
              <el-form-item label="CPU版本号">
                ：{{ aicbqCfgData.cpuVersion }}
              </el-form-item>
            </el-col>

            <el-col :span="9">
              <el-form-item label="通信板版本号">
                ：{{ aicbqCfgData.tongxunVersion }}
              </el-form-item>
            </el-col>
          </el-row>
          <el-divider style="margin-top: 0;margin-bottom: 0;width: 96%;" v-if="aicbqCfgData.deviceType === '1'" />
          <el-row class="el-row" v-if="aicbqCfgData.deviceType === '1'">
            <el-col :span="7">
              <el-form-item label="整图周规则">
                ：{{ jxweekString() }}
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="触发传大图">
                <span v-if="aicbqCfgData.wiTaskManwakeupFlag === '1'">：是</span>
                <span v-if="aicbqCfgData.wiTaskManwakeupFlag !== '1'">：否</span>
              </el-form-item>
            </el-col>
            <el-col :span="9">
              <el-form-item label="月初末传大图">
                <span v-if="aicbqCfgData.wiTaskMonthFlag === '1'">：是</span>
                <span v-if="aicbqCfgData.wiTaskMonthFlag !== '1'">：否</span>
              </el-form-item>
            </el-col>
          </el-row>
          <el-divider style="margin-top: 0;margin-bottom: 0;width: 96%;" v-if="aicbqCfgData.deviceType === '1'" />
          <el-row class="el-row" v-if="aicbqCfgData.deviceType === '1'">
            <el-col :span="20">
              <el-form-item label="传大图规则">
                <span>：{{ global.getWiTaskSpecdateTip(aicbqCfgData, 1) }}</span>
              </el-form-item>
            </el-col>
          </el-row>
          <el-divider style="margin-top: 0;margin-bottom: 0;width: 96%;" />
          <el-row class="el-row">
            <el-col :span="20">
              <el-form-item label="传日志规则">
                <span>：{{ global.getLogUploadRulesTip(aicbqCfgData, 1) }}</span>
              </el-form-item>
            </el-col>
          </el-row>
          <el-divider style="margin-top: 0;margin-bottom: 0;width: 96%;" />
          <el-row class="el-row">
            <el-col :span="7">
              <el-form-item label="输出串口日志">
                <span v-if="aicbqCfgData.isprintcomlog === '1'">：是</span>
                <span v-if="aicbqCfgData.isprintcomlog !== '1'">：否</span>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="上传错误日志">
                <span v-if="aicbqCfgData.uploadLastFailLogFlag === '1'">：是</span>
                <span v-if="aicbqCfgData.uploadLastFailLogFlag !== '1'">：否</span>
              </el-form-item>
            </el-col>
            <el-col :span="9">
              <el-form-item label="触发传日志">
                <span v-if="aicbqCfgData.logTaskManwakeupFlag === '1'">：是</span>
                <span v-if="aicbqCfgData.logTaskManwakeupFlag !== '1'">：否</span>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </el-tab-pane>

      <el-tab-pane label="AI配置" v-if="aicbqCfgData.deviceType === '1' && userType === '0'">
        <el-form label-position="left" label-width="100px" style="margin-left: 40px;margin-top: 10px;">
          <el-row class="el-row" v-if="aicbqCfgData.deviceType === '1'">
            <el-col :span="7">
              <el-form-item label="强制拉回概率">
                ：{{ aicbqCfgData.aiPullBack }}%
              </el-form-item>
            </el-col>

            <el-col :span="8">
              <el-form-item label="识别概率阈值">
                ：{{ aicbqCfgData.aiPass }}
              </el-form-item>
            </el-col>

            <el-col :span="9">
              <el-form-item label="位概率阈值">
                ：{{ aicbqCfgData.aiSinglePass }}
              </el-form-item>
            </el-col>
          </el-row>
          <el-divider style="margin-top: 0;margin-bottom: 0;width: 96%;" />
          <el-row class="el-row" v-if="aicbqCfgData.deviceType === '1'">
            <el-col :span="7">
              <el-form-item label="上传图片类型">
                ：{{ aicbqCfgData.imageType }}
              </el-form-item>
            </el-col>

            <el-col :span="8">
              <el-form-item label="图像外扩像素">
                ：{{ aicbqCfgData.imageMargin }}
              </el-form-item>
            </el-col>

            <el-col :span="9">
              <el-form-item label="上传模型结果">
                <span v-if="aicbqCfgData.uploadCnnFlag === '1'">：是</span>
                <span v-if="aicbqCfgData.uploadCnnFlag !== '1'">：否</span>
              </el-form-item>
            </el-col>
          </el-row>
          <el-divider style="margin-top: 0;margin-bottom: 0;width: 96%;" />
          <el-row class="el-row" v-if="aicbqCfgData.deviceType === '1'">
            <el-col :span="15">
              <el-form-item label="指定数字区域">
                ：{{ global.getImageConfigip(aicbqCfgData) }}
              </el-form-item>
            </el-col>

            <el-col :span="9">
              <el-form-item label="NMS阈值">
                ：{{ aicbqCfgData.nmsThreshold }}
              </el-form-item>
            </el-col>
          </el-row>

          <el-divider style="margin-top: 0;margin-bottom: 0;width: 96%;" />

          <el-row class="el-row" v-if="aicbqCfgData.deviceType === '1'">
            <el-col :span="7">
              <el-form-item label="大框去野数字">
                ：{{ aicbqCfgData.isUseDetectedNum == '1' ? '是' : '否' }}
              </el-form-item>
            </el-col>
          </el-row>

          <el-divider style="margin-top: 0;margin-bottom: 0;width: 96%;" />
          <el-row class="el-row">
            <el-col :span="7">
              <el-form-item label="上报图片类型">
                ：{{ aicbqCfgData.regionImageType ? (aicbqCfgData.regionImageType == '1' ? 'JPG' : 'BMP') : '' }}
              </el-form-item>
            </el-col>
            <el-col :span="7">
              <el-form-item label="JPG压缩类型">
                ：{{ aicbqCfgData.jpgCompressType }}
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </el-tab-pane>

      <el-tab-pane label="压力表" v-if="aicbqCfgData.deviceType === '2' && userType === '0'">
        <el-form label-position="left" label-width="100px" style="margin-left: 40px;margin-top: 10px;">
          <el-row class="el-row">
            <el-col :span="7">
              <el-form-item label="量程范围">
                <span>：{{ aicbqCfgData.pgRangeMin }} - {{ aicbqCfgData.pgRangeMax }}</span>
              </el-form-item>
            </el-col>

            <el-col :span="8">
              <el-form-item label="数据精度">
                <span v-if="aicbqCfgData.pgPrecisionType === 0">：1</span>
                <span v-if="aicbqCfgData.pgPrecisionType === 1">：0.1</span>
                <span v-if="aicbqCfgData.pgPrecisionType === 2">：0.01</span>
                <span v-if="aicbqCfgData.pgPrecisionType === 3">：0.001</span>
                <span v-if="aicbqCfgData.pgPrecisionType === 4">：0.0001</span>
              </el-form-item>
            </el-col>

            <el-col :span="9">
              <el-form-item label="校正参数">
                ：{{ aicbqCfgData.pgCorrectvalue }}
              </el-form-item>
            </el-col>
          </el-row>

          <el-row class="el-row">
            <el-col :span="7">
              <el-form-item label="图片是否描点">
                <span>：{{ aicbqCfgData.pgIsDebug === '1' ? '是' : '否' }}</span>
              </el-form-item>
            </el-col>

            <el-col :span="8">
              <el-form-item label="数据初始化">
                ：{{ aicbqCfgData.pgInitTargetRegion === '1' ? '是' : '否' }}
              </el-form-item>
            </el-col>

            <el-col :span="9">
              <el-form-item label="坐标点优先级">
                ：{{ Dic.PGManualConfigLevel[aicbqCfgData.pgManualConfigLevel] }}
              </el-form-item>
            </el-col>
          </el-row>

          <el-row class="el-row" v-if="aicbqCfgData.deviceType === '2'">
            <el-col>
              <el-form-item label="坐标点赋值">
                <span
                  style="display :inline-block;width:60%;overflow: hidden;text-overflow:ellipsis;white-space:nowrap;"
                  :title="aicbqCfgData.pgManualConfigCol">：{{ aicbqCfgData.pgManualConfigCol }}</span>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script lang="ts" setup>
import { TAicbqCfg, TAicbqCfgQueryParam, PageResult } from "@/types";
import { onMounted, reactive, toRefs } from "vue";
import TAicbqCfgAction from "@/api/taicbqcfg"
import { ElMessage } from "element-plus";
import { watch } from "@vue/runtime-core";
import Dic from "@/dictionary/aicbqcfg";
import tool from "@/until/tool";
import global from '@/until/global';
import vueQr from 'vue-qr/src/packages/vue-qr.vue';

const props = defineProps({
  //子组件接收父组件传递过来的值
  deviceSn: String,
  stationCode: String,
})

//使用父组件传递过来的值
const { deviceSn } = toRefs(props)
const { stationCode } = toRefs(props)
let userType = localStorage.getItem("UserType") + '';
const state = reactive({
  aicbqCfgData: {} as TAicbqCfg,
});

const {
  aicbqCfgData,
} = toRefs(state);

const queryCfg = () => {
  state.aicbqCfgData = {} as TAicbqCfg;

  let queryParams = { page: 1, rows: 1, useFlag: '1' } as TAicbqCfgQueryParam;
  if (props.deviceSn) {
    queryParams.deviceSn = props.deviceSn;
  } else if (props.stationCode) {
    queryParams.stationCode = props.stationCode;
  } else {
    return;
  }

  TAicbqCfgAction.QueryTAicbqCfgList(queryParams)
    .then((result) => {
      //console.log(result);
      if (result.status === 200) {
        const { res, flag, errot } = result.data;
        if (flag != undefined && flag == 1) {
          const pageData = res as PageResult<TAicbqCfg[]>;
          if (pageData.list.length > 0) {
            state.aicbqCfgData = pageData.list[0];
          } else {
            ElMessage.info("当前设备没有有效的配置记录");
          }
        }
      }
    })
    .catch((error) => {
      //请求失败时的操作
      ElMessage.error(error);
    });
}

watch([deviceSn, stationCode], ([deviceSn0, deviceSn1], [stationCode0, stationCode1]) => {
  queryCfg();
})

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 jxweekString = () => {
  let temp = '';
  if (state.aicbqCfgData.upWholeImgWeek1 == '1') {
    temp += '一';
  }
  if (state.aicbqCfgData.upWholeImgWeek2 == '1') {
    temp += '二';
  }
  if (state.aicbqCfgData.upWholeImgWeek3 == '1') {
    temp += '三';
  }
  if (state.aicbqCfgData.upWholeImgWeek4 == '1') {
    temp += '四';
  }
  if (state.aicbqCfgData.upWholeImgWeek5 == '1') {
    temp += '五';
  }
  if (state.aicbqCfgData.upWholeImgWeek6 == '1') {
    temp += '六';
  }
  if (state.aicbqCfgData.upWholeImgWeek7 == '1') {
    temp += '日';
  }
  if (temp === '') {
    temp = '不上传';
  }
  return temp;
}

onMounted(() => {
  queryCfg();

});
</script>

<style lang="scss" scoped>
.el-row {
  height: 45px;
  display: flex;
}
</style>