<!-- 感知源 -->
<template>
  <div>
    <div class="titleBoxs">
      <div class="title">感知源</div>
      <div class="btnBox"></div>
    </div>
    <div class="content-box-sun">
      <!-- 组织机构盒子 -->
      <div class="org-box">
        <div class="org-content-box">
          <div class="tree-box">
            <MOSTY.DepartmentTree
              width="100%"
              placeholder="管理部门ID"
              clearable
              filterable
              v-model="deptId"
            />
          </div>
        </div>
      </div>
      <div class="right-box-sun">
        <div class="chart-box">
          <div class="text-box">
            <div
              v-for="(item, index) in sbLxData"
              :key="index + 'sblx'"
              class="text-item"
            >
              <span>
                <dict-tag
                  :value="item.sblx"
                  :options="D_BZ_SBLX"
                  :tag="false"
                ></dict-tag>
              </span>
              <span class="text-color">{{ item.sl }}</span
              >个
            </div>
            <!-- <div class="text-item">
              <span>视频监控:</span>
              <span class="text-color">313</span>个
            </div>
            <div class="text-item">
              <span>人卡:</span>
              <span class="text-color">313</span>个
            </div>
            <div class="text-item">
              <span>车卡:</span>
              <span class="text-color">313</span>个
            </div>
            <div class="text-item">
              <span>卡口:</span>
              <span class="text-color">313</span>个
            </div>
            <div class="text-item">
              <span>交警视频:</span>
              <span class="text-color">313</span>个
            </div>
            <div class="text-item">
              <span>制高点视频:</span>
              <span class="text-color">313</span>个
            </div> -->
          </div>
          <pie :dict="D_BZ_SBLX" :data="sbLxData" />
        </div>
        <!-- 表格盒子 -->
        <div class="table-box">
         
          <div class="tabBox">
            <el-table
              :data="tableData"
              border
              row-key="id"
              style="width: 100%"
              :key="keyCount"
              :height="tableHeight"
              v-loading="loadingTable"
              element-loading-background="rgba(0,0,0,0.3)"
              element-loading-text="数据加载中。。"
            >
              <el-table-column type="selection" width="40" align="center" />
              <el-table-column
                label="序号"
                type="index"
                align="center"
                width="60"
              />
              <el-table-column label="单位部门" prop="ssbm" align="center" />
              <el-table-column label="视频监控" prop="spjk" align="center" />
              <el-table-column label="人卡" prop="bz" align="center" />
              <el-table-column label="车卡" prop="bz" align="center" />
              <el-table-column label="卡口" prop="jtkk" align="center" />
              <el-table-column label="交警视频" prop="bz" align="center" />
              <el-table-column label="制高点视频" prop="bz" align="center" />
              <el-table-column
                label="操作"
                align="center"
                fixed="right"
                width="150px"
              >
                <template #default="{ row }">
                  <el-button @click="detail(row)" 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.pageCurrent"
                :page-sizes="[10, 20, 50, 100]"
                :page-size="listQuery.pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total"
              >
              </el-pagination>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="dialog" v-if="dialogFormVisible">
      <div class="head_box">
        <span class="title">{{ title }}</span>
        <div>
          <el-button size="small" @click="close">关闭</el-button>
        </div>
      </div>
      <el-form
        ref="elform"
        :model="form"
        :rules="rules"
        :inline="true"
        label-position="top"
        disabled
      >
        <el-form-item label="单位部门" prop="name">
          <el-input v-model="form.ssbm"></el-input>
        </el-form-item>
        <el-form-item label="视频监控" prop="name">
          <el-input v-model="form.spjk"></el-input>
        </el-form-item>
        <el-form-item label="人卡" prop="name">
          <el-input v-model="form.name"></el-input>
        </el-form-item>
        <el-form-item label="车卡" prop="name">
          <el-input v-model="form.name"></el-input>
        </el-form-item>
        <el-form-item label="卡口" prop="jtkk">
          <el-input v-model="form.jtkk"></el-input>
        </el-form-item>
        <el-form-item label="交警视频" prop="name">
          <el-input v-model="form.name"></el-input>
        </el-form-item>
        <el-form-item label="制高点视频" prop="name">
          <el-input v-model="form.name"></el-input>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
