<template>
  <el-form :inline="true" :model="formInline" ref="formRef" :rules="rules" class="form-inline" label-position="top">
    <div style="display: flex;flex-direction: column;">
      <div style="flex-grow: 1;height: 66vh;overflow-y: auto;overflow-x: hidden">
        <div class="disposition-title">基本参数</div>
        <el-row :gutter="20">
          <el-col :span="4">
            <el-form-item label="部别" prop="division" style="width: 200px">
              <el-input v-model="selectData.as_depart" disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="台站名称" prop="name" style="width: 200px">
              <el-input v-model="selectData.as_name" disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="站号" prop="numberStation" style="width: 200px">
              <el-input v-model="selectData.as_code" disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="地图级别" prop="level" style="width: 200px">
              <el-select v-model="selectData.map_level" disabled>
                <el-option label="1" :value="0"></el-option>
                <el-option label="2" :value="1"></el-option>
                <el-option label="3" :value="2"></el-option>
                <el-option label="4" :value="3"></el-option>
                <el-option label="5" :value="4"></el-option>
                <el-option label="6" :value="5"></el-option>
                <el-option label="7" :value="6"></el-option>
                <el-option label="8" :value="7"></el-option>
                <el-option label="9" :value="8"></el-option>
                <el-option label="10" :value="9"></el-option>
                <el-option label="11" :value="10"></el-option>
                <el-option label="12" :value="11"></el-option>
                <el-option label="13" :value="12"></el-option>
                <el-option label="14" :value="13"></el-option>
                <el-option label="15" :value="14"></el-option>
                <el-option label="16" :value="15"></el-option>
                <el-option label="17" :value="16"></el-option>
                <el-option label="18" :value="17"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="所属基地" prop="base" style="width: 200px">
              <el-input v-model="selectData.as_base" disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="所属旅" prop="brigade" style="width: 200px">
              <el-input v-model="selectData.as_meteoro" disabled></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="4">
            <el-form-item label="架设方式" prop="methodErection" style="width: 200px">
              <el-select v-model="selectData.install_type" disabled>
                <el-option label="业务站" :value="0"></el-option>
                <el-option label="无人站" :value="1"></el-option>
                <el-option label="梯度站" :value="2"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="上传间隔" prop="interval" style="width: 200px">
              <div style="display:flex;align-items: center">
                <el-select v-model="selectData.update_space" disabled style="width: 180px">
                  <el-option label="1" :value="1"></el-option>
                  <el-option label="5" :value="5"></el-option>
                  <el-option label="10" :value="10"></el-option>
                  <el-option label="60" :value="60"></el-option>
                  <el-option label="0" :value="0"></el-option>
                </el-select>
                <span style="padding-left: 10px">分</span>
              </div>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="省" prop="provinces" style="width: 200px">
              <el-input v-model="selectData.as_province" disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="市县" prop="cities" style="width: 200px">
              <el-input v-model="selectData.as_city" disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="区镇" prop="districts" style="width: 200px">
              <el-input v-model="selectData.as_area" disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="乡镇" prop="townships" style="width: 200px">
              <el-input v-model="selectData.as_address" disabled></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="4">
            <el-form-item label="相对县城距离" prop="interval" style="width: 200px">
              <div style="display:flex;align-items: center">
                <el-input v-model="selectData.county_dist" disabled style="width: 160px"></el-input>
                <span style="padding-left: 10px">公里</span>
              </div>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="相对县城方向" prop="direction" style="width: 200px">
              <el-select v-model="selectData.county_pos" disabled>
                <el-option label="东方" :value="0"></el-option>
                <el-option label="南方" :value="1"></el-option>
                <el-option label="西方" :value="2"></el-option>
                <el-option label="北方" :value="3"></el-option>
                <el-option label="东南方" :value="4"></el-option>
                <el-option label="东北方" :value="5"></el-option>
                <el-option label="东北方" :value="6"></el-option>
                <el-option label="西北方" :value="7"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="经度" prop="longitude" style="width: 200px">
              <div style="display:flex;align-items: center">
                <el-input v-model="selectData.as_lon" disabled></el-input>
                <!--                <el-select v-model="formInline.longitude2" placeholder="" style="width: 60px;margin-left: 10px">-->
                <!--                  <el-option label="E" value="E"></el-option>-->
                <!--                  <el-option label="W" value="W"></el-option>-->
                <!--                </el-select>-->
              </div>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="纬度" prop="latitude" style="width: 200px">
              <div style="display:flex;align-items: center">
                <el-input v-model="selectData.as_lat" disabled></el-input>
                <!--                <el-select v-model="formInline.latitude2" placeholder=""  style="width: 60px;margin-left: 10px">-->
                <!--                  <el-option label="N" value="N"></el-option>-->
                <!--                  <el-option label="S" value="S"></el-option>-->
                <!--                </el-select>-->
              </div>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="观测场海拔高度" prop="fieldElevation" style="width: 200px">
              <div style="display:flex;align-items: center">
                <el-input v-model="selectData.observe_height" disabled style="width: 180px"></el-input>
                <span style="padding-left: 10px">米</span>
              </div>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="气压传感器海拔高度" prop="sensorElevation" style="width: 200px">
              <div style="display:flex;align-items: center">
                <el-input v-model="selectData.pressure_height" disabled style="width: 180px"></el-input>
                <span style="padding-left: 10px">米</span>
              </div>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="4">
            <el-form-item label="测风器距地高度" prop="heightAnmometers" style="width: 200px">
              <div style="display:flex;align-items: center">
                <el-input v-model="selectData.tower_height" disabled style="width: 180px"></el-input>
                <span style="padding-left: 10px">米</span>
              </div>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="建站日期" prop="buildWebsiteTime" style="width: 200px">
              <el-date-picker
                disabled
                v-model="selectData.build_time"
                type="date"
                placeholder="请选择"
              />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="观测组长" prop="leader" style="width: 200px">
              <el-input v-model="selectData.check_leader" disabled style="width: 180px"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="台长" prop="drector" style="width: 200px">
              <el-input v-model="selectData.station_leader" disabled style="width: 180px"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="预审员" prop="preExaminer" style="width: 200px">
              <el-input v-model="selectData.as_auditor" disabled style="width: 180px"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="授时许可" prop="grantPermission" style="width: 200px">
              <el-select v-model="selectData.set_time" disabled>
                <el-option label="不准授时" :value="0"></el-option>
                <el-option label="允许授时" :value="1"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="4">
            <el-form-item label="观测方式" prop="modeObservation" style="width: 200px">
              <el-select v-model="selectData.view_mode" disabled>
                <el-option label="人工" :value="0"></el-option>
                <el-option label="自动" :value="1"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="观测次数" prop="numberObservation" style="width: 200px">
              <div style="display:flex;align-items: center">
                <el-input v-model="selectedItems.length" style="width: 180px" disabled></el-input>
                <span style="padding-left: 10px">次</span>
              </div>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="20">
            <el-form-item label="" prop="modeObservation" style="width: 200px">
              <div style="display: flex;align-items: center">
                <span>观测时次</span>
                <el-checkbox v-model="allTime" style="margin-left: 10px" label="全选" disabled/>
              </div>
              <sCheckbox style="margin-top: 5px" :data="selectedItemData" :data2="selectedItems"
                         @update:data2="updateSelectedItems"></sCheckbox>
            </el-form-item>
          </el-col>
        </el-row>
        <div class="disposition-title">通信设置</div>
        <el-row :gutter="20">
          <el-col :span="20">
            <div style="display: flex;align-items: center;margin-bottom: 5px">
              <span>主通信</span>
              <el-checkbox v-model="isFromCommunication"  disabled style="margin-left: 10px" label="启用从通信"/>
            </div>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="4">
            <el-form-item label="通信方式" prop="methods" style="width: 200px">
              <el-select v-model="primaryCommunications.comm_type" disabled>
                <el-option label="串口" :value="0"></el-option>
                <el-option label="北斗" :value="1"></el-option>
                <el-option label="4G" :value="2"></el-option>
                <el-option label="文件" :value="3"></el-option>
                <el-option label="TCPClient" :value="4"></el-option>
              </el-select>
            </el-form-item>
          </el-col>


          <el-col :span="4" v-if="primaryCommunications.comm_type===0">
            <el-form-item label="串口号" prop="port" style="width: 200px">
              <el-input v-model="stringSlogans" disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4" v-if="primaryCommunications.comm_type===0">
            <el-form-item label="通信参数" prop="port" style="width: 200px">
              <el-input v-model="parameter" disabled></el-input>
            </el-form-item>
          </el-col>

          <el-col :span="4" v-if="primaryCommunications.comm_type===1">
            <el-form-item label="自动站通信机ID" prop="port" style="width: 200px">
              <el-input v-model="comID" disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4" v-if="primaryCommunications.comm_type===1">
            <el-form-item label="服务端通信机ID" prop="port" style="width: 200px">
              <el-input v-model="serveID" disabled></el-input>
            </el-form-item>
          </el-col>

          <el-col :span="4" v-if="primaryCommunications.comm_type===2">
            <el-form-item label="传输协议" prop="agreement" disabled="" style="width: 200px">
              <el-select v-model="comID4g">
                <el-option label="TCP" value="TCP"></el-option>
                <el-option label="TCP+DDP" value="TCP+DDP"></el-option>
                <el-option label="UDP" value="UDP"></el-option>
                <el-option label="UDP+DDP" value="UDP+DDP"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="4" v-if="primaryCommunications.comm_type===2">
            <el-form-item label="SIM卡号" prop="sim" style="width: 200px">
              <el-input v-model="sim" disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4" v-if="primaryCommunications.comm_type===2">
            <el-form-item label="通信模块ID" prop="modelId" style="width: 200px">
              <el-input v-model="serveID4g" disabled></el-input>
            </el-form-item>
          </el-col>

          <el-col :span="4" v-if="primaryCommunications.comm_type===2">
            <el-form-item label="端口号" prop="modelId"  style="width: 200px">
              <el-input v-model="port4g" disabled></el-input>
            </el-form-item>
          </el-col>


          <el-col :span="4" v-if="primaryCommunications.comm_type===3">
            <el-form-item label="扫码间隔" prop="agreement"  style="width: 200px">
              <el-select v-model="intervalFile" disabled>
                <el-option label="1分钟" value="1"></el-option>
                <el-option label="10分钟" value="10"></el-option>
                <el-option label="60分钟" value="60"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="4" v-if="primaryCommunications.comm_type===3">
            <el-form-item label="文件类型" prop="sim" style="width: 200px">
              <el-select v-model="typeFile" disabled>
                <el-option label="mdb" value="0"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="4" v-if="primaryCommunications.comm_type===3">
            <el-form-item label="文件路径" prop="modelId" style="width: 200px">
              <el-input v-model="urlFile" disabled></el-input>
            </el-form-item>
          </el-col>


          <el-col :span="4" v-if="primaryCommunications.comm_type===4">
            <el-form-item label="ip地址" prop="port" style="width: 200px">
              <el-input v-model="ip" disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4" v-if="primaryCommunications.comm_type===4">
            <el-form-item label="端口号" prop="port" style="width: 200px">
              <el-input v-model="port" disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4"
                  v-if="primaryCommunications.comm_type===4||primaryCommunications.comm_type===0||primaryCommunications.comm_type===1">
            <el-form-item label="通信模式" prop="communicationMode" style="width: 200px">
              <el-select v-model="primaryCommunications.comm_mode" disabled>
                <el-option label="主动+补收" :value="0"></el-option>
                <el-option label="被动" :value="1"></el-option>
                <el-option label="主动" :value="2"></el-option>
                <el-option label="被动 + 补收" :value="3"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20" v-if="primaryCommunications.comm_type!==3">
          <el-col :span="20">
            <el-form-item label="" prop="modeObservation" style="width: 200px">
              <div style="display: flex;align-items: center">
                <span>命令设置</span>
                <!-- <el-button type="primary" plain style="margin-left: 10px">设置命令</el-button>-->
              </div>
            </el-form-item>
            <!-- 表格主体 -->
            <div class="table-box" style="width:920px;">
              <el-table stripe ref="tableRef" :border="true" :data="primaryTableData" size="small" height="140">
                <template v-for="item in columns" :key="item">
                  <el-table-column v-bind="item" :align="item.align ?? 'left'" :reserve-selection="item.type == 'selection'"
                                   :show-overflow-tooltip="true">
                    <template #default="scope">
                      <template v-if="item.prop === 'commandInterval'">
                        {{scope.row.commandInterval}} 分钟
                      </template>
                    </template>
                  </el-table-column>
                </template>

                <!-- 无数据 -->
                <template #empty>
                  <div class="table-empty">
                    <slot name="empty">
                      <div>暂无数据</div>
                    </slot>
                  </div>
                </template>
              </el-table>
            </div>
          </el-col>
        </el-row>




        <el-row :gutter="20">
          <el-col :span="20">
            <div style="display: flex;align-items: center;margin-bottom: 5px;margin-top: 20px">
              <span>从通信</span>
            </div>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="4">
            <el-form-item label="通信方式" prop="methods" style="width: 200px">
              <el-select v-model="fromCommunication.comm_type" disabled>
                <el-option label="串口" :value="0"></el-option>
                <el-option label="北斗" :value="1"></el-option>
                <el-option label="4G" :value="2"></el-option>
                <el-option label="文件" :value="3"></el-option>
                <el-option label="TCPClient" :value="4"></el-option>
              </el-select>
            </el-form-item>
          </el-col>


          <el-col :span="4" v-if="fromCommunication.comm_type===0">
            <el-form-item label="串口号" prop="port" style="width: 200px">
              <el-input v-model="stringSlogans2" disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4" v-if="fromCommunication.comm_type===0">
            <el-form-item label="通信参数" prop="port" style="width: 200px">
              <el-input v-model="parameter2" disabled></el-input>
            </el-form-item>
          </el-col>

          <el-col :span="4" v-if="fromCommunication.comm_type===1">
            <el-form-item label="自动站通信机ID" prop="port" style="width: 200px">
              <el-input v-model="comID2" disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4" v-if="fromCommunication.comm_type===1">
            <el-form-item label="服务端通信机ID" prop="port" style="width: 200px">
              <el-input v-model="serveID2" disabled></el-input>
            </el-form-item>
          </el-col>

          <el-col :span="4" v-if="fromCommunication.comm_type===2">
            <el-form-item label="传输协议" prop="agreement" disabled="" style="width: 200px">
              <el-select v-model="comID4g2">
                <el-option label="TCP" value="TCP"></el-option>
                <el-option label="TCP+DDP" value="TCP+DDP"></el-option>
                <el-option label="UDP" value="UDP"></el-option>
                <el-option label="UDP+DDP" value="UDP+DDP"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="4" v-if="fromCommunication.comm_type===2">
            <el-form-item label="SIM卡号" prop="sim" style="width: 200px">
              <el-input v-model="sim2" disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4" v-if="fromCommunication.comm_type===2">
            <el-form-item label="通信模块ID" prop="modelId" style="width: 200px">
              <el-input v-model="serveID4g2" disabled></el-input>
            </el-form-item>
          </el-col>

          <el-col :span="4" v-if="fromCommunication.comm_type===2">
            <el-form-item label="端口号" prop="modelId"  style="width: 200px">
              <el-input v-model="port4g2" disabled></el-input>
            </el-form-item>
          </el-col>


          <el-col :span="4" v-if="fromCommunication.comm_type===3">
            <el-form-item label="扫码间隔" prop="agreement"  style="width: 200px">
              <el-select v-model="intervalFile2" disabled>
                <el-option label="1分钟" value="1"></el-option>
                <el-option label="10分钟" value="10"></el-option>
                <el-option label="60分钟" value="60"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="4" v-if="fromCommunication.comm_type===3">
            <el-form-item label="文件类型" prop="sim" style="width: 200px">
              <el-select v-model="typeFile2" disabled>
                <el-option label="mdb" value="0"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="4" v-if="fromCommunication.comm_type===3">
            <el-form-item label="文件路径" prop="modelId" style="width: 200px">
              <el-input v-model="urlFile2" disabled></el-input>
            </el-form-item>
          </el-col>


          <el-col :span="4" v-if="fromCommunication.comm_type===4">
            <el-form-item label="ip地址" prop="port" style="width: 200px">
              <el-input v-model="ip2" disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4" v-if="fromCommunication.comm_type===4">
            <el-form-item label="端口号" prop="port" style="width: 200px">
              <el-input v-model="port2" disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4"
                  v-if="fromCommunication.comm_type===4||fromCommunication.comm_type===0||fromCommunication.comm_type===1">
            <el-form-item label="通信模式" prop="communicationMode" style="width: 200px">
              <el-select v-model="fromCommunication.comm_mode" disabled>
                <el-option label="主动+补发" :value="0"></el-option>
                <el-option label="被动" :value="1"></el-option>
                <el-option label="主动" :value="2"></el-option>
                <el-option label="被动 + 补收" :value="3"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20" v-if="fromCommunication.comm_type!==3">
          <el-col :span="20">
            <el-form-item label="" prop="modeObservation" style="width: 200px">
              <div style="display: flex;align-items: center">
                <span>命令设置</span>
                <!-- <el-button type="primary" plain style="margin-left: 10px">设置命令</el-button>-->
              </div>
            </el-form-item>
            <!-- 表格主体 -->
            <div class="table-box" style="width:920px;">
              <el-table stripe ref="tableRef" :border="true" :data="primaryTableData2" size="small" height="140">
                <template v-for="item in columns" :key="item">
                  <el-table-column v-bind="item" :align="item.align ?? 'left'" :reserve-selection="item.type == 'selection'" :show-overflow-tooltip="true">
                    <template #default="scope">
                      <template v-if="item.prop === 'commandInterval'">
                        {{scope.row.commandInterval}} 分钟
                      </template>
                    </template>
                  </el-table-column>
                </template>

                <!-- 无数据 -->
                <template #empty>
                  <div class="table-empty">
                    <slot name="empty">
                      <div>暂无数据</div>
                    </slot>
                  </div>
                </template>
              </el-table>
            </div>
          </el-col>
        </el-row>
      </div>
      <div class="disposition-bottom">
        <el-button disabled> 取消</el-button>
        <el-button type="primary" disabled> 下一步</el-button>
      </div>
    </div>
  </el-form>
