Commit 0a49210d70cfa9b34e64b2d4c37cdc864a5902d0
1 parent
dde14fa3
feat(approval): 审批系统去掉门店业态预设条件:从门店预设条件值中手动提取 bizType 交集
Showing
2 changed files
with
96 additions
and
14 deletions
src/pages/approval/ApprovalSetting/subpages/components/DefaultFlowNewOrEdit.tsx
... | ... | @@ -111,7 +111,7 @@ export default function DefaultSettingNewOrEdit(props: Props) { |
111 | 111 | } |
112 | 112 | }, [visible, data]); |
113 | 113 | |
114 | - // 从已选择门店中获取 bizType 交集 | |
114 | + // 从已选择门店中自动计算 bizType 交集 | |
115 | 115 | const shopBizTypes = useMemo(() => { |
116 | 116 | const shopCondVals = conditionVals.filter((i) => i.flowTriggerDto.type === TriggerType.门店); |
117 | 117 | if (!shopCondVals.length) return []; |
... | ... | @@ -126,6 +126,21 @@ export default function DefaultSettingNewOrEdit(props: Props) { |
126 | 126 | }); |
127 | 127 | return Array.from(bizTypeSet.values()); |
128 | 128 | }, [conditionVals]); |
129 | + // 计算最新 bizType 交集 | |
130 | + const getShopBizTypes = (cVals: ApprovalSetting.ConditionVal[]) => { | |
131 | + const shopCondVals = cVals.filter((i) => i.flowTriggerDto.type === TriggerType.门店); | |
132 | + if (!shopCondVals.length) return []; | |
133 | + const bizTypeSet = new Set<number>(); | |
134 | + shopCondVals.forEach((s) => { | |
135 | + try { | |
136 | + const options = JSON.parse(s.value); | |
137 | + options.forEach((o: FlowSetting.CondValItem) => { | |
138 | + bizTypeSet.add(o.bizType!); | |
139 | + }); | |
140 | + } catch {} | |
141 | + }); | |
142 | + return Array.from(bizTypeSet.values()); | |
143 | + }; | |
129 | 144 | |
130 | 145 | const hide = () => { |
131 | 146 | onCancel && onCancel(); |
... | ... | @@ -171,8 +186,21 @@ export default function DefaultSettingNewOrEdit(props: Props) { |
171 | 186 | }); |
172 | 187 | }; |
173 | 188 | |
189 | + // 门店业态值减少时交互:旧业态值不存在于新业态值数组 | |
190 | + const clearRoles = (newCondVals: ApprovalSetting.ConditionVal[]) => { | |
191 | + const oldShopBizTypes = [...shopBizTypes]; | |
192 | + const newShopBizTypes = getShopBizTypes(newCondVals); | |
193 | + oldShopBizTypes.forEach((i) => { | |
194 | + if (!newShopBizTypes.includes(i)) { | |
195 | + // 清空已添加审批角色列表 | |
196 | + setRoles([]); | |
197 | + } | |
198 | + }); | |
199 | + }; | |
200 | + | |
174 | 201 | const onConditionChange = (item: ApprovalSetting.ConditionVal, values: any, index: number) => { |
175 | 202 | const { value, flowTriggerDto } = item; |
203 | + | |
176 | 204 | // idOrCode--bizType |
177 | 205 | let newValue; |
178 | 206 | if (flowTriggerDto.type === TriggerType.门店) { |
... | ... | @@ -185,10 +213,12 @@ export default function DefaultSettingNewOrEdit(props: Props) { |
185 | 213 | } else { |
186 | 214 | newValue = Array.isArray(values) ? values.map((i) => ({ idOrCode: i.value, name: i.label })) : values; |
187 | 215 | } |
216 | + | |
217 | + // 计算新条件值 | |
218 | + const newCondVals = [...conditionVals]; | |
188 | 219 | if (flowTriggerDto && [2, 3, 4, 5, 6, 7, 8].includes(flowTriggerDto.judgeRule ?? 0)) { |
189 | 220 | const _item = { ...item, value: JSON.stringify(newValue) }; |
190 | - conditionVals[index] = _item; | |
191 | - setConditionVals([...conditionVals]); | |
221 | + newCondVals[index] = _item; | |
192 | 222 | } else { |
193 | 223 | const _item = { |
194 | 224 | ...item, |
... | ... | @@ -197,9 +227,16 @@ export default function DefaultSettingNewOrEdit(props: Props) { |
197 | 227 | ...newValue, |
198 | 228 | }), |
199 | 229 | }; |
200 | - conditionVals[index] = _item; | |
201 | - setConditionVals([...conditionVals]); | |
230 | + newCondVals[index] = _item; | |
202 | 231 | } |
232 | + | |
233 | + // 门店业态值减少时交互 | |
234 | + if (flowTriggerDto.type === TriggerType.门店) { | |
235 | + clearRoles(newCondVals); | |
236 | + } | |
237 | + | |
238 | + // 更新条件值 | |
239 | + setConditionVals(newCondVals); | |
203 | 240 | }; |
204 | 241 | |
205 | 242 | // 选择需要配置的预设条件 |
... | ... | @@ -208,6 +245,10 @@ export default function DefaultSettingNewOrEdit(props: Props) { |
208 | 245 | const currVal = conditionVals.find((c) => c.flowTriggerDto.id === i); |
209 | 246 | return { value: currVal ? currVal.value : '', flowTriggerDto: preCondition.find((p) => p.id === i)! }; |
210 | 247 | }); |
248 | + | |
249 | + // 门店业态值减少时交互 | |
250 | + clearRoles(tempVals); | |
251 | + | |
211 | 252 | setConditionVals(tempVals); |
212 | 253 | }; |
213 | 254 | ... | ... |
src/pages/approval/FlowSetting/subpages/ConditionSetting/components/CustomFlowNewOrEdit.tsx
... | ... | @@ -51,7 +51,7 @@ export default function CustomFlowNewOrEdit(props: Props) { |
51 | 51 | const [form] = Form.useForm(); |
52 | 52 | |
53 | 53 | // 触发条件对应表单值 |
54 | - const [conditionVals, setConditionVals] = useState<ApprovalSetting.ConditionVal[]>([]); | |
54 | + const [conditionVals, setConditionVals] = useState<FlowSetting.ConditionVal[]>([]); | |
55 | 55 | // 条件审批配置-->默认审批流程-->附加审批角色 |
56 | 56 | const [roles, setRoles] = useState<FlowSetting.ApprovalRoleItem[][]>([]); |
57 | 57 | |
... | ... | @@ -85,7 +85,7 @@ export default function CustomFlowNewOrEdit(props: Props) { |
85 | 85 | setSelectList(tempData); |
86 | 86 | |
87 | 87 | // 主要条件要必选 |
88 | - const essVals: ApprovalSetting.ConditionVal[] = []; | |
88 | + const essVals: FlowSetting.ConditionVal[] = []; | |
89 | 89 | preCondition.forEach((i) => { |
90 | 90 | const currVal = (data?.conditionValues ?? []).find((c) => c.flowTriggerDto.id === i.id); |
91 | 91 | if (i.essential && !currVal) { |
... | ... | @@ -129,7 +129,7 @@ export default function CustomFlowNewOrEdit(props: Props) { |
129 | 129 | } |
130 | 130 | }, [visible, data]); |
131 | 131 | |
132 | - // 从已选择门店中获取 bizType 交集 | |
132 | + // 从已选择门店中自动计算 bizType 交集 | |
133 | 133 | const shopBizTypes = useMemo(() => { |
134 | 134 | const shopCondVals = conditionVals.filter((i) => i.flowTriggerDto.type === TriggerType.门店); |
135 | 135 | if (!shopCondVals.length) return []; |
... | ... | @@ -144,6 +144,21 @@ export default function CustomFlowNewOrEdit(props: Props) { |
144 | 144 | }); |
145 | 145 | return Array.from(bizTypeSet.values()); |
146 | 146 | }, [conditionVals]); |
147 | + // 计算最新 bizType 交集 | |
148 | + const getShopBizTypes = (cVals: FlowSetting.ConditionVal[]) => { | |
149 | + const shopCondVals = cVals.filter((i) => i.flowTriggerDto.type === TriggerType.门店); | |
150 | + if (!shopCondVals.length) return []; | |
151 | + const bizTypeSet = new Set<number>(); | |
152 | + shopCondVals.forEach((s) => { | |
153 | + try { | |
154 | + const options = JSON.parse(s.value); | |
155 | + options.forEach((o: FlowSetting.CondValItem) => { | |
156 | + bizTypeSet.add(o.bizType!); | |
157 | + }); | |
158 | + } catch {} | |
159 | + }); | |
160 | + return Array.from(bizTypeSet.values()); | |
161 | + }; | |
147 | 162 | |
148 | 163 | const hide = () => { |
149 | 164 | onCancel && onCancel(); |
... | ... | @@ -184,8 +199,21 @@ export default function CustomFlowNewOrEdit(props: Props) { |
184 | 199 | }); |
185 | 200 | }; |
186 | 201 | |
187 | - const onConditionChange = (item: ApprovalSetting.ConditionVal, values: any, index: number) => { | |
202 | + // 门店业态值减少时交互:旧业态值不存在于新业态值数组 | |
203 | + const clearRoles = (newCondVals: FlowSetting.ConditionVal[]) => { | |
204 | + const oldShopBizTypes = [...shopBizTypes]; | |
205 | + const newShopBizTypes = getShopBizTypes(newCondVals); | |
206 | + oldShopBizTypes.forEach((i) => { | |
207 | + if (!newShopBizTypes.includes(i)) { | |
208 | + // 清空已添加审批角色列表 | |
209 | + setRoles([]); | |
210 | + } | |
211 | + }); | |
212 | + }; | |
213 | + | |
214 | + const onConditionChange = (item: FlowSetting.ConditionVal, values: any, index: number) => { | |
188 | 215 | const { value, flowTriggerDto } = item; |
216 | + | |
189 | 217 | // idOrCode--bizType |
190 | 218 | let newValue; |
191 | 219 | if (flowTriggerDto.type === TriggerType.门店) { |
... | ... | @@ -198,10 +226,12 @@ export default function CustomFlowNewOrEdit(props: Props) { |
198 | 226 | } else { |
199 | 227 | newValue = Array.isArray(values) ? values.map((i) => ({ idOrCode: i.value, name: i.label })) : values; |
200 | 228 | } |
229 | + | |
230 | + // 计算新条件值 | |
231 | + const newCondVals = [...conditionVals]; | |
201 | 232 | if (flowTriggerDto && [2, 3, 4, 5, 6, 7, 8].includes(flowTriggerDto.judgeRule ?? 0)) { |
202 | 233 | const _item = { ...item, value: JSON.stringify(newValue) }; |
203 | - conditionVals[index] = _item; | |
204 | - setConditionVals([...conditionVals]); | |
234 | + newCondVals[index] = _item; | |
205 | 235 | } else { |
206 | 236 | const _item = { |
207 | 237 | ...item, |
... | ... | @@ -210,9 +240,16 @@ export default function CustomFlowNewOrEdit(props: Props) { |
210 | 240 | ...newValue, |
211 | 241 | }), |
212 | 242 | }; |
213 | - conditionVals[index] = _item; | |
214 | - setConditionVals([...conditionVals]); | |
243 | + newCondVals[index] = _item; | |
215 | 244 | } |
245 | + | |
246 | + // 门店业态值减少时交互 | |
247 | + if (flowTriggerDto.type === TriggerType.门店) { | |
248 | + clearRoles(newCondVals); | |
249 | + } | |
250 | + | |
251 | + // 更新条件值 | |
252 | + setConditionVals(newCondVals); | |
216 | 253 | }; |
217 | 254 | |
218 | 255 | // 选择需要配置的预设条件 |
... | ... | @@ -221,6 +258,10 @@ export default function CustomFlowNewOrEdit(props: Props) { |
221 | 258 | const currVal = conditionVals.find((c) => c.flowTriggerDto?.id == i); |
222 | 259 | return { value: currVal ? currVal.value : '', flowTriggerDto: preCondition.find((p) => p.id === i)! }; |
223 | 260 | }); |
261 | + | |
262 | + // 门店业态值减少时交互 | |
263 | + clearRoles(tempVals); | |
264 | + | |
224 | 265 | setConditionVals(tempVals); |
225 | 266 | }; |
226 | 267 | |
... | ... | @@ -251,7 +292,7 @@ export default function CustomFlowNewOrEdit(props: Props) { |
251 | 292 | </Select> |
252 | 293 | </Form.Item> |
253 | 294 | |
254 | - {conditionVals.map((item: ApprovalSetting.ConditionVal, index: number) => { | |
295 | + {conditionVals.map((item: FlowSetting.ConditionVal, index: number) => { | |
255 | 296 | const { flowTriggerDto, value } = item; |
256 | 297 | const originalData = JSON.parse(value || '{}'); // 触发的条件选的值 |
257 | 298 | const { name, judgeRule = 0, type, id } = flowTriggerDto ?? {}; // 触发条件信息 | ... | ... |