<template>
  <div>
    <div class="titleBox">
      <div class="title">智能装备管理</div>
      <div class="btnBox">
        <el-button type="primary" @click="addEditLoad('add', '')">
          <el-icon style="vertical-align: middle"><CirclePlus /></el-icon>
          <span style="vertical-align: middle">新增</span>
        </el-button>
        <el-button
          @click="deletList('')"
          :disabled="multipleSelection.length == 0"
          typeof="danger"
        >
          <el-icon style="vertical-align: middle"><Delete /></el-icon>
          <span style="vertical-align: middle">批量删除</span>
        </el-button>
        <el-button type="info" plain icon="Upload" @click="isImport = true">
          <span style="vertical-align: middle">导入</span>
        </el-button>
      </div>
    </div>
    <div class="searchBox" ref="searchBox">
      <el-form :model="listQuery" :inline="true">
        <el-form-item label="所属部门">
          <MOSTY.Department width="100%" clearable v-model="listQuery.ssbmdm" />
        </el-form-item>
        <el-form-item label="装备类型">
          <el-cascader
            v-model="listQuery.scode"
            :options="D_BZ_ZBLX_LZ"
            :props="propsTree"
            clearable
            :show-all-levels="false"
          >
          </el-cascader>
        </el-form-item>
        <el-form-item label="装备状态">
          <el-select
            clearableupdate
            v-model="listQuery.zbzt"
            placeholder="请选择装备状态"
          >
            <el-option
              v-for="item in D_ZDY_SBZT"
              :label="item.label"
              :key="item.value"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="装备名称">
          <el-input
            v-model="listQuery.sbmc"
            placeholder="请输入装备名称"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button @click="handleFilter"> 查询 </el-button>
          <el-button @click="reset()"> 重置 </el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="cntBox-bb">
      <div class="tabBox">
        <el-table
          @selection-change="handleSelectionChange"
          :data="tableData"
          border
          row-key="id"
          :tree-props="{ children: 'itemList', hasChildren: true }"
          :height="tableHeight"
          :key="keyCount"
          style="width: 100%"
          v-loading="loadingTable"
          element-loading-background="rgba(0,0,0,0.3)"
          element-loading-text="数据加载中。。"
        >
          <el-table-column align="center" type="selection" width="55" />
          <el-table-column
            type="index"
            align="center"
            width="60px"
            label="序号"
          >
          </el-table-column>
          <el-table-column width="120" align="center" label="图片">
            <template #default="{ row }">
              <div class="phone">
                <el-image
                  v-if="row.tpid"
                  :src="urlImg + row.tpid"
                  fit="cover"
                  lazy
                />
                <el-image v-else :src="Person" fit="cover" lazy />
              </div>
            </template>
          </el-table-column>
          <el-table-column
            prop="ssbm"
            label="所属部门"
            width="250px"
            align="center"
          ></el-table-column>
          <el-table-column
            prop="scode"
            show-overflow-tooltip
            align="center"
            width="150px"
            label="装备类型"
          >
            <template #default="{ row }">
              <dict-tag :options="zbAllList" :value="row.scode" :tag="false" />
            </template>
          </el-table-column>

          <el-table-column
            prop="xh"
            show-overflow-tooltip
            label="装备型号"
            align="center"
          ></el-table-column>
          <el-table-column
            prop="sbmc"
            show-overflow-tooltip
            label="装备名称"
            align="center"
            width="200px"
          ></el-table-column>
          <el-table-column
            prop="sbbh"
            label="唯一标识码"
            align="center"
            width="200px"
          ></el-table-column>
          <el-table-column
            prop="cgrq"
            show-overflow-tooltip
            label="购置日期"
            align="center"
            width="100px"
          >
          </el-table-column>

          <el-table-column
            prop="dqsj"
            show-overflow-tooltip
            label="到期日期"
            align="center"
            width="100px"
          >
          </el-table-column>

          <el-table-column label="状态" align="center" width="100px">
            <template #default="{ row }">
              <dict-tag :value="row.zbzt" :options="D_ZDY_SBZT"></dict-tag>
            </template>
          </el-table-column>
          <el-table-column
            label="操作"
            align="center"
            fixed="right"
            width="260px"
          >
            <template #default="{ row }">
              <el-button @click="lookGj(row, 'clgj')" size="small"
                >轨迹回放</el-button
              >
              <el-button @click="addEditLoad('edit', row.id)" size="small"
                >修改</el-button
              >
              <!-- <el-button @click="handleReportLoss(row)" type="warning" size="small" v-if="row.sfbs != 1">报损</el-button> -->
              <!-- <el-button @click="handelRellBack(row)" type="warning" size="small" v-if="row.xfid">回退</el-button> -->
              <!-- <el-button @click="handleLssued(row)" type="success" size="small" v-if="!row.xfid">下发</el-button> -->
              <el-button @click="delDictItem(row.id)" type="danger" size="small"
                >删除</el-button
              >
            </template>
          </el-table-column>
        </el-table>
        <div class="fenye" :style="{ top: tableHeight + 'px' }">
          <el-pagination
            class="pagination"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="listQuery.pageNo"
            :page-sizes="[10, 20, 50, 100]"
            :page-size="listQuery.pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total"
          >
          </el-pagination>
        </div>
      </div>
         <div class="mapbox" v-if="isShowMap" :style="{ height: tableHeight +50+ 'px' }">
        <!-- 轨迹回放 -->
         <MapDialog  v-model:modelValue="isShowMap" lxtype="gjhf" :data="gJDate"/>
      </div>
    </div>

    <div v-if="dialogFormVisible" class="dialog">
      <div class="head_box">
        <span class="title">{{ diaTitle }}</span>
        <div>
          <el-button
            @click="submit"
            v-show="!disable"
            type="primary"
            size="small"
            :loading="btnLoading"
            >保存</el-button
          >
          <el-button size="small" @click="closeForm">关闭</el-button>
        </div>
      </div>
      <el-form
        ref="elform"
        :model="form"
        :rules="rules"
        :inline="true"
        label-position="top"
      >
        <div
          style="
            width: 25%;
            display: flex;
            justify-content: center;
            margin-bottom: 10px;
          "
        >
          <div style="position: relative; width: 90px; height: 100px">
            <el-upload
              action="/mosty-api/mosty-base/minio/image/upload/id"
              :on-change="upImgFile"
              :on-success="upImg"
              :show-file-list="false"
            >
              <el-image v-if="imgUrl" :src="imgUrl" fit="cover" />
              <el-icon v-else><Plus></Plus></el-icon>
              <span
                v-if="imgUrl"
                style="position: absolute; top: -52px; right: -20px"
              >
                <el-icon size="20" @click.stop="deletImg"><Close /></el-icon>
              </span>
            </el-upload>
          </div>
        </div>

        <el-form-item prop="ssbmdm" label="所属部门">
          <MOSTY.Department
            :placeholder="form.ssbm"
            style="width: 100%"
            ref="cascader"
            clearable
            filterable
            :options="depList"
            :props="props"
            v-model:modelValue="form.ssbmdm"
          />
        </el-form-item>
        <el-form-item prop="scode" label="装备类型">
          <el-cascader
            v-model="zdlxData"
            :options="D_BZ_ZBLX_LZ"
            :props="propsTree"
            clearable
            :show-all-levels="false"
            @change="changeZblx"
          >
          </el-cascader>
        </el-form-item>
        <el-form-item prop="sbmc" label="装备名称">
          <el-input
            v-model="form.sbmc"
            placeholder="请输入装备名称"
            clearable
            style="width: 100%"
          />
        </el-form-item>
        <el-form-item label="装备型号">
          <el-input
            v-model="form.xh"
            placeholder="请输入装备型号"
            clearable
            style="width: 100%"
          />
        </el-form-item>
        <el-form-item label="装备厂商">
          <el-input
            v-model="form.sccs"
            placeholder="请输入装备厂商"
            clearable
            style="width: 100%"
          />
        </el-form-item>
        <el-form-item prop="cgrq" label="购置日期">
          <el-date-picker
            style="width: 100%"
            format="YYYY/MM/DD"
            value-format="YYYY-MM-DD"
            v-model="form.cgrq"
            type="date"
            placeholder="请选择日期"
            :disabledDate="disableCgrq"
          />
        </el-form-item>

        <el-form-item prop="dqsj" label="到期日期">
          <el-date-picker
            @focus="cgrqTs"
            format="YYYY/MM/DD"
            value-format="YYYY-MM-DD"
            v-model="form.dqsj"
            type="date"
            placeholder="请选择日期"
            style="width: 100%"
            :disabledDate="disableDqsj"
          />
        </el-form-item>
        <el-form-item class="tiaos" prop="sbbh" :label="sbbhtext">
          <el-input
            v-model="form.sbbh"
            placeholder="请输入"
            clearable
            style="width: 100%"
          />
          <el-button @click="getTS">调试</el-button>
        </el-form-item>
        <el-form-item prop="zbzt" label="设备状态">
          <el-select
            v-model="form.zbzt"
            class="m-2"
            placeholder="请选择"
            style="width: 100%"
          >
            <el-option
              v-for="item in D_ZDY_SBZT"
              :label="item.label"
              :key="item.value"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item prop="sfrh" label="是否融合">
          <el-select
            style="width: 100%"
            v-model="form.sfrh"
            placeholder="请选择是否融合"
            clearable
          >
             <el-option
              v-for="(item, index) in D_BZ_SF"
              :key="index"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="sfzy" label="是否专业">
          <el-select
            style="width: 100%"
            v-model="form.sfzy"
            placeholder="请选择是否专业"
            clearable
          >
             <el-option
              v-for="(item, index) in D_BZ_SF"
              :key="index"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="sfxt" label="是否通讯">
          <el-select
            style="width: 100%"
            v-model="form.sfxt"
            placeholder="请选择是否通讯"
            clearable
          >
             <el-option
              v-for="(item, index) in D_BZ_SF"
              :key="index"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="备注" style="width: 100%">
          <el-input
            v-model="form.bz"
            placeholder="请输入关键字"
            show-word-limit
            type="textarea"
          />
        </el-form-item>
      </el-form>
    </div>
    <!-- 下发弹窗口 -->
    <el-dialog
      title="选择下发单位"
      width="600px"
      :model-value="lssuedDialog"
      :close-on-click-modal="false"
      :destroy-on-close="true"
      @close="lssuedDialog = false"
    >
      <el-form :model="lssuedForm" ref="lssued" :rules="ruleslssued">
        <el-form-item label="选择大队" prop="ssbmdm">
          <MOSTY.Department
            width="100%"
            clearable
            v-model="lssuedForm.ssbmdm"
          />
        </el-form-item>
        <el-form-item label="选择数量" prop="sl">
          <el-input
            v-model="lssuedForm.sl"
            placeholder="请选择数量"
            clearable
            disabled
            style="width: 100%"
          />
        </el-form-item>
        <div class="footerBtn">
          <el-button @click="okLssued" :loading="reportLossLoading">
            确定下发
          </el-button>
        </div>
      </el-form>
    </el-dialog>
    <!-- 报损 -->
    <el-dialog
      title="报损"
      width="600px"
      :model-value="reportLossDialog"
      :close-on-click-modal="false"
      :destroy-on-close="true"
      @close="reportLossDialog = false"
    >
      <el-form :model="reportLossForm" ref="reportLoss" :rules="ruleReportLoss">
        <el-form-item label="选择数量" prop="sl">
          <el-input
            v-model="reportLossForm.sl"
            placeholder="请选择数量"
            clearable
            style="width: 100%"
            :rules="[{ required: true, message: '选择数量', trigger: 'blur' }]"
          />
        </el-form-item>
        <div class="footerBtn">
          <el-button @click="okreportLoss" :loading="reportLossLoading">
            确定报损
          </el-button>
        </div>
      </el-form>
    </el-dialog>
    <!-- 回退 -->
    <el-dialog
      title="回退"
      width="1000px"
      :model-value="rellbackDialog"
      :close-on-click-modal="false"
      :destroy-on-close="true"
    >
      <el-table
        border
        :data="DataRellback"
        width="100%"
        element-loading-background="rgba(0,0,0,0.3)"
      >
        <el-table-column label="装备信息" align="center">
          <el-table-column
            label="单位名称"
            prop="ssxgaj"
            align="center"
          ></el-table-column>
          <el-table-column
            label="库存"
            prop="kc"
            align="center"
          ></el-table-column>
          <el-table-column
            label="报损"
            prop="bs"
            align="center"
          ></el-table-column>
          <el-table-column
            label="下发"
            prop="xf"
            align="center"
          ></el-table-column>
        </el-table-column>
        <el-table-column label="" width="100" />
        <el-table-column label="回退信息" align="center">
          <el-table-column label="库存" prop="kc" align="center" width="136px">
            <template #default="{ row }">
              <el-input-number
                v-model="row.kc"
                :min="0"
                :max="row.kc"
                size="small"
              ></el-input-number>
            </template>
          </el-table-column>
          <el-table-column label="报损" prop="bs" align="center" width="136px">
            <template #default="{ row }">
              <el-input-number
                v-model="row.bs"
                :min="0"
                :max="row.bs"
                size="small"
              ></el-input-number>
            </template>
          </el-table-column>
          <el-table-column label="下发" prop="xf" align="center" width="136px">
            <template #default="{ row }">
              <el-input-number
                v-model="row.xf"
                :min="0"
                :max="row.xf"
                size="small"
              ></el-input-number>
            </template>
          </el-table-column>
        </el-table-column>
      </el-table>
      <div class="footerBtn">
        <el-button> 确定回退 </el-button>
      </div>
    </el-dialog>

    <!-- 导入 -->
    <Export
      :show="isImport"
      lx="znzb"
      @closeImport="isImport = false"
      @handleImport="handleFilter"
    />
  </div>
