<!-- 选择设备 -->
<script lang="ts" setup name="SelectEquipmentDialog">
import { ElMessage } from 'element-plus'
import type { Ref } from 'vue'
import { ref } from 'vue'
import dayjs from 'dayjs'
import type { DateModelType } from 'element-plus'
import type { TableColumn } from '@/components/NormalTable/table_interface'
import { getSampleList } from '@/api/business/manager/interchangeReceipt'
import { getUid } from '@/utils/getUid'
import { getDictByCode } from '@/api/system/dict'
import type { dictType } from '@/global'
const emits = defineEmits(['confirm'])
const dialogFormVisible = ref(false) // 控制对话框显隐
const isMulti = ref(false)// 表格是否多选
const customerId = ref('') // 任务单id、委托方id
// 查询条件
const listQuery = ref({
orderId: '', // 任务单id
customerId: '', // 委托方id
customerName: '', // 委托方名称
sampleName: '', // 样品名称、设备名称
sampleNo: '', // 样品编号、设备编号
model: '', // 规格型号
helpInstruction: '', // 辅助字段
manufactureNo: '', // 出厂编号
sampleStatus: '', // 设备收发状态
offset: 1,
limit: 20,
})
const dateRange = ref<[DateModelType, DateModelType]>(['', ''])// 筛选时间段数据
const checkoutList = ref([]) // 多选选中的内容
const orderId = ref('') // 任务单id
const loadingTable = ref(false) // 表格loading
const list = ref([]) as any // 表格数据
const total = ref(0) // 数组总数
const columns = ref<TableColumn[]>([
{ text: '设备名称', value: 'sampleName', align: 'center' },
{ text: '型号规格', value: 'sampleModel', align: 'center' },
{ text: '辅助字段', value: 'helpInstruction', align: 'center' },
{ text: '出厂编号', value: 'manufactureNo', align: 'center' },
{ text: '生产厂家', value: 'manufacturer', align: 'center' },
{ text: '委托方', value: 'customerName', align: 'center' },
{ text: '使用部门', value: 'deptName', align: 'center' },
{ text: '负责人', value: 'undertakerName', align: 'center' },
{ text: '设备当前收发状态', value: 'sampleStatusName', align: 'center' },
])
// -------------------------------------------字典------------------------------------------
const sampleStatusList = ref<dictType[]>([]) // 样品状态
// 获取字典值
async function getDict() {
// 样品状态
getDictByCode('sampleStatus').then((res) => {
sampleStatusList.value = res.data
})
}
getDict()
// 数据查询
function fetchData(isNowPage = false) {
listQuery.value.limit = isMulti.value ? 20 : 5
loadingTable.value = true
if (!isNowPage) {
// 是否显示当前页,否则跳转第一页
listQuery.value.offset = 1
}
listQuery.value.customerId = customerId.value
listQuery.value.orderId = orderId.value
getSampleList(listQuery.value).then((response) => {
list.value = response.data.rows.map((item: Object, index: number) => {
return {
...item,
id: getUid(),
}
})
total.value = parseInt(response.data.total)
loadingTable.value = false
})
}
// 重置
const clearList = () => {
listQuery.value = {
orderId: '', // 任务单id
customerId: '', // 委托方id
customerName: '', // 委托方名称
sampleName: '', // 样品名称、设备名称
sampleNo: '', // 样品编号、设备编号
model: '', // 规格型号
helpInstruction: '', // 辅助字段
manufactureNo: '', // 出厂编号
sampleStatus: '', // 设备收发状态
offset: 1,
limit: 20,
}
dateRange.value = ['', '']
fetchData()
}
// 搜索
const search = () => {
fetchData(true)
}
// 多选选中
const handleSelectionChange = (val: any) => {
checkoutList.value = val
}
// 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写
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
}
search()
}
// 点击确定
const confirmSelect = () => {
if (!checkoutList.value.length) {
ElMessage.warning('请选择设备')
}
else {
emits('confirm', checkoutList.value)
dialogFormVisible.value = false
}
}
// 取消
const resetForm = () => {
dialogFormVisible.value = false
clearList()
}
/**
* 初始化
* @param isMultiParam 是否多选 true多选、false单选
* @param getCustomerId 任务单id
*/
const initDialog = (isMultiParam: boolean, getCustomerId: string, getOrderId: string) => {
isMulti.value = isMultiParam
customerId.value = getCustomerId // 任务单id
orderId.value = getOrderId // 任务单id
dialogFormVisible.value = true // 显示对话框
fetchData()
}
// ----------------------------------------------钩子------------------------------------------------------
defineExpose({ initDialog })
</script>
<template>
<el-dialog v-if="dialogFormVisible" v-model="dialogFormVisible" title="选择设备" width="65%">
<!-- 筛选条件 -->
<search-area :need-clear="true" @search="search" @clear="clearList">
<search-item>
<el-input v-model.trim="listQuery.sampleName" placeholder="设备名称" class="short-input" clearable />
</search-item>
<search-item>
<el-input v-model.trim="listQuery.model" placeholder="规格型号" class="short-input" clearable />
</search-item>
<search-item>
<el-input v-model.trim="listQuery.helpInstruction" placeholder="辅助字段" class="short-input" clearable />
</search-item>
<search-item>
<el-input v-model.trim="listQuery.manufactureNo" placeholder="出厂编号" class="short-input" clearable />
</search-item>
<search-item>
<el-select
v-model="listQuery.sampleStatus"
class="short-input"
placeholder="设备收发状态"
filterable
clearable
>
<el-option v-for="item in sampleStatusList" :key="item.id" :label="item.name" :value="item.value" />
</el-select>
</search-item>
</search-area>
<!-- 查询结果Table显示 -->
<div style="padding: 12px;">
<normal-table
:data="list"
:total="total"
:columns="columns"
:query="listQuery"
is-showmulti-select
:list-loading="loadingTable"
:is-multi="isMulti"
:height="260"
@change="changePage"
@multi-select="handleSelectionChange"
>
<!-- 序号 -->
<template #preColumns>
<el-table-column label="#" width="55" align="center" fixed>
<template #default="scope">
{{ (listQuery.offset - 1) * listQuery.limit + scope.$index + 1 }}
</template>
</el-table-column>
</template>
</normal-table>
</div>
<template #footer>
<span class="dialog-footer">
<el-button type="primary" @click="confirmSelect">确认</el-button>
<el-button @click="resetForm">
取消
</el-button>
</span>
</template>
</el-dialog>
</template>
<style lang="scss" scoped>
:deep(.el-radio__label) {
display: none;
}
</style>