<script setup>
import * as MOSTY from "@/components/MyComponents/index";
import pie from "./components/pie.vue";
import { selectDeptPage } from "@/api/user-manage";
import { getSblist, getSbLx } from "@/api/patrolStatistics/perceptualSource.js";
import { ref, watch, getCurrentInstance, onMounted, reactive } from "vue";
const { proxy } = getCurrentInstance();
// const { D_BZ_SBLX } = proxy.$dict("D_BZ_SBLX");
import { getItem } from "@/utils/storage";
const keyCount = ref(0); //tabel组件刷新值
const form = ref({}); //新增表单
const tableData = ref([]); //表格数据
const total = ref(0);
const chackAdd = ref(false); //新增修改切换
const loading = ref(false); //新增保存按钮截流
const ids = ref([]); //表格选中id集合
const searchBox = ref(null); //搜索盒子
const loadingTable = ref(true); //表格加载状态
const tableHeight = ref(); // 表格高度
const dialogFormVisible = ref(false);
const title = ref("新增"); //弹窗标题
const elform = ref(null); //新增表单容器
const listQuery = ref({
  pageCurrent: 1,
  pageSize: 10
}); //搜索表单
//表单验证
const rules = ref({});
// 部门树
const defaultProps = {
  children: "childDeptList",
  label: "orgName"
};
// 01-视频监控  02-交通卡 03-人卡 04-车卡 05-电子围栏 06-WIFI探针 07-IMSI、IMEI
const D_BZ_SBLX = ref([
  {
    label: '视频监控',
    value: '01',
    dm: '01'
  },
  {
    label: '交通卡',
    value: '02',
    dm: '02'
  },
  {
    label: '人卡',
    value: '03',
    dm: '03'
  },
  {
    label: '车卡',
    value: '04',
    dm: '04'
  },
  {
    label: '电子围栏',
    value: '05',
    dm: '05'
  },
  {
    label: 'WIFI探针',
    value: '06',
    dm: '06'
  },
  {
    label: 'IMSI、IMEI',
    value: '07',
    dm: '07'
  },
]);
const sbLxData = ref([])
//获取设备类型统计
function getSbtj() {
  try {
    const params = {
      ssbmdm: deptId.value,
      permissions: getItem("PermissionsInfo").permissionsSqlNoAlias
    };
    getSbLx(params).then((res) => {
      sbLxData.value = res.map((item) => {
        return {
          sblx: item.sblx,
          sl: item.sl
        };
      });
    });
  } catch (error) {}
}
const deptId = ref(null);
function handleNodeClick(val) {}
watch(
  () => deptId.value,
  () => {
    listQuery.value.pageCurrent = 1;
    listQuery.value.pageSize = 10;
    getListData();
    getSbtj();
  }
);
// 获取列表
function getListData() {
  try {
    loadingTable.value = true;
    const data = {
      page: listQuery.value.pageCurrent,
      size: listQuery.value.pageSize,
      ssbmdm: deptId.value,
      permissions: getItem("PermissionsInfo").permissionsSqlNoAlias
    };
    getSblist(data).then((res) => {
      loadingTable.value = false;
      total.value = res.total;
      tableData.value = res || [];
    });
  } catch (error) {
     loadingTable.value = false;
  }
}
//打开新增弹窗
function add() {
  chackAdd.value = true;
  dialogFormVisible.value = true;
}
//关闭弹窗
function close() {
  dialogFormVisible.value = false;
  form.value = {};
}
//提交
function submit() {
  elform.value.validate((valid) => {
    if (valid) {
      loading.value = true;
      setTimeout(() => {
        loading.value = false;
      }, 1500);
      if (chackAdd.value) {
        proxy.$message({
          type: "success",
          message: "新增成功"
        });
      } else {
        proxy.$message({
          type: "success",
          message: "修改成功"
        });
      }
    }
  });
}
//修改
function detail(row) {
  // API(row.id).then((res) => {
  //   form.value = res;
  // });
  chackAdd.value = false;
  form.value = row;
  title.value = "详情";
  dialogFormVisible.value = true;
}
//批量数据
const handleSelectionChange = (val) => {
  ids.value = [];
  if (val) {
    val.forEach((item) => {
      ids.value.push(item.id);
    });
  }
};
//删除
function delDictItem(row) {
  proxy
    .$confirm("确定要删除", "警告", {
      type: "warning"
    })
    .then(() => {
      // DELETE([row.id]).then(() => {
      //   proxy.$message({
      //     type: "success",
      //     message: "删除成功"
      //   });
      //   getListData();
      // });
    })
    .catch(() => {
      proxy.$message.info("已取消");
    });
}
//批量删除
function batchDelete() {
  proxy
    .$confirm("确定要删除", "警告", {
      type: "warning"
    })
    .then(() => {
      //       DELETE(ids.value).then((res) => {
      //         proxy.$message({
      //           message: "删除成功",
      //           type: "success"
      //         });
      //         getListData();
      //       });
    })
    .catch(() => {
      proxy.$message.info("已取消");
    });
}
//点击查询
const handleFilter = () => {
  listQuery.value.pageCurrent = 1;
  getListData();
};
//点击重置
const reset = () => {
  listQuery.value = {
    pageCurrent: 1,
    pageSize: 10
  };
  getListData();
};
// 表格高度计算
const tabHeightFn = () => {
  tableHeight.value = window.innerHeight - 520;
};
/**
 * pageSize 改变触发
 */
const handleSizeChange = (currentSize) => {
  listQuery.value.pageSize = currentSize;
  getListData();
};

/**
 * 页码改变触发
 */
const handleCurrentChange = (currentPage) => {
  listQuery.value.pageCurrent = currentPage;
  getListData();
};
onMounted(() => {
  getSbtj();
  // getSysMenuTree();
  getListData();
  tabHeightFn();
  window.onresize = function () {
    tabHeightFn();
  };
  proxy.mittBus.on("mittFn", (data) => {
    keyCount.value = data;
  });
});
</script>
<style lang="scss" scoped>
@import "~@/assets/css/layout.scss";
@import "~@/assets/css/element-plus.scss";
.chart-box {
  height: 280px;
  display: flex;
  justify-content: center;
  align-items: center;
}
.text-box {
  height: 160px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.text-item {
  width: 140px;
  display: flex;
  justify-content: space-between;
}
.text-color {
  color: rgb(181, 1, 1);
}
</style>