</template>

<script setup>
import MapDialog from './mapDialog.vue'
import Export from "@/components/export/index.vue";
import { selectDeptPage } from "@/api/user-manage";
import { getTree } from "@/api/basicsmanage/watchmanZbgl";
import * as MOSTY from "@/components/MyComponents/index";
import Person from "@/assets/images/layout/default_male.png";
import { ElMessage } from "element-plus";
import emitter from "@/utils/eventBus.js";
import {
  ref,
  reactive,
  onMounted,
  getCurrentInstance,
  onUnmounted,
  watch,
  nextTick
} from "vue";
import {
  getZnzb,
  addZnzb,
  putZnzb,
  infoZnzb,
  delZnzb,
  lssuedZnzb,
  RellBackZnzb,
  ReportLossZnzb
} from "@/api/basicsmanage/intelligence";
const urlImg = ref("/mosty-api/mosty-base/minio/image/download/");
const { proxy } = getCurrentInstance();
const { D_BZ_ZNZBFL, D_ZDY_SBZT, D_BZ_SF, D_BZ_ZBLX_LZ } = proxy.$dict(
  "D_BZ_ZNZBFL",
  "D_ZDY_SBZT",
  "D_BZ_SF",
  "D_BZ_ZBLX_LZ"
);
const propsTree = ref({
  checkStrictly: true,
  emitPath: false,
  multiple: false
});
const isImport = ref(false);
const imgUrl = ref("");
const tableData = ref([]); //列表数据
const keyCount = ref(0); //tabel组件刷新值
const searchBox = ref(null); // 搜索盒子
const tableHeight = ref(); // 表格高度
const multipleSelection = ref([]); //批量数据
const loadingTable = ref(true); //表格加载
const listQuery = ref({
  pageNo: 1,
  pageSize: 20,
  scode: ""
});
const isShowMap = ref(false)
const gJDate = ref({})
const zdlxData = ref("");
const total = ref(0); //总数据
const dialogFormVisible = ref(false); //是否显示新增弹窗
const diaTitle = ref("新增智能装备"); //弹窗标题
const disable = ref(false); //保存禁用
const btnLoading = ref(false); //保存加载
const elform = ref(null);
const formDefault = ref({}); //重置表单
//新增表单对象
const form = ref({
  ssbmdm: "",
  scode: "",
  sbmc: "",
  xh: "",
  sccs: "",
  cgrq: "",
  dqsj: "",
  sbbh: "",
  sbIpv4: "",
  sbIpv6: "",
  sbMac: "",
  sbImei: "",
  bz: "",
  sbbh: ""
});
//表单验证
const rules = reactive({
  ssbmdm: [{ required: true, message: "请选择部门", trigger: "change" }],
  scode: [{ required: true, message: "请选择装备类型", trigger: "change" }],
  sbmc: [{ required: true, message: "请填写装备名称", trigger: "change" }],
  xh: [{ required: true, message: "请填写装备型号", trigger: "change" }],
  sccs: [{ required: true, message: "请填写装备厂商", trigger: "change" }],
  cgrq: [{ required: true, message: "请选择购置日期", trigger: "change" }],
  dqsj: [{ required: true, message: "请选择到期日期", trigger: "change" }],
  sbbh: [{ required: true, message: "请填写标识码", trigger: "change" }]
});
const lssuedDialog = ref(false); //下发弹窗
const lssuedFormDefault = ref({}); //下发弹窗默认
const lssuedForm = ref({ ssbmdm: "", sl: "1" }); //下发弹窗表单
const lssued = ref(null); //下发表单校验
const ruleslssued = reactive({
  ssbmdm: [{ required: true, message: "请选择部门", trigger: "change" }],
  sl: [{ required: true, message: "请选择数量", trigger: "change" }]
});
const reportLossLoading = ref(false); //下发加载状态
const reportLossDialog = ref(false); // 报损弹窗
const reportLossForm = ref({ sl: "" }); // 报损弹窗表单
const reportLoss = ref(null); //报损校验
const ruleReportLoss = reactive({
  sl: [{ required: true, message: "请选择数量", trigger: "change" }]
}); //报损表单验证
const rellbackDialog = ref(false); //回退弹窗
const DataRellback = ref([{ ssxgaj: "测试", kc: "1", bs: "2", xf: "1" }]); //回退数据
const tabOption = ref([
  { label: "所属部门", prop: "ssbm" },
  { label: "装备类型", prop: "scode" },
  { label: "装备型号", prop: "xh" },
  { label: "装备名称", prop: "sbmc" },
  { label: "购置日期", prop: "cgrq" },
  { label: "到期日期", prop: "dqsj" },
  { label: "状态", prop: "zbzt", dict: D_ZDY_SBZT }
]);
const downData = ref([]); //导出列表
const sbbhtext = ref("唯一标识码");
const depList = ref([]); //部门数据
//级联选择器配置
const props = {
  expandTrigger: "children",
  children: "childDeptList",
  label: "orgName",
  value: "orgCode",
  checkStrictly: true,
  emitPath: false
};
watch(()=>isShowMap.value,(val)=>{
  emitter.emit('closeMeun')
})
watch(
  () => form.value.scode,
  (val) => {
    sbbhtext.value = val == "02" ? "呼号" : "唯一标识码";
  }
);
const zbAllList = ref([]);
watch(
  () => D_BZ_ZBLX_LZ.value,
  (val) => {
    val.forEach((p) => {
      zbAllList.value.push(p);
      if (p.itemList && p.itemList.length > 0) {
        getChildren(p);
      }
    });
  }
);
onMounted(() => {
  formDefault.value = JSON.parse(JSON.stringify(form.value));
  lssuedFormDefault.value = JSON.parse(JSON.stringify(lssuedForm.value));
  handleFilter();
  tabHeightFn();
  proxy.mittBus.on("mittFn", (data) => {
    keyCount.value = data;
  });
});

