Newer
Older
xc-business-system / src / views / equipement / standard / checkData / list.vue
lyg on 17 Apr 2024 9 KB 标准装置bug修改
<!-- 核查数据管理列表 -->
<script lang="ts" setup name="checkDataList">
import type { Ref } from 'vue'
import { ElLoading, ElMessage, ElMessageBox } from 'element-plus'
import type { DateModelType } from 'element-plus'
import type { IList, IListQuery } from './checkData-interface'
import type { TableColumn } from '@/components/NormalTable/table_interface'
import { getDictByCode } from '@/api/system/dict'
import type { dictType } from '@/global'
import { exportFile } from '@/utils/exportUtils'
import { exportCheckDataList, getCheckDataList } from '@/api/equipment/standard/checkData'
import { keepSearchParams } from '@/utils/keepQuery'

onBeforeRouteLeave((to: any) => {
  keepSearchParams(to.path, 'checkDataList')
})
const $router = useRouter()
const loadingTable = ref(false)
const operateWidth = ref('150') // 操作栏的宽度
// 查询条件
const listQuery: Ref<IListQuery> = ref({
  checkDateEnd: '', // 核查日期结束
  checkDateStart: '', // 核查日期开始
  checkEquipmentModel: '', // 核查标准设备型号
  checkEquipmentName: '', // 核查标准设备名称
  createUserName: '', // 核查员
  dataNo: '', // 数据编号
  equipmentModel: '', // 被核查设备规格型号
  equipmentName: '', // 被核查设备名称
  standardEquipmentName: '', // 被核查标准装置名称
  limit: 20,
  offset: 1,
})

const timeRange = ref<[DateModelType, DateModelType]>(['', '']) // 查询条件
// 表头
const columns = ref<TableColumn[]>([
  { text: '核查数据编号', value: 'dataNo', align: 'center', width: '160' },
  { text: '核查日期', value: 'checkDate', align: 'center', width: '120' },
  { text: '被核查标准装置名称', value: 'standardEquipmentName', align: 'center' },
  { text: '被核查设备名称', value: 'equipmentName', align: 'center' },
  { text: '被核查设备规格型号', value: 'equipmentModel', align: 'center' },
  { text: '核查标准设备名称', value: 'checkEquipmentName', align: 'center' },
  { text: '核查标准设备型号', value: 'checkEquipmentModel', align: 'center' },
  { text: '核查员', value: 'createUserName', align: 'center' },
])
const list = ref<IList[]>([]) // 列表
const total = ref(0) // 数据总条数
const checkoutList = ref<string[]>([]) // 选中的内容
// ------------------------------------------字典----------------------------------------------
const equipmentTypeList = ref<dictType[]>([])// 标准装置分类
const standardList = ref<dictType[]>([])// 检校标准装置

function getDict() {
  // 标准装置分类
  getDictByCode('eqptDeviceType').then((response) => {
    equipmentTypeList.value = response.data
  })
  // 检校标准装置
  getDictByCode('bizStandardEquipmentType').then((response) => {
    standardList.value = response.data
  })
}
// ---------------------------------------------------------------------------------------------

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

// 数据查询
function fetchData(isNowPage = false) {
  loadingTable.value = true
  if (!isNowPage) {
    // 是否显示当前页,否则跳转第一页
    listQuery.value.offset = 1
  }
  getCheckDataList(listQuery.value).then((response) => {
    list.value = response.data.rows
    total.value = parseInt(response.data.total)
    loadingTable.value = false
  })
}

// 清除条件
const clearList = () => {
  listQuery.value = {
    checkDateEnd: '', // 核查日期结束
    checkDateStart: '', // 核查日期开始
    checkEquipmentModel: '', // 核查标准设备型号
    checkEquipmentName: '', // 核查标准设备名称
    createUserName: '', // 核查员
    dataNo: '', // 数据编号
    equipmentModel: '', // 被核查设备规格型号
    equipmentName: '', // 被核查设备名称
    standardEquipmentName: '', // 被核查标准装置名称
    limit: 20,
    offset: 1,
  }
  timeRange.value = ['', '']
  fetchData()
}

