Newer
Older
xc-business-system / src / views / business / taskMeasure / measureData / list.vue
<!-- 实验室任务列表 -->
<script name="MeasureDataList" lang="ts" setup>
import { getCurrentInstance, ref } from 'vue'
import type { Ref } from 'vue'
import type { DateModelType } from 'element-plus'
import { ElLoading, ElMessage, ElMessageBox } from 'element-plus'
import type { IList, IListQuery } from './measureData-interface'
import type { TableColumn } from '@/components/NormalTable/table_interface'
import { getDeviceNameList, getModelAllList } from '@/api/business/measure/item'
import { exportFile } from '@/utils/exportUtils'
import { exportMeasureDataList, getLocationList, getMeasureDataList } from '@/api/business/taskMeasure/measureData'
const $router = useRouter()
// 查询条件
const timeRange = ref<[DateModelType, DateModelType]>(['', ''])
const listQuery: Ref<IListQuery> = ref({
  createUserName: '', // 检定员
  customerName: '', // 委托单位
  dataNo: '', // 检定数据编号
  manufactureNo: '', // 出厂编号
  measureAddress: '', // 测试、校准或检定地点
  model: '', // 规格型号
  sampleName: '', // 受检设备名称
  traceDateEnd: '', // 测试、校准或检定日期结束
  traceDateStart: '', // 测试、校准或检定日期开始
  offset: 1,
  limit: 20,
})
const operateWidth = ref('110') // 操作栏的宽度

const columns = ref<TableColumn[]>([ // 表头
  { text: '检定数据编号', value: 'dataNo', width: '160', align: 'center' },
  { text: '委托单位', value: 'customerName', align: 'center' },
  { text: '测试、校准或检定日期', value: 'traceDate', align: 'center', width: '120' },
  { text: '测试、校准或检定地点', value: 'measureAddress', align: 'center' },
  { text: '受检设备名称', value: 'sampleName', align: 'center' },
  { text: '规格型号', value: 'model', align: 'center' },
  { text: '出厂编号', value: 'manufactureNo', align: 'center' },
  { text: '辅助字段', value: 'helpInstruction', align: 'center' },
  { text: '设备检定项分类', value: 'itemCategoryName', align: 'center' },
  { text: '所使用的测量标准及配套设备名称', value: 'equipmentNameStr', align: 'center' },
  { text: '所使用的测量标准及配套设备型号', value: 'equipmentModelStr', align: 'center' },
  { text: '所使用的测量标准及配套设备编号', value: 'equipmentManufactureNoStr', align: 'center' },
  { text: '检定员', value: 'createUserName', align: 'center', width: '120' },
])
const list = ref<IList[]>([]) // 表格数据
const total = ref(0) // 总数
const loadingTable = ref(false) // 表格加载状态
const checkoutList = ref<IList[]>([]) // 选中的内容
const checkoutListAllContent = ref<IList[]>([]) // 选中的内容
// --------------------------------------------字典--------------------------------------
const deviceNameList = ref<string[]>([]) // 设备名称
const modelList = ref<any[]>([])// 规格型号
const helpList = ref<any[]>([])// 辅助字段
const allList = ref<any[]>([])
const positionList = ref([]) as any // 测试、校准或检定地点

async function getDict() {
  // 设备名称
  getDeviceNameList().then((res) => {
    deviceNameList.value = res.data
  })

  // 规格型号及辅助字段
  getModelAllList({}).then((res) => {
    allList.value = res.data
    modelList.value = Array.from(new Set(res.data.filter((item: any) => item.model).map((item: any) => item.model)))
    helpList.value = Array.from(new Set(res.data.filter((item: any) => item.helpInstruction).map((item: any) => item.helpInstruction)))
  })

  // 测试、校准或检定地点
  getLocationList({
    locationName: '', // 地点名称
    locationNo: '', // 地点编号
    limit: 999999,
    offset: 1,
  }).then((res) => {
    positionList.value = res.data.rows.map((item: { id: string; locationName: string; temperature: string; humidity: string }) => {
      return {
        id: item.id,
        name: item.locationName, // 地点名称
        temperature: `${item.temperature}` || '', // 温度
        humidity: `${item.humidity}` || '', // 湿度
      }
    })
  })
}

// -----------------------------------------表格数据--------------------------------------------

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

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

