<!-- 处置警情分析 -->
<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="org-search-box">
            <el-input v-model="input" placeholder="请输入关键字搜索" />
            <el-button>搜索</el-button>
          </div> -->
          <div class="tree-box" :style="{ height: orgHeight + 'px' }">
            <!-- <el-tree
              :data="orgList"
              node-key="id"
              :default-expanded-keys="[7]"
              :props="defaultProps"
              accordion
              @node-click="handleNodeClick"
            /> -->
            <MOSTY.DepartmentTree
              width="100%"
              placeholder="管理部门ID"
              clearable
              filterable
              v-model="listQuery.deptId"
            />
          </div>
        </div>
      </div>
      <div class="right-box-sun">
        <div class="chart-box">
          <div class="searchBox chart-pie-box">
            <div>警情处置统计</div>
            <pie2 />
          </div>
        </div>
        <!-- 表格盒子 -->
        <div class="table-box">
          <div class="searchBox" ref="searchBox">
            <el-form :model="listQuery" :inline="true">
              <el-form-item label="根据时间查询">
                <el-date-picker
                  v-model="value1"
                  type="date"
                  placeholder="请选择"
                  :size="size"
                />
              </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="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="数据加载中。。"
              @selection-change="handleSelectionChange"
            >
              <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="cjrXm" align="center" />
              <el-table-column label="处警人身份证号" width="180" prop="cjrSfzh" align="center" />
              <el-table-column label="处警人联系电话" width="180" prop="cjrLxdh" align="center" />
              <el-table-column label="处警员编号" prop="cjyBh" align="center" />
              <el-table-column label="反馈内容" prop="fknr" align="center" />
              <el-table-column label="状态" prop="cjzt" align="center">
                <template #default="{ row }">
                  <el-tag v-show="row.cjzt == 1">已派警</el-tag>
                  <el-tag v-show="row.cjzt == 2">处置完毕</el-tag>
                  <el-tag v-show="row.cjzt == 3">开始处置</el-tag>
                  <el-tag v-show="row.cjzt == 4">已反馈</el-tag>
                </template>
              </el-table-column>

              <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"
        disabled
        :inline="true"
        label-position="top"
      >
        <el-divider content-position="left"
          ><i class="el-icon-timer">报警信息</i></el-divider
        >
        <el-form-item label="报警时间">
          <el-input v-model="form.bjsj"></el-input>
        </el-form-item>
        <el-form-item label="报警电话">
          <el-input v-model="form.bjdh"></el-input>
        </el-form-item>
        <el-form-item label="报警电话用户姓名">
          <el-input v-model="form.bjdh_yhxm"></el-input>
        </el-form-item>
        <el-form-item label="报警电话用户地址">
          <el-input v-model="form.bjdh_yhdz"></el-input>
        </el-form-item>
        <el-form-item label="报警人姓名">
          <el-input v-model="form.bjr_xm"></el-input>
        </el-form-item>
        <el-form-item label="报警人性别">
          <!-- <el-input v-model="form.bjr_xb" ></el-input> -->
          <el-select clearable v-model="form.bjr_xb" placeholder="请选择性别">
            <el-option
              v-for="(item, index) in D_BZ_XB"
              :key="index"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="联系电话">
          <el-input v-model="form.bjdh"></el-input>
        </el-form-item>

        <el-divider content-position="left"
          ><i class="el-icon-timer">报警内容</i></el-divider
        >
        <el-form-item label="事发地址" style="width: 48%">
          <el-input v-model="form.sfdz" type="textarea"></el-input>
        </el-form-item>
        <el-form-item label="报警内容" style="width: 48%">
          <el-input v-model="form.bjnr" type="textarea"></el-input>
        </el-form-item>
        <el-form-item label="管辖单位">
          <el-input v-model="form.ssbm"></el-input>
        </el-form-item>
        <el-form-item label="报警类别">
          <el-input v-model="form.bjlbmc"></el-input>
        </el-form-item>
        <el-form-item label="报警类型">
          <el-input v-model="form.bjlxmc"></el-input>
        </el-form-item>
        <el-form-item label="报警细类">
          <el-input v-model="form.bjxlmc"></el-input>
        </el-form-item>
        <el-form-item label="路灯杆编号">
          <el-input v-model="form.ldgbh"></el-input>
        </el-form-item>

        <el-form-item label="有无危险物质">
          <!-- <el-input v-model="form.ywwxwz" ></el-input> -->
          <el-select clearable v-model="form.ywwxwz">
            <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="有无爆炸、泄露">
          <!-- <el-input v-model="form.ywbzxl" placeholder="请输入有无爆炸、泄露"></el-input> -->
          <el-select clearable v-model="form.ywbzxl">
            <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="有无被困人员">
          <!-- <el-input v-model="form.ywbkry" placeholder="请输入有无被困人员"></el-input> -->
          <el-select clearable v-model="form.ywbkry">
            <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="是否涉外">
          <!-- <el-input v-model="form.sfsw" placeholder="请输入是否涉外"></el-input> -->
          <el-select clearable v-model="form.sfsw">
            <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="是否外语报警">
          <!-- <el-input v-model="form.sfswybj" placeholder="请输入是否外语报警"></el-input> -->
          <el-select clearable v-model="form.sfswybj">
            <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="报警方式">
          <el-input v-model="form.bjfsbh"></el-input>
        </el-form-item>

        <el-divider content-position="left"
          ><i class="el-icon-timer">接警信息</i></el-divider
        >

        <el-form-item label="接警员编号">
          <el-input v-model="form.jjybh"></el-input>
        </el-form-item>
        <el-form-item label="接警员姓名">
          <el-input v-model="form.jjyxm"></el-input>
        </el-form-item>
        <el-form-item label="接警时间">
          <el-input v-model="form.jjsj"></el-input>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
