Newer
Older
xc-business-system / src / views / business / measure / classification / list.vue
dutingting on 29 Nov 9 KB 解决冲突
<!-- 检定项分类管理列表 -->
<script lang="ts" setup name="BusinessMeasureClassificationList">
import type { Ref } from 'vue'
import { ElLoading, ElMessage, ElMessageBox } from 'element-plus'
import type { IList, IListQuery } from './classification-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 { exportClassificationList, getClassificationList } from '@/api/business/measure/classification'
const $router = useRouter()
const loadingTable = ref(false)
const operateWidth = ref('110') // 操作栏的宽度
// 查询条件
const listQuery: Ref<IListQuery> = ref({
  belongStandardEquipment: '', // 检校标准库
  categoryName: '', // 检定项分类名称
  categoryNo: '', // 检定项分类编号
  deviceType: '', // 智能模型分类
  measureCategory: '', // 检校类别
  limit: 20,
  offset: 1,
})

// 表头
const columns = ref<TableColumn[]>([
  { text: '检定项分类编号', value: 'categoryNo', align: 'center', width: '160', followLink: true },
  { text: '智能模型分类', value: 'deviceTypeName', align: 'center', width: '90' },
  { text: '检定项分类名称', value: 'categoryName', align: 'center' },
  { text: '检校标准库', value: 'belongStandardEquipmentName', align: 'center' },
  { text: '检校类别', value: 'measureCategoryName', align: 'center', width: '90' },
  { text: '依据技术文件', value: 'fileArr', align: 'center', isLink: true },
  { text: '地点', value: 'labLocation', align: 'center' },
])
const list = ref<IList[]>([]) // 列表
const total = ref(0) // 数据总条数
const checkoutList = ref<string[]>([]) // 选中的内容
// ------------------------------------------字典----------------------------------------------
const deviceTypeList = ref<dictType[]>([])// 智能模型分类
const standardList = ref<dictType[]>([])// 检校标准装置
const standardMapList = ref<dictType[]>([])// 检校标准装置
const measureCategoryList = ref<dictType[]>([])// 检校类别

function getDict() {
  // 检校类别
  getDictByCode('measureCategory').then((response) => {
    measureCategoryList.value = response.data
  })
  // 智能模型分类
  getDictByCode('eqptDeviceType').then((response) => {
    deviceTypeList.value = response.data
  })
  // 检校标准库
  getDictByCode('bizStandardEquipmentType').then((response) => {
    standardList.value = response.data
    standardMapList.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
  }
  getClassificationList(listQuery.value).then((response) => {
    list.value = response.data.rows.map((item: any) => {
      return {
        ...item,
        fileArr: item.technologyFile.split(';'),
      }
    })
    total.value = parseInt(response.data.total)
    loadingTable.value = false
  })
}

// 清除条件
const clearList = () => {
  listQuery.value = {
    belongStandardEquipment: '', // 检校标准库
    categoryName: '', // 检定项分类名称
    categoryNo: '', // 检定项分类编号
    deviceType: '', // 智能模型分类
    measureCategory: '', // 检校类别
    limit: 20,
    offset: 1,
  }
  fetchData()
}

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

// 新建
const add = () => {
  $router.push({
    path: 'classification/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: IList, type: 'detail' | 'edit') => {
  $router.push({
    path: `classification/${type}/${row.id}`,
    query: {
      ...row,
    },
  })
}

// 导出
const exportAll = () => {
  const loading = ElLoading.service({
    lock: true,
    text: '下载中请稍后',
    background: 'rgba(255, 255, 255, 0.6)',
  })
  if (list.value.length > 0) {
    const params = {
      belongStandardEquipment: listQuery.value.belongStandardEquipment, // 检校标准库
      categoryName: listQuery.value.categoryName, // 检定项分类名称
      categoryNo: listQuery.value.categoryNo, // 检定项分类编号
      deviceType: listQuery.value.deviceType, // 智能模型分类
      measureCategory: listQuery.value.measureCategory, // 检校类别
      offset: 1,
      limit: 20,
      ids: checkoutList.value,
    }
    exportClassificationList(params).then((res) => {
      const blob = new Blob([res.data])
      loading.close()
      exportFile(blob, '检定项分类管理.xlsx')
    })
  }
  else {
    loading.close()
    ElMessage.warning('无数据可导出数据')
  }
}
// ---------------------------------------钩子----------------------------------------------
watch(() => listQuery.value.deviceType, (newValue) => { // 监听到智能模型分类变化,联动检校标准装置数据
  listQuery.value.belongStandardEquipment = ''
  if (newValue === '1') { // 电学
    standardMapList.value = standardList.value.slice(0, 3)
  }
  else if (newValue === '2') { // 压力
    standardMapList.value = standardList.value.slice(3, 8)
  }
  else if (newValue === '0') { // 无线电
    standardMapList.value = standardList.value.slice(8)
  }
  else { // 3其他
    standardMapList.value = standardList.value
  }
})

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

<template>
  <div class="classification">
    <!-- 布局 -->
    <app-container>
      <search-area :need-clear="true" @search="searchList" @clear="clearList">
        <search-item>
          <el-select
            v-model="listQuery.deviceType"
            placeholder="智能模型分类"
            class="short-input"
            filterable
            clearable
          >
            <el-option v-for="item in deviceTypeList" :key="item.id" :label="item.name" :value="item.value" />
          </el-select>
        </search-item>
        <search-item>
          <el-select
            v-model="listQuery.belongStandardEquipment"
            placeholder="检校标准库"
            filterable
            clearable
            class="short-input"
          >
            <el-option v-for="item in standardMapList" :key="item.id" :label="item.name" :value="item.value" />
          </el-select>
        </search-item>
        <search-item>
          <el-input v-model.trim="listQuery.categoryNo" placeholder="检定项分类编号" class="short-input" clearable />
        </search-item>
        <search-item>
          <el-input v-model.trim="listQuery.categoryName" placeholder="检定项分类名称" class="short-input" clearable />
        </search-item>
        <search-item>
          <el-select
            v-model="listQuery.measureCategory"
            placeholder="检校类别"
            filterable
            clearable
            class="short-input"
          >
            <el-option v-for="item in measureCategoryList" :key="item.id" :label="item.name" :value="item.value" />
          </el-select>
        </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>

<style lang="scss">
.classification {
  // 单元格样式
  .el-table__cell {
    position: static !important; // 解决el-image 和 el-table冲突层级冲突问题
  }
}
</style>