// 确定上传
function handleImport(val) {}

// 轨迹回放
function lookGj(row, type) {
  nextTick(()=>{
    if (row.sbbh) {
      gJDate.value = row;
      isShowMap.value = true;
    } else {
      proxy.$message({ type: "warning", message: "该数据无设备标号" });
      isShowMap.value = false;
    }
  })
}

// 递归处理数据
function getChildren(item) {
  zbAllList.value.push(item);
  if (item.itemList && item.itemList.length > 0) {
    item.itemList.forEach((v) => {
      getChildren(v);
    });
  }
}

// 查询
function handleFilter() {
  listQuery.value.pageNo = 1;
  getListData();
}
//获取数据
function getListData() {
  loadingTable.value = true;
  getZnzb(listQuery.value)
    .then((res) => {
      tableData.value = res.records;
      total.value = res.total;
      loadingTable.value = false;
    })
    .catch(() => {
      loadingTable.value = true;
    });
}
//批量数据
function handleSelectionChange(val) {
  multipleSelection.value = [];
  downData.value = [];
  if (!val) return false;
  val.forEach((item) => {
    multipleSelection.value.push(item.id);
    downData.value.push(item);
  });
}

//单个删除 - 批量删除
function delDictItem(id) {
  proxy
    .$confirm("确定要删除", "警告", { type: "warning" })
    .then(() => {
      let ids = id ? [id] : multipleSelection.value;
      deleteData(ids);
    })
    .catch(() => {
      proxy.$message.info("已取消");
    });
}

