<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, ElMessageBox } from 'element-plus' import type { ITaskList, ITaskQuery } from './task-interface' import DistributeDialog from './components/distributeDialog.vue' import batchDistributeDialog from './components/batchDistributeDialog.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/schedule/task' import type { dictType } from '@/global' import { tagBinding } from '@/api/reader' import type { IMenu } from '@/components/buttonBox/buttonBox' import { interchangeListUrge } from '@/api/business/schedule/interchangeList' import { keepSearchParams, renewSearchParams } from '@/utils/keepQuery' const { proxy } = getCurrentInstance() as any const $router = useRouter() // 右上角按钮 const menu = ref<IMenu[]>([]) const active = ref('') // 当前选中状态 const activeTitle = ref('') // active对应的审批状态名字 // 查询条件 const timeRange = ref<[DateModelType, DateModelType]>(['', '']) const listQuery: Ref<ITaskQuery> = ref({ sampleNo: '', // 样品编号 sampleName: '', // 样品名称 sampleModel: '', // 型号 manufacturingNo: '', // 出厂编号 orderNo: '', // 委托单编号 customerNo: '', // 委托方代码 customerName: '', // 委托方名称 isUrgent: '', // 是否加急 sampleBelong: '', // 样品属性 startTime: '', // 应检完时间-开始 endTime: '', // 应检完时间-结束 sampleStatus: '2', // 样品状态:默认待分发 offset: 1, limit: 20, }) // 页面跳转之前保存参数 onBeforeRouteLeave((to: any) => { keepSearchParams(to.path, 'schedule-task', listQuery.value) }) // 重新赋值 listQuery.value = renewSearchParams('schedule-task') || { sampleNo: '', // 样品编号 sampleName: '', // 样品名称 orderNo: '', // 委托单编号 customerNo: '', // 委托方代码 customerName: '', // 委托方名称 isUrgent: '', // 是否加急 sampleBelong: '', // 样品属性 startTime: '', // 应检完时间-开始 endTime: '', // 应检完时间-结束 sampleStatus: '2', // 样品状态:默认待分发 offset: 1, limit: 20, } // --------------获取所需字典值---------------- const sampleBelongList = ref<dictType[]>([]) // 样品属性列表 function getDict() { // 获取样品属性 getDictByCode('sampleBelong').then((response) => { sampleBelongList.value = response.data }) getDictByCode('sampleStatus').then((response) => { // 制作右上角的菜单 response.data.forEach((item: dictType) => { if (['待分发', '检测中', '检测完成', '已超期'].includes(item.name)) { if (item.name === '待分发') { active.value = item.value activeTitle.value = item.name } menu.value.push({ name: item.name, id: `${item.value}`, }) } }) console.log('88', menu.value) if (window.sessionStorage.getItem('taskActive') != null) { active.value = window.sessionStorage.getItem('taskActive') as string } else { active.value = menu.value.find(item => item.name === '待分发')!.id as string // 待分发 } }) } // 表头 const toTaskColumns = ref<TableColumn[]>([ // { text: '样品编号', value: 'sampleNo', width: '160', align: 'center' }, { text: '样品名称', value: 'sampleName', width: '120', align: 'center' }, { text: '型号', value: 'sampleModel', align: 'center' }, { text: '出厂编号', value: 'manufacturingNo', width: '120', align: 'center' }, { text: '委托单编号', value: 'orderNo', align: 'center', width: '160' }, { text: '分发性质', value: 'handOutProperty', width: '100', align: 'center' }, { text: '委托方名称', value: 'customerName', width: '120', align: 'center' }, { text: '是否加急', value: 'isUrgentName', align: 'center', width: '55px', styleFilter: (row: ITaskList) => { return row.isUrgentName == '是' ? 'color: red' : '' } }, { text: '应检完时间', value: 'requireOverTime', align: 'center', width: '165px' }, { text: '样品属性', value: 'sampleBelongName', width: '100', align: 'center' }, { text: '当前检定环节', value: 'currentSegment', align: 'center', width: '90' }, { text: '证书出具', value: 'certificationState', align: 'center', width: '90' }, { text: '委托方代码', value: 'customerNo', align: 'center', width: '160' }, ]) // 表头 const columns = ref<TableColumn[]>([ // { text: '样品编号', value: 'sampleNo', width: '160', align: 'center' }, { text: '样品名称', value: 'sampleName', width: '120', align: 'center' }, { text: '型号', value: 'sampleModel', align: 'center' }, { text: '出厂编号', value: 'manufacturingNo', width: '120', align: 'center' }, { text: '委托单编号', value: 'orderNo', align: 'center', width: '160' }, { text: '委托方代码', value: 'customerNo', align: 'center', width: '160' }, { text: '委托方名称', value: 'customerName', width: '120', align: 'center' }, { text: '是否加急', value: 'isUrgentName', align: 'center', width: '55px', styleFilter: (row: ITaskList) => { return row.isUrgentName == '是' ? 'color: red' : '' } }, { text: '应检完时间', value: 'requireOverTime', align: 'center', width: '165px' }, { text: '样品属性', value: 'sampleBelongName', width: '100', align: 'center' }, { text: '当前检定环节', value: 'currentSegment', align: 'center', width: '90' }, { text: '证书出具', value: 'certificationState', align: 'center', width: '90' }, ]) // 表格数据 const list = ref<ITaskList[]>([]) // 总数 const total = ref(0) // 表格加载状态 const loadingTable = ref(false) const checkoutIdList = ref<string[]>([]) // 选中的内容 const checkoutList: any = ref([]) // 数据查询 function fetchData(isNowPage = false) { loadingTable.value = true // if (!isNowPage) { // // 是否显示当前页,否则跳转第一页 // listQuery.value.offset = 1 // } listQuery.value.sampleStatus = active.value || '2' list.value = [] getTaskList(listQuery.value).then((response) => { list.value = response.data.rows.map((item: ITaskList) => { item.isUrgentName = item.isUrgent == 1 ? '是' : '否' item.certificationState = `${item.alreadyCertifications}/${item.requireCertifications}` return item }) total.value = response.data.total loadingTable.value = false }) } // 多选发生改变时 function handleSelectionChange(e: any) { checkoutIdList.value = e.map((item: { sampleId: string }) => item.sampleId) checkoutList.value = e } // 点击搜索 const searchList = () => { fetchData(true) } // 点击重置 const clearList = () => { listQuery.value = { sampleNo: '', // 样品编号 sampleName: '', // 样品名称 sampleModel: '', // 型号 manufacturingNo: '', // 出厂编号 orderNo: '', // 委托单编号 customerNo: '', // 委托方代码 customerName: '', // 委托方名称 isUrgent: '', // 是否加急 sampleBelong: '', // 样品属性 sampleStatus: active.value, // 分发状态 startTime: '', // 应检定开始时间 endTime: '', // 应检定结束时间 offset: 1, limit: 20, } timeRange.value = ['', ''] fetchData(true) } // 点击详情 const handleDetail = (row: ITaskList) => { console.log('跳转任务分发详情') // $router.push(`/schedule/task/distribute/${row.sampleId}?order=${row.orderId}&customerId=${row.customerId}`) $router.push(`/schedule/task/detail/${row.sampleId}?order=${row.orderId}&customerId=${row.customerId}`) } // 点击分发, 弹窗 const distributeDialogRef = ref() const handleDistribute = (row: ITaskList) => { distributeDialogRef.value.initDialog(row.orderId, row.sampleId, listQuery.value.sampleStatus) } // 点击标签绑定 // 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 selectRow = ref() // 标签绑定选择的行数据 const scanSampleRef = ref() // 标签绑定弹窗ref // 点击标签绑定 const scan = (row: ITaskList) => { selectRow.value = row // 点击标签绑定的行数据 scanSampleRef.value.initDialog(true) } // 扫描结束 const scanOver = (value: any) => { const label = value.labelBind tagBinding({ label, sampleId: selectRow.value.sampleId }).then((res) => { ElMessage.success(' 绑定成功') scanSampleRef.value.closeDialog() }) } // ----------------------------------------------------------------------------------- const batchDistributeDialogRef = ref() const tableRef = ref() // 点击批量分发 const batchDistribute = () => { console.log('点击批量分发') if (!checkoutIdList.value.length) { ElMessage.warning('请先选中表格里的数据') return false } batchDistributeDialogRef.value.initDialog(checkoutList.value) } // 批量分发完成 const batchDistributeSuccess = () => { tableRef.value.clearMulti() fetchData() } // 导出 const exportAll = () => { const loading = ElLoading.service({ lock: true, text: '下载中请稍后', background: 'rgba(255, 255, 255, 0.8)', }) if (list.value.length > 0) { const obj = { sampleNo: '', // 样品编号 sampleName: '', // 样品名称 sampleModel: '', // 型号 manufacturingNo: '', // 出厂编号 orderNo: '', // 委托单编号 customerNo: '', // 委托方代码 customerName: '', // 委托方名称 isUrgent: '', // 是否加急 sampleBelong: '', // 样品属性 sampleStatus: active.value, // 分发状态 startTime: '', // 应检定开始时间 endTime: '', // 应检定结束时间 } const params = { ...obj, ids: checkoutIdList.value, } exportTaskList(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 (checkoutIdList.value.length <= 0 && list.value.length > 0) { printJSON(list.value, properties, '任务分发列表') } else if (checkoutIdList.value.length > 0) { const printList = list.value.filter((item: ITaskList) => checkoutIdList.value.includes(item.sampleId)) printJSON(printList, properties, '任务分发列表') } else { ElMessage.warning('无可打印内容') } } // 催办 const urge = (row: ITaskList) => { ElMessageBox.confirm( '确认催办吗?', '提示', { confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning', }, ) .then(() => { interchangeListUrge({ orderId: row.orderId, reason: '', sampleId: row.sampleId, status: '' }).then((res) => { if (res.code === 200) { ElMessage.success('已催办') fetchData(true) } }) }) } // 选择按钮变更 watch(active, (val: string) => { if (val === null) { active.value = '2' return } active.value = val window.sessionStorage.setItem('taskActive', val) tableRef.value && tableRef.value.clearMulti() fetchData(false) }) watch(timeRange, (val: any) => { if (val) { listQuery.value.startTime = val[0] listQuery.value.endTime = val[1] } else { listQuery.value.startTime = '' listQuery.value.endTime = '' } }) onMounted(() => { getDict() // 获取字典-审批状态 fetchData(false) }) </script> <template> <app-container> <div class="float-radio-buttons"> <!-- 三级菜单 --> <el-radio-group v-model="active"> <el-radio-button v-for="item in menu" :key="item.name" :label="item.id"> {{ item.name }} </el-radio-button> </el-radio-group> </div> <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.sampleName" placeholder="样品名称" clearable class="short-input" /> </search-item> <search-item> <el-input v-model.trim="listQuery.sampleModel" placeholder="型号" clearable class="short-input" /> </search-item> <search-item> <el-input v-model.trim="listQuery.manufacturingNo" placeholder="出厂编号" clearable class="short-input" /> </search-item> <search-item> <el-input v-model.trim="listQuery.orderNo" placeholder="委托单编号" clearable class="short-input" /> </search-item> <search-item> <el-input v-model.trim="listQuery.customerNo" placeholder="委托方代码" class="short-input" clearable /> </search-item> <search-item> <el-date-picker v-model="timeRange" type="datetimerange" range-separator="到" format="YYYY-MM-DD HH:mm:ss" value-format="YYYY-MM-DD HH:mm:ss" start-placeholder="应检完开始时间" end-placeholder="应检完结束时间" /> </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.sampleBelong" placeholder="样品属性" style="width: 120px;" clearable> <el-option v-for="item in sampleBelongList" :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('/schedule/taskList/batchDistribute') && listQuery.sampleStatus === '2'" icon="icon-batch" title="批量分发" type="primary" @click="batchDistribute" /> <icon-button v-if="proxy.hasPerm('/schedule/taskList/export')" icon="icon-export" title="导出" type="primary" @click="exportAll" /> <icon-button v-if="proxy.hasPerm('/schedule/taskList/print')" icon="icon-print" title="打印" type="primary" @click="printList" /> </template> <normal-table ref="tableRef" :data="list" :total="total" :columns="listQuery.sampleStatus === '2' ? toTaskColumns : 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="180"> <template #default="{ row }"> <el-button size="small" link type="primary" @click="handleDetail(row)"> 详情 </el-button> <el-button v-if="proxy.hasPerm('/schedule/taskList/binding')" size="small" link type="primary" @click="scan(row)"> 标签绑定 </el-button> <!-- 检测完成的不允许分发 --> <el-button v-if="proxy.hasPerm('/schedule/taskList/distribute') && listQuery.sampleStatus !== '4'" size="small" type="primary" link @click="handleDistribute(row)" > 分发 </el-button> <el-button v-if="proxy.hasPerm('/schedule/taskList/urge') && listQuery.sampleStatus === '8'" size="small" link type="primary" @click="urge(row)" > 催办 </el-button> </template> </el-table-column> </template> </normal-table> <!-- 任务分发弹窗 --> <distribute-dialog ref="distributeDialogRef" @close="fetchData" /> <!-- 标签绑定 --> <!-- <bar-code-bind ref="barCodeBind" @confirm="bindLabelOver" /> --> <scan-sample-dialog ref="scanSampleRef" title="标签绑定" @confirm="scanOver" /> <!-- 批量分发弹窗 --> <batch-distribute-dialog ref="batchDistributeDialogRef" @on-success="batchDistributeSuccess" /> </table-container> </app-container> </template> <style lang="scss" scoped> .short-input { width: 160px; } </style>