<template>
  <div class="airportInfo">
    <div class="headerBox">
      <Minheader :is-Preser="true" :is-statuser="true" @preserForm="preserForm">
        <template #header>
          <div class="status flex-wrap">
            <div class="manageTitle">预警告警场景</div>
          </div>
        </template>
      </Minheader>
      <div class="diacont">
        <el-form :model="tableForm" class="w100 fw" :rules="formRules" ref="warningEditsForm">
          <!-- <div class="outersurface pd30">
            <el-form-item label="策略名称" size="default">
              <el-input v-model="tableForm.name" placeholder="请输入策略名称" />
            </el-form-item>
          </div> -->
          <div class="outersurface pd30">
            <el-form-item label="名称" prop="alarmname" size="default">
              <el-input v-model="tableForm.alarmname" placeholder="请输入名称" />
            </el-form-item>
          </div>
          <div class="outersurface pd30">
            <el-form-item label="航司二字码" size="default" prop="IATACode">
              <el-select style="width: 100%" v-model="tableForm.IATACode" class="input-shadow" filterable allow-create default-first-option clearable placeholder="请选择航司二字码">
                <el-option v-for="item in iaCodeArr" :key="item.airlineCompanyID" :label="item.ITATCode" :value="item.ITATCode">
                </el-option>
              </el-select>
            </el-form-item>
          </div>
          <div class="outersurface pd30">
            <el-form-item label="国内国际" size="default" prop="ditype" :rules="formRules.isNotNull">
              <el-select style="width: 100%" v-model="tableForm.ditype" class="input-shadow" filterable allow-create default-first-option placeholder="请选择国内国际">
                <el-option v-for="(item,index) in ditypeAll" :key="index" :label="item.k" :value="item.v">
                </el-option>
              </el-select>
            </el-form-item>
          </div>
          <div class="outersurface pd30">
            <el-form-item label="起飞机场" size="default" prop="departmentAirport" :rules="formRules.isNotNull">
              <el-select style="width: 100%" v-model="tableForm.departmentAirport" class="input-shadow" filterable allow-create default-first-option clearable placeholder="请选择起飞机场">
                <el-option v-for="item in tableOption" :key="item.airportID" :label="item.IATACode" :value="item.IATACode">
                </el-option>
              </el-select>
            </el-form-item>
          </div>
          <div class="outersurface pd30">
            <el-form-item label="降落机场" size="default">
              <el-select style="width: 100%" v-model="tableForm.landingAirport" class="input-shadow" filterable allow-create default-first-option clearable placeholder="请选择降落机场">
                <el-option v-for="item in tableOption" :key="item.airportID" :label="item.IATACode" :value="item.IATACode">
                </el-option>
              </el-select>
            </el-form-item>
          </div>
          <div class="outersurface pd30">
            <el-form-item label="航班号" size="default" prop="flightNo">
              <el-input v-model="tableForm.flightNo" placeholder="请输入航班号" />
            </el-form-item>
          </div>
          <div class="outersurface pd30">
            <el-form-item label="机型" prop="planetype" size="default">
              <el-select style="width: 100%" v-model="tableForm.planetype" class="input-shadow" filterable allow-create default-first-option placeholder="请选择机型">
                <el-option label="宽体机" value="宽体机" />
                <el-option label="窄体机" value="窄体机" />
                <el-option label="全部" value="全部" />
              </el-select>
            </el-form-item>
          </div>
          <div class="outersurface pd30">
            <el-form-item label="客货机" prop="flighttype" size="default">
              <el-select style="width: 100%" v-model="tableForm.flighttype" class="input-shadow" filterable allow-create default-first-option placeholder="请选择客货机">
                <el-option label="客机" value="客机" />
                    <el-option label="货机" value="货机" />
                    <el-option label="全部" value="全部" />
              </el-select>
            </el-form-item>
          </div>
          <div class="outersurface pd30">
            <el-form-item label="停机位" prop="landingstand" size="default">
              <el-input ref="inputRef" v-model="tableForm.landingstand" placeholder="请输入停机位" />
            </el-form-item>
          </div>
          <div class="outersurface pd30">
            <el-form-item label="生效时间" size="default" prop="startDate" :rules="formRules.isNotNull">
              <el-date-picker v-model="tableForm.startDate" :rows="1" type="datetime" format="YYYY-MM-DD HH:mm:ss" value-format="YYYY-MM-DD HH:mm:ss" placeholder="选择日期时间">
              </el-date-picker>
            </el-form-item>
          </div>
          <div class="outersurface pd30">
            <el-form-item label="失效时间" size="default" prop="endDate">
              <el-date-picker format="YYYY-MM-DD HH:mm:ss" value-format="YYYY-MM-DD HH:mm:ss" v-model="tableForm.endDate" :rows="1" type="datetime" placeholder="选择日期时间">
              </el-date-picker>
            </el-form-item>
          </div>
          <div class="outersurface pd30">
            <el-form-item label="描述" prop="alarmdesc" size="default">
              <el-input v-model="tableForm.alarmdesc" placeholder="请输入描述" />
            </el-form-item>
          </div>
        </el-form>
      </div>
    </div>
    <el-popover
      ref="popoverRef"
      :virtual-ref="inputRef"
      virtual-triggering
      placement="right"
      trigger="click"
      content="多个停机位用逗号分隔，例如 51,52"
    />
    <div class="centerBox">
      <Minheader :is-auth="true" :is-statuser="true" :is-Search="false" powerData="add_alert_policy_button" @addForm="addForm" style="margin-top: 20px">
        <template #header>
          <div class="status flex-wrap">
            <div class="manageTitle">预警告警策略</div>
          </div>
        </template>
      </Minheader>
    </div>
    <div class="containers scroll-y">
      <DataTable :tableHeader="tableCols" :tableData="tableData" :tableBtnGroup="tableBtnGroup" :tableProperty="{ rowKey: 'ID' }" @btnClick="btnClick" />
    </div>
    <Dialog width="600px" :flag="flag" :type="type" :msgTitle="msgTitle" :delName="delName" @resetForm="resetForm" @delRest="delRest" @submitForm="submitForm" @delRemove="delRemove">
      <div class="diacont">
        <el-form :model="tableForms" :rules="formRules" ref="warningEditForm">
          <el-row :gutter="24">
            <el-col :span="12">
              <el-form-item label="策略名称" size="default" prop="StrategyName" :rules="formRules.isNotNull">
                <el-input v-model="tableForms.StrategyName" placeholder="请输入策略名称" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="计算依据" size="default">
                <el-select style="width: 100%" v-model="tableForms.calculationBasis" class="input-shadow" filterable default-first-option placeholder="请选择计算依据">
                  <el-option v-for="item in calculationBasis" :key="item.v ? item.v : item.planDepartureApt" :label="item.k ? item.k : item.planDepartureApt" :value="item.v ? item.v : item.planDepartureApt">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="基准节点" size="default">
                <el-select style="width: 100%" v-model="tableForms.beginNode" class="input-shadow" filterable default-first-option clearable placeholder="请选择开始节点" @change="changeSelect">
                  <el-option v-for="item in tableOptionser" :key="item.nodeID" :label="item.nodeName" :value="item.nodeCode">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <!-- <el-col :span="12">
              <el-form-item label="开始位置" size="default">
                <el-select style="width: 100%" v-model="tableForms.beginPosition" class="input-shadow" filterable default-first-option clearable placeholder="请选择开始位置" @change="changebegin">
                  <el-option v-for="item in tableOptionbegin" :key="item.positionID" :label="item.positionDescribe" :value="item.locationCode">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col> -->
            <el-col :span="12">
              <el-form-item label="报警节点" size="default">
                <el-select style="width: 100%" v-model="tableForms.endNode" class="input-shadow" filterable default-first-option clearable placeholder="请选择结束节点" @change="changeSelected">
                  <el-option v-for="item in tableOptionser" :key="item.nodeID" :label="item.nodeName" :value="item.nodeCode">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <!-- <el-col :span="12">
              <el-form-item label="结束位置" size="default">
                <el-select style="width: 100%" v-model="tableForms.endPosition" class="input-shadow" filterable default-first-option clearable placeholder="请选择结束位置" @change="changeEndPos">
                  <el-option v-for="item in tableOptionbegin" :key="item.positionID" :label="item.positionDescribe" :value="item.locationCode">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col> -->
            <el-col :span="12">
              <el-form-item label="超时预警" size="default" prop="warningDuration">
                <el-input v-model="tableForms.warningDuration" placeholder="请输入超时分钟" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="超时报警" size="default" prop="alarmDuration">
                <el-input v-model="tableForms.alarmDuration" placeholder="请输入超时分钟" />
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="运单数报警百分比" :label-width="140" size="default">
                <el-input v-model="tableForms.percentage" placeholder="请输入运单数报警百分比" />
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="板卡数报警百分比" :label-width="140" size="default">
                <el-input v-model="tableForms.percentuld" placeholder="请输入板卡数报警百分比" />
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>
    </Dialog>
  </div>