</template>

<script setup lang="tsx">
import sCheckbox from "../../../../components/SCheckbox/index.vue"
import {defineProps, onMounted, reactive, ref} from "vue";
import {ColumnProps} from "@/components/ProTable/interface";
import {getYascomm} from "@/api/modules/allData";

const props = defineProps<{
  selectData?: {};
}>();
const formRef = ref<any>();
const formInline = ref<any>({
  division: "",
  name: "",
  numberStation: "",
  level: "",
  base: "",
  brigade: "",
  methodErection: "",
  interval: "",
  provinces: "",
  cities: "",
  districts: "",
  townships: "",
  distance: "",
  direction: "",
  longitude: "",
  longitude2: "E",
  latitude: "",
  latitude2: "N",
  fieldElevation: "",
  sensorElevation: "",
  modeObservation: "",
  numberObservation: "",
  heightAnmometers: "",
  buildWebsiteTime: "",
  leader: "",
  drector: "",
  preExaminer: "",
  grantPermission: "",
  allTime: "",
  enableCorrespondence: "",
  methods: "",
  agreement: "",
  sim: "",
  modelId: "",
  port: "",
  communicationMode: ""
})

const rules = ref<any>(
  {
    division: [{required: true, message: "部别不能为空", trigger: "blur"}],
    name: [{required: true, message: "台站名称不能为空", trigger: "blur"}],
    numberStation: [{required: true, message: "站号不能为空", trigger: "blur"}],
    base: [{required: true, message: "所属基地不能为空", trigger: "blur"}],
    brigade: [{required: true, message: "所属旅不能为空", trigger: "blur"}],
    methodErection: [{required: true, message: "架设方式不能为空", trigger: "blur"}],
    provinces: [{required: true, message: "省不能为空", trigger: "blur"}],
    cities: [{required: true, message: "市县不能为空", trigger: "blur"}],
    districts: [{required: true, message: "区镇不能为空", trigger: "blur"}],
    townships: [{required: true, message: "乡镇不能为空", trigger: "blur"}],
    distance: [{required: true, message: "相对县城距离不能为空", trigger: "blur"}],
    longitude: [{required: true, message: "相对县城方向不能为空", trigger: "blur"}],
    latitude: [{required: true, message: "相对县城方向不能为空", trigger: "blur"}],
    fieldElevation: [{required: true, message: "观测场海拔高度不能为空", trigger: "blur"}],
    sensorElevation: [{required: true, message: "气压传感器海拔高度不能为空", trigger: "blur"}],

  }
);

