Newer
Older
xc-business-system / src / views / resource / system / sysDoc / list.vue
<!-- 体系文件列表 -->
<script name="SysDocList" lang="ts" setup>
import { ElLoading, ElMessage, ElMessageBox, dayjs } from 'element-plus'
import type { DateModelType } from 'element-plus'
import type { IFileInfo, IListQuery } from './sysDoc-interface'
import type { TableColumn } from '@/components/NormalTable/table_interface'
import { getDictByCode } from '@/api/system/dict'
import { delFileSystem, exportSysDocList, getFileSystemList } from '@/api/resource/fileSystem'
import type { IDictType } from '@/commonInterface/resource-interface'
import FilePreviewDialog from '@/components/filePreview/filePreviewDialog.vue'
import { exportFile } from '@/utils/exportUtils'
import type { deptType } from '@/global'
import ImagePreviewDialog from '@/components/ImagePreview/imagePreviewDialog.vue'
const { proxy } = getCurrentInstance() as any
const router = useRouter()

const fileTypeDict = ref<Array<IDictType>>([])

// 查询条件
const searchQuery = ref<IListQuery>({
  fileNo: '', // 文件编号
  fileName: '', // 文件名
  fileDistributeNo: '', // 文件发放号
  fileType: '', // 文件类别
  history: '0', // 体系文件
  labCode: '', // 实验室代码
  groupCode: '', // 组别代码、部门
  effectiveDateStart: '', // 实施时间开始
  effectiveDateEnd: '', // 实施时间结束
  promulgateTimeEnd: '', // 颁布时间开始
  promulgateTimeStart: '', // 颁布时间结束
  versionNo: '', // 版本号
  offset: 1,
  limit: 20,
})
const total = ref(0) // 数据条数
const loadingTable = ref(false) // 表格loading

const promulgateDate = ref<[DateModelType, DateModelType]>(['', ''])// 筛选时间段数据
const effectiveDate = ref<[DateModelType, DateModelType]>(['', ''])// 筛选时间段数据
// 表头
const columns = ref<TableColumn[]>([
  { text: '实验室', value: 'labCodeName', align: 'center' },
  { text: '部门', value: 'groupCodeName', align: 'center' },
  { text: '文件类型', value: 'fileTypeName', align: 'center', width: '140' },
  { text: '文件编号', value: 'fileNo', align: 'center', width: '180' },
  { text: '文件名称', value: 'fileName_hide', align: 'center', followLink: true, width: '220' },
  { text: '版本号', value: 'versionNo', align: 'center' },
  { text: '颁布日期', value: 'promulgateTime', align: 'center', width: '120' },
  { text: '实施日期', value: 'effectiveDate', align: 'center', width: '120' },
  { text: '发放号', value: 'fileDistributeNo', align: 'center' },
  { text: '编制人', value: 'createUserName', align: 'center' },
])
const sysFileList = ref<Array<IFileInfo>>([]) // 表格数据
const checkoutList = ref<string[]>([]) // 选中的内容
// -----------------------------------------字典--------------------------------------------------------------
const useDeptList = ref<deptType[]>([]) // 部门
const labDeptList = ref<deptType[]>([]) // 实验室
// 查询字典
const getDictFun = () => {
  // 实验室
  getDictByCode('bizLabCode').then((response) => {
    labDeptList.value = response.data
  })

  // 部门
  getDictByCode('bizGroupCode').then((response) => {
    useDeptList.value = response.data
  })
}
// ----------------------------------------列表数据----------------------------------------------------

// 详情
const detail = (row: IFileInfo) => {
  sessionStorage.setItem('sysFileInfo', JSON.stringify(row))
  router.push({
    query: {
      title: '体系文件',
      type: 'detail',
    },
    path: 'sysDoc/detail',
  })
}

// 数据查询
function fetchData(isNowPage = false) {
  loadingTable.value = true
  if (!isNowPage) {
    // 是否显示当前页,否则跳转第一页
    searchQuery.value.offset = 1
  }
  getFileSystemList(searchQuery.value).then((response) => {
    if (response.code === 200) {
      sysFileList.value = response.data.rows.map((item: { fileName: string; effectiveDate: string; promulgateTime: string }) => {
        return {
          ...item,
          effectiveDate: dayjs(item.effectiveDate).format('YYYY-MM-DD') !== 'Invalid Date' ? dayjs(item.effectiveDate).format('YYYY-MM-DD') : '',
          promulgateTime: dayjs(item.promulgateTime).format('YYYY-MM-DD') !== 'Invalid Date' ? dayjs(item.promulgateTime).format('YYYY-MM-DD') : '',
          followLinkArr: [item.fileName],
        }
      })
      total.value = parseInt(response.data.total)
    }
    loadingTable.value = false
  }).catch(() => {
    loadingTable.value = false
  })
}