</template>

<script setup lang="ts">
import _ from "lodash";
import Minheader from "@/components/minheader/index.vue";
import DataTable from "@/components/tableTemp/index.vue";
import Dialog from "@/components/dialog/index.vue";
import {
  Query,
  GeneralDataReception,
  htQuery,
  dataToChange,
} from "@/api/webApi";
import { ElMessage } from "element-plus";
import { onMounted } from "vue";
const formRules = useElement().formRules;
const router = useRouter();
const route = useRoute();
const page = ref<number>(0); //分页参数
const dataContent = ref<object>({});
const noMore = ref<boolean>(false);
const rowTitle = ref<string>("");
const tableCols = ref<any>([]); //表头数据
const iaCodeArr = ref<any>([]); //航司二字码
const serviceId = ref<string | any>("");
const beginPositionId = ref<string | any>("");
const endPositionId = ref<string | any>("");
const tableObj = ref({}); //增删改数据缓存
const delName = ref<string | any>("");
const inputRef = ref(null)
const tableForm = reactive({
  alarmSceneId: null,
  IATACode: null,
  departmentAirport: null,
  landingAirport: null,
  flightNo: null,
  startDate: null,
  endDate: null,
  planetype: null,
  flighttype: null,
  landingstand: null,
  alarmname: null,
  alarmdesc: null,
  event: 2,
  ditype: "ALL",
}); //报警预警场景
const tableForms = reactive<any>({
  alarmStrategyID: null,
  StrategyName: null,
  calculationBasis: "1",
  warningDuration: null,
  alarmDuration: null,
  beginNode: null,
  beginPosition: null,
  endNode: null,
  endPosition: null,
  alarmSceneId: route.query.alarmSceneId,
  event: null,
  percentage: null,
  percentuld: null,
}); //弹窗内容
const tableOption = ref<any>([]); //下拉
const tableOptionser = ref<any>([]); //下拉
const tableOptionbegin = ref<any>([]); //下拉
const tableOptionend = ref<any>([]); //下拉
const tableOptionendPos = ref<any>([]); //下拉
const calculationBasis = ref<any>([
  {
    k: "离港",
    v: "1",
  },
  {
    k: "进港",
    v: "0",
  },
]); //下拉
const ditypeAll = ref<any>([
  {
    k: "全部",
    v: "ALL",
  },
  {
    k: "国内",
    v: "DOM",
  },
  {
    k: "国际",
    v: "INT",
  },
]);
const flag = ref<boolean>(false); //弹窗开关
const type = ref<string>(""); //判断是否删除
const msgTitle = ref<string>("新增预警告警策略"); //弹窗标题
//列表
const tableData = ref<any>([]);
//表头
const state = reactive({
  list: [
    { label: "名称", key: "name", width: "100px" },
    { label: "三字码", key: "china", width: "50px" },
    { label: "四字码", key: "englin", width: "50px" },
    { label: "中文简称", key: "two", width: "50px" },
    { label: "英文简称", key: "three", width: "50px" },
    { label: "全称", key: "text", width: "50px" },
    { label: "时区", key: "text1", width: "50px" },
    { label: "公司名称", key: "text2", width: "50px" },
  ],
  listLoading: true,
});
const tableBtnGroup = ref([
  {
    name: "编辑",
    className: "editBtn",
    param: 2,
    is: "edit_alert_policy_button",
  },
  {
    name: "删除",
    className: "delBtn",
    param: 3,
    is: "delete_alert_policy_button",
  },
]);
//新增
const addForm = () => {
  msgTitle.value = "新增预警告警策略";
  flag.value = true;
  type.value = "add";
  tableForms.event = 1;
};
//取消
const resetForm = () => {
  warningEditForm.value?.resetFields()
  flag.value = false;
  // tableForms.alarmStrategyID = null;
  // tableForms.StrategyName = null;
  // // tableForms.calculationBasis = null;
  // tableForms.warningDuration = null;
  // tableForms.alarmDuration = null;
  // tableForms.beginNode = null;
  // tableForms.beginPosition = null;
  // tableForms.endNode = null;
  // tableForms.endPosition = null;
  // tableForms.percentage = null;
  // tableForms.percentuld = null;
  // delName.value = null;
};
const delRemove = async () => {
  // tableForms.event = 3;
  const { code, message } = await dataToChange(
    DATACONTENT_ID.sysServiceClIds,
    tableForms,
    3
  );
  if (code == 0) {
    ElMessage.success("保存成功");
    resetTable();
    getQuery();
    resetForm();
    flag.value = false;
    tableObj.value = {};
  } else {
    ElMessage.error("操作失败");
    tableObj.value = {};
    resetForm();
  }
};
//删除
const delRest = () => {
  flag.value = false;
};
//编辑-删除
const btnClick = (row, index, param) => {
  if (param === 2) {
    msgTitle.value = "编辑预警告警策略";
    flag.value = true;
    type.value = "edit";
    const newVal = _.cloneDeep(index);
    // newVal.beginPosition = Number(newVal.beginPosition);
    // newVal.endPosition = Number(newVal.endPosition);
    newVal.calculationBasis = `${newVal.calculationBasis}`;
    for (const key in tableForms) {
      for (const p in newVal) {
        if (key == p) {
          tableForms[key] = newVal[p];
        }
      }
    }
  } else if (param === 3) {
    msgTitle.value = "删除预警告警策略";
    flag.value = true;
    type.value = "del";
    // tableForms.event = 3;
    delName.value = index.StrategyName;
    tableForms.alarmStrategyID = index.alarmStrategyID;
    delete tableForms.StrategyName;
    delete tableForms.calculationBasis;
    delete tableForms.warningDuration;
    delete tableForms.alarmDuration;
    delete tableForms.beginNode;
    delete tableForms.endNode;
    delete tableForms.endPosition;
    delete tableForms.percentage;
    delete tableForms.beginPosition;
    delete tableForms.percentuld;
    // delete tableForms.alarmSceneId;
    delete tableForms.event;
    // tableForms.StrategyName = index.StrategyName;
    // tableForms.calculationBasis = index.calculationBasis;
    // tableForms.warningDuration = index.warningDuration;
    // tableForms.alarmDuration = index.alarmDuration;
    // tableForms.beginNode = index.beginNode;
    // tableForms.beginPosition = index.beginPosition;
    // tableForms.endNode = index.endNode;
    // tableForms.endPosition = index.endPosition;
    // tableForms.percentage = index.percentage;
  } else if (param === 4) {
  }
};