/** 提交按钮 */
const submitForm = () => {
  formRef.value?.validate(async (valid: boolean) => {
    if (valid) {

    }
  });
}

const selectedItemData = ref<number[]>([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24]);
const selectedItems = ref<number[]>([]);

function updateSelectedItems(newSelectedItems: number[]) {
  selectedItems.value = newSelectedItems;
}

const allTime = ref(false)


const pageable = ref<any>({
  asCode: props.selectData.as_code,
  pageNum: 1,
  pageSize: 20,
});

const primaryCommunications = ref({});
const fromCommunication = ref({});
const isFromCommunication = ref(true)

//串口
const stringSlogans = ref()
const parameter = ref()
const stringSlogans2 = ref()
const parameter2 = ref()

//北斗
const comID = ref()
const serveID = ref()
const comID2 = ref()
const serveID2 = ref()

//4G
const comID4g = ref()
const sim = ref()
const serveID4g = ref()
const port4g = ref()
const comID4g2 = ref()
const sim2 = ref()
const serveID4g2 = ref()
const port4g2 = ref()

//文件
const intervalFile = ref()
const typeFile = ref()
const urlFile = ref()
const intervalFile2 = ref()
const typeFile2 = ref()
const urlFile2 = ref()

//TPC
const ip = ref()
const port = ref()
const ip2 = ref()
const port2 = ref()


