vue2-client 1.16.15 → 1.16.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -32,12 +32,11 @@
32
32
  </a-button>
33
33
  </div>
34
34
 
35
- <a-divider/>
35
+ <a-divider v-if="isMixedPaymentEnabled && selectedMethods.length > 1"/>
36
36
 
37
- <!-- 支付详情(同一行展示) -->
38
- <div v-if="(isMixedPaymentEnabled && selectedMethods.length > 0) || (!isMixedPaymentEnabled && selectedMethod)" class="mixed-payment-section simple">
39
- <!-- 混合支付:所有金额输入在同一行展示 -->
40
- <div v-if="isMixedPaymentEnabled" class="payment-operation-row">
37
+ <!-- 支付详情(同一行展示,仅在混合支付且选择方式>1时出现) -->
38
+ <div v-if="isMixedPaymentEnabled && selectedMethods.length > 1" class="mixed-payment-section simple">
39
+ <div class="payment-operation-row">
41
40
  <div class="payment-inline">
42
41
  <div v-for="method in selectedMethods" :key="method" class="inline-field">
43
42
  <label class="form-label">{{ getAmountLabel(method) }}</label>
@@ -51,21 +50,6 @@
51
50
  </div>
52
51
  </div>
53
52
  </div>
54
- <!-- 单一支付:同一行展示一个输入 -->
55
- <div v-if="!isMixedPaymentEnabled && selectedMethod" class="payment-operation-row">
56
- <div class="payment-inline">
57
- <div class="inline-field">
58
- <label class="form-label">{{ getAmountLabel(selectedMethod) }}</label>
59
- <a-input
60
- v-model="paymentAmounts[selectedMethod]"
61
- type="number"
62
- placeholder="请输入金额"
63
- class="form-input"
64
- @change="updatePaymentAmount(selectedMethod, $event)"
65
- />
66
- </div>
67
- </div>
68
- </div>
69
53
  </div>
70
54
 
71
55
  <a-divider/>
@@ -163,6 +147,29 @@ export default {
163
147
  if (hasParam) this.hasInitialized = true
164
148
  },
