Newer
Older
jh-business-system / src / views / equipement / standard / list.vue
<!-- 标准装置台账信息列表 -->
<script name="StandardBookInfoList" lang="ts" setup>
import type { Ref } from 'vue'
import { getCurrentInstance, onMounted, ref } from 'vue'
import { ElLoading, ElMessage, ElMessageBox } from 'element-plus'
import dayjs from 'dayjs'
import type { DateModelType } from 'element-plus'
import type { IList, IListQuery } from './book-interface'
import showPhoto from '@/components/showPhoto/index.vue'
import type { TableColumn } from '@/components/NormalTable/table_interface'
import { SCHEDULE } from '@/utils/scheduleDict'
import { getDictByCode } from '@/api/system/dict'
import type { IMenu } from '@/components/buttonBox/buttonBox'
import useUserStore from '@/store/modules/user'
import { approvalDelete, batchImport, cancelApproval, deleteList, getStandardList, getStream, refuseApproval } from '@/api/equipment/standard/book'
import { exportFile } from '@/utils/exportUtils'
import useBridgeCount from '@/components/buttonBox/useBridgeCount'
import useTemplateDownload from '@/utils/useTemplateDownload'
import type { deptType } from '@/global'
const $router = useRouter()
const { proxy } = getCurrentInstance() as any
const active = ref('')
const operateWidth = ref('180') // 操作栏的宽度
const user = useUserStore() // 用户信息
const dateRangeNext = ref<[DateModelType, DateModelType]>(['', ''])// 下次复查日期
const dateRangeLast = ref<[DateModelType, DateModelType]>(['', ''])// 最近复查日期
const dateRangeLastChange = ref<[DateModelType, DateModelType]>(['', ''])// 下次变更日期

// 查询条件
const listQuery: Ref<IListQuery> = ref({
  deptId: '', //	部门id
  deptName: '', //		部门名称
  inUseStatus: '', //		在用状态
  lastChangeDateEnd: '', //		最近变更日期结束
  lastChangeDateStart: '', //		最近变更日期开始
  lastReviewDateEnd: '', //		最近复查日期结束
  lastReviewDateStart: '', //		最近复查日期开始
  majorType: '', //		专业类别
  nextReviewDateEnd: '', //		下次复查日期结束
  nextReviewDateStart: '', //		下次复查日期开始
  pdf: true, //		是否为pdf
  standardCertNo: '', //		计量标准证书号
  standardName: '', //		计量标准装置名称
  storageLocation: '', //		存放地点(字典code)
  offset: 1,
  limit: 20,
})
const total = ref(0) // 数据条数
const loadingTable = ref(false) // 表格loading
// 表头
const columns = ref<TableColumn[]>([
  { text: '计量标准证书号', value: 'standardCertNo', align: 'center' },
  { text: '计量标准装置名称', value: 'standardName', align: 'center' },
  { text: '实验室', value: 'deptName', align: 'center', width: '120' },
  { text: '专业类别', value: 'majorTypeName', align: 'center', width: '120' },
  { text: '最近复查日期', value: 'lastReviewDate', align: 'center', width: '120' },
  { text: '标准证书', value: 'standardCertFile', align: 'center' },
])
const list = ref<IList[]>([]) // 表格数据
const checkoutList = ref<string[]>([])// 选中的内容

// -----------------------------------------字典--------------------------------------------------------------
const bizStandardManagerStateList = ref({}) as any // 在用状态
const labDeptList = ref<deptType[]>([]) // 实验室
const useDeptList = ref<deptType[]>([]) // 部门列表
const majorTypeList = ref<deptType[]>([]) // 部门列表

// 查询字典
const getDict = async () => {
  loadingTable.value = true
  // 在用状态
  getDictByCode('bizStandardManagerState').then((response) => {
    bizStandardManagerStateList.value = response.data
  })
  // 实验室
  getDictByCode('bizGroupCodeEquipment').then((response) => {
    labDeptList.value = response.data
  })

  // 部门
  getDictByCode('bizGroupCode').then((response) => {
    useDeptList.value = response.data
  })

  // 专业类别
  getDictByCode('bizMajorType').then((response) => {
    majorTypeList.value = response.data
  })
}
// -------------------------------------------列表数据操作------------------------------------------------------------
// 数据查询
function fetchData(isNowPage = false) {
  loadingTable.value = true
  if (!isNowPage) {
    // 是否显示当前页,否则跳转第一页
    listQuery.value.offset = 1
  }
  // 检定部门(全部)只能查看本部门的标准装置
  // getStandardList({ ...listQuery.value, deptId: active.value === '0' && user.deptType === '3' ? user.deptId : '' }).then((response) => {
  getStandardList({ ...listQuery.value }).then((response) => {
    list.value = response.data.rows.map((item: { lastReviewDate: string; agreementAmount: number; nextReviewDate: string; lastChangeDate: string }) => {
      return {
        ...item,
        lastReviewDate: item.lastReviewDate ? dayjs(item.lastReviewDate).format('YYYY-MM-DD') : item.lastReviewDate, // 最近复查日期
        nextReviewDate: item.nextReviewDate ? dayjs(item.nextReviewDate).format('YYYY-MM-DD') : item.nextReviewDate, // 最近复查日期
        lastChangeDate: item.lastChangeDate || '/', // 最近变更日期
      }
    })
    total.value = parseInt(response.data.total)
    loadingTable.value = false
  }).catch(() => {
    loadingTable.value = false
  })
}
// 搜索
const searchList = () => {
  fetchData(true)
}