//主表格数据
const primaryTableData = ref([]);
const primaryTableData2 = ref([]);

const getYascommList = async () => {
  const {data} = await getYascomm(pageable.value);
  const averageList = data[props.selectData.as_code]
  if (averageList != undefined) {
    primaryCommunications.value = averageList.find(station => station.comm_level === 0);
    if(primaryCommunications.value){
      // 分析串口类型数据
      if (primaryCommunications.value.comm_type === 0) {
        // 通信基本信息
        if (primaryCommunications.value.comm_param) {
          const params = primaryCommunications.value.comm_param.split(',');
          if (params.length > 1) {
            stringSlogans.value= params[0],
            parameter.value= params.slice(1).join(',')
          }
        }

        //通信命令数据
        if (primaryCommunications.value.comm_cmd) {
          primaryTableData.value = parseCommandData(primaryCommunications.value.comm_cmd)
        }
      }
      // 北斗
      else if (primaryCommunications.value.comm_type === 1) {
        // 通信基本信息
        if (primaryCommunications.value.comm_param) {
          const params = primaryCommunications.value.comm_param.split(',');
          if (params.length >= 2) {
            comID.value = params[0].trim()
              serveID.value = params[1].trim()
          }

        }

        //通信命令数据
        if (primaryCommunications.value.comm_cmd) {
          primaryTableData.value = parseCommandData(primaryCommunications.value.comm_cmd)
        }
      }
      //4G
      else if (primaryCommunications.value.comm_type === 2) {
        // 通信基本信息
        if (primaryCommunications.value.comm_param) {
          const params = primaryCommunications.value.comm_param.split(',');
          if (params.length >= 4) {
            comID4g.value = params[0].trim()
              sim.value = params[1].trim()
            serveID4g.value = params[2].trim()
            port4g.value = params[3].trim()
          }
        }

        //通信命令数据
        if (primaryCommunications.value.comm_cmd) {
          primaryTableData.value = parseCommandData(primaryCommunications.value.comm_cmd)
        }
      }
      //文件
      else if (primaryCommunications.value.comm_type === 3) {
        // 通信基本信息
        if (primaryCommunications.value.comm_param) {
          const params = primaryCommunications.value.comm_param.split(',');
          if (params.length >=3) {
            intervalFile.value = params[1].trim()
              typeFile.value = params[0].trim()
            urlFile.value = params[2].trim()

          }
        }
      }
      // 分析TCP类型数据
      else if (primaryCommunications.value.comm_type === 4) {
        // 通信基本信息
        if (primaryCommunications.value.comm_param) {
          const params = primaryCommunications.value.comm_param.split(',');
          if (params.length === 2) {
            ip.value = params[0].trim()
              port.value = params[1].trim()
          }
        }

        //通信命令数据
        if (primaryCommunications.value.comm_cmd) {
          primaryTableData.value = parseCommandData(primaryCommunications.value.comm_cmd)
        }
      }
    }

    fromCommunication.value = averageList.find(station => station.comm_level === 1);
    if(fromCommunication.value){
      isFromCommunication.value = fromCommunication.value.use_able === 1 ? true : false
      // 分析串口类型数据
      if (primaryCommunications.value.comm_type === 0) {
        // 通信基本信息
        if (fromCommunication.value.comm_param) {
          const params = fromCommunication.value.comm_param.split(',');
          if (params.length > 1) {
            stringSlogans2.value= params[0],
            parameter2.value= params.slice(1).join(',')
          }
        }

        //通信命令数据
        if (fromCommunication.value.comm_cmd) {
          primaryTableData2.value = parseCommandData(fromCommunication.value.comm_cmd)
        }
      }
      // 北斗
      else if (fromCommunication.value.comm_type === 1) {
        // 通信基本信息
        if (fromCommunication.value.comm_param) {
          const params = fromCommunication.value.comm_param.split(',');
          if (params.length >= 2) {
            comID2.value = params[0].trim()
            serveID2.value = params[1].trim()
          }

        }

        //通信命令数据
        if (fromCommunication.value.comm_cmd) {
          primaryTableData2.value = parseCommandData(fromCommunication.value.comm_cmd)
        }
      }
      //4G
      else if (fromCommunication.value.comm_type === 2) {
        // 通信基本信息
        if (fromCommunication.value.comm_param) {
          const params = fromCommunication.value.comm_param.split(',');
          if (params.length >= 4) {
            comID4g2.value = params[0].trim()
            sim2.value = params[1].trim()
            serveID4g2.value = params[2].trim()
            port4g2.value = params[3].trim()
          }
        }

        //通信命令数据
        if (fromCommunication.value.comm_cmd) {
          primaryTableData2.value = parseCommandData(fromCommunication.value.comm_cmd)
        }
      }
      //文件
      else if (fromCommunication.value.comm_type === 3) {
        // 通信基本信息
        if (fromCommunication.value.comm_param) {
          const params = fromCommunication.value.comm_param.split(',');
          if (params.length >=3) {
            intervalFile2.value = params[1].trim()
            typeFile2.value = params[0].trim()
            urlFile2.value = params[2].trim()

          }
        }
      }
      // 分析TCP类型数据
      else if (fromCommunication.value.comm_type === 4) {
        // 通信基本信息
        if (fromCommunication.value.comm_param) {
          const params = fromCommunication.value.comm_param.split(',');
          if (params.length === 2) {
            ip2.value = params[0].trim()
            port2.value = params[1].trim()
          }
        }

        //通信命令数据
        if (fromCommunication.value.comm_cmd) {
          primaryTableData2.value = parseCommandData(fromCommunication.value.comm_cmd)
        }
      }
    }
  }
}

