Newer
Older
jh-business-system / src / views / equipement / equipment / list.vue
<!-- 设备台账管理列表页 -->
<script name="EquipmentInfoBookList" setup lang="ts">
import type { Ref } from 'vue'
import { onMounted, ref, watch } from 'vue'
import type { DateModelType } from 'element-plus'
import { ElLoading, ElMessage, ElMessageBox } from 'element-plus'
import dayjs from 'dayjs'
import type { IList, IListQuery } from './book-interface'
import { batchImport, deleteEquipment, getEquipmentList } from '@/api/equipment/info/book'
import type { deptType } from '@/global'
import type { TableColumn } from '@/components/NormalTable/table_interface'
import { getDictByCode } from '@/api/system/dict'
import useTemplateDownload from '@/utils/useTemplateDownload'
import useUserStore from '@/store/modules/user'
import { getAllUserList } from '@/api/system/user'

const user = useUserStore()
const $router = useRouter()
const approvalDialog = ref() // 审批对话ref
const delRef = ref() // 删除弹窗组件ref
// 查询条件
const listQuery: Ref<IListQuery> = ref({
  deptId: '', //	部门id
  deptName: '', //		实验室/部门名称
  directorId: '', //		负责人id
  equipmentName: '', //		设备名称
  manufactureNo: '', //		出厂编号
  manufacturer: '', //		生产厂家
  measureValidDateEnd: '', //		检定有效期结束
  measureValidDateStart: '', //		检定有效期开始
  meterStandardName: '', //		所属标准装置名称
  model: '', //		型号规格
  pdf: true, //		是否为pdf(导出使用)
  traceCompany: '', //		溯源单位
  usageStatus: '', //		使用状态(字典code)
  offset: 1,
  limit: 20,
})
const total = ref(0) // 数据条数
const loadingTable = ref(false) // 表格loading
// 表头
const columns = ref<TableColumn[]>([
  { text: '设备名称', value: 'equipmentName', align: 'center' },
  { text: '型号规格', value: 'model', align: 'center' },
  { text: '出厂编号', value: 'manufactureNo', align: 'center' },
  { text: '生产厂家', value: 'manufacturer', align: 'center' },
  { text: '实验室', value: 'deptName', align: 'center' },
  { text: '负责人', value: 'directorName', align: 'center', width: '120' },
  { text: '使用状态', value: 'usageStatusName', align: 'center', width: '90' },
  { text: '溯源单位', value: 'traceCompany', align: 'center' },
  { text: '检定有效期', value: 'measureValidDate', align: 'center', width: '120' },
])
const list = ref<IList[]>([]) // 表格数据
const dateRange = ref<[DateModelType, DateModelType]>(['', ''])// 筛选时间段数据
const checkoutList = ref<string[]>([])// 选中的内容

// -----------------------------------------字典--------------------------------------------------------------
const useDeptList = ref<deptType[]>([]) // 所属部门列表
const labDeptList = ref<deptType[]>([]) // 实验室
const usageStatusList = ref<deptType[]>([]) // 使用状态
const userList = ref<{ [key: string]: string }[]>([]) // 用户列表
// 查询字典
const getDict = async () => {
  // 获取用户列表
  getAllUserList({
    keywords: '',
    beginTime: '',
    endTime: '',
    deptId: '',
    offset: 1,
    limit: 999999,
    sort: 'id',
    deptType: '',
  }).then((res) => {
    userList.value = res.data.rows
  })
  // 实验室
  getDictByCode('bizGroupCodeEquipment').then((response) => {
    labDeptList.value = response.data
  })

  // 部门
  getDictByCode('bizGroupCode').then((response) => {
    useDeptList.value = response.data
  })
  // 使用状态
  getDictByCode('bizUsageStatus').then((response) => {
    usageStatusList.value = response.data
  })
}
// -------------------------------------------------------------------------------------------------------
// 数据查询
function fetchData(isNowPage = false) {
  loadingTable.value = true
  if (!isNowPage) {
    // 是否显示当前页,否则跳转第一页
    listQuery.value.offset = 1
  }
  getEquipmentList({ ...listQuery.value }).then((response) => {
    list.value = response.data.rows.map((item: { estimateSignDate: string; agreementAmount: number; measureValidDate: string }) => {
      return {
        ...item,
        measureValidDate: item.measureValidDate ? dayjs(item.measureValidDate).format('YYYY-MM-DD') : item.measureValidDate,
      }
    })
    total.value = parseInt(response.data.total)
    loadingTable.value = false
  }).catch(() => {
    loadingTable.value = false
  })
}
// 搜索
const searchList = () => {
  fetchData(true)
}

