<template>
    <div>
        <el-row>
            <el-form ref="addFormRef" :model="formEditData" :inline="true" style="margin-top:-30px;">
                <el-form-item label="任务描述" style="margin-left: 20px;">
                    <el-input v-model="formEditData.taskDescribe" placeholder="创建原因" size="small" maxlength="40"
                        style="width:300px;" clearable />
                </el-form-item>

                <el-form-item label="远程任务创建时间:" style="margin-left: 10px;">
                    <el-config-provider :locale="locale">
                        <el-date-picker v-model="formEditData.executionTime" type="datetime" placeholder="选择执行时间"
                            ref="datePicker" value-format="YYYY-MM-DD HH:mm:ss" size="small"
                            style="max-width: 190px;" />
                    </el-config-provider>
                </el-form-item>

                <!-- <el-form-item label="提前分钟" style="margin-left: 10px;">
                    <el-input v-model.number="formEditData.minutesAhead" placeholder="提前分钟" size="small"
                        style="max-width:100px;" show-word-limit clearable maxlength="3" />
                </el-form-item> -->

                <el-form-item>
                    <el-button type="primary" style="margin-left:10px" @click="submitAddForm"
                        :disabled="state.saveDisabled">
                        保存
                    </el-button>

                    <el-form-item>
                        <el-button type="primary" style="margin-left:10px" @click="closeForm">
                            取消
                        </el-button>
                    </el-form-item>
                </el-form-item>
            </el-form>
        </el-row>
        <el-divider style="margin-top: -10px;height: 2px;background-color: #b6d7fb;" />
        <el-row>
            <el-tabs style="margin-top: -15px;height: 600px;margin-bottom: -20px;" type="border-card">
                <el-tab-pane label="基础配置">
                    <el-form ref="addFormRef" :model="formAddData">
                        <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"
                                        @change="WeekRuleChange" />
                                    <el-checkbox label="二" size="small" v-model="week2" :disabled="!upWholeImgWeekRule"
                                        @change="WeekRuleChange" />
                                    <el-checkbox label="三" size="small" v-model="week3" :disabled="!upWholeImgWeekRule"
                                        @change="WeekRuleChange" />
                                    <el-checkbox label="四" size="small" v-model="week4" :disabled="!upWholeImgWeekRule"
                                        @change="WeekRuleChange" />
                                    <el-checkbox label="五" size="small" v-model="week5" :disabled="!upWholeImgWeekRule"
                                        @change="WeekRuleChange" />
                                    <el-checkbox label="六" size="small" v-model="week6" :disabled="!upWholeImgWeekRule"
                                        @change="WeekRuleChange" />
                                    <el-checkbox label="日" size="small" v-model="week7" :disabled="!upWholeImgWeekRule"
                                        @change="WeekRuleChange" />
                                    <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"
                                        @change="WeekRuleChange" />
                                </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" />
                                </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" />
                                </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" />
                                </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="xMin"
                                            :disabled="!imageConfig" style="width: 60px;" maxlength="3" size="small"
                                            oninput="value=value.replace(/[^\d]/g, '');if(value>319) value=333" />
                                        <el-input v-model="formAddData.imageNumRegionYMin" placeholder="yMin"
                                            :disabled="!imageConfig" style="width: 60px;" maxlength="3" size="small"
                                            oninput="value=value.replace(/[^\d]/g, '');if(value>239) value=333" />
                                        <span> -- </span>
                                        <el-input v-model="formAddData.imageNumRegionXMax" placeholder="xMax"
                                            :disabled="!imageConfig" style="width: 65px;" maxlength="3" size="small"
                                            oninput="value=value.replace(/[^\d]/g, '');if(value>319) value=333" />
                                        <el-input v-model="formAddData.imageNumRegionYMax" placeholder="yMax"
                                            :disabled="!imageConfig" style="width: 65px;" 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: 105px;" />
                                    <el-input v-model="formAddData.originy" placeholder="origin-y"
                                        :disabled="!pgManualConfig" maxlength="4"
                                        onkeyup="value=value.replace(/[^\d]/g, '')" style="width: 107px;" />
                                    <el-input v-model="formAddData.endx" placeholder="end-x" :disabled="!pgManualConfig"
                                        v-if="pgManualConfig" maxlength="4" onkeyup="value=value.replace(/[^\d]/g, '')"
                                        style="width: 105px;" />
                                    <el-input v-model="formAddData.endy" placeholder="end-y" :disabled="!pgManualConfig"
                                        v-if="pgManualConfig" maxlength="4" onkeyup="value=value.replace(/[^\d]/g, '')"
                                        style="width: 107px;" />
                                    <el-input v-model="formAddData.centerx" placeholder="center-x"
                                        :disabled="!pgManualConfig" v-if="pgManualConfig" maxlength="4"
                                        onkeyup="value=value.replace(/[^\d]/g, '')" style="width: 105px;" />
                                    <el-input v-model="formAddData.centery" placeholder="center-y"
                                        :disabled="!pgManualConfig" v-if="pgManualConfig" maxlength="4"
                                        onkeyup="value=value.replace(/[^\d]/g, '')" style="width: 107px;" />
                                </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-tab-pane label="设备列表">
                    <el-table :data="state.formEditData.detailModels" border stripe style="width: 100%," height="540px"
                        ref="tableDevList" size="large"
                        :header-cell-style="{ background: '#FF000000', color: '#000000' }"
                        @keyup.enter.native="appendDetail">
                        <el-table-column type="index" width="50" align="center" />
                        <el-table-column label="设备SN" align="left" width="150">
                            <template #default="scope">
                                <el-input v-model="scope.row.deviceSn" maxlength="11" :disabled="!props.isAdd">
                                </el-input>
                            </template>
                        </el-table-column>

                        <el-table-column label="删除" align="center" width="70">
                            <template #default="scope">
                                <el-button type="text" @click="handleDeleteDev(scope.row)" :disabled="!props.isAdd">
                                    删除
                                </el-button>
                            </template>
                        </el-table-column>

                        <el-table-column fit></el-table-column>
                    </el-table>
                </el-tab-pane>
            </el-tabs>
        </el-row>
    </div>
