
<script setup>
import { getYjzlList } from "@/api/warningCenter/warningInstruct.js";
import { ref, getCurrentInstance, onMounted } from "vue";
const { proxy } = getCurrentInstance();
const { D_BZ_ZLLX,D_BZ_ZLLY,D_BZ_ZLYXQ } = proxy.$dict("D_BZ_ZLLX",'D_BZ_ZLLY','D_BZ_ZLYXQ');
//等级颜色值
const djColor = [
  {
    label:'红色',
    value:'10'
  },
  {
    label:'橙色',
    value:'20'
  },
  {
    label:'黄色',
    value:'30'
  },
  {
    label:'蓝色',
    value:'40'
  },
]
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({
  pageNum: 1,
  pageSize: 10,
  zlnr: ''
}); //搜索表单
//表单验证
const rules = ref({
  name: [{ required: true, message: "请输入名称", trigger: "change" }]
});

// 获取列表
function getListData() {
  loadingTable.value = true;
  getYjzlList(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) {
  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(() => {
    })
    .catch(() => {
      proxy.$message.info("已取消");
    });
}
//批量删除
function batchDelete() {
  proxy
    .$confirm("确定要删除", "警告", {
      type: "warning"
    })
    .then(() => {
    })
    .catch(() => {
      proxy.$message.info("已取消");
    });
}
//点击查询
const handleFilter = () => {
  listQuery.value.pageNum = 1;
  getListData();
};
//点击重置
const reset = () => {
  listQuery.value = {
    pageNum: 1,
    pageSize: 10,
    zlnr: ''
  };
  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 label="指令内容">
          <el-input
            v-model="listQuery.zlnr"
            placeholder="请输入指令内容"
            clearable
          ></el-input>
        </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="ssbm" align="center"/>
        <el-table-column prop="zlnr" label="指令内容" show-overflow-tooltip  align="center"/>

        <el-table-column prop="zllx" label="指令类型" align="center">
          <template #default="{ row }">
            <dict-tag :value="row.zllx" :options="D_BZ_ZLLX"></dict-tag>
          </template>
        </el-table-column>
        <el-table-column prop="zlly" label="指令来源" align="center">
          <template #default="{ row }">
            <dict-tag :value="row.zlly" :options="D_BZ_ZLLY"></dict-tag>
          </template>
        </el-table-column>

        <el-table-column prop="zlzxzt" label="处置状态" align="center">
          <template #default="{ row }">
            <el-tag v-if="row.zlzxzt == '01'">签收</el-tag>
            <el-tag v-if="(row.zlzxzt == '02' || row.zlzxzt == '03') && row.zllx != '07'">到达现场</el-tag>
            <el-tag v-if="['11', '21', '22','23','24','25'].includes(row.zlzxzt)|| (row.zlzxzt == '31' && row.zllx != '07')">处置完成</el-tag>
            <el-tag v-if="row.zlzxzt == '32'">完结</el-tag>
            <el-tag v-if="['92', '93', '94'].includes(row.zlzxzt)">已完成</el-tag>

          </template>
        </el-table-column>

        <el-table-column
          prop="zldj"
          label="指令等级"
          align="center"
          show-overflow-tooltip
        >
        <template #default="{row}">
          <dict-tag :value='row.zldj' :options='djColor' :tag="false"></dict-tag>
        </template>
        </el-table-column>

        <el-table-column
          prop="zlfssj"
          label="发生时间"
          align="center"
          show-overflow-tooltip
        >
        </el-table-column>

        <el-table-column prop="zlgqsj" label="过期时间" align="center">
        </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
            :loading="loading"
            type="primary"
            size="small"
            @click="submit"
            >保存</el-button
          > -->
          <el-button size="small" @click="close">关闭</el-button>
        </div>
      </div>
      <el-form
        ref="elform"
        :model="form"
        :rules="rules"
        :inline="true"
        label-position="top"
        disabled
      >
        <!-- <div>
          <el-image style="width: 110px" :src="form.bzxzpUrl"></el-image>
        </div> -->
        <div class="infoBOX">
          <el-form-item label="指令预警类型">
            <el-select v-model="form.zllx">
              <el-option v-for="dict in D_BZ_ZLLX" :key="dict.value" :value="dict.value" :label="dict.label"></el-option>
            </el-select>
          </el-form-item>
          <!-- <el-form-item label="预警人车标签">
            <el-input placeholder="请输入人车标签" v-model="form.rylbmc" />
          </el-form-item> -->
          <el-form-item label="指令级别">
            <el-select disabled="disabled" v-model="form.zldj">
              <el-option v-for="dict in djColor" :key="dict.value" :label="dict.label" :value="dict.value"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="指令发生时间">
            <el-input v-model="form.zlfssj" disabled="disabled"></el-input>
          </el-form-item>
          <el-form-item label="指令过期时间">
            <el-input v-model="form.zlgqsj" disabled="disabled"></el-input>
          </el-form-item>
          <!-- <el-form-item label="指令签收状态">
            <el-select disabled="disabled" v-model="form.zlczztdm">
              <el-option label="已签收" value="0"></el-option>
              <el-option label="未签收" value="1"></el-option>
            </el-select>
          </el-form-item> -->
          <el-form-item label="指令处理状态">
            <el-select disabled="disabled" v-model="form.sfcl">
              <el-option label="已处理" value="1"></el-option>
              <el-option label="未处理" value="0"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="指令有效期">
            <el-select disabled="disabled" v-model="form.zlyxq">
              <el-option
                v-for="(item, index) in D_BZ_ZLYXQ"
                :key="index"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <!-- <el-form-item label="指令签收类型">
            <el-select disabled="disabled" v-model="form.zlqslxdm">
              <el-option
                v-for="(item, index) in D_GA_ZLQSLX"
                :key="index"
                :label="item.zdmc"
                :value="item.dm"
              >
              </el-option>
            </el-select>
          </el-form-item> -->
          <el-form-item label="发生地点">
            <el-input v-model="form.zlfsdd" disabled="disabled"></el-input>
          </el-form-item>
          <el-form-item label="指令完成说明">
            <el-input v-model="form.zlwcsm" disabled="disabled"></el-input>
          </el-form-item>
          <div class="infoItem">
            <el-form-item style="width:48%" label="指令标题">
              <el-input
                v-model="form.zlbt"
                placeholder="请输入指令标题"
              ></el-input>
            </el-form-item>
            <el-form-item style="width:100%" label="指令内容">
              <el-input
                v-model="form.zlnr"
                :minRows="2"
                type="textarea"
                placeholder="指令内容"
              ></el-input>
            </el-form-item>
            <el-form-item style="width:100%" label="备注">
              <el-input
                v-model="form.bz"
                :minRows="2"
                type="textarea"
                placeholder="--"
              ></el-input>
            </el-form-item>
          </div>
        </div>
      </el-form>
    </div>
  </div>
</template>
<style lang='scss' scoped>
@import "~@/assets/css/layout.scss";
@import "~@/assets/css/element-plus.scss";
.el-form {
  display: flex;
}
.dialog[data-v-f309fb5e] .el-form-item--default {
  // width: 48%;
}
.infoBOX {
  width: calc(100% - 120px);
  margin-left: 10px;
  display: flex;
  flex-wrap: wrap;
}
.infoItem {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  .dialog[data-v-f309fb5e] .el-form-item--default {
    width: 100%;
  }
}
</style>