Commit 1d77d32af991add91fc26c2599b565e3452221b4
1 parent
194ce9b3
业务线 小程序不用写死,从后端接口获取
Showing
1 changed file
with
61 additions
and
47 deletions
pages-sub/problem/work-order-manage/add-maintain-order.vue
| ... | ... | @@ -236,6 +236,8 @@ const workFieldFormRef = ref(null) |
| 236 | 236 | const showWorkTypeSheet = ref(false) |
| 237 | 237 | // 作业类型选项:字典 maintain_type(打开弹窗时取,避免字典异步加载导致首次为空) |
| 238 | 238 | const workTypeOptions = ref([]) |
| 239 | +// 该业务线已配置工单填报项(biz_type=1)的作业类型 ID 集合,用于自动带出和下拉标记 | |
| 240 | +const configuredWorkTypeIds = ref(new Set()) | |
| 239 | 241 | |
| 240 | 242 | // 当前作业类型下的动态字段数量(0 时给「无需填报」提示) |
| 241 | 243 | const dynamicFieldCount = ref(0) |
| ... | ... | @@ -432,21 +434,8 @@ onLoad((options) => { |
| 432 | 434 | workOrderForm.busiLine = orderItem.busiLine |
| 433 | 435 | // 业务线可能是逗号分隔多值(如 "yl,hj"),字段配置按单值定位,取首段 |
| 434 | 436 | workOrderForm.businessType = String(orderItem.busiLine || '').split(',')[0].trim() |
| 435 | - // 来源数据若已带作业类型则回显(工单主表当前无该字段,通常为空,由用户手选) | |
| 436 | - if (orderItem.workTypeId) { | |
| 437 | - workOrderForm.workTypeId = orderItem.workTypeId | |
| 438 | - workOrderForm.workTypeName = uni.$dict.getDictLabel('maintain_type', orderItem.workTypeId) || '' | |
| 439 | - } else { | |
| 440 | - // 先按工单名「大类/小类」的小类匹配作业类型(如 秩序管理/经营秩序 -> 2014 经营秩序) | |
| 441 | - const matchedWorkType = matchWorkTypeByOrderName(orderItem.orderName) | |
| 442 | - if (matchedWorkType) { | |
| 443 | - workOrderForm.workTypeId = matchedWorkType.value | |
| 444 | - workOrderForm.workTypeName = matchedWorkType.label | |
| 445 | - } else { | |
| 446 | - // 兜底:该业务线只配了一个作业类型的字段时自动选中,进页即可看到填报项 | |
| 447 | - loadDefaultWorkType() | |
| 448 | - } | |
| 449 | - } | |
| 437 | + // 作业类型:按「该业务线已配置填报项的类型」自动带出(见 initWorkType) | |
| 438 | + initWorkType(orderItem) | |
| 450 | 439 | // 共同处理人(如有数据则回显,转换为数组格式) |
| 451 | 440 | if (orderItem.coHandlers && orderItem.coHandlersName) { |
| 452 | 441 | // 处理ID:如果是字符串(逗号分隔),转为数组;本身是数组则直接赋值 |
| ... | ... | @@ -716,9 +705,17 @@ const hideKeyboard = () => { |
| 716 | 705 | |
| 717 | 706 | // 打开作业类型选择弹窗 |
| 718 | 707 | const openWorkTypeSheet = () => { |
| 719 | - // up-action-sheet 用 name 展示,value 作为回传值 | |
| 708 | + // up-action-sheet 用 name 展示,value 作为回传值; | |
| 709 | + // 该业务线没配填报项的类型加后缀,避免选到没有填报项的类型还以为是配置丢了 | |
| 710 | + const configuredIds = configuredWorkTypeIds.value | |
| 720 | 711 | workTypeOptions.value = uni.$dict.getDictSimpleList('maintain_type') |
| 721 | - .map(item => ({ name: item.label, value: item.value })) | |
| 712 | + .map(item => ({ | |
| 713 | + name: configuredIds.size === 0 || configuredIds.has(String(item.value)) | |
| 714 | + ? item.label | |
| 715 | + : `${item.label}(无填报项)`, | |
| 716 | + label: item.label, | |
| 717 | + value: item.value | |
| 718 | + })) | |
| 722 | 719 | if (workTypeOptions.value.length === 0) { |
| 723 | 720 | uni.showToast({ |
| 724 | 721 | title: '暂无作业类型字典数据', |
| ... | ... | @@ -737,7 +734,8 @@ const onWorkTypeSelect = (e) => { |
| 737 | 734 | return |
| 738 | 735 | } |
| 739 | 736 | workOrderForm.workTypeId = e.value |
| 740 | - workOrderForm.workTypeName = e.name | |
| 737 | + // 展示名用字典原名,去掉下拉里的「(无填报项)」后缀 | |
| 738 | + workOrderForm.workTypeName = e.label || e.name | |
| 741 | 739 | dynamicFieldCount.value = 0 |
| 742 | 740 | if (workOrderFormRef.value) { |
| 743 | 741 | workOrderFormRef.value.validateField('workTypeName') |
| ... | ... | @@ -750,48 +748,64 @@ const onDynamicFieldsLoaded = (count) => { |
| 750 | 748 | } |
| 751 | 749 | |
| 752 | 750 | /** |
| 753 | - * 按工单名匹配作业类型:工单名格式「大类/小类」,小类与字典 maintain_type 的 label 同名 | |
| 754 | - * (如 秩序管理/经营秩序 -> 2014 经营秩序),命中即自动带出,养护员仍可在弹窗里手改。 | |
| 755 | - * @param {String} orderName 工单名,如「秩序管理/经营秩序」 | |
| 756 | - * @returns {{value: String, label: String}|null} 未命中返回 null | |
| 751 | + * 拉取该业务线已配置工单填报项(biz_type=1)的作业类型,结果同时用于: | |
| 752 | + * ① 自动带出作业类型;② 作业类型下拉里标记哪些类型有填报项。 | |
| 753 | + * @returns {Promise<Array<{workTypeId, workTypeName}>>} 拉取失败返回空数组 | |
| 757 | 754 | */ |
| 758 | -const matchWorkTypeByOrderName = (orderName) => { | |
| 759 | - const subName = String(orderName || '').split('/').pop().trim() | |
| 760 | - if (!subName) { | |
| 761 | - return null | |
| 762 | - } | |
| 763 | - const dictList = uni.$dict.getDictSimpleList('maintain_type') || [] | |
| 764 | - return dictList.find(item => item.label === subName) || null | |
| 765 | -} | |
| 766 | - | |
| 767 | -/** | |
| 768 | - * 兜底自动带出作业类型:该业务线下只有一个作业类型配置了填报项时直接选中, | |
| 769 | - * 动态字段块随之渲染(v-if 绑在 workTypeId 上),用户不用先猜该选哪个作业类型。 | |
| 770 | - * 配了多个时不自动选,交给用户手选。 | |
| 771 | - */ | |
| 772 | -const loadDefaultWorkType = async () => { | |
| 755 | +const loadConfiguredWorkTypes = async () => { | |
| 773 | 756 | if (!workOrderForm.businessType) { |
| 774 | - return | |
| 757 | + return [] | |
| 775 | 758 | } |
| 776 | 759 | try { |
| 777 | 760 | const list = await getConfiguredWorkTypes({ |
| 778 | 761 | businessType: workOrderForm.businessType, |
| 779 | 762 | bizType: 1 |
| 780 | 763 | }) |
| 781 | - if (!Array.isArray(list) || list.length !== 1) { | |
| 782 | - return | |
| 783 | - } | |
| 784 | - const only = list[0] | |
| 785 | - workOrderForm.workTypeId = only.workTypeId | |
| 786 | - workOrderForm.workTypeName = only.workTypeName | |
| 787 | - || uni.$dict.getDictLabel('maintain_type', only.workTypeId) | |
| 788 | - || '' | |
| 789 | - dynamicFieldCount.value = 0 | |
| 764 | + const arr = Array.isArray(list) ? list : [] | |
| 765 | + configuredWorkTypeIds.value = new Set(arr.map(item => String(item.workTypeId))) | |
| 766 | + return arr | |
| 790 | 767 | } catch (error) { |
| 791 | 768 | console.warn('获取已配置填报项的作业类型失败:', error) |
| 769 | + return [] | |
| 792 | 770 | } |
| 793 | 771 | } |
| 794 | 772 | |
| 773 | +/** | |
| 774 | + * 自动带出作业类型(只在该业务线已配置填报项的类型里选,完全匹配): | |
| 775 | + * ① 来源数据已带作业类型 -> 直接回显; | |
| 776 | + * ② 工单名「大类/小类」的小类与某个已配置类型的名称完全一致 -> 选中它; | |
| 777 | + * 如 秩序管理/经营秩序 -> 2014 经营秩序,秩序管理/交通秩序 -> 2013 交通秩序; | |
| 778 | + * ③ 没匹配上,但该业务线只配了 1 个类型 -> 直接选中; | |
| 779 | + * ④ 其余情况留空,由养护员在弹窗里手选。 | |
| 780 | + * 带出后仍可手改。 | |
| 781 | + * @param {Object} orderItem 待办行数据,需含 orderName、workTypeId | |
| 782 | + */ | |
| 783 | +const initWorkType = async (orderItem) => { | |
| 784 | + const configuredList = await loadConfiguredWorkTypes() | |
| 785 | + if (orderItem.workTypeId) { | |
| 786 | + workOrderForm.workTypeId = orderItem.workTypeId | |
| 787 | + workOrderForm.workTypeName = uni.$dict.getDictLabel('maintain_type', orderItem.workTypeId) || '' | |
| 788 | + return | |
| 789 | + } | |
| 790 | + if (configuredList.length === 0) { | |
| 791 | + return | |
| 792 | + } | |
| 793 | + const subName = String(orderItem.orderName || '').split('/').pop().trim() | |
| 794 | + const matched = subName | |
| 795 | + ? configuredList.find(item => (item.workTypeName | |
| 796 | + || uni.$dict.getDictLabel('maintain_type', item.workTypeId)) === subName) | |
| 797 | + : null | |
| 798 | + const picked = matched || (configuredList.length === 1 ? configuredList[0] : null) | |
| 799 | + if (!picked) { | |
| 800 | + return | |
| 801 | + } | |
| 802 | + workOrderForm.workTypeId = picked.workTypeId | |
| 803 | + workOrderForm.workTypeName = picked.workTypeName | |
| 804 | + || uni.$dict.getDictLabel('maintain_type', picked.workTypeId) | |
| 805 | + || '' | |
| 806 | + dynamicFieldCount.value = 0 | |
| 807 | +} | |
| 808 | + | |
| 795 | 809 | // 动态字段提交幂等流水号(后端按 userId+clientSeq 去重) |
| 796 | 810 | const genClientSeq = () => `${Date.now()}-${Math.random().toString(16).slice(2, 10)}` |
| 797 | 811 | ... | ... |