Newer
Older
HuangJiPC / src / pages / views / alarmWarning / conponents / alarmLogsReal.vue
@zhangdeliang zhangdeliang on 21 Jun 13 KB update
<template>
  <!-- 实时日志 -->
  <div class="alarmLogsReal">
    <div class="searchBox">
      <n-space>
        <n-select
          v-model:value="searchValue1"
          :options="stationOptions"
          style="width: 200px"
          clearable
          filterable
          placeholder="请选择站点名称"
        />
        <n-select v-model:value="searchValue2" style="width: 200px" clearable :options="gdList" placeholder="请选择是否转工单"> </n-select>
        <n-date-picker v-model:value="timeRange" type="datetimerange" clearable />
        <n-button type="primary" @click="handleClick('search')">搜索 </n-button>
      </n-space>
    </div>
    <div class="tableBox">
      <n-data-table
        ref="tableRef"
        :bordered="false"
        :max-height="700"
        striped
        :columns="columns"
        :loading="tableLoading"
        :data="tableData"
        :remote="true"
        :pagination="pagination"
      >
      </n-data-table>
    </div>
  </div>
  <!-- 工单详情弹窗 -->
  <n-modal
    title="报警提醒工单详细"
    :mask-closable="false"
    preset="dialog"
    :show-icon="false"
    :style="{ width: '800px' }"
    v-model:show="modalShow"
  >
    <div class="reportDetai">
      <div class="part" style="width: 50%">
        <div class="title">工单名称:</div>
        <div class="content">{{ workDetail.jobName }}</div>
      </div>
      <div class="part" style="width: 50%">
        <div class="title">养护人员:</div>
        <div class="content">{{ workDetail.jobPerson }}</div>
      </div>
      <div class="part" style="width: 50%">
        <div class="title">缺陷描述:</div>
        <div class="content">{{ workDetail.jobStepDesc }}</div>
      </div>
      <div class="part" style="width: 50%">
        <div class="title">工单状态:</div>
        <div class="content" v-if="workDetail.workOrderStatus == 0">已完成</div>
        <div class="content" v-if="workDetail.workOrderStatus == 1">未完成</div>
      </div>
      <div class="title" style="width: 100%">报警提醒工单流程历史记录</div>
      <n-data-table :bordered="false" striped :columns="columns2" :data="tableData2" :remote="true"> </n-data-table>
    </div>
  </n-modal>
  <!-- 报警提醒详细历史记录弹窗 -->
  <n-modal
    title="报警提醒详细历史记录"
    :mask-closable="false"
    preset="dialog"
    :show-icon="false"
    :style="{ width: '800px' }"
    v-model:show="modalShow2"
  >
    <div class="reportDetai">
      <n-data-table :bordered="false" striped :columns="columns3" :data="tableData3" :pagination="pagination2" :remote="true">
      </n-data-table>
    </div>
  </n-modal>
</template>

<script>
import { onMounted, reactive, toRefs, h } from 'vue';
import { warntempSearch, warntempHistory, queryAlarmReminderListHistory, warntempDetail, getStationame } from '@/services';
import { NButton } from 'naive-ui';
import { formatDate } from '@/utils/util';