const searchList = () => {
  fetchData(true)
}

// 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写
const changePage = (val: { size?: number; page?: number }) => {
  if (val && val.size) {
    searchQuery.value.limit = val.size
  }
  if (val && val.page) {
    searchQuery.value.offset = val.page
  }
  fetchData(true)
}

// 重置
const reset = () => {
  searchQuery.value = {
    fileNo: '', // 文件编号
    fileName: '', // 文件名
    fileDistributeNo: '', // 文件发放号
    fileType: '', // 文件类别
    history: '0', // 体系文件
    labCode: '', // 实验室代码
    groupCode: '', // 组别代码、部门
    effectiveDateStart: '', // 实施时间开始
    effectiveDateEnd: '', // 实施时间结束
    promulgateTimeEnd: '', // 颁布时间开始
    promulgateTimeStart: '', // 颁布时间结束
    versionNo: '', // 版本号
    offset: 1,
    limit: 20,
  }
  promulgateDate.value = ['', '']
  effectiveDate.value = ['', '']
  fetchData(true)
}

// 多选发生改变时
function handleSelectionChange(e: any) {
  checkoutList.value = e.map((item: { id: string }) => item.id)
}

// 导出
const exportAll = () => {
  const loading = ElLoading.service({
    lock: true,
    text: '下载中请稍后',
    background: 'rgba(255, 255, 255, 0.8)',
  })
  if (sysFileList.value.length > 0) {
    const params = {
      fileNo: searchQuery.value.fileNo, // 文件编号
      fileName: searchQuery.value.fileName, // 文件名
      fileDistributeNo: searchQuery.value.fileDistributeNo, // 文件发放号
      fileType: searchQuery.value.fileType, // 文件类别
      history: '0', // 体系文件
      labCode: searchQuery.value.labCode, // 实验室代码
      groupCode: searchQuery.value.groupCode, // 组别代码、部门
      effectiveDateStart: searchQuery.value.effectiveDateStart, // 实施时间开始
      effectiveDateEnd: searchQuery.value.effectiveDateEnd, // 实施时间结束
      promulgateTimeEnd: searchQuery.value.promulgateTimeEnd, // 颁布时间开始
      promulgateTimeStart: searchQuery.value.promulgateTimeStart, // 颁布时间结束
      versionNo: searchQuery.value.versionNo, // 版本号
      offset: 1,
      limit: 20,
      ids: checkoutList.value,
    }
    exportSysDocList(params).then((res) => {
      const blob = new Blob([res.data])
      loading.close()
      exportFile(blob, '体系文件列表.xlsx')
    })
  }
  else {
    loading.close()
    ElMessage.warning('无数据可导出数据')
  }
}

// 获取文件类别字典值
const getFileTypeDict = () => {
  getDictByCode('bizFileType').then((res) => {
    if (res.code === 200) {
      fileTypeDict.value = res.data
      sessionStorage.setItem('bizFileType', JSON.stringify(fileTypeDict.value))
    }
  })
}
const getGroupCodeDict = () => {
  getDictByCode('bizLabCode').then((res) => {
    if (res.code === 200) {
      sessionStorage.setItem('bizLabCode', JSON.stringify(res.data))
    }
  })
}
const getLabCodeDict = () => {
  getDictByCode('bizGroupCode').then((res) => {
    if (res.code === 200) {
      sessionStorage.setItem('bizGroupCode', JSON.stringify(res.data))
    }
  })
}
const getDict = async () => {
  getFileTypeDict()
  getLabCodeDict()
  getGroupCodeDict()
  getDictFun() // 获取实验室、部门
}
const refFilePreviewDlg = ref()
const refImagePreviewDlg = ref()
// 点击文件名称
const handleClickFollowLink = (row: any) => {
  if (row.pdfUrl === '') {
    ElMessage.warning('无可预览项目')
  }
  else if (row.pdfUrl && row.pdfUrl.lastIndexOf('.pdf') > 0) {
    refFilePreviewDlg.value.initDialog(row.pdfUrl)
  }
  else {
    refImagePreviewDlg.value.initDialog(row.pdfUrl)
  }
}