// 命令类型数据映射
const commandTypeData = {
  0: "观测数据",
  1: "工况数据",
  2: "数据"
};

// 解析数据的方法
function parseCommandData(data) {
  if(data===';'){
    return ;
  }
  // 分割命令组
  const commands = data.split(";");
  commands.shift();
  // 存储解析后的命令数据
  const parsedCommands = [];

  // 遍历每个命令组
  commands.forEach(commandGroup => {
    // 分割命令名称、命令间隔和命令类型
    const [commandName, commandInterval, commandType] = commandGroup.split("|");

    // 根据命令类型获取对应的描述
    const commandTypeDesc = commandTypeData[parseInt(commandType)] || "未知类型";

    // 添加解析后的命令数据到数组
    parsedCommands.push({
      commandName,
      commandInterval: parseInt(commandInterval),
      commandTypeDesc
    });
  });

  return parsedCommands;
}

const processTableData = ref([]);

// 表格配置项
const columns = reactive<ColumnProps[]>([
  {prop: "commandName", label: "命令名称"},
  {prop: "commandName", label: "命令标识符"},
  {prop: "commandTypeDesc", label: "命令类型"},
  {prop: "commandInterval", label: "间隔时间(分钟)"}
]);

onMounted(() => {
  const observe_time = props.selectData.observe_time
  if (observe_time) {
    const timeArray = observe_time.split(';').map(item => parseInt(item, 10));
    selectedItems.value = timeArray;
    allTime.value = selectedItems.value.length === 24 ? true : false
  }
  getYascommList()
})
</script>

<style scoped>
.table-box {
  height: auto;
}
</style>