// 点击搜索
const searchList = () => {
  fetchData(true)
}
// 点击重置
const clearList = () => {
  listQuery.value = {
    createUserName: '', // 检定员
    customerName: '', // 委托单位
    dataNo: '', // 检定数据编号
    manufactureNo: '', // 出厂编号
    measureAddress: '', // 测试、校准或检定地点
    model: '', // 规格型号
    sampleName: '', // 受检设备名称
    traceDateEnd: '', // 测试、校准或检定日期结束
    traceDateStart: '', // 测试、校准或检定日期开始
    offset: 1,
    limit: 20,
  }
  timeRange.value = ['', '']
  fetchData(false)
}

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

// --------------------------------------按钮(导出)--------------------------------------------------------
// 导出
const exportAll = () => {
  const loading = ElLoading.service({
    lock: true,
    text: '下载中请稍后',
    background: 'rgba(255, 255, 255, 0.8)',
  })
  if (list.value.length > 0) {
    const param = {
      createUserName: listQuery.value.createUserName, // 检定员
      customerName: listQuery.value.customerName, // 委托单位
      dataNo: listQuery.value.dataNo, // 检定数据编号
      manufactureNo: listQuery.value.manufactureNo, // 出厂编号
      measureAddress: listQuery.value.measureAddress, // 测试、校准或检定地点
      model: listQuery.value.model, // 规格型号
      sampleName: listQuery.value.sampleName, // 受检设备名称
      traceDateEnd: listQuery.value.traceDateEnd, // 测试、校准或检定日期结束
      traceDateStart: listQuery.value.traceDateStart, // 测试、校准或检定日期开始
      offset: 1,
      limit: 20,
      ids: checkoutList.value,
    }
    exportMeasureDataList(param).then((res) => {
      exportFile(res.data, '检定数据管理')
      loading.close()
    })
      .catch((_) => {
        loading.close()
      })
  }
  else {
    loading.close()
    ElMessage.warning('无数据可导出数据')
  }
}

// --------------------------------------点击批量编辑------------------------------------------------
const batchEdit = () => {
  if (checkoutListAllContent.value.length > 4) {
    ElMessage.warning('最多可编辑4个')
    return false
  }
  if (!checkoutListAllContent.value.every((item: any) => item.itemCategoryId === checkoutListAllContent.value[0].itemCategoryId)) {
    ElMessage.warning('只允许配置同一个检定项的数据')
    return false
  }
  $router.push({
    path: 'measureData/edit',
    query: {
      batchEdit: 'true',
      batchEditRow: JSON.stringify(checkoutListAllContent.value),
    },
  })
}

// ---------------------------------------钩子-------------------------------------------------------
watch(timeRange, (val) => { // 监听时间变化
  if (val) {
    listQuery.value.traceDateStart = `${val[0]}`
    listQuery.value.traceDateEnd = `${val[1]}`
  }
  else {
    listQuery.value.traceDateStart = ''
    listQuery.value.traceDateEnd = ''
  }
})

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

<template>
  <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-input v-model.trim="listQuery.customerName" 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="测试、校准或检定日期(结束)"
          style="width: 480px;"
        />
      </search-item>
      <search-item>
        <el-input v-model.trim="listQuery.measureAddress" placeholder="测试、校准或检定地点" clearable />
      </search-item>
      <search-item>
        <el-select v-model.trim="listQuery.sampleName" filterable class="short-input" placeholder="受检设备名称" clearable>
          <el-option v-for="item in deviceNameList" :key="item" :label="item" :value="item" />
        </el-select>
      </search-item>
      <search-item>
        <el-select v-model.trim="listQuery.model" filterable class="short-input" placeholder="型号规格" clearable>
          <el-option v-for="item in modelList" :key="item" :label="item" :value="item" />
        </el-select>
      </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.createUserName" placeholder="检定员" class="short-input" clearable />
      </search-item>
    </search-area>
    <table-container>
      <template #btns-right>
        <!-- <icon-button icon="icon-scan" title="扫描检完" type="primary" @click="batchOverScan" /> -->
        <!-- <icon-button icon="icon-edit" title="批量编辑" @click="batchEdit" /> -->
        <icon-button icon="icon-export" title="导出" @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>
      <!-- 退回弹窗 -->
      <rollback-dialog ref="rollbackRef" @on-success="fetchData(true)" />
      <!-- 任务分发弹窗 -->
      <distribute-dialog ref="distributeDialogRef" @close="fetchData(true)" />
    </table-container>
  </app-container>
</template>

<style lang="scss" scoped>
.short-input {
  width: 160px;
}
</style>