watch(promulgateDate, (val) => { // 监听颁布日期
  if (val) {
    searchQuery.value.promulgateTimeStart = `${val[0]}`
    searchQuery.value.promulgateTimeEnd = `${val[1]}`
  }
  else {
    searchQuery.value.promulgateTimeStart = ''
    searchQuery.value.promulgateTimeEnd = ''
  }
})

watch(effectiveDate, (val) => { // 监听实施时间
  if (val) {
    searchQuery.value.effectiveDateStart = `${val[0]}`
    searchQuery.value.effectiveDateEnd = `${val[1]}`
  }
  else {
    searchQuery.value.effectiveDateStart = ''
    searchQuery.value.effectiveDateEnd = ''
  }
})
onMounted(async () => {
  await getDict()
  searchList()
})
</script>

<template>
  <app-container>
    <!-- 筛选条件 -->
    <search-area :need-clear="true" @search="searchList" @clear="reset">
      <search-item>
        <el-select
          v-model="searchQuery.labCode"
          placeholder="实验室"
          class="short-input"
          filterable
          clearable
        >
          <el-option v-for="item in labDeptList" :key="item.id" :label="item.name" :value="item.value" />
        </el-select>
      </search-item>
      <search-item>
        <el-select
          v-model="searchQuery.groupCode"
          placeholder="部门"
          class="short-input"
          filterable
          clearable
        >
          <el-option v-for="item in useDeptList" :key="item.id" :label="item.name" :value="item.value" />
        </el-select>
      </search-item>
      <search-item>
        <el-select v-model="searchQuery.fileType" class="short-input" placeholder="文件类型" clearable>
          <el-option v-for="item in fileTypeDict" :key="item.id" :value="item.value" :label="item.name" />
        </el-select>
      </search-item>
      <search-item>
        <el-input v-model="searchQuery.fileNo" class="short-input" placeholder="文件编号" clearable />
      </search-item>
      <search-item>
        <el-input v-model="searchQuery.fileName" class="short-input" placeholder="文件名称" clearable />
      </search-item>
      <search-item>
        <el-input v-model="searchQuery.versionNo" class="short-input" placeholder="版本号" clearable />
      </search-item>
      <search-item>
        <el-date-picker
          v-model="promulgateDate"
          class="short-input"
          type="daterange"
          range-separator="至"
          format="YYYY-MM-DD"
          value-format="YYYY-MM-DD"
          start-placeholder="颁布日期(开始)"
          end-placeholder="颁布日期(结束)"
        />
      </search-item>
      <search-item>
        <el-date-picker
          v-model="effectiveDate"
          class="short-input"
          type="daterange"
          range-separator="至"
          format="YYYY-MM-DD"
          value-format="YYYY-MM-DD"
          start-placeholder="实施日期(开始)"
          end-placeholder="实施日期(结束)"
        />
      </search-item>
      <search-item>
        <el-input v-model="searchQuery.fileDistributeNo" class="short-input" placeholder="发放号" clearable />
      </search-item>
    </search-area>

    <!-- 表格数据展示 -->
    <table-container>
      <!-- 表头区域 -->
      <template #btns-right>
        <icon-button icon="icon-export" title="导出" @click="exportAll" />
      </template>

      <!-- 表格区域 -->
      <normal-table
        :data="sysFileList" :total="total" :columns="columns"
        :query="{ limit: searchQuery.limit, offset: searchQuery.offset }"
        :list-loading="loadingTable"
        is-showmulti-select
        @change="changePage"
        @multi-select="handleSelectionChange"
        @handleClickFollowLink="handleClickFollowLink"
      >
        <template #preColumns>
          <el-table-column label="序号" width="55" align="center">
            <template #default="scope">
              {{ (searchQuery.offset - 1) * searchQuery.limit + scope.$index + 1 }}
            </template>
          </el-table-column>
        </template>
        <template #columns>
          <el-table-column fixed="right" label="操作" align="center" width="130">
            <template #default="{ row }">
              <el-button size="small" type="primary" link @click="detail(row)">
                查看
              </el-button>
            </template>
          </el-table-column>
        </template>
      </normal-table>
    </table-container>
    <file-preview-dialog ref="refFilePreviewDlg" />
    <image-preview-dialog ref="refImagePreviewDlg" />
  </app-container>
</template>