<script setup>
import * as MOSTY from "@/components/MyComponents/index";
import pie2 from "./components/pie2.vue";
import { selectDeptPage } from "@/api/user-manage";
import { ref, getCurrentInstance, onMounted, reactive } from "vue";
const { proxy } = getCurrentInstance();

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({
  name: [{ required: true, message: "请输入名称", trigger: "change" }]
});
// 切换按钮
const signTable = ref(1);
const checkedBtn1 = ref("primary");
const checkedBtn2 = ref("default");
const checkedBtn3 = ref("default");
const checkedBtn4 = ref("default");
function getTab(val) {
  switch (val) {
    case 1:
      checkedBtn1.value = "primary";
      checkedBtn2.value = "default";
      checkedBtn3.value = "default";
      checkedBtn4.value = "default";
      signTable.value = 1;
      break;
    case 2:
      checkedBtn1.value = "default";
      checkedBtn2.value = "primary";
      checkedBtn3.value = "default";
      checkedBtn4.value = "default";
      signTable.value = 2;
      break;
    case 3:
      checkedBtn1.value = "default";
      checkedBtn2.value = "default";
      checkedBtn3.value = "primary";
      checkedBtn4.value = "default";
      signTable.value = 3;
      break;
    case 4:
      checkedBtn1.value = "default";
      checkedBtn2.value = "default";
      checkedBtn3.value = "default";
      checkedBtn4.value = "primary";
      signTable.value = 4;
      break;
  }
}
// 部门树
const defaultProps = {
  children: "childDeptList",
  label: "orgName"
};
const orgList = ref([]);
const getSysMenuTree = () => {
  const params = {
    menuName: "",
    current: 1,
    size: 100
  };
  selectDeptPage(params).then((res) => {
    orgList.value = res.records;
  });
};
function handleNodeClick(val) {}
// 获取列表
function getListData() {
  tableData.value = [];
  loadingTable.value = true;
  setTimeout(() => {
    tableData.value = [
      {
        ssbm: "仁寿公安局",
        cjrXm: "曾海峰",
        cjrSfzh: "511**********1316",
        cjrLxdh: "138******12",
        cjyBh: "123651",
        cjDwbh: "22264984",
        fknr: "暂无",
        cjzt: "1"
      },
      {
        ssbm: "仁寿公安局",
        cjrXm: "邓林",
        cjrSfzh: "511**********1316",
        cjrLxdh: "138******12",
        cjyBh: "134651",
        cjDwbh: "23454984",
        fknr: "暂无",
        cjzt: "2"
      },
      {
        ssbm: "仁寿公安局",
        cjrXm: "邓伟",
        cjrSfzh: "511**********1316",
        cjrLxdh: "138******12",
        cjyBh: "312651",
        cjDwbh: "65454984",
        fknr: "暂无",
        cjzt: "3"
      },
      {
        ssbm: "仁寿公安局",
        cjrXm: "胖大白",
        cjrSfzh: "511**********1316",
        cjrLxdh: "138******12",
        cjyBh: "112651",
        cjDwbh: "23454984",
        fknr: "暂无",
        cjzt: "4"
      },
      {
        ssbm: "仁寿公安局",
        cjrXm: "孙江燕",
        cjrSfzh: "511**********1316",
        cjrLxdh: "138******12",
        cjyBh: "134231",
        cjDwbh: "62344984",
        fknr: "暂无",
        cjzt: "2"
      }
    ];
    loadingTable.value = false;
    total.value = tableData.value.length;
  }, 1500);
}
//打开新增弹窗
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 orgHeight = ref();
const tabHeightFn = () => {
  tableHeight.value = window.innerHeight - 57 - 37 - 470;
  orgHeight.value = window.innerHeight - 57 - 37 - 100;
};
/**
 * pageSize 改变触发
 */
const handleSizeChange = (currentSize) => {
  listQuery.value.pageSize = currentSize;
  getListData();
};

/**
 * 页码改变触发
 */
const handleCurrentChange = (currentPage) => {
  listQuery.value.pageCurrent = currentPage;
  getListData();
};
onMounted(() => {
  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: space-between;
  margin-bottom: 10px;
}
.chart-pie-box {
  width: 100%;
}
.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>