// 删除接口
function deleteData(ids) {
  delZnzb(ids).then(() => {
    proxy.$message({ type: "success", message: "删除成功" });
    getListData();
  });
}

// 重置
function reset() {
  listQuery.value = { pageNo: 1, pageSize: 20 };
  getListData();
}

/**
 * size 改变触发
 */
function handleSizeChange(currentSize) {
  listQuery.value.pageSize = currentSize;
  getListData();
}

/**
 * 页码改变触发
 */
function handleCurrentChange(currentPage) {
  listQuery.value.pageNo = currentPage;
  getListData();
}

function changeZblx(val) {
  form.value.scode = val ? val : "";
}

function upImgFile(row) {}
function upImg(row) {
  form.value.tpid = row.data;
  imgUrl.value = urlImg.value + row.data;
}
function deletImg() {
  imgUrl.value = "";
  form.value.tpid = "";
}

//新增-修改
function addEditLoad(type, id) {
  if (id) {
    dialogFormVisible.value = true;
    infoZnzb(id).then((res) => {
      disable.value = false;
      diaTitle.value = res.sbmc + "装备修改";
      form.value = res;
      zdlxData.value = res.scode;
      imgUrl.value = res.tpid ? urlImg.value + res.tpid : "";
    });
  } else {
    disable.value = false;
    diaTitle.value = "新增智能装备";
    dialogFormVisible.value = true;
  }
}