</template>

<script lang="ts" setup>
import { reactive, toRefs, ref, onMounted, defineEmits } from "vue";
import { ElForm, ElMessage, ElTable } from 'element-plus';
import TaskBatchRemoteAction from "@/api/taskbatch/taskbatchremote";
import {
    TaskBatchRemoteModel, PageResult, TaskBatchRemoteDetailModel,
    TaskRemoteCfg, TCheckModel, TCheckFzModel, TStkinModel, TStkoutModel,
    TStkinDetailModelQueryParam, TStkinDetailModel, TStkoutDetailModelQueryParam,
    TStkoutDetailModel
} from '@/types';
import zhCn from 'element-plus/lib/locale/lang/zh-cn';
//import CfgForm from '@/components/batchcfg/cfgform/index.vue';
import TCheckAction from "@/api/qualitymanagement/tcheck";
import TStkinDetailAction from "@/api/tstkindetail";
import TStkoutDetailAction from "@/api/tstkoutdetail";
import { AxiosPromise } from "axios";
import Dic from "@/dictionary/aicbqcfg";
import tool from "@/until/tool";
import Moment from "moment";

const props = defineProps({
    data: Object,
    isAdd: Boolean,
    taskType: Number,
    checkObject: Object,
    stInObject: Object,
    stOutObject: Object,
    childEvent: Event
})

const { data } = toRefs(props)
const { isAdd } = toRefs(props)
const { taskType } = toRefs(props)

//子->父
const emit = defineEmits(['change'])

const datePicker = ref();