165
149
  methods: {
150
+ // 同步 data 中的 selectedMethods / paymentAmounts 到本地状态;并补回缺失的 data 字段
151
+ hydrateFromData () {
152
+ const incomingMethods = Array.isArray(this.data && this.data.selectedMethods) ? this.data.selectedMethods : undefined
153
+ const incomingAmounts = this.data && this.data.paymentAmounts && typeof this.data.paymentAmounts === 'object' ? this.data.paymentAmounts : undefined
154
+
155
+ if (incomingMethods) {
156
+ this.selectedMethods = [...incomingMethods]
157
+ this.selectedMethod = this.selectedMethods[0] || ''
158
+ } else {
159
+ this.data.selectedMethods = [...this.selectedMethods]
160
+ this.data.selectedMethod = this.selectedMethod
161
+ }
162
+
163
+ if (incomingAmounts) {
164
+ // 用 $set 逐项写入,保持响应式
165
+ Object.keys(incomingAmounts).forEach(k => this.$set(this.paymentAmounts, k, incomingAmounts[k]))
166
+ } else if (!this.data.paymentAmounts) {
167
+ this.$set(this.data, 'paymentAmounts', { ...this.paymentAmounts })
168
+ }
169
+
170
+ // 根据 amounts 回算合计
171
+ this.calculateTotalPayment()
172
+ },
166
173
  selectMethod (value) {
167
174
  this.selectedMethod = value
168
175
  this.data.selectedMethod = value
@@ -170,6 +177,8 @@ export default {
170
177
  if (!this.isMixedPaymentEnabled && value) {
171
178
  if (!this.paymentAmounts[value]) this.initPaymentData(value)
172
179
  }
180
+ // 同步到数据模型,单一模式下也记录 selectedMethods 便于父层读取
181
+ this.data.selectedMethods = this.isMixedPaymentEnabled ? [...this.selectedMethods] : (value ? [value] : [])
173
182
  this.$emit(this.eventNames.method, value)
174
183
  },
175
184
  // 新增:切换支付方式选择(支持多选)
@@ -187,6 +196,7 @@ export default {
187
196
 
188
197
  // 更新选中状态
189
198
  this.selectedMethod = this.selectedMethods.length > 0 ? this.selectedMethods[0] : ''
199
+ this.data.selectedMethod = this.selectedMethod
190
200
  this.data.selectedMethods = [...this.selectedMethods]
191
201
 
192
202
  this.$emit(this.eventNames.methods, this.selectedMethods)
@@ -198,14 +208,18 @@ export default {
198
208
  if (index > -1) {
199
209
  this.selectedMethods.splice(index, 1)
200
210
  this.removePaymentData(methodKey)
211
+ // 同步所选方式到数据模型
212
+ this.data.selectedMethods = [...this.selectedMethods]
213
+ this.selectedMethod = this.selectedMethods[0] || ''
214
+ this.data.selectedMethod = this.selectedMethod
201
215
  this.$emit(this.eventNames.methods, this.selectedMethods)
202
216
  }
203
217
  },
204
- // 新增:初始化支付数据
205
- initPaymentData (methodKey) {
206
- this.$set(this.paymentAmounts, methodKey, '')
218
+ // 新增:初始化支付数据(可传入初始金额,默认空字符串)
219
+ initPaymentData (methodKey, initialValue = '') {
220
+ this.$set(this.paymentAmounts, methodKey, initialValue)
207
221
  if (!this.data.paymentAmounts || typeof this.data.paymentAmounts !== 'object') this.$set(this.data, 'paymentAmounts', {})
208
- this.$set(this.data.paymentAmounts, methodKey, '')
222
+ this.$set(this.data.paymentAmounts, methodKey, initialValue)
209
223
  },
210
224
  // 新增:移除支付数据
211
225
  removePaymentData (methodKey) {
@@ -217,11 +231,7 @@ export default {
217
231
  const method = this.config.paymentMethods.find(m => m.key === methodKey)
218
232
  return method ? method.label : methodKey
219
233
  },
220
- // 获取金额字段展示名(配置映射 / paymentMethods.amountLabel / 默认「{方式}金额」)
221
- getAmountLabel (methodKey) {
222
- return (this.amountLabelMap && this.amountLabelMap[methodKey]) || `${methodKey}金额`
223
- },
224
- // 新增:获取支付金额字段标签(优先配置映射,其次方法自带 amountLabel,最后回退)
234
+ // 获取支付金额字段标签(优先配置映射,其次方法自带 amountLabel,最后回退)
225
235
  getAmountLabel (methodKey) {
226
236
  const mapped = (this.config.paymentAmountLabels && this.config.paymentAmountLabels[methodKey]) || ''
227
237
  if (mapped) return mapped
@@ -268,22 +278,44 @@ export default {
268
278
  if (res.eventNames && typeof res.eventNames === 'object') {
269
279
  this.eventNames = { ...this.eventNames, ...res.eventNames }
270
280
  }
271
- this.selectedMethod = res.paymentMethods?.[0]?.key || ''
272
-
273
- // 如果启用混合支付,初始化选中状态
274
- if (this.isMixedPaymentEnabled && res.paymentMethods?.length > 0) {
275
- this.selectedMethods = [res.paymentMethods[0].key]
276
- this.initPaymentData(res.paymentMethods[0].key)
277
- } else if (!this.isMixedPaymentEnabled && this.selectedMethod) {
278
- // 单一支付初始化
279
- this.initPaymentData(this.selectedMethod)
281
+ // 处理默认选中项(支持 paymentMethods[].default === true)
282
+ const methods = Array.isArray(this.config.paymentMethods) ? this.config.paymentMethods : []
283
+ const defaultMethods = methods.filter(m => m && m.default === true)
284
+
285
+ if (this.isMixedPaymentEnabled) {
286
+ // 混合支付:默认选中全部 default=true 的方式;若没有默认,则保留现有逻辑选择第一个
287
+ if (defaultMethods.length > 0) {
288
+ this.selectedMethods = defaultMethods.map(m => m.key).filter(Boolean)
289
+ } else if (methods.length > 0) {
290
+ this.selectedMethods = [methods[0].key]
291
+ } else {
292
+ this.selectedMethods = []
293
+ }
294
+ // 初始化金额为 0
295
+ this.selectedMethods.forEach(k => this.initPaymentData(k, 0))
296
+ this.selectedMethod = this.selectedMethods[0] || ''
297
+ // 同步到数据模型
298
+ this.data.selectedMethods = [...this.selectedMethods]
299
+ } else {
300
+ // 单一支付:若存在默认项,选中第一个默认;否则选中第一个
301
+ if (defaultMethods.length > 0) {
302
+ this.selectedMethod = defaultMethods[0] && defaultMethods[0].key || ''
303
+ } else {
304
+ this.selectedMethod = methods[0] && methods[0].key || ''
305
+ }
306
+ if (this.selectedMethod) this.initPaymentData(this.selectedMethod, 0)
307
+ // 同步到数据模型,单一模式下也记录 selectedMethods
308
+ this.data.selectedMethods = this.selectedMethod ? [this.selectedMethod] : []
280
309
  }
281
310
 
282
311
  // 初始化数据:仅当传入了有效 param 时才拉取数据
283
312
  const hasParam = param && Object.keys(param || {}).length > 0
284
313
  if (hasParam && res.dataSourceConfig) {
285
314
  runLogic(res.dataSourceConfig, param, 'af-his').then(resData => {
286
- this.data = { ...resData }
315
+ // 合并数据,避免覆盖 selectedMethods / paymentAmounts 等本地状态
316
+ this.data = { ...this.data, ...resData }
317
+ // 让本地状态与 data 保持一致
318
+ this.hydrateFromData()
287
319
  }).catch(error => {
288
320
  console.warn('数据获取失败(保持现有数据):', error)
289
321
  })
@@ -295,10 +327,12 @@ export default {
295
327
  this.getConfig(this.queryParamsName, param)
296
328
  },
297
329
  async init (conditionData) {
298
- if(conditionData.data){
299
- this.data = { ...conditionData.data }
330
+ if (conditionData.data) {
331
+ // 合并初始化数据,避免覆盖 selectedMethods / paymentAmounts 等本地状态
332
+ this.data = { ...this.data, ...conditionData.data }
333
+ this.hydrateFromData()
300
334
  }
301
- if(conditionData.params){
335
+ if (conditionData.params) {
302
336
  await this.getConfig(this.queryParamsName, conditionData.params)
303
337
  }
304
338
  this.hasInitialized = true
@@ -342,9 +376,16 @@ export default {
342
376
  this.$emit(this.eventNames.action, actionData)
343
377
  },
344
378
  bottomFieldsChange (e, item) {
345
- if (item.changeEventName && this.$listeners[item.changeEventName]) {
346
- this.$emit(item.changeEventName, e, item)
347
- }
379
+ // 统一抛出到底部字段变更事件到父级组件
380
+ this.$emit('bottomFieldChange', {
381
+ event: e,
382
+ item: item,
383
+ field: item.field,
384
+ value: e && e.target ? e.target.value : undefined
385
+ })
386
+
387
+ // 保持原有的自定义事件逻辑(向后兼容)
388
+ if (item.changeEventName && this.$listeners[item.changeEventName]) this.$emit(item.changeEventName, e, item)
348
389
  }
349
390
  },
350
391
  watch: {