Newer
Older
smart-metering-front / src / views / business / lab / components / selectMeasureDevice.vue
dutingting on 6 Mar 2023 5 KB 原始记录详情所用设备完成
<!-- 查询所用设备(测量设备) -->
<script setup lang="ts" name="SelectMeasureDevice">
import { ref } from 'vue'
import type { Ref } from 'vue'
import { ElMessage } from 'element-plus'
import dayjs from 'dayjs'
import type { TableColumn } from '@/components/NormalTable/table_interface'
import type { fixedAssetsParams, fixedAssetsType } from '@/views/device/standingBook/standingBook-interface'
import { listPageApi } from '@/api/device/standingBook'

const props = defineProps({
  visible: {
    type: Boolean,
    default: false,
  },
})
const emits = defineEmits(['changeVisible', 'confirmCheckout'])

// 查询条件
const searchQuery = ref({
  equipmentNo: '', // 设备编号
  equipmentName: '', // 名称
  mesureType: '', // 检定方式
  managerState: '1', // 管理状态 1表示在用(启封)
  useDept: '', // 使用部门
  assetType: '1', // 资产类型 1表示测量设备
  equipmentCategory: '', // 设备类别
  isCalibrationTestEquipment: '', // 校准/检定设备
  isMeasureAccount: '', // 测量工装
  isStandardSupportEquipment: '', // 标准配套设备
  isFixedAssets: '', // 固定资产
  validStartDate: '', // 有效开始日期
  validEndDate: '', // 有效结束日期
  abc: '',
  limit: 20,
  offset: 1,
  // ids: [] as string[],
})
// 表头
const columns = ref<TableColumn[]>([
  { text: '设备编号', value: 'equipmentNo', align: 'center', width: 160, fixed: true },
  { text: '名称', value: 'equipmentName', align: 'center', fixed: true },
  { text: '型号', value: 'modelNo', align: 'center' },
  { text: 'ABC', value: 'abc', align: 'center', width: 58 },
  { text: '检定方式', value: 'mesureTypeName', align: 'center', width: 90 },
  { text: '管理状态', value: 'managerStateName', align: 'center', width: 100 },
  { text: '使用部门', value: 'useDeptName', align: 'center' },
  { text: '使用人', value: 'usePersonName', align: 'center' },
  { text: '有效日期', value: 'validDate', align: 'center', width: 165 },
  { text: '备注', value: 'remark', align: 'center' },
])
// 表格数据
const list = ref<fixedAssetsType[]>([])
// 总数
const total = ref(0)
// 表格加载状态
const loadingTable = ref(false)
// 选中的内容
const checkoutList = ref<string[]>([])

// 数据查询
function fetchData(isNowPage = false) {
  loadingTable.value = true
  if (!isNowPage) {
    // 是否显示当前页,否则跳转第一页
    searchQuery.value.offset = 1
  }
  listPageApi(searchQuery.value).then((res) => {
    if (res.code === 200) {
      list.value = res.data.rows.map((item: fixedAssetsType) => {
        return {
          ...item,
          validDate: dayjs(item.validDate).format('YYYY-MM-DD'),
        }
      })
      total.value = res.data.total
    }
    loadingTable.value = false
  }).catch((_) => {
    loadingTable.value = false
  })
}

// 多选发生改变时
function handleSelectionChange(e: any) {
  checkoutList.value = e.map((item: any) => {
    return {
      ...item,
      isEdit: false,
    }
  })
}
// 点击搜索
const searchList = () => {
  fetchData(true)
}
// 点击重置
const clearList = () => {
  searchQuery.value = {
    equipmentNo: '', // 设备编号
    equipmentName: '', // 名称
    mesureType: '', // 检定方式
    managerState: '', // 管理状态
    useDept: '', // 使用部门
    assetType: '1', // 资产类型 1表示测量设备
    equipmentCategory: '', // 设备类别
    isCalibrationTestEquipment: '', // 校准/检定设备
    isMeasureAccount: '', // 测量工装
    isStandardSupportEquipment: '', // 标准配套设备
    isFixedAssets: '', // 固定资产
    validStartDate: '', // 有效开始日期
    validEndDate: '', // 有效结束日期
    abc: '',
    limit: 20,
    offset: 1,
  // ids: [] as string[],
  }
  fetchData(true)
}

// 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写
const changePage = (val: { size?: number; page?: number }) => {
  if (val && val.size) {
    searchQuery.value.limit = val.size
  }
  if (val && val.page) {
    searchQuery.value.offset = val.page
  }
  fetchData(true)
}

// 点击取消
const cancle = () => {
  emits('changeVisible', false)
}

// 点击确定
const clickConfirmSample = () => {
  if (!checkoutList.value.length) {
    ElMessage({
      message: '请选中',
      type: 'warning',
    })
  }
  // 将选择好的样品传给父组件
  emits('confirmCheckout', checkoutList.value)
  cancle()
}

watch(() => props.visible, (newValue) => {
  if (newValue) {
    fetchData(true)
  }
})
</script>

<template>
  <div class="select-kehu-dialog">
    <el-dialog v-model="visible" title="选择样品" width="65%" @close="cancle">
      <search-area
        :need-clear="true"
        @search="searchList" @clear="clearList"
      >
        <search-item>
          <el-input v-model="searchQuery.equipmentNo" placeholder="设备编号" clearable class="w-50 m-2" style="width: 185px;" />
        </search-item>
        <search-item>
          <el-input v-model="searchQuery.equipmentName" placeholder="名称" clearable class="w-50 m-2" style="width: 185px;" />
        </search-item>
      </search-area>
      <normal-table
        :data="list"
        :total="total"
        :columns="columns"
        :query="searchQuery"
        :list-loading="loadingTable"
        is-showmulti-select
        :is-multi="false"
        @change="changePage"
        @multiSelect="handleSelectionChange"
      >
        <!-- 序号 -->
        <template #preColumns>
          <el-table-column label="#" width="55" align="center" fixed>
            <template #default="scope">
              {{ (searchQuery.offset - 1) * searchQuery.limit + scope.$index + 1 }}
            </template>
          </el-table-column>
        </template>
      </normal-table>
      <template #footer>
        <el-button type="primary" @click="clickConfirmSample">
          确定
        </el-button>
        <el-button @click="cancle">
          取消
        </el-button>
      </template>
    </el-dialog>
  </div>
</template>