<template>
  <div>
    <div class="titleBox">
      <PageTitle title="预警管理"> </PageTitle>
    </div>
    <!-- 表格 -->
    <div ref="searchBox">
      <Search :searchArr="searchConfiger" @submit="onSearch" />
    </div>
    <div class="tabBox">
      <MyTable :tableData="pageData.tableData" :tableColumn="pageData.tableColumn" :tableHeight="pageData.tableHeight"
        :key="pageData.keyCount" :tableConfiger="pageData.tableConfiger" :controlsWidth="pageData.controlsWidth"
        @chooseData="chooseData">
        <template #yjTp="{ row }">
          <div class="phone">
            <el-image v-if="row.tp" :src="urlImg + row.yjTp" fit="cover" lazy />
            <el-image v-else :src="row.yjLx=='1'?default_male:car" fit="cover" lazy />
          </div>
        </template>
        <template #yjLx="{ row }">
          <dict-tag :options="D_BZ_YJLX" :value="row.yjLx" :tag="false" />
        </template>
        <template #gzyfx="{ row }">
          <dict-tag :options="D_BZ_GZYFX" :value="row.gzyfx" :tag="false" />
        </template>

        <!-- 操作 -->
        <template #controls="{ row }">
          <el-link type="primary" @click="addEdit('detail', row)">详情</el-link>
        </template>
      </MyTable>
      <Pages @changeNo="changeNo" @changeSize="changeSize" :tableHeight="pageData.tableHeight" :pageConfiger="{
        ...pageData.pageConfiger,
        total: pageData.total
      }"></Pages>
    </div>
    <!-- 编辑详情 -->
    <!-- 编辑详情 -->
    <EditAddForm ref="detailDiloag" :dict="{ D_BZ_YJLX, D_BZ_YJJB, D_BZ_GZYFX }" />
  </div>
</template>

<script setup>
import PageTitle from "@/components/aboutTable/PageTitle.vue";
import MyTable from "@/components/aboutTable/MyTable.vue";
import Pages from "@/components/aboutTable/Pages.vue";
import EditAddForm from "./components/editAddForm.vue";
import Search from "@/components/aboutTable/Search.vue";
import { jczgetPageList, selectJczFullList } from "@/api/mosty-jcz.js";
import { reactive, ref, onMounted, getCurrentInstance, watch } from "vue";
const { proxy } = getCurrentInstance();
const urlImg = "/mosty-api/mosty-base/minio/image/download/";
const { D_BZ_YJLX, D_BZ_YJJB, D_BZ_GZYFX } = proxy.$dict("D_BZ_YJLX", "D_BZ_YJJB", "D_BZ_GZYFX");
const jczList = ref()
const default_male = require('@/assets/images/default_male.png')
const car = require('@/assets/images/car.png')

const searchConfiger = ref([
  {
    label: "感知源编号",
    prop: "yjGzyid",
    placeholder: "感知源编号",
    showType: "input",
  },
  {
    label: "所属检查站",
    prop: "jczid",
    placeholder: "所属检查站",
    showType: "select",
    options: {}
  },
  {
    label: "预警类型",
    prop: "yjLx",
    placeholder: "预警类型",
    showType: "select",
    options: D_BZ_YJLX
  },
  {
    label: "感知源方向",
    prop: "gzyfx",
    placeholder: "感知源方向",
    showType: "select",
    options: D_BZ_GZYFX
  },
  {
    label: "发生时间",
    prop: "startTime",
    placeholder: "发生时间",
    showType: "datetimerange"
  }
]);

const detailDiloag = ref();
const pageData = reactive({
  tableData: [], //表格数据
  keyCount: 0,
  tableConfiger: {
    rowHieght: 61,
    showSelectType: "null",
    loading: false
  },
  total: 0,
  pageConfiger: {
    pageSize: 20,
    pageCurrent: 1
  }, //分页
  controlsWidth: 250, //操作栏宽度
  tableColumn: [
    { label: "预警图片", prop: "yjTp", showSolt: true },
    { label: "所属检查站", prop: "jczmc" },
    { label: "感知源名称", prop: "yjGzymc" },
    { label: "感知源编号", prop: "yjGzyid" },
    { label: "预警时间", prop: "yjSj" },
    { label: "预警人员", prop: "yjRyxm" },
    { label: "预警标签", prop: "yjbq" },
    { label: "预警车牌号", prop: "yjClcph" },
    { label: "预警类型", prop: "yjLx", showSolt: true },
    { label: "方向", prop: "gzyfx", showSolt: true },
  ]
});
onMounted(() => {
  tabHeightFn();
  getselectJczFullList()
});
//查询条件
const queryCondition = ref({});
// 获取数据
const getjczgetXfllList = () => {
  pageData.tableConfiger.loading = true;
  const promes = { ...queryCondition.value, ...pageData.pageConfiger };
  jczgetPageList(promes)
    .then((res) => {
      pageData.tableData = res.records;
      pageData.total = res.total;
    })
    .finally(() => {
      pageData.tableConfiger.loading = false;
    });
};

// 获取检查站数据

const getselectJczFullList = () => {
  selectJczFullList().then((res) => {
    jczList.value = res.map(item => ({
      label: item.jczmc,
      value: item.id
    }))
    searchConfiger.value[1].options = jczList.value

  })

}

getjczgetXfllList();
// 搜索
const onSearch = (val) => {
  console.log(val);
  const startTime = {
    ...val,
    startTime: val.startTime ? val.startTime[0] : "",
    endTime: val.startTime ? val.startTime[1] : ""
  }

  queryCondition.value = { ...queryCondition.value, ...startTime };
  getjczgetXfllList();
};

const changeNo = (val) => {
  pageData.pageConfiger.pageNum = val;
};
const changeSize = (val) => {
  pageData.pageConfiger.pageSize = val;
};
// 新增
const addEdit = (type, row) => {
  detailDiloag.value.init(type, row);
};
const searchBox = ref(null);
// 表格高度计算
const tabHeightFn = () => {
  pageData.tableHeight =
    window.innerHeight - searchBox.value.offsetHeight - 280;
  window.onresize = function () {
    tabHeightFn();
  };
};
</script>

<style>
.el-loading-mask {
  background: rgba(0, 0, 0, 0.5) !important;
}
</style>
