<!-- 界面警情统计 -->
<template>
  <div class="container">
    <div class="titleBox">
      <div class="title">警情趋势</div>
      <div class="btnBox"></div>
    </div>
    <!-- class="searchBox" ref="searchBox" -->
    <div class="min_box">
      <div class="treeBox" :style="{ height: treeHeight }">
        <MOSTY.DepartmentTree
          width="280px"
          placeholder="管理部门ID"
          clearable
          filterable
          v-model="listQuery.deptId"
        />
      </div>
      <div class="flex_e">
        <div class="chart-box">
          <div class="searchBox single-chart-box">
            <div>今日警情数量走势图</div>
            <div style="position: relative">
              <linechart :data="jrjqSlzsData" />
            </div>
          </div>
          <div class="searchBox single-chart-box2">
            <div>预警值</div>
            <div class="display-box">
              <div class="display-item item1">
                <p class="dis-text">大于9000分值</p>
                <p class="dis-text">
                  <span class="dis-num">1</span> &nbsp;&nbsp;&nbsp; 0%
                </p>
              </div>
              <div class="display-item item2">
                <p class="dis-text">5000-9000分值</p>
                <p class="dis-text">
                  <span class="dis-num">1</span> &nbsp;&nbsp;&nbsp; 0%
                </p>
              </div>
              <div class="display-item item3">
                <p class="dis-text">1000-5000分值</p>
                <p class="dis-text">
                  <span class="dis-num">1</span> &nbsp;&nbsp;&nbsp; 0%
                </p>
              </div>
              <div class="display-item item4">
                <p class="dis-text">1000以下分值</p>
                <p class="dis-text">
                  <span class="dis-num">2</span> &nbsp;&nbsp;&nbsp; 0%
                </p>
              </div>
            </div>
          </div>
        </div>
        <div class="chartAndTable-box">
          <div class="searchBox tab">
            <div class="mysearch" ref="searchBox">
             
            </div>
            <el-table
              :data="tableData"
              border
              style="width: 100%"
              :height="tableHeight"
              :key="keyCount"
              v-loading="loadingTable"
              element-loading-background="rgba(0,0,0,0.3)"
              element-loading-text="数据加载中。。"
            >
              <el-table-column
                label="序号"
                type="index"
                align="center"
                width="60"
              />
              <el-table-column label="单位部门" prop="ssbm" align="center" />
              <el-table-column label="警情总数" prop="jqzs" align="center" />
              <el-table-column label="同比增长率" prop="tbzzl" align="center" />
              <el-table-column label="环比增长率" prop="hbzzl" align="center" />
              <el-table-column label="操作" align="center" fixed="right">
                <template #default="{ row }">
                  <el-button @click="update(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.page"
                :page-sizes="[10, 20, 50, 100]"
                :page-size="listQuery.size"
                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"
        :inline="true"
        label-position="top"
        disabled
      >
        <el-form-item label="所属部门" prop="ssbm">
          <el-input v-model="form.ssbm"></el-input>
        </el-form-item>
        <el-form-item label="警情总数" prop="jqzs">
          <el-input v-model="form.jqzs"></el-input>
        </el-form-item>
        <el-form-item label="同比增长率" prop="tbzzl">
          <el-input v-model="form.tbzzl"></el-input>
        </el-form-item>
        <el-form-item label="环比增长率" prop="hbzzl">
          <el-input v-model="form.hbzzl"></el-input>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
<script setup>
import {
  getJmjq,
  getJqlxTj,
  getJrjqTj,
  getJrjqSlzs,
  getJrjqYj
} from "@/api/patrolStatistics/interfaceAlarm.js";
import { getJqqs } from "@/api/warningCenter/alarmTrend.js";
import * as MOSTY from "@/components/MyComponents/index";
import linechart from "./components/line.vue";
const treeHeight = ref(""); // 树高度
const treeHeightFn = () => {
  treeHeight.value = window.innerHeight - 57 - 37 - 93 + "px";
};
import { ref, getCurrentInstance, onMounted } from "vue";
const { proxy } = getCurrentInstance();
const { D_BZ_CZZT } = proxy.$dict("D_BZ_CZZT");
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 jrjqCzfxData = ref([]);
const jrjqLxData = ref([]);
const jrjqSlzsData = ref([{ x: 0, y: 0 }]);
const jrjqYjData = ref({
  total: 100,
  value: 0.0
});
const listQuery = ref({
  page: 1,
  size: 10
}); //搜索表单
//表单验证
const rules = ref({
  name: [{ required: true, message: "请输入名称", trigger: "change" }]
});

