Commit dbafbb13db9c9fc37671e3819adb1801b734f3df

Authored by 史婷婷
1 parent c75e27cb

feat: 变更单-新增&编辑-数量kg-数量字段改为可输入两位小数(包括合计)

@@ -393,7 +393,8 @@ export default { @@ -393,7 +393,8 @@ export default {
393 const v = Number(it && it.quantity) 393 const v = Number(it && it.quantity)
394 return acc + (isNaN(v) ? 0 : v) 394 return acc + (isNaN(v) ? 0 : v)
395 }, 0) 395 }, 0)
396 - this.form.afterTotalQuantity = sum 396 + const fixedSum = Number(sum.toFixed(2))
  397 + this.form.afterTotalQuantity = fixedSum
397 }, 398 },
398 } 399 }
399 } 400 }
@@ -312,7 +312,8 @@ export default { @@ -312,7 +312,8 @@ export default {
312 const v = Number(it && it.quantity) 312 const v = Number(it && it.quantity)
313 return acc + (isNaN(v) ? 0 : v) 313 return acc + (isNaN(v) ? 0 : v)
314 }, 0) 314 }, 0)
315 - this.form.afterTotalQuantity = sum 315 + const fixedSum = Number(sum.toFixed(2));
  316 + this.form.afterTotalQuantity = fixedSum;
316 }, 317 },
317 } 318 }
318 } 319 }
@@ -113,8 +113,9 @@ @@ -113,8 +113,9 @@
113 <template v-slot:footer> 113 <template v-slot:footer>
114 <uni-easyinput type="digit" v-model="item.quantity" placeholder="请输入数量kg" 114 <uni-easyinput type="digit" v-model="item.quantity" placeholder="请输入数量kg"
115 :inputBorder="false" 115 :inputBorder="false"
116 - @input="onNonNegativeNumberInput($event, item, idx, 'quantity')"  
117 - @blur="onNonNegativeNumberBlur(item, idx, 'quantity')" /> 116 + @input="onTwoDecimalInput($event, item, idx, 'quantity')"
  117 + @blur="onTwoDecimalBlur(item, idx, 'quantity')"
  118 + />
118 </template> 119 </template>
119 </uni-list-item> 120 </uni-list-item>
120 <uni-list-item v-if="item.showSalesPrice" title="销售价格"> 121 <uni-list-item v-if="item.showSalesPrice" title="销售价格">
@@ -380,6 +381,49 @@ export default { @@ -380,6 +381,49 @@ export default {
380 if (isNaN(n)) item[field] = '' 381 if (isNaN(n)) item[field] = ''
381 if (typeof idx === 'number') this.$set(this.items, idx, { ...item }) 382 if (typeof idx === 'number') this.$set(this.items, idx, { ...item })
382 }, 383 },
  384 + // 限制输入为2位小数
  385 + onTwoDecimalInput(val, item, idx, field) {
  386 + let v = String(val != null ? val : (item && item[field]) || '')
  387 + v = v.replace(/[^0-9.]/g, '')
  388 + v = v.replace(/(\..*)\./g, '$1')
  389 +
  390 + // Restrict to 2 decimal places
  391 + const decimalIndex = v.indexOf('.')
  392 + if (decimalIndex !== -1 && v.length > decimalIndex + 3) {
  393 + v = v.substring(0, decimalIndex + 3)
  394 + }
  395 +
  396 + if (v.startsWith('.')) v = '0' + v
  397 +
  398 + // If the value was modified (truncated or cleaned)
  399 + if (String(val) !== v) {
  400 + // Hack: Temporarily set the dirty value to trigger Vue update mechanism
  401 + // This ensures that when we set the clean value back, Vue detects a change
  402 + item[field] = val
  403 + if (typeof idx === 'number') this.$set(this.items, idx, { ...item })
  404 +
  405 + // Then revert to the clean value asynchronously
  406 + setTimeout(() => {
  407 + item[field] = v
  408 + if (typeof idx === 'number') this.$set(this.items, idx, { ...item })
  409 + }, 0)
  410 + } else {
  411 + item[field] = v
  412 + if (typeof idx === 'number') this.$set(this.items, idx, { ...item })
  413 + }
  414 + },
  415 + onTwoDecimalBlur(item, idx, field) {
  416 + let v = String((item && item[field]) || '')
  417 + const num = Number(v)
  418 + if (isNaN(num) || num < 0) {
  419 + item[field] = '0'
  420 + } else {
  421 + if (v.endsWith('.')) {
  422 + item[field] = v.slice(0, -1)
  423 + }
  424 + }
  425 + if (typeof idx === 'number') this.$set(this.items, idx, { ...item })
  426 + },
383 toggleViewCollapse() { 427 toggleViewCollapse() {
384 this.collapsedView = !this.collapsedView 428 this.collapsedView = !this.collapsedView
385 }, 429 },