//提交
function submit() {
  elform.value.validate((valid) => {
    if (!valid) return false;
    btnLoading.value = true;
    if (diaTitle.value == "新增智能装备") {
      addZnzb(form.value)
        .then(() => {
          proxy.$message({ type: "success", message: "新增成功" });
          btnLoading.value = false;
          closeForm();
          handleFilter();
        })
        .catch(() => {
          btnLoading.value = false;
        });
    } else {
      putZnzb(form.value)
        .then(() => {
          proxy.$message({ type: "success", message: "修改成功" });
          btnLoading.value = false;
          closeForm();
          handleFilter();
        })
        .catch(() => {
          btnLoading.value = false;
        });
    }
  });
}

// 关闭新增-编辑表单
function closeForm() {
  form.value = JSON.parse(JSON.stringify(formDefault.value));
  zdlxData.value = "";
  dialogFormVisible.value = false;
  imgUrl.value = "";
}

// 处理下发
function handleLssued(row) {
  lssuedDialog.value = true;
  lssuedForm.value.id = row.id;
}
// 提交下发
function okLssued() {
  lssued.value.validate((valid) => {
    if (!valid) return false;
    reportLossLoading.value = true;
    lssuedZnzb(lssuedForm.value)
      .then((res) => {
        proxy.$message({ type: "success", message: "下发成功" });
        lssuedForm.value = JSON.parse(JSON.stringify(lssuedFormDefault.value));
        zdlxData.value = "";
        lssuedDialog.value = false;
        reportLossLoading.value = false;
        handleFilter();
      })
      .catch(() => {
        reportLossLoading.value = false;
      });
  });
}
// 报损
function handleReportLoss(row) {
  reportLossDialog.value = true;
  reportLossForm.value.id = row.id;
}
// 确定报损
function okreportLoss() {
  reportLoss.value.validate((valid) => {
    if (!valid) return false;
    reportLossLoading.value = true;
    ReportLossZnzb(reportLossForm.value)
      .then((res) => {
        proxy.$message({ type: "success", message: "报损成功" });
        reportLossForm.value.sl = "";
        reportLossForm.value.id = "";
        reportLossDialog.value = false;
        reportLossLoading.value = false;
        handleFilter();
      })
      .catch(() => {
        reportLossLoading.value = false;
      });
  });
}