export default {
  name: 'alarmLogsReal',
  setup() {
    const allData = reactive({
      stationOptions: [],
      // 搜索
      searchValue1: null,
      searchValue2: null,
      gdList: [
        { value: 0, label: '否' },
        { value: 1, label: '是' },
        { value: 2, label: '忽略' },
      ],
      timeRange: [Date.now() - 24 * 30 * 60 * 60 * 1000, Date.now()],
      tableData3: [],
      historyId: '',
      columns3: [
        {
          title: '站点名称',
          key: 'siteName',
          align: 'center',
        },
        {
          title: '因子名称',
          key: 'factorsName',
          align: 'center',
        },
        {
          title: '实时监测值',
          key: 'warnValue',
          align: 'center',
        },
        {
          title: '判断类型',
          key: 'compareWayDesc',
          align: 'center',
        },
        {
          title: '报警阀值',
          key: 'warnConfigValue',
          align: 'center',
        },
        {
          title: '持续时间',
          key: 'durationTime',
          align: 'center',
        },
        {
          title: '警戒级别',
          key: 'warnType',
          align: 'center',
          render(row) {
            let value = '';
            switch (row.warnType) {
              case 1:
                value = '预警';
                break;
              case 2:
                value = '报警';
                break;
              case 3:
                value = '设备异常';
                break;
              case 4:
                value = '设备离线';
                break;
              case 5:
                value = '设备故障';
                break;
            }
            return value;
          },
        },
        {
          title: '观测时间',
          key: 'ttTime',
          align: 'center',
        },
      ],
      modalShow2: false,
      modalShow: false,
      columns2: [
        {
          title: '序号',
          align: 'center',
          width: '60',
          render(row, index) {
            return (paginationReactive.page - 1) * paginationReactive.pageSize + index + 1;
          },
        },
        { title: '任务名称', align: 'center', key: 'taskName' },
        { title: '任务执行人', align: 'center', key: 'taskAssignee' },
        { title: '审批意见', align: 'center', key: 'remark' },
        { title: '创建时间', align: 'center', key: 'gmtCreated', width: '160' },
      ],
      tableData2: [],
      workDetail: {},
      tableLoading: true,
      // 表格
      columns: [
        {
          title: '站点名称',
          key: 'siteName',
          align: 'center',
        },
        {
          title: '因子名称',
          key: 'factorsName',
          align: 'center',
        },
        {
          title: '实时监测值',
          key: 'warnValue',
          align: 'center',
        },
        {
          title: '判断类型',
          key: 'compareWayDesc',
          align: 'center',
        },
        {
          title: '报警阀值',
          key: 'warnConfigValue',
          align: 'center',
        },
        {
          title: '持续时间',
          key: 'durationTime',
          align: 'center',
        },
        {
          title: '警戒级别',
          key: 'warnType',
          align: 'center',
          render(row) {
            let value = '';
            switch (row.warnType) {
              case 1:
                value = '预警';
                break;
              case 2:
                value = '报警';
                break;
              case 3:
                value = '设备异常';
                break;
              case 4:
                value = '设备离线';
                break;
              case 5:
                value = '设备故障';
                break;
            }
            return value;
          },
        },
        {
          title: '是否转工单',
          key: 'isWorkOrder',
          align: 'center',
          render(row) {
            let value = '';
            switch (row.isWorkOrder) {
              case 0:
                value = '否';
                break;
              case 1:
                value = '是';
                break;
              case 2:
                value = '忽略';
                break;
            }
            return value;
          },
        },
        {
          title: '工单状态',
          key: 'workOrderStatus',
          align: 'center',
          render(row) {
            let value = '';
            switch (row.workOrderStatus) {
              case 0:
                value = '未处理';
                break;
              case 1:
                value = '已处理';
                break;
            }
            return value;
          },
        },
        {
          title: '观测时间',
          key: 'ttTime',
          align: 'center',
        },
        {
          title: '操作',
          key: 'actions',
          align: 'center',
          render(row) {
            let arrs = [...allData.actionColumn];
            let obj = {
              size: 'small',
              btnType: 'primary',
              type: 'detail',
              default: '工单详情',
            };
            // 已经转工单,并且已完成的才有详情历史记录查看
            if (row.isWorkOrder == 1) {
              arrs.push(obj);
            }
            const btn = arrs.map((item, index) => {
              return h(
                NButton,
                {
                  text: true,
                  size: item.size,
                  style: {
                    margin: '10px',
                  },
                  type: item.btnType,
                  onClick: () => handleClick(item.type, row),
                },
                { default: () => item.default }
              );
            });
            return btn;
          },
        },
      ],
      actionColumn: [
        {
          size: 'small',
          btnType: 'primary',
          type: 'history',
          default: '报警历史记录',
        },
      ],
      tableData: [],
    });

    //分页
    const paginationReactive = reactive({
      page: 1,
      pageSize: 10,
      showSizePicker: true,
      pageSizes: [10, 20, 50],
      showQuickJumper: true,
      pageCount: 0,
      itemCount: 0,
      onChange: (page) => {
        paginationReactive.page = page;
        getTableData();
      },
      onPageSizeChange: (pageSize) => {
        paginationReactive.pageSize = pageSize;
        paginationReactive.page = 1;
        getTableData();
      },
    });
    const paginationReactive2 = reactive({
      page: 1,
      pageSize: 10,
      showSizePicker: true,
      pageSizes: [10, 20, 50],
      showQuickJumper: true,
      pageCount: 0,
      itemCount: 0,
      onChange: (page) => {
        paginationReactive2.page = page;
        getHistory();
      },
      onPageSizeChange: (pageSize) => {
        paginationReactive2.pageSize = pageSize;
        paginationReactive2.page = 1;
        getHistory();
      },
    });
    //获取站点名称下拉框
    const GetStationName = async () => {
      let res = await getStationame();
      if (res && res.code == 1) {
        let data = res.data;
        data.forEach((item) => {
          let { stCode, stName } = item;
          allData.stationOptions.push({ value: stCode, label: stName });
        });
      }
    };
    // 获取表格数据
    const getTableData = async () => {
      allData.tableLoading = true;
      let times = allData.timeRange ? formatDate(allData.timeRange[0]) : null;
      let timee = allData.timeRange ? formatDate(allData.timeRange[1]) : null;
      let pramas = {
        current: paginationReactive.page,
        size: paginationReactive.pageSize,
        data: {
          endTime: timee,
          siteNo: allData.searchValue1,
          isWorkOrder: allData.searchValue2,
          startTime: times,
        },
      };
      let res = await warntempSearch(pramas);
      if (res && res.code == 200) {
        let datas = res.data;
        allData.tableData = datas.list || [];
        paginationReactive.pageCount = datas.pages;
        paginationReactive.itemCount = datas.total;
      }
      allData.tableLoading = false;
    };
    const handleClick = (type, row) => {
      switch (type) {
        case 'search':
          getTableData();
          break;
        case 'detail':
          allData.modalShow = true;
          getDetail(row);
          break;
        case 'history':
          allData.modalShow2 = true;
          allData.historyId = row.id;
          getHistory();
          break;
      }
    };
    // 详情信息
    async function getDetail(row) {
      // 详情
      let params1 = {
        workOrderId: row.workOrderId,
      };
      let res1 = await warntempDetail(params1);
      if (res1 && res1.code == 200) {
        allData.workDetail = res1.data;
      }
      // 历史记录
      let params2 = {
        processInstanceId: row.processInstanceId,
      };
      let res2 = await warntempHistory(params2);
      if (res2 && res2.code == 200) {
        allData.tableData2 = res2.data;
      }
    }
    // 报警提醒详细历史记录
    async function getHistory() {
      let pramas = {
        current: paginationReactive2.page,
        size: paginationReactive2.pageSize,
        data: {
          id: allData.historyId,
        },
      };
      let res = await queryAlarmReminderListHistory(pramas);
      if (res && res.code == 200) {
        allData.tableData3 = res.data.list;
        paginationReactive2.pageCount = res.data.pages;
        paginationReactive2.itemCount = res.data.total;
      }
    }
    onMounted(() => {
      getTableData();
      GetStationName();
    });
    return {
      ...toRefs(allData),
      pagination: paginationReactive,
      pagination2: paginationReactive2,
      getTableData,
      handleClick,
      GetStationName,
    };
  },
};
</script>

<style lang="less">
.alarmLogsReal {
  .tableBox {
    margin-top: 10px;
  }
}
.reportDetai {
  margin: 20px auto;
  display: flex;
  flex-wrap: wrap;
  padding-left: 20px;

  .title {
    width: 100px;
    color: #00e6e6;
    font-size: 15px;
  }
  .part {
    display: flex;
    width: 100%;
    margin-bottom: 10px;
    .content {
      flex: 1;
      .n-image {
        margin-right: 10px;
      }
    }
  }
}
</style>