// 重置
const clearList = () => {
  listQuery.value = {
    deptId: '', //	部门id
    deptName: '', //		部门名称
    inUseStatus: '', //		在用状态
    lastChangeDateEnd: '', //		最近变更日期结束
    lastChangeDateStart: '', //		最近变更日期开始
    lastReviewDateEnd: '', //		最近复查日期结束
    lastReviewDateStart: '', //		最近复查日期开始
    majorType: '', //		专业类别
    nextReviewDateEnd: '', //		下次复查日期结束
    nextReviewDateStart: '', //		下次复查日期开始
    pdf: true, //		是否为pdf
    standardCertNo: '', //		计量标准证书号
    standardName: '', //		计量标准装置名称
    storageLocation: '', //		存放地点(字典code)
    offset: 1,
    limit: 20,
  }
  dateRangeNext.value = ['', '']// 下次复查日期
  dateRangeLast.value = ['', '']// 最近复查日期
  dateRangeLastChange.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 add = () => {
  $router.push({ path: 'standardList/add' })
}

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 handleEdit = (row: IList, type: string) => {
  if (type === 'edit' || type === 'detail') { // 编辑、详情
    $router.push({
      path: `standardList/${type}/${row.id}`,
      query: {
        standardName: row.standardName,
      },
    })
  }
  else {
    ElMessageBox.confirm(
      `确认${type}吗?`,
      '提示',
      {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning',
      },
    ).then(() => {
      if (type === '删除') {
        deleteList({ id: row.id }).then(() => {
          ElMessage.success(`已${type}`)
          fetchData()
        })
      }
    })
  }
}
// ----------------------------------------------钩子------------------------------------------------------
watch(dateRangeNext, (val) => { // 下次复查日期
  if (val) {
    listQuery.value.nextReviewDateStart = `${val[0]}`
    listQuery.value.nextReviewDateEnd = `${val[1]}`
  }
  else {
    listQuery.value.nextReviewDateStart = ''
    listQuery.value.nextReviewDateEnd = ''
  }
})
watch(dateRangeLast, (val) => { // 最近复查日期
  if (val) {
    listQuery.value.lastReviewDateStart = `${val[0]}`
    listQuery.value.lastReviewDateEnd = `${val[1]}`
  }
  else {
    listQuery.value.lastReviewDateStart = ''
    listQuery.value.lastReviewDateEnd = ''
  }
})

watch(dateRangeLastChange, (val) => { // 最近变更日期
  if (val) {
    listQuery.value.lastChangeDateStart = `${val[0]}`
    listQuery.value.lastChangeDateEnd = `${val[1]}`
  }
  else {
    listQuery.value.lastChangeDateStart = ''
    listQuery.value.lastChangeDateEnd = ''
  }
})

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

<template>
  <app-container>
    <search-area :need-clear="true" @search="searchList" @clear="clearList">
      <search-item>
        <el-input v-model.trim="listQuery.standardCertNo" placeholder="计量标准证书号" class="short-input" clearable />
      </search-item>
      <search-item>
        <el-input v-model.trim="listQuery.standardName" placeholder="计量标准装置名称" class="short-input" clearable />
      </search-item>
      <search-item>
        <dept-select
          ref="deptSelect"
          v-model="listQuery.deptId"
          placeholder="实验室"
          :dept-show="true"
        />
      </search-item>
      <search-item>
        <el-select
          v-model="listQuery.majorType"
          placeholder="专业类别"
          class="short-input"
          filterable
          clearable
        >
          <el-option v-for="item in majorTypeList" :key="item.id" :label="item.name" :value="item.value" />
        </el-select>
      </search-item>
      <search-item>
        <el-date-picker
          v-model="dateRangeLast"
          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"
        >
          <template #default="scope">
            <show-photo v-if="item.value === 'standardCertFile' && scope.row[item.value] !== '/'" :minio-file-name="scope.row[item.value]" style="margin-right: 10px;" />
          </template>
        </el-table-column>
        <el-table-column
          fixed="right"
          label="操作"
          width="120"
          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>
</template>

<style lang="ts" scoped>

</style>