<script lang="ts" setup name="CustomerList"> import { getCurrentInstance, ref } from 'vue' import type { Ref } from 'vue' import type { DateModelType } from 'element-plus' import { ElLoading, ElMessage } from 'element-plus' import type { ITaskList, ITaskQuery } from './task-interface' import DistributeDialog from './components/distributeDialog.vue' import BarCodeBind from '@/components/BarCodeBind/index.vue' import type { TableColumn } from '@/components/NormalTable/table_interface' import { printJSON } from '@/utils/printUtils' import { exportFile } from '@/utils/exportUtils' import { getDictByCode } from '@/api/system/dict' import { exportTaskList, getTaskList } from '@/api/business/task' import type { dictType } from '@/global' const { proxy } = getCurrentInstance() as any const $router = useRouter() // 查询条件 const timeRange = ref<[DateModelType, DateModelType]>(['', '']) const listQuery: Ref<ITaskQuery> = ref({ sampleNo: '', // 样品编号 sampleName: '', // 样品名称 orderNo: '', // 委托书编号 customerNo: '', // 委托方代码 customerName: '', // 委托方名称 isUrgent: '', // 是否加急 sampleAttr: '', // 样品属性 startTime: '', // 应检完时间-开始 endTime: '', // 应检完时间-结束 formId: 'jlglsygfsp', // 任务分发formId offset: 1, limit: 20, }) // --------------获取所需字典值---------------- const sampleAttrList = ref<dictType[]>([]) // 样品属性列表 function getDict() { // 获取样品属性 getDictByCode('sampleBelong').then((response) => { sampleAttrList.value = response.data }) } getDict() // 表头 const columns = ref<TableColumn[]>([ { text: '样品编号', value: 'sampleNo', width: '110', align: 'center' }, { text: '样品名称', value: 'sampleName', width: '120', align: 'center' }, { text: '型号', value: 'sampleModel', align: 'center' }, { text: '出厂编号', value: 'manufacturingNo', align: 'center' }, { text: '委托书编号', value: 'orderNo', align: 'center' }, { text: '委托方代码', value: 'customerNo', align: 'center' }, { text: '委托方名称', value: 'customerName', align: 'center' }, { text: '是否加急', value: 'isUrgent', align: 'center', width: '55px', filter: (row: ITaskList) => { return row.isUrgent == '1' ? '是' : '否' }, styleFilter: (row: ITaskList) => { return row.isUrgent == '1' ? 'color: red' : '' } }, { text: '应检完时间', value: 'requireOverTime', align: 'center', width: '110px' }, { text: '样品属性', value: 'sampleAttrName', align: 'center' }, { text: '当前检定环节', value: 'currentMeasureStateName', align: 'center' }, { text: '证书出具', value: 'certificationState', align: 'center', filter: (row: ITaskList) => { return `${row.currentCertifications}/${row.requireCertifications}` } }, { text: '标签信息', value: 'labelBind', align: 'center' }, { text: '分发性质', value: 'distributeState', align: 'center', width: '90px' }, ]) // 表格数据 const list = ref<ITaskList[]>([]) // 总数 const total = ref(0) // 表格加载状态 const loadingTable = ref(false) // 选中的内容 const checkoutList = ref<string[]>([]) // 数据查询 function fetchData(isNowPage = false) { loadingTable.value = true if (!isNowPage) { // 是否显示当前页,否则跳转第一页 listQuery.value.offset = 1 } // 模拟数据 list.value = [ { orderId: '1', sampleNo: '1yp123456', sampleName: '压力表', orderNo: 'wtd123456', customerNo: 'kh123456', customerName: '北京无线电测量研究所', isUrgent: '1', sampleAttr: '1', sampleAttrName: '客户样品', sampleModel: 'JBT-011', manufacturingNo: '24432231124', requireOverTime: '2023-02-01', sampleId: '1', currentMeasureState: '1', currentMeasureStateName: '待分配', currentCertifications: 0, requireCertifications: 0, labelBind: '', distributeState: '1', distributeStateName: '初次分发' }, { orderId: '1', sampleNo: '1yp123457', sampleName: '压力表', orderNo: 'wtd123456', customerNo: 'kh123456', customerName: '北京无线电测量研究所', isUrgent: '0', sampleAttr: '1', sampleAttrName: '客户样品', sampleModel: 'JBT-011', manufacturingNo: '24432231124', requireOverTime: '2023-02-01', sampleId: '1', currentMeasureState: '1', currentMeasureStateName: '待分配', currentCertifications: 0, requireCertifications: 0, labelBind: '', distributeState: '2', distributeStateName: '退回分发' }, ] loadingTable.value = false // getTaskList(listQuery.value).then((response) => { // list.value = response.data.rows // total.value = parseInt(response.data.total) // loadingTable.value = false // }) } // 多选发生改变时 function handleSelectionChange(e: any) { checkoutList.value = e.map((item: { id: string }) => item.id) } // 点击搜索 const searchList = () => { fetchData(true) } // 点击重置 const clearList = () => { listQuery.value = { sampleNo: '', // 样品编号 sampleName: '', // 样品名称 orderNo: '', // 委托书编号 customerNo: '', // 委托方代码 customerName: '', // 委托方名称 isUrgent: '', // 是否加急 sampleAttr: '', // 样品属性 formId: 'jlglsygfsp', offset: 1, limit: 20, } } // 点击详情 const handleDetail = (row: ITaskList) => { $router.push(`/schedule/task/distribute/${row.sampleId}`) } // 点击分发, 弹窗 const distributeDialogRef = ref() const handleDistribute = (row: ITaskList) => { distributeDialogRef.value.initDialog(row.orderId, row.sampleId) } // 点击标签绑定 const barCodeBind = ref() const bindLabel = (row: ITaskList) => { barCodeBind.value.initDialog(row.sampleId) } // 标签绑定完成 const bindLabelOver = () => { searchList() } // 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写 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 exportAll = () => { const loading = ElLoading.service({ lock: true, text: '下载中请稍后', background: 'rgba(255, 255, 255, 0.8)', }) if (list.value.length > 0) { // const params = { // bussinessSize: listQuery.value.bussinessSize, // 业务规模 // customerName: listQuery.value.customerName, // 公司名称 // customerNo: listQuery.value.customerNo, // 任务分发编号 // grade: listQuery.value.grade, // 履约评级 // ids: checkoutList.value, // } // exportCustomerList(params).then((res) => { // const blob = new Blob([res.data]) // exportFile(blob, '任务分发列表.xlsx') // }) } else { ElMessage.warning('无数据可导出数据') } loading.close() } // 打印列表 function printList() { // 打印列 const properties = columns.value.map((item) => { return { field: item.value, displayName: item.text, } }) if (checkoutList.value.length <= 0 && list.value.length > 0) { printJSON(list.value, properties, '任务分发列表') } else if (checkoutList.value.length > 0) { const printList = list.value.filter((item: ITaskList) => checkoutList.value.includes(item.sampleId)) printJSON(printList, properties, '任务分发列表') } else { ElMessage.warning('无可打印内容') } } fetchData(true) </script> <template> <app-container> <search-area :need-clear="true" @search="searchList" @clear="clearList" > <search-item> <el-input v-model.trim="listQuery.sampleNo" placeholder="样品编号" class="short-input" clearable /> </search-item> <search-item> <el-input v-model.trim="listQuery.sampleNo" placeholder="样品名称" clearable class="short-input" /> </search-item> <search-item> <el-input v-model.trim="listQuery.sampleNo" placeholder="委托书编号" clearable class="short-input" /> </search-item> <search-item> <el-input v-model.trim="listQuery.sampleNo" placeholder="委托方代码" class="short-input" clearable /> </search-item> <search-item> <el-date-picker v-model="timeRange" type="datetimerange" range-separator="到" format="YYYY-MM-DD" value-format="YYYY-MM-DD" start-placeholder="应检完开始时间" end-placeholder="应检完结束时间" style="width: 280px;" /> </search-item> <search-item> <el-select v-model="listQuery.isUrgent" placeholder="是否加急" style="width: 120px;" clearable> <el-option label="是" value="1" /> <el-option label="否" value="0" /> </el-select> </search-item> <search-item> <el-select v-model="listQuery.sampleAttr" placeholder="样品属性" style="width: 120px;" clearable> <el-option v-for="item in sampleAttrList" :key="item.id" :label="item.name" :value="item.value" /> </el-select> </search-item> </search-area> <table-container> <template #btns-right> <icon-button v-if="proxy.hasPerm('/meter/customer/export')" icon="icon-export" title="导出" type="primary" @click="exportAll" /> <icon-button v-if="proxy.hasPerm('/meter/customer/export')" icon="icon-print" title="打印" type="primary" @click="printList" /> </template> <normal-table :data="list" :total="total" :columns="columns" :query="listQuery" :list-loading="loadingTable" is-showmulti-select @change="changePage" @multi-select="handleSelectionChange" > <template #columns> <el-table-column label="操作" align="center" fixed="right" width="145"> <template #default="{ row }"> <el-button size="small" link type="primary" @click="handleDetail(row)"> 详情 </el-button> <el-button size="small" link type="primary" @click="bindLabel(row)"> 标签绑定 </el-button> <el-button v-if="proxy.hasPerm('/meter/customer/update')" size="small" type="primary" link @click="handleDistribute(row)"> 分发 </el-button> </template> </el-table-column> </template> </normal-table> <!-- 任务分发弹窗 --> <distribute-dialog ref="distributeDialogRef" @close="fetchData" /> <!-- 标签绑定 --> <bar-code-bind ref="barCodeBind" @confirm="bindLabelOver" /> </table-container> </app-container> </template> <style lang="scss" scoped> .short-input { width: 160px; } </style>