// 处理回退
function handelRellBack(row) {
  proxy
    .$confirm("确定要回退", "警告", { type: "warning" })
    .then(() => {
      RellBackZnzb({ id: row.id }).then((res) => {
        proxy.$message({ type: "success", message: "回退成功" });
        handleFilter();
      });
    })
    .catch(() => {
      proxy.$message.info("已取消");
    });
}

//购置日期限制
function disableCgrq(row) {
  let time = new Date();
  return time.getTime() <= row.getTime();
}
// 到期日期限制
function disableDqsj(row) {
  if (form.value.cgrq) {
    let time = new Date(form.value.cgrq);
    return time.getTime() >= row.getTime();
  } else {
    return true;
  }
}
function cgrqTs() {
  if (!form.value.cgrq) {
    ElMessage({
      message: "请先选择购置日期",
      type: "warning"
    });
  }
}
// 表格高度计算
const tabHeightFn = () => {
  tableHeight.value = window.innerHeight - searchBox.value.offsetHeight - 240;
  window.onresize = function () {
    tabHeightFn();
  };
};

// 调试
function getTS() {
  if (form.value.sbbh == "" || form.value.sbbh == null) {
    proxy.$message({
      type: "warning",
      message: `请先输入${sbbhtext.value}`
    });
  } else {
    SPPUC.init(
      "pars2",
      "#369",
      function () {},
      function (device_id, type, [lng, lat, speed, device_type, device_name]) {}
    );
    SPPUC.rdCard(form.value.sbbh, 6, ["60%", "40%"]);
  }
}
onUnmounted(() => {
  proxy.mittBus.off("mittFn");
});
</script>

<style lang="scss" scoped>
@import "~@/assets/css/layout.scss";
@import "~@/assets/css/element-plus.scss";
.tiaos {
  position: relative;
  .el-button {
    position: absolute;
    right: 0;
    bottom: 0;
    right: -100px;
  }
}
.footerBtn {
  text-align: right;
  margin: 4px 0;
}
.phone {
  width: 95px;
  height: 120px;
  .el-image {
    width: 95px;
    max-height: 120px;
  }
}
::v-deep .el-upload {
  width: 90px;
  height: 100px;
  border: 1px dashed #e0e0e0;
  margin-bottom: 14px;
  .el-icon {
    margin-top: 34px;
    font-size: 26px;
  }
  .el-image {
    width: 100%;
    height: 100%;
  }
}
.cntBox-bb{
  display: flex;
  height: 100%;
  .tabBox{
    flex: 1;
    height: 100%;
  }
  .mapbox{
    width: 1000px;
    padding: 0 10px;
    box-sizing: border-box;
  }
}
</style>