// 重置
const clearList = () => {
  listQuery.value = {
    deptId: '', //	部门id
    deptName: '', //		实验室/部门名称
    directorId: '', //		负责人id
    equipmentName: '', //		设备名称
    manufactureNo: '', //		出厂编号
    manufacturer: '', //		生产厂家
    measureValidDateEnd: '', //		检定有效期结束
    measureValidDateStart: '', //		检定有效期开始
    meterStandardName: '', //		所属标准装置名称
    model: '', //		型号规格
    pdf: true, //		是否为pdf(导出使用)
    traceCompany: '', //		溯源单位
    usageStatus: '', //		使用状态(字典code)
    offset: 1,
    limit: 20,
  }
  dateRange.value = ['', '']
  fetchData(true)
}

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

// 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写
// 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)
// }

// 改变页容量
function handleSizeChange(val: number) {
  listQuery.value.limit = val
  fetchData()
}
// 改变当前页
function handleCurrentChange(val: number) {
  listQuery.value.offset = val
  fetchData(true)
}
// -------------------------------------表格上方工具栏-----------------------------------
const fileRef = ref() // 文件上传input
const onFileChange = (event: any) => {
  // 原生上传
  if (event.target.files?.length !== 0) {
    // 创建formdata对象
    const fd = new FormData()
    fd.append('file', event.target.files[0])
    const loading = ElLoading.service({
      lock: true,
      background: 'rgba(255, 255, 255, 0.8)',
    })
    // 调批量导入接口
    batchImport(fd).then((res) => {
      ElMessage.success('上传成功')
      event.target.value = null
      loading.close()
      fetchData(true)
      loading.close()
    }).catch(() => {
      event.target.value = null
      loading.close()
    })
  }
}
// 批量导入
const handleBatchImport = () => {
  fileRef.value.click()
}

// 新建
const add = () => {
  $router.push({ path: 'equipmentList/add' })
}
// ----------------------------------------------操作---------------------------------------------------
const handleEdit = (row: IList, type: string) => {
  if (type === 'edit' || type === 'detail') { // 编辑、详情
    $router.push({
      path: `equipmentList/${type}/${row.id}`,
      query: {
        equipmentNo: row.equipmentNo, // 设备编号
        processId: row.processId, // 流程实例id
        taskId: row.taskId, // 任务id
        colorMark: row.colorMark,
        decisionItem: row.decisionItem,
      },
    })
  }
  else {
    ElMessageBox.confirm(
      `确认${type}吗?`,
      '提示',
      {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning',
      },
    ).then(() => {
      deleteEquipment({ id: row.id }).then(() => {
        ElMessage.success(`已${type}`)
        fetchData()
      })
    })
  }
}
// ----------------------------------------------钩子------------------------------------------------------
watch(dateRange, (val) => {
  if (val) {
    listQuery.value.measureValidDateStart = `${val[0]}`
    listQuery.value.measureValidDateEnd = `${val[1]}`
  }
  else {
    listQuery.value.measureValidDateStart = ''
    listQuery.value.measureValidDateEnd = ''
  }
})

onMounted(async () => {
  getDict()
  fetchData()
})
</script>

