Newer
Older
smart-metering-front / src / views / workbench / workList.vue
dutingting on 29 Jun 2023 6 KB 工作提醒详情跳转处理
<!-- 工作提醒列表页 -->
<script name="WorkList" setup lang="ts">
import type { Ref } from 'vue'
import { ElLoading, ElMessage, ElMessageBox } from 'element-plus'
import type { DateModelType } from 'element-plus'
import { number } from 'echarts'
import type { IWorkMessageListQuery } from './workbench-interface'
import type { TableColumn } from '@/components/NormalTable/table_interface'
import { getWorkMessageList } from '@/api/workbench/workbench'
import { getDictByCode } from '@/api/system/dict'
import type { dictType } from '@/global'
import { formUrl } from '@/utils/scheduleDict'
const $router = useRouter()
const { proxy } = getCurrentInstance() as any
const messageSourceModuleList = ref<dictType[]>([]) // 是否加急
const statusList = [
  {
    id: '1',
    name: '已读',
  },
  {
    id: '0',
    name: '未读',
  },
]
// 查询条件
const listQuery: Ref<IWorkMessageListQuery> = ref({
  endTime: '', // 消息提醒结束时间
  messageSourceModule: '', // 来源模块(字典code)
  messageType: '', // 消息提醒的业务类型(字典code)
  remindDeptId: '', // 消息提醒的用户部门id
  remindId: '', // 消息提醒的用户id
  startTime: '', // 消息提醒开始时间
  status: '', // 已读1未读0
  offset: 1,
  limit: 20,
})
const total = ref(0) // 数据条数
const loadingTable = ref(false) // 表格loading
const list = ref([]) // 表格数据
// 筛选时间段数据
const dateRange = ref<[DateModelType, DateModelType]>(['', ''])
// 表头
const columns = ref<TableColumn[]>([
  { text: '创建时间', value: 'createTime', align: 'center', width: '180' },
  { text: '主题', value: 'messageTitle', align: 'center' },
  { text: '来源模块', value: 'messageSourceModuleName', align: 'center' },
  // { text: '来源模块', value: 'messageContent', align: 'center' },
  { text: '读取状态', value: 'statusName', align: 'center', width: '100' },
])

// 获取审批提醒列表页
function fetchData(isNowPage = false) {
  loadingTable.value = true
  if (!isNowPage) {
    // 是否显示当前页,否则跳转第一页
    listQuery.value.offset = 1
  }
  const param = {
    ...listQuery.value,
    status: Number(listQuery.value.status),
  }
  getWorkMessageList(param).then((response) => {
    list.value = response.data.rows.map((item: { statusName: string ; status: string }) => {
      return {
        ...item,
        statusName: item.status == '1' ? '已读' : '未读',
      }
    })
    total.value = parseInt(response.data.total)
    loadingTable.value = false
  }).catch(() => {
    loadingTable.value = false
  })
}

// 搜索
const searchList = () => {
  fetchData(false)
}
// 时间变更
watch(dateRange, (val) => {
  if (val) {
    listQuery.value.startTime = `${val[0]}`
    listQuery.value.endTime = `${val[1]}`
  }
  else {
    listQuery.value.startTime = ''
    listQuery.value.endTime = ''
  }
})
// 重置
const reset = () => {
  listQuery.value = {
    endTime: '', // 消息提醒结束时间
    messageSourceModule: '', // 来源模块(字典code)
    messageType: '', // 消息提醒的业务类型(字典code)
    remindDeptId: '', // 消息提醒的用户部门id
    remindId: '', // 消息提醒的用户id
    startTime: '', // 消息提醒开始时间
    status: '', // 已读1未读0
    offset: 1,
    limit: 20,
  }
  dateRange.value = ['', '']
  fetchData(true)
}
// 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写
const changePage = (val: { size?: number; page?: number }) => {
  if (val && val.size) {
    listQuery.value.limit = val.size
  }
  if (val && val.page) {
    listQuery.value.offset = val.page
  }
  fetchData(true)
}

// 获取字典值
const getDict = async () => {
  // 来源模块
  getDictByCode('messageSourceModule').then((response) => {
    messageSourceModuleList.value = response.data
  })
}

// 跳转详情页
const detail = (row: any) => {
  if (row.messageType === '1') { // 计量管理-证书到期提醒
    $router.push({
      name: 'CertificateLogDetail',
      params: {
        type: 'detail',
      },
      query: {
        id: row.businessId, // 证书提醒列表id
        title: '详情',
        name: '证书状况',
      },
    })
  }
  else if (row.messageType === '2') { // 业务看板-设备到期提醒
    $router.push({
      path: `/board/equipmentReminderDetail/detail/${row.id}`,
      query: {
        title: '详情',
        name: '固定资产',
        id: row.businessId, // 测量设备列表id
      },
    })
  }
  else if (row.messageType === '3') { // 业务看板-标准装置到期提醒
    $router.push(`/board/detail/${row.businessId}`)
  }
  else if (row.messageType === '4') { // 业务看板-样品超期提醒
    $router.push(`/board/overdueReminderDetail/${row.businessId}?order=${row.relationBusinessId}`)
  }
}

onMounted(async () => {
  await getDict() // 获取字典
  fetchData(true) // 获取数据
})
</script>

<template>
  <!-- 布局 -->
  <app-container>
    <search-area :need-clear="true" @search="searchList" @clear="reset">
      <search-item>
        <el-select
          v-model.trim="listQuery.messageSourceModule"
          clearable
          placeholder="来源模块"
          size="default"
        >
          <el-option
            v-for="item in messageSourceModuleList"
            :key="item.id"
            :label="item.name"
            :value="item.value"
          />
        </el-select>
      </search-item>
      <search-item>
        <el-select
          v-model.trim="listQuery.status"
          placeholder="读取状态"
        >
          <el-option
            v-for="item in statusList"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          />
        </el-select>
      </search-item>
      <search-item>
        <el-date-picker
          v-model="dateRange"
          class="short-input"
          type="daterange"
          range-separator="到"
          format="YYYY-MM-DD HH:mm:ss"
          value-format="YYYY-MM-DD HH:mm:ss"
          start-placeholder="创建开始时间"
          end-placeholder="创建结束时间"
        />
      </search-item>
    </search-area>
    <table-container>
      <normal-table
        :data="list" :total="total" :columns="columns" :query="listQuery" :list-loading="loadingTable"
        @change="changePage"
      >
        <template #preColumns>
          <el-table-column label="#" width="55" align="center">
            <template #default="scope">
              {{ (listQuery.offset - 1) * listQuery.limit + scope.$index + 1 }}
            </template>
          </el-table-column>
        </template>
        <template #columns>
          <el-table-column label="操作" align="center" fixed="right" width="90">
            <template #default="{ row }">
              <el-button size="small" link type="primary" @click="detail(row)">
                详情
              </el-button>
            </template>
          </el-table-column>
        </template>
      </normal-table>
    </table-container>
  </app-container>
</template>