onMounted(() => {
    if (props.data != null && !props.isAdd) {
        state.formEditData = props.data as TaskBatchRemoteModel;
        state.formAddRemoteCfgData = state.formEditData.taskRemoteCfgModel;
        loadDateByEdit();
    }
    if (props.isAdd) {
        state.formEditData = {} as TaskBatchRemoteModel;
        state.formEditData.createMan = localStorage.getItem("UserName") || "";
        state.formEditData.taskType = props.taskType + '';

        state.formEditData.detailModels = [] as TaskBatchRemoteDetailModel[];
        state.formEditData.taskRemoteCfgModel = {} as TaskRemoteCfg;

        if (props.taskType === 9) {//手动新增时先添加10行
            for (let i = 0; i < 10; i++) {
                state.formEditData.detailModels.push({} as TaskBatchRemoteDetailModel);
            }
        }

        if (props.checkObject) {//从拷机过来的
            let checkModel = props.checkObject as TCheckModel;
            let typeLabel = '';
            if (checkModel.startTime) {
                if (checkModel.endTime) {
                    typeLabel = '[拷机后]' + checkModel.checkName;
                } else {
                    typeLabel = '[拷机中]' + checkModel.checkName;
                }
            } else {
                typeLabel = '[拷机前]' + checkModel.checkName;
            }
            state.formEditData.executionTime = new Date();
            state.formEditData.taskDescribe = typeLabel;
            state.formEditData.sourceTaskId = checkModel.checkId;
            queryTCheckDetailList(checkModel.checkId);
        } else if (props.stInObject) {//从入库过来的
            let inModel = props.stInObject as TStkinModel;
            state.formEditData.taskDescribe = '[入库]' + inModel.billCode;
            state.formEditData.sourceTaskId = inModel.billCode;
            queryTStkinDetailList(inModel);

        } else if (props.stOutObject) {//从出库过来的
            let outModel = props.stOutObject as TStkoutModel;
            state.formEditData.taskDescribe = '[出库]' + outModel.billCode;
            state.formEditData.sourceTaskId = outModel.billCode;
            queryTStkoutDetailList(outModel);
        }
    }
});

let locale = ref(zhCn);
const state = reactive({
    detailData: [] as TaskBatchRemoteDetailModel[],
    formEditData: {} as TaskBatchRemoteModel,
    saveDisabled: false,
    formAddRemoteCfgData: {} as TaskRemoteCfg,
    deviceType: '1',
});

const {
    formEditData,
    formAddRemoteCfgData: formAddData
} = toRefs(state);

const submitAddForm = () => {
    state.saveDisabled = true;
    let axi = {} as AxiosPromise;

    state.formEditData.taskRemoteCfgModel = state.formAddRemoteCfgData;
    if (sampleInterval.value) {
        state.formEditData.taskRemoteCfgModel.upInterval = state.formEditData.taskRemoteCfgModel.sampleInterval;
    }
    if (props.isAdd) {
        axi = TaskBatchRemoteAction.AddTaskBatchRemote(state.formEditData);
    } else {
        axi = TaskBatchRemoteAction.EditTaskBatchRemote(state.formEditData);
    }

    //TaskBatchRemoteAction.AddTaskBatchRemote(state.formEditData).then((result) => {
    axi.then((result) => {
        const { res, flag, error } = result.data;
        if (flag === "1") {
            ElMessage.success("保存成功");
            emit('change', true)
            state.saveDisabled = false;
        }
        else {
            ElMessage.warning(error);
            state.saveDisabled = false;
        }
    });
}

//移除设备
const handleDeleteDev = (val: TaskBatchRemoteDetailModel) => {
    let index = state.formEditData.detailModels.indexOf(val);
    state.formEditData.detailModels.splice(index, 1);
}

const appendDetail = () => {
    state.formEditData.detailModels.push({} as TaskBatchRemoteDetailModel);
    let activeEl = document.activeElement;
    if (activeEl) {
        const container = activeEl.parentElement;
    }
}

//查询拷机明细,加载到设备列表中
const queryTCheckDetailList = (checkId: string) => {
    TCheckAction.QueryTCheckDetail(checkId).then((result) => {
        if (result.status === 200) {
            const { res, flag, error } = result.data;
            if (flag === "1") {
                const data = res as TCheckFzModel;
                state.formEditData.executionTime = tool.dateFormat(data.planEndTime, 'YYYYMMDDHHmmss', 'YYYY-MM-DD HH:mm:ss');

                data.detailList.forEach(s => {
                    let detail = {} as TaskBatchRemoteDetailModel;
                    detail.deviceSn = s.deviceSn;
                    state.formEditData.detailModels.push(detail);
                })
            } else {
                ElMessage.error(error || "未知异常...");
            }
        }
    }).catch((error) => {
        //请求失败时的操作
        ElMessage.error(error || "未知异常...");
    });
};