// 搜索
const searchList = () => {
  fetchData(true)
}

// 新建
const add = () => {
  $router.push({
    path: 'checkData/add',
  })
}

// 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写
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 handleEdit = (row: any, type: 'detail' | 'edit') => {
  $router.push({
    path: `checkData/${type}/${row.id}`,
    query: {
      ...row,
      belongStandardEquipment: row.belongStandardEquipment,
      equipmentId: row.equipmentId,
    },
  })
}

// 导出
const exportAll = () => {
  const loading = ElLoading.service({
    lock: true,
    text: '下载中请稍后',
    background: 'rgba(255, 255, 255, 0.6)',
  })
  if (list.value.length > 0) {
    const params = {
      checkDateEnd: listQuery.value.checkDateEnd, // 核查日期结束
      checkDateStart: listQuery.value.checkDateStart, // 核查日期开始
      checkEquipmentModel: listQuery.value.checkEquipmentModel, // 核查标准设备型号
      checkEquipmentName: listQuery.value.checkEquipmentName, // 核查标准设备名称
      createUserName: listQuery.value.createUserName, // 核查员
      dataNo: listQuery.value.dataNo, // 数据编号
      equipmentModel: listQuery.value.equipmentModel, // 被核查设备规格型号
      equipmentName: listQuery.value.equipmentName, // 被核查设备名称
      standardEquipmentName: listQuery.value.standardEquipmentName, // 被核查标准装置名称
      offset: 1,
      limit: 20,
      ids: checkoutList.value,
    }
    exportCheckDataList(params).then((res) => {
      const blob = new Blob([res.data])
      loading.close()
      exportFile(blob, '核查数据管理.xlsx')
    })
  }
  else {
    loading.close()
    ElMessage.warning('无数据可导出数据')
  }
}

// ---------------------------------------钩子----------------------------------------------
watch(timeRange, (val) => {
  if (val) {
    listQuery.value.checkDateStart = `${val[0]}`
    listQuery.value.checkDateEnd = `${val[1]}`
  }
  else {
    listQuery.value.checkDateStart = ''
    listQuery.value.checkDateEnd = ''
  }
})
onMounted(async () => {
  await getDict()
  fetchData(false)
})
</script>

<template>
  <div>
    <!-- 布局 -->
    <app-container>
      <search-area :need-clear="true" @search="searchList" @clear="clearList">
        <search-item>
          <el-input v-model.trim="listQuery.dataNo" placeholder="核查数据编号" class="short-input" clearable />
        </search-item>
        <search-item>
          <el-date-picker
            v-model="timeRange"
            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.trim="listQuery.standardEquipmentName" placeholder="被核查标准装置名称" class="short-input" clearable />
        </search-item>
        <search-item>
          <el-input v-model.trim="listQuery.equipmentName" placeholder="被核查设备名称" class="short-input" clearable />
        </search-item>
        <search-item>
          <el-input v-model.trim="listQuery.equipmentModel" placeholder="被核查设备规格型号" class="short-input" clearable />
        </search-item>
        <!-- <search-item>
          <el-input v-model.trim="listQuery.checkEquipmentName" placeholder="核查标准设备名称" class="short-input" clearable />
        </search-item>
        <search-item>
          <el-input v-model.trim="listQuery.checkEquipmentModel" placeholder="核查标准设备型号" class="short-input" clearable />
        </search-item> -->
        <search-item>
          <el-input v-model.trim="listQuery.createUserName" placeholder="核查员" class="short-input" clearable />
        </search-item>
      </search-area>
      <table-container>
        <template #btns-right>
          <icon-button icon="icon-add" title="新建" type="primary" @click="add" />
          <icon-button icon="icon-export" title="导出" type="primary" @click="exportAll" />
        </template>
        <normal-table
          :data="list" :total="total" :columns="columns" :query="listQuery" :list-loading="loadingTable"
          is-showmulti-select @change="changePage" @multi-select="handleSelectionChange"
        >
          <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="operateWidth"
            >
              <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>
              </template>
            </el-table-column>
          </template>
        </normal-table>
      </table-container>
    </app-container>
  </div>
</template>