
<script setup>
import { getYjxxList, getInfo } from "@/api/warningCenter/warningInfo.js";
import { ref, getCurrentInstance, onMounted } from "vue";
const { proxy } = getCurrentInstance();
const { D_BZ_YJLX, D_BZ_tyjb } = proxy.$dict("D_BZ_YJLX", "D_BZ_tyjb");
const keyCount = ref(0); //tabel组件刷新值
const form = ref({}); //新增表单
const tableData = ref([]); //表格数据
const tableDataFk = 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({
  pageNum: 1,
  pageSize: 10,
  // seqwQzsj: []
}); //搜索表单
//表单验证
const rules = ref({
  name: [{ required: true, message: "请输入名称", trigger: "change" }]
});

// 获取列表
function getListData() {
  loadingTable.value = true;
  getYjxxList(listQuery.value).then((res) => {
    tableData.value = res.records;
    total.value = res.total;
    loadingTable.value = false;
  }).catch(()=>{
    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 update(row) {
  getInfo(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 handleDictItemQs(row) {
  proxy
    .$confirm("确定要签收", {
      type: "info"
    })
    .then(() => {})
    .catch(() => {
      proxy.$message.info("已取消");
    });
}
function handleDictItemFk(row) {
  proxy
    .$confirm("确定要反馈", {
      type: "info"
    })
    .then(() => {})
    .catch(() => {
      proxy.$message.info("已取消");
    });
}
//点击查询
const handleFilter = () => {
  listQuery.value.pageNum = 1;
  getListData();
};
//点击重置
const reset = () => {
  listQuery.value = {
    pageNum: 1,
    pageSize: 10
  };
  getListData();
};
// 表格高度计算
const tabHeightFn = () => {
 tableHeight.value = window.innerHeight - searchBox.value.offsetHeight - 240;
};
/**
 * pageSize 改变触发
 */
const handleSizeChange = (currentSize) => {
  listQuery.value.pageSize = currentSize;
  getListData();
};

/**
 * 页码改变触发
 */
const handleCurrentChange = (currentPage) => {
  listQuery.value.pageNum = currentPage;
  getListData();
};
onMounted(() => {
  getListData();
  tabHeightFn();
  window.onresize = function () {
    tabHeightFn();
  };
  proxy.mittBus.on("mittFn", (data) => {
    keyCount.value = data;
  });
});
</script>
    
    
<template>
  <div>
    <div class="titleBox">
      <div class="title">预警信息</div>
    </div>
    <div class="searchBox" ref="searchBox">
      <el-form :model="listQuery" :inline="true">
        <el-form-item prop="yjlx" label="预警类型">
          <el-select clearable style="width: 100%" v-model="listQuery.yjLx">
            <el-option
              v-for="(dict, index) in D_BZ_YJLX"
              :key="index"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="预警对象">
          <el-input
            v-model="listQuery.yjRyxm"
            placeholder="请输入预警对象"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item label="发生时间">
          <el-date-picker
            v-model="listQuery.seqwQzsj"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始时间"
            end-placeholder="结束时间"
            format="YYYY-MM-DD HH:mm"
            value-format="YYYY-MM-DD HH:mm"
          />
        </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 label="序号" type="index" width="60" align="center" />
        <el-table-column label="布控图片" prop="yjXtp" align="center">
          <template #default="{ row }">
            <el-image style="width: 100px; height: 100px" :src="row.yjXtp" />
          </template>
        </el-table-column>
        <el-table-column label="预警图片" prop="yjtp" align="center">
          <template #default="{ row }">
            <el-image style="width: 100px; height: 100px" :src="row.yjTp" />
          </template>
        </el-table-column>
        <el-table-column
          label="感知源名称"
          prop="yjGzymc"
          align="center"
        ></el-table-column>
        <el-table-column
          label="预警发生时间"
          prop="yjFssj"
          align="center"
        ></el-table-column>
        <el-table-column
          label="预警对象"
          prop="yjRyxm"
          align="center"
        >
        <template #default="{row}">
          {{row.yjClcph||row.yjRyxm}}
        </template>
        </el-table-column>
        <el-table-column label="预警类型" prop="yjLx" align="center">
          <template #default="{ row }">
            <dict-tag
              :options="D_BZ_YJLX"
              :value="row.yjLx"
              :tag="false"
            ></dict-tag>
          </template>
        </el-table-column>
        <el-table-column
          label="操作"
          align="center"
          fixed="right"
          width="100px"
        >
          <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.pageNum"
          :page-sizes="[10, 20, 50, 100]"
          :page-size="listQuery.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
        >
        </el-pagination>
      </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="预警类型">
          <el-select v-model="form.yjLx">
            <el-option
              v-for="dict in D_BZ_YJLX"
              :key="dict.value"
              :value="dict.value"
              :label="dict.label"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="感知源名称">
          <el-input v-model="form.yjGzymc"></el-input>
        </el-form-item>
        <el-form-item label="预警发生时间">
          <el-input v-model="form.yjFssj"></el-input>
        </el-form-item>
        <el-form-item label="预警对象">
          <el-input v-show='form.yjLx == 1' v-model="form.yjRyxm"></el-input>
          <el-input v-show='form.yjLx != 1' v-model="form.yjClcph"></el-input>
        </el-form-item>
        <el-form-item label="预警标签">
          <el-input v-model="form.yjlyBqmc"></el-input>
        </el-form-item>
        <el-form-item label="预警级别">
          <el-select v-model="form.yjJb">
            <el-option
              v-for="(dict, index) in D_BZ_tyjb"
              :key="index"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="预警地址">
          <el-input v-model="form.yjDz"></el-input>
        </el-form-item>
        <el-form-item style="width: 100%" label="预警内容">
          <el-input v-model="form.yjNr"></el-input>
        </el-form-item>
        <el-form-item label="布控图片">
          <el-image
            :preview-src-list="[form.yjXtp]"
            fit="cover"
            style="width: 100px; height: 100px"
            :src="form.yjXtp"
          ></el-image>
        </el-form-item>
        <el-form-item label="预警图片">
          <el-image
            :preview-src-list="[form.yjTp]"
            fit="cover"
            style="width: 100px; height: 100px"
            :src="form.yjTp"
          ></el-image>
        </el-form-item>
      </el-form>
      <!-- <div class="dialogContnt">
        <div class="top">
          <table class="top-cnt" cellpadding="0" cellspacing="0">
            <tr>
              <td class="item-title">预警人姓名</td>
              <td class="item-cnt">{{ form.yjRyxm }}</td>
              <td class="item-title">预警人员证件号码</td>
              <td class="item-cnt">{{ form.yjRysfzh }}</td>
            </tr>
            <tr>
              <td class="item-title">预警时间</td>
              <td class="item-cnt">{{ form.yjFssj }}</td>
              <td class="item-title">预警级别</td>
              <td class="item-cnt">{{ form.yjJb }}</td>
            </tr>
            <tr>
              <td class="item-title">预警类型</td>
              <td class="item-cnt">{{ form.yjLx }}</td>
              <td class="item-title">人员类别</td>
              <td class="item-cnt">{{ form.rylb }}</td>
            </tr>
            <tr>
              <td class="item-title">活动发生地所属公安机关</td>
              <td class="item-cnt" colspan="3">{{ form.ssbm }}</td>
            </tr>
            <tr>
              <td class="item-title">预警标签</td>
              <td class="item-cnt" colspan="3">{{ form.yjbq }}</td>
            </tr>
            <tr>
              <td class="item-title">活动发生详址</td>
              <td class="item-cnt" colspan="3">{{ form.yjDz }}</td>
            </tr>

            <tr>
              <td class="item-title">预警信息详情</td>
              <td class="item-cnt" colspan="3">{{ form.yjNr }}</td>
            </tr>
          </table>
        </div>
      </div> -->
    </div>
  </div>
</template>
<style lang='scss' scoped>
@import "~@/assets/css/layout.scss";
@import "~@/assets/css/element-plus.scss";
.dialogContnt {
  max-height: 66vh;
  overflow: hidden;
  .top {
    width: 100%;
    height: 300px;
    margin-top: 20px;
    .top-cnt {
      margin: 0 auto;
      width: 80%;
      height: 100%;
      border: 1px solid #ccc;
      border-top: none;
      tr td {
        border: 1px solid #ccc;
        vertical-align: middle;
      }
      .item-title {
        width: 170px;
        text-align: right;
        padding-right: 10px;
        // background: #e7eaed;
      }
      .item-cnt {
        padding-left: 6px;
      }
      .item-foot {
        text-align: center;
      }
    }
  }
  .bottom {
    height: calc(66vh - 300px);
    .bottom-title {
      color: #fff;
      font-size: 16px;
      line-height: 30px;
      border-bottom: 1px dashed #ccc;
      margin-bottom: 10px;
    }
    .bottom-cnt {
      height: calc(66vh - 340px);
      box-sizing: border-box;
    }
  }
}
</style>