//查询入库设备明细信息,加载到设备列表中
const queryTStkinDetailList = (inModel: TStkinModel) => {
    let queryParams = {} as TStkinDetailModelQueryParam;
    queryParams.billCode = inModel.billCode;
    queryParams.page = 1;
    queryParams.rows = 1000;
    TStkinDetailAction.QueryTStkinDetailModelList(queryParams).then((result) => {
        if (result.status === 200) {
            const { res, flag, error } = result.data;
            if (flag === "1") {
                const pageData = res as PageResult<TStkinDetailModel[]>;
                pageData.list.forEach(s => {
                    let detail = {} as TaskBatchRemoteDetailModel;
                    detail.deviceSn = s.deviceSn;
                    state.formEditData.detailModels.push(detail);
                })
            } else {
                ElMessage.error(error || "查询设备明细异常...");
            }
        }
    })
        .catch((error: any) => {
            ElMessage.error(error || "查询设备明细异常...");
        });
};

//查询入库设备明细信息,加载到设备列表中
const queryTStkoutDetailList = (outModel: TStkoutModel) => {
    let queryParams = {} as TStkoutDetailModelQueryParam;
    queryParams.billCode = outModel.billCode;
    queryParams.page = 1;
    queryParams.rows = 1000;

    TStkoutDetailAction.QueryTStkoutDetailModelList(queryParams)
        .then((result) => {
            if (result.status === 200) {
                const { res, flag, error } = result.data;
                if (flag === "1") {
                    const pageData = res as PageResult<TStkoutDetailModel[]>;
                    state.formEditData.executionTime
                    pageData.list.forEach(s => {
                        let detail = {} as TaskBatchRemoteDetailModel;
                        detail.deviceSn = s.deviceSn;
                        state.formEditData.detailModels.push(detail);
                    })
                } else {
                    ElMessage.error(error || "查询设备明细异常...");
                }
            }
        })
        .catch((error) => {
            ElMessage.error(error || "查询设备明细异常...");
        });
};

const closeForm = () => {
    emit('change', false)
}

/* 开始 ---- 记录打开了那一项的配置开关,简单写法,应该可优化 */
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 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;
    WeekRuleChange();
}

/* 日期控件开始 */
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
        },
    },
]
/* 日期控件结束 */

const isDebugSwitchChange = () => {
    state.formAddRemoteCfgData.pgIsDebug = pgIsDebug.value ? '1' : '0';

}

const pgInitSwitchChange = () => {
    state.formAddRemoteCfgData.pgInitTargetRegion = pgInitTargetRegion.value ? '1' : '0';

}

const comlogSwitchChange = () => {
    state.formAddRemoteCfgData.isprintcomlog = isprintcomlog.value ? '1' : '0';

}

const isresetwdtSwitchChange = () => {
    state.formAddRemoteCfgData.isresetwdt = isresetwdt.value ? '1' : '0';

}

const uploadLastFailLogFlagSwitchChange = () => {
    state.formAddRemoteCfgData.uploadLastFailLogFlag = uploadLastFailLogFlag.value ? '1' : '0';

}

const wiTaskSpecdateFlagSwitchChange = () => {
    state.formAddRemoteCfgData.wiTaskSpecdateDate = Moment((new Date())).format("YYYYMMDD");

}

const logUploadRulesSwitchChange = () => {
    state.formAddRemoteCfgData.logUploadDate = Moment((new Date())).format("YYYYMMDD");

}

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

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

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

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

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

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

    isUseDetectedNum.value = state.formAddRemoteCfgData.isUseDetectedNum != null;

    regionImageType.value=state.formAddRemoteCfgData.regionImageType!=null;
    jpgCompressType.value=state.formAddRemoteCfgData.jpgCompressType!=null;
};

//周规则发生改变
const WeekRuleChange = () => {
    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.formAddRemoteCfgData.upWholeImgWeekRule = weeks;
    }
}
</script>