<template>
  <div class="equipment-info-book">
    <app-container>
      <search-area :need-clear="true" @search="searchList" @clear="clearList">
        <search-item>
          <el-input v-model.trim="listQuery.equipmentName" placeholder="设备名称" class="short-input" clearable />
        </search-item>
        <search-item>
          <el-input v-model.trim="listQuery.model" placeholder="型号规格" class="short-input" clearable />
        </search-item>
        <search-item>
          <el-input v-model.trim="listQuery.manufactureNo" placeholder="出厂编号" class="short-input" clearable />
        </search-item>
        <search-item>
          <el-input v-model.trim="listQuery.manufacturer" placeholder="生产厂家" class="short-input" clearable />
        </search-item>
        <!-- <search-item>
          <el-select
            v-model="listQuery.usageStatus"
            placeholder="使用状态"
            class="short-input"
            filterable
            clearable
          >
            <el-option v-for="item in usageStatusList" :key="item.id" :label="item.name" :value="item.value" />
          </el-select>
        </search-item> -->

        <search-item>
          <!-- <el-select
            v-model="listQuery.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> -->
          <dept-select
            ref="deptSelect"
            v-model="listQuery.deptId"
            placeholder="实验室"
            :dept-show="true"
          />
        </search-item>
        <search-item>
          <el-select
            v-model="listQuery.directorId"
            placeholder="负责人"
            class="short-input"
            filterable
            clearable
          >
            <el-option v-for="item in userList" :key="item.id" :label="item.name" :value="item.id" />
          </el-select>
        </search-item>
        <search-item>
          <el-input v-model.trim="listQuery.traceCompany" placeholder="溯源单位" class="short-input" clearable />
        </search-item>
        <search-item>
          <el-date-picker
            v-model="dateRange"
            class="short-input"
            type="daterange"
            range-separator="至"
            format="YYYY-MM-DD"
            value-format="YYYY-MM-DD"
            start-placeholder="检定有效期(开始)"
            end-placeholder="检定有效期(结束)"
          />
        </search-item>
      </search-area>

      <table-container>
        <template #btns-right>
          <icon-button icon="icon-add" title="新建" type="primary" @click="add" />
          <icon-button icon="icon-import" title="批量导入" type="primary" @click="handleBatchImport" />
          <icon-button icon="icon-template" title="模板下载" type="primary" @click="useTemplateDownload('设备台账管理')" />
        </template>
        <input v-show="false" id="fileInput" ref="fileRef" type="file" accept="*" @change="onFileChange">
        <el-table
          v-loading="loadingTable"
          :data="list"
          border
          style="width: 100%;"
          :row-key="(row: any) => { return row.id || row.index }"
          @selection-change="handleSelectionChange"
        >
          <el-table-column :reserve-selection="true" type="selection" width="38" fixed="left" />
          <el-table-column label="序号" width="55" align="center">
            <template #default="scope">
              {{ (listQuery.offset - 1) * listQuery.limit + scope.$index + 1 }}
            </template>
          </el-table-column>
          <el-table-column
            v-for="item in columns"
            :key="item.value"
            :prop="item.value"
            :label="item.text"
            :width="item.width"
            :show-overflow-tooltip="true"
            align="center"
          />
          <el-table-column
            fixed="right"
            label="操作"
            width="150"
            align="center"
          >
            <template #default="{ row }">
              <el-button
                size="small"
                type="primary"
                link
                @click="handleEdit(row, 'detail')"
              >
                查看
              </el-button>
              <el-button
                size="small"
                link
                type="primary"
                @click="handleEdit(row, 'edit')"
              >
                编辑
              </el-button>
              <el-button
                size="small"
                link
                type="danger"
                @click="handleEdit(row, '删除')"
              >
                删除
              </el-button>
            </template>
          </el-table-column>
        </el-table>
        <!-- 页码 -->
        <el-pagination
          style="width: 100%;margin-top: 10px;"
          :current-page="listQuery.offset"
          :page-sizes="[5, 10, 20, 30, 50, 100, 150, 200]"
          :page-size="listQuery.limit"
          :total="total"
          layout="total, sizes, prev, pager, next"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </table-container>
    </app-container>
  </div>
</template>