//获取预警报警场景(按照ID)
const sysServiceWarn = async () => {
  try {
    const result: any = await htQuery(DATACONTENT_ID.sysServiceCjId, {
      alarmSceneId: route.query.alarmSceneId,
    });
    if (result.length) {
      const newVal = _.cloneDeep(result[0]);
      for (const key in tableForm) {
        for (const p in newVal) {
          if (key == p) {
            tableForm[key] = newVal[p];
          }
        }
      }
    } else {
      // this.page--;
      // this.$message.error.message;
      // this.loading = false;
    }
  } catch (error) {
    // this.page--;
    // this.loading = false;
  }
};
//飞机场-下拉数据
const getSelectDatas = async (id, name?) => {
  const { code, returnData } = await Query({
    id,
    dataContent: name ? [name] : name === null ? [null] : [],
  });
  if (code == 0) {
    tableOption.value = returnData.listValues;
  } else {
    tableOption.value = [];
  }
};
//获取弹框-下拉数据
const getSelectData = async (id, name, dataNme) => {
  const { code, returnData } = await Query({
    id,
    dataContent: name ? [name] : name === null ? [null] : [],
  });
  if (code == 0) {
    // return returnData.listValues;
    if (dataNme === "calculationBasis") {
      calculationBasis.value = returnData.listValues;
    }
    // if (dataNme === "beginNode") {
    //   tableOptionser.value = returnData.listValues;
    // } else if (dataNme === "beginPosition") {
    //   tableOptionbegin.value = returnData.listValues;
    // } else if (dataNme === "endNode") {
    //   tableOptionend.value = returnData.listValues;
    // } else if (dataNme === "endPosition") {
    //   tableOptionendPos.value = returnData.listValues;
    // }
  } else {
  }
};
//获取表格数据
const getQuery = async () => {
  try {
    const columnSet = [
      {
        queryTemplateColumnSetID: 290,
        queryTemplateID: 18033,
        columnName: "alarmStrategyID",
        columnLabel: "策略编号",
        columnDescribe: "策略编号",
        needSort: 0,
        needFilters: 1,
        needShow: 0,
        needGroup: 0,
        dataType: "int",
        listqueryTemplateID: null,
        needCount: null,
        orderNumber: null,
        needSearch: null,
      },
      {
        queryTemplateColumnSetID: 291,
        queryTemplateID: 18033,
        columnName: "StrategyName",
        columnLabel: "策略名称",
        columnDescribe: "策略名称",
        needSort: 0,
        needFilters: 1,
        needShow: 1,
        needGroup: 0,
        dataType: "varchar",
        listqueryTemplateID: null,
        needCount: null,
        orderNumber: null,
        needSearch: null,
      },
      {
        queryTemplateColumnSetID: 292,
        queryTemplateID: 18033,
        columnName: "calculationBasis",
        columnLabel: "计算依据",
        columnDescribe: "计算依据",
        needSort: 0,
        needFilters: 1,
        needShow: 0,
        needGroup: 0,
        dataType: "int",
        listqueryTemplateID: 1803423,
        needCount: null,
        orderNumber: null,
        needSearch: null,
      },
      {
        queryTemplateColumnSetID: 292,
        queryTemplateID: 18033,
        columnName: "calculationBasisName",
        columnLabel: "计算依据",
        columnDescribe: "计算依据",
        needSort: 0,
        needFilters: 1,
        needShow: 1,
        needGroup: 0,
        dataType: "int",
        listqueryTemplateID: 1803423,
        needCount: null,
        orderNumber: null,
        needSearch: null,
      },
      {
        queryTemplateColumnSetID: 293,
        queryTemplateID: 18033,
        columnName: "warningDuration",
        columnLabel: "超时预警",
        columnDescribe: "超时预警",
        needSort: 0,
        needFilters: 1,
        needShow: 1,
        needGroup: 0,
        dataType: "number",
        listqueryTemplateID: null,
        needCount: null,
        orderNumber: null,
        needSearch: null,
      },
      {
        queryTemplateColumnSetID: 294,
        queryTemplateID: 18033,
        columnName: "alarmDuration",
        columnLabel: "超时报警",
        columnDescribe: "超时报警",
        needSort: 0,
        needFilters: 1,
        needShow: 1,
        needGroup: 0,
        dataType: "number",
        listqueryTemplateID: null,
        needCount: null,
        orderNumber: null,
        needSearch: null,
      },
      {
        queryTemplateColumnSetID: 295,
        queryTemplateID: 18033,
        columnName: "beginNode",
        columnLabel: "基准节点",
        columnDescribe: "基准节点",
        needSort: 0,
        needFilters: 1,
        needShow: 0,
        needGroup: 0,
        dataType: "varchar",
        listqueryTemplateID: 1803424,
        needCount: null,
        orderNumber: null,
        needSearch: null,
      },
      {
        queryTemplateColumnSetID: 295,
        queryTemplateID: 18033,
        columnName: "beginNodeName",
        columnLabel: "基准节点",
        columnDescribe: "基准节点",
        needSort: 0,
        needFilters: 1,
        needShow: 1,
        needGroup: 0,
        dataType: "varchar",
        listqueryTemplateID: 1803424,
        needCount: null,
        orderNumber: null,
        needSearch: null,
      },
      // {
      //   queryTemplateColumnSetID: 296,
      //   queryTemplateID: 18033,
      //   columnName: "beginPosition",
      //   columnLabel: "开始位置",
      //   columnDescribe: "开始位置",
      //   needSort: 0,
      //   needFilters: 1,
      //   needShow: 1,
      //   needGroup: 0,
      //   dataType: "varchar",
      //   listqueryTemplateID: 1803425,
      //   needCount: null,
      //   orderNumber: null,
      //   needSearch: null,
      // },
      {
        queryTemplateColumnSetID: 297,
        queryTemplateID: 18033,
        columnName: "endNode",
        columnLabel: "报警节点",
        columnDescribe: "报警节点",
        needSort: 0,
        needFilters: 1,
        needShow: 0,
        needGroup: 0,
        dataType: "varchar",
        listqueryTemplateID: 1803424,
        needCount: null,
        orderNumber: null,
        needSearch: null,
      },
      {
        queryTemplateColumnSetID: 297,
        queryTemplateID: 18033,
        columnName: "endNodeName",
        columnLabel: "报警节点",
        columnDescribe: "报警节点",
        needSort: 0,
        needFilters: 1,
        needShow: 1,
        needGroup: 0,
        dataType: "varchar",
        listqueryTemplateID: 1803424,
        needCount: null,
        orderNumber: null,
        needSearch: null,
      },
      // {
      //   queryTemplateColumnSetID: 298,
      //   queryTemplateID: 18033,
      //   columnName: "endPosition",
      //   columnLabel: "结束位置",
      //   columnDescribe: "结束位置",
      //   needSort: 0,
      //   needFilters: 1,
      //   needShow: 1,
      //   needGroup: 0,
      //   dataType: "varchar",
      //   listqueryTemplateID: 1803425,
      //   needCount: null,
      //   orderNumber: null,
      //   needSearch: null,
      // },
      {
        queryTemplateColumnSetID: 305,
        queryTemplateID: 18033,
        columnName: "alarmSceneId",
        columnLabel: "场景编号",
        columnDescribe: "场景编号",
        needSort: 0,
        needFilters: 1,
        needShow: 0,
        needGroup: 0,
        dataType: "int",
        listqueryTemplateID: null,
        needCount: null,
        orderNumber: null,
        needSearch: null,
      },
      {
        queryTemplateColumnSetID: 305,
        queryTemplateID: 18033,
        columnName: "percentage",
        columnLabel: "运单数报警百分比",
        columnDescribe: "运单数报警百分比",
        needSort: 0,
        needFilters: 0,
        needShow: 1,
        needGroup: 0,
        dataType: "int",
        listqueryTemplateID: null,
        needCount: null,
        orderNumber: null,
        needSearch: null,
      },
      {
        queryTemplateColumnSetID: 305,
        queryTemplateID: 18033,
        columnName: "percentuld",
        columnLabel: "板卡数报警百分比",
        columnDescribe: "板卡数报警百分比",
        needSort: 0,
        needFilters: 0,
        needShow: 1,
        needGroup: 0,
        dataType: "int",
        listqueryTemplateID: null,
        needCount: null,
        orderNumber: null,
        needSearch: null,
      },
    ];
    const result: any = await htQuery(DATACONTENT_ID.sysServiceClId, {
      alarmSceneId: route.query.alarmSceneId,
    });
    if (result && result.length) {
      if (result.length === 0) {
        page.value--;
        noMore.value = true;
      }
      const titleColumn = columnSet.find((item) => item.needShow === 1);
      if (titleColumn) {
        rowTitle.value = titleColumn.columnName;
      }
      tableData.value.push(...result);
      tableCols.value = columnSet;
      // columnSet.forEach((item) => {
      //   if (item.columnName === "calculationBasis") {
      //     getSelectData(item.listqueryTemplateID, "", "calculationBasis");
      //   }
      // });
      tableCols.value.forEach((element) => {
        element.label = element.columnLabel;
        element.key = element.columnName;
      });
    } else {
      tableCols.value = columnSet;
      page.value--;
    }
  } catch (error) {
    page.value--;
  }
};
//开始节点
const changeSelect = (value) => {
  // console.log(value);
  // tableOptionbegin.value = getSelectData(beginPositionId, value,'beginPosition');
  // tableForms.beginPosition = "";
};
//开始位置
const changebegin = (value) => {};
//结束节点
const changeSelected = (value) => {
  // tableOptionendPos.value = getSelectData(endPositionId, value);
  // tableForms.endPosition = "";
};
//结束位置
const changeEndPos = (value) => {};
//确认提交
const warningEditForm: any = ref(null);
const submitForm = () => {
  warningEditForm.value.validate(async (valid: any) => {
    if (valid) {
      const event = type.value == "add" ? 1 : 2;
      const newObj = _.cloneDeep(tableForms);
      const { code, message } =
        event == 1
          ? await dataToChange(DATACONTENT_ID.sysServiceClIds, newObj, event)
          : await dataToChange(
              DATACONTENT_ID.sysServiceClIds,
              newObj,
              event,
              "alarmStrategyID"
            );
      if (code == 0) {
        ElMessage.success("保存成功");
        resetTable();
        getQuery();
        resetForm();
        flag.value = false;
        tableObj.value = {};
      } else {
        tableObj.value = {};
        resetForm();
        ElMessage.error("操作失败");
      }
    } else {
      return false;
    }
  });
};
const resetTable = () => {
  page.value = 0;
  noMore.value = false;
  tableData.value = [];
};
//新增-编辑-删除
const generalDataReception = async (data) => {
  try {
    let obj = {
      alarmSceneId: route.query.alarmSceneId,
    };
    data = {
      ...data,
      ...obj,
    };
    const { code } = await GeneralDataReception({
      serviceId: serviceId.value,
      dataContent: JSON.stringify(data),
    });
    if (code == 0) {
      ElMessage.success(`操作成功`);
      // this.$message.success("操作成功");
      resetTable();
      getQuery();
      resetForm();
      flag.value = false;
      // rmFlag.value = false;
      tableObj.value = {};
      // this.$router.go(0);
    } else {
      ElMessage.error(`操作失败`);
      // this.$message.error("操作失败");
      // this.flag = false;
      // this.rmFlag = false;
      tableObj.value = {};
      resetForm();
    }
  } catch (error) {
    flag.value = false;
    //  rmFlag.value = false;
    tableObj.value = {};
    resetForm();
  }
};
//编辑数据
const warningEditsForm: any = ref(null);
const preserForm = async () => {
  const arr = JSON.parse(JSON.stringify(tableForm));
  warningEditsForm.value.validate(async (valid: any) => {
    if (valid) {
      const { code, message } = await dataToChange(
        DATACONTENT_ID.sysServiceCjIds,
        arr,
        2,
        "alarmSceneId"
      );
      if (code == 0) {
        ElMessage.success("保存成功");
        sysServiceWarn();
        // router.go(0);
      } else {
        ElMessage.error("操作失败");
      }
    } else {
      return false;
    }
  });
};
//表格-增/删/改
const generalDataReceptions = async (data) => {
  try {
    data = {
      ...data,
    };
    const { code, message } = await GeneralDataReception({
      serviceId: route.query.submitID,
      dataContent: JSON.stringify(data),
    });
    if (code === "0") {
      ElMessage.success(`操作成功`);
      // router.push({ path: "/systemSettings/warningSet" });
    } else {
      ElMessage.error(`操作失败`);
    }
  } catch (error) {}
};
//获取航司二字码
const getIaCode = async () => {
  const result = await htQuery(DATACONTENT_ID.sysServiceHsId);
  iaCodeArr.value = result;
};
//获取机场
const getAirpot = async () => {
  const result = await htQuery(DATACONTENT_ID.sysServiceHzId);
  tableOption.value = result;
};
//获取节点
const getJdData = async () => {
  const result = await htQuery(DATACONTENT_ID.sysServiceJdId);
  tableOptionser.value = result;
};
//获取位置
const getWzData = async () => {
  const result = await htQuery(DATACONTENT_ID.sysServiceWzId);
  tableOptionbegin.value = result;
};
onMounted(() => {
  sysServiceWarn();
  getQuery();
  // getSelectDatas(route.query.listqueryTemplateID);
  getIaCode();
  getAirpot();
  getJdData();
  getWzData();
});
</script>

<style lang="scss" scoped>
.airportInfo {
  .headerBox {
    width: 100%;
    min-height: 200px;
    background: #ffffff;
    border-radius: 4px;
    padding: 24px;
    .diacont {
      width: 100%;
      padding: 0;
      .w100 {
        width: 100%;
      }
      .fw {
        display: flex;
        flex-wrap: wrap;
      }
      .outersurface {
        width: 20%;
      }
      .pd30 {
        padding: 0 30px 0 0;
      }
      .outertwowid {
        width: 40%;
      }
      .outerthreewid {
        width: 60%;
      }
    }
  }
  .centerBox {
    padding: 0 24px;
  }
  .containers {
    height: 540px;
  }
}
::v-deep .el-form-item__label {
  width: 100px;
}
</style>