// 获取列表
function getListData() {
  loadingTable.value = false;
  //   getJmjq(listQuery.value).then((res) => {
  //     tableData.value = res.list;
  total.value = 5;
  tableData.value = [
    {
      ssbm: "仁寿公安局",
      jqzs: "10",
      tbzzl: "15%",
      hbzzl: "12%"
    },
    {
      ssbm: "仁寿公安局",
      jqzs: "10",
      tbzzl: "15%",
      hbzzl: "12%"
    },
    {
      ssbm: "仁寿公安局",
      jqzs: "18",
      tbzzl: "15%",
      hbzzl: "12%"
    },
    {
      ssbm: "仁寿公安局",
      jqzs: "20",
      tbzzl: "18%",
      hbzzl: "16%"
    },
    {
      ssbm: "仁寿公安局",
      jqzs: "30",
      tbzzl: "35%",
      hbzzl: "20%"
    }
  ];
  //   });
}
// 获取图表数据
function getEchData() {
  getJqlxTj().then((res) => {
    jrjqLxData.value = res.map((item) => {
      return {
        name: item.bjlx,
        value: item.sl
      };
    });
  });
  getJrjqTj().then((res) => {
    jrjqCzfxData.value = res.map((item) => {
      const nameArr = D_BZ_CZZT.value.map(a=>a).filter((e) => e.value == item.czzt)
      return {
        name: nameArr.length?nameArr[0]['label']:'',
        value: item.sl
      };
    });
  });
  getJqqs().then((res) => {
    jrjqSlzsData.value = res.time.map((item, index) => {
      return { x: 2 * index + 2 + "时", y: res.count[index] };
    });
  });
  getJrjqYj().then((res) => {
    jrjqYjData.value.value = res[0].sl;
  });
}
//打开新增弹窗
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 update(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.page = 1;
  getListData();
};
//点击重置
const reset = () => {
  listQuery.value = {
    page: 1,
    size: 10
  };
  getListData();
};
// 表格高度计算
const tabHeightFn = () => {
  tableHeight.value =
    window.innerHeight - 57 - 37 - searchBox.value.offsetHeight - 440;
};
/**
 * size 改变触发
 */
const handleSizeChange = (currentSize) => {
  listQuery.value.size = currentSize;
  getListData();
};

/**
 * 页码改变触发
 */
const handleCurrentChange = (currentPage) => {
  listQuery.value.page = currentPage;
  getListData();
};
onMounted(() => {
  getListData();
  tabHeightFn();
  treeHeightFn();
  getEchData();
  window.onresize = function () {
    tabHeightFn();
    treeHeightFn();
    keyCount.value = 1;
    setTimeout(() => {
      keyCount.value = 0;
    }, 100);
  };
  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 {
  display: flex;
  justify-content: space-between;
}
.tab {
  width: 100%;
}
.single-chart-box {
  height: 280px;
  width: 60%;
  box-sizing: border-box;
}
.single-chart-box2 {
  height: 280px;
  width: 38%;
  box-sizing: border-box;
}
.chartAndTable-box {
  margin-top: 15px;
  display: flex;
  justify-content: space-between;
}
.left-box {
  width: 32%;
  box-sizing: border-box;
}
.right-table {
  width: 100%;
  box-sizing: border-box;
}
.min_box {
  display: flex;
  .flex_e {
    flex: 1;
  }
}
// .container{
// width: 1639px;
// }
.mysearch {
  width: 100%;
  overflow: hidden;
}
.display-box {
  display: flex;
  box-sizing: border-box;
  justify-content: space-around;
  flex-wrap: wrap;
  .display-item {
    width: 150px;
    height: 80px;
    margin: 12px 0;
    border-radius: 10px;
    color: #000;
    .dis-text {
      text-align: center;
      line-height: 15px;
    }
    .dis-num {
      font-size: 24px;
    }
  }
  .item4 {
    background-color: rgb(8, 39, 241);
    color: #fff;
  }
}
.item1 {
  background-color: rgb(207, 11, 11);
}
.item2 {
  background-color: rgb(202, 75, 20);
}
.item3 {
  background-color: rgb(247, 239, 10);
}
.item4 {
  background-color: rgb(8, 39, 241);
}
</style>
