<template>
  <div>
    <div class="titleBox">
      <PageTitle title="过检车辆管理">
        <el-button type="primary" @click="addEdit('add', '')" v-if="Auth">
          <el-icon style="vertical-align: middle">
            <CirclePlus />
          </el-icon>
          <span style="vertical-align: middle" @click="addEdit('add', row)">新增</span>
        </el-button>
      </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 #cqgt="{ row }">
          <div class="phone">
            <el-image v-if="row.cqgt" :src="urlImg + row.cqgt" fit="cover" lazy />
            <el-image v-else :src="Person" fit="cover" lazy />
          </div>
        </template>
        <!-- 操作 -->
        <template #controls="{ row }">
          <template v-if="Auth"> <el-link type="primary" @click="addEdit('edit', row)">修改</el-link>
            <el-link type="primary" @click="delDictItem(row.id)">删除</el-link></template>
          <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_JCZLX, D_BZ_ZQLX, D_BZ_DLLX, D_BZ_JCZJB }"
      @getjczgetXfllList="getjczgetXfllList" />
  </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 Search from "@/components/aboutTable/Search.vue";
import EditAddForm from "./components/editAddForm.vue";
import { GjcltxselectPage, GjcltxdeleteById } from "@/api/mosty-jcz.js";
import { isAuth } from '@/utils/tools.js'
import { reactive, ref, onMounted, getCurrentInstance } from "vue";
const { proxy } = getCurrentInstance();
const { D_BZ_JCZLX, D_BZ_ZQLX, D_BZ_DLLX, D_BZ_JCZJB } = proxy.$dict(
  "D_BZ_JCZLX",
  "D_BZ_ZQLX",
  "D_BZ_DLLX",
  "D_BZ_JCZJB"
);
const urlImg = "/mosty-api/mosty-base/minio/image/download/";
const searchConfiger = ref([
  {
    showType: "department",
    prop: "ssbmdm",
    placeholder: "请选择所属部门",
    label: "所属部门"
  },
  {
    label: "车辆张贴物品特征代码",
    prop: "clztwptzdm",
    placeholder: "车辆张贴物品特征代码",
    showType: "input"
  },
  {
    label: "车后部物品特征代码",
    prop: "chbwptzdm",
    placeholder: "车后部物品特征代码",
    showType: "input"
  },
  {
    label: "车前部物品特征代码",
    prop: "zqlx",
    placeholder: "车前部物品特征代码",
    showType: "input"
  },

  {
    label: "车辆异常痕迹代码",
    prop: "clychjdm",
    placeholder: "请选择环林卡口类型",
    showType: "input"
  }
]);

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: "cqgt",
      showSolt: true,
      showOverflowTooltip: true
    },
    { label: "所属部门", prop: "ssbm", showOverflowTooltip: true },
    {
      label: "车辆张贴物品特征代码",
      prop: "clztwptzdm",
      showOverflowTooltip: true
    },
    {
      label: "车后部物品特征代码",
      prop: "chbwptzdm",
      showOverflowTooltip: true
    },
    { label: "车前部物品特征代码", prop: "zqlx", showOverflowTooltip: true },
    { label: "车辆异常痕迹代码", prop: "clychjdm", showOverflowTooltip: true },
    {
      label: "卡口名称",
      prop: "kkMc",
      showOverflowTooltip: true
    },

    {
      label: "机动车号牌号码",
      prop: "hphm",
      showSolt: true,
      showOverflowTooltip: true
    },

    {
      label: "通行时间",
      prop: "txsj",
      showOverflowTooltip: true
    }
  ]
});
const Auth = ref(false)

onMounted(() => {
  Auth.value = isAuth()
  tabHeightFn();
});

//查询条件
const queryCondition = ref({});
// 获取数据
const getjczgetXfllList = () => {
  pageData.tableConfiger.loading = true;
  const promes = { ...queryCondition.value, ...pageData.pageConfiger };
  GjcltxselectPage(promes)
    .then((res) => {
      pageData.tableData = res.records;
      pageData.total = res.total;
    })
    .finally(() => {
      pageData.tableConfiger.loading = false;
    });
};
getjczgetXfllList();
// 搜索
const onSearch = (val) => {
  queryCondition.value = { ...queryCondition.value, ...val };
  getjczgetXfllList();
};

const changeNo = (val) => {
  pageData.pageConfiger.pageCurrent = val;
};
const changeSize = (val) => {
  pageData.pageConfiger.pageSize = val;
};

// 获取列表
// 删除
const delDictItem = (ids) => {
  proxy
    .$confirm("确定删除该数据？", "警告", { type: "warning" })
    .then(() => {
      GjcltxdeleteById({ ids: [ids] }).then((res) => {
        ElMessage({ message: "删除成功", type: "success" });
        pageData.pageConfiger.pageCurrent = 1;
        getjczgetXfllList();
      });
    })
    .catch(() => {
      proxy.$message.info("已取消");
    });
};

// 新增
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>
