Commit 795b6561fa3ee27fedbe5268964470995f209c06

Authored by 史婷婷
1 parent dbafbb13

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

... ... @@ -273,7 +273,8 @@ export default {
273 273 const v = Number(it && it.revokeQuantity)
274 274 return acc + (isNaN(v) ? 0 : v)
275 275 }, 0)
276   - this.form.totalRevokeQuantity = sum
  276 + const fixedSum = Number(sum.toFixed(2))
  277 + this.form.totalRevokeQuantity = fixedSum
277 278 },
278 279 }
279 280 }
... ...
... ... @@ -195,7 +195,8 @@ export default {
195 195 const v = Number(it && it.revokeQuantity)
196 196 return acc + (isNaN(v) ? 0 : v)
197 197 }, 0)
198   - this.form.totalRevokeQuantity = sum
  198 + const fixedSum = Number(sum.toFixed(2))
  199 + this.form.totalRevokeQuantity = fixedSum
199 200 },
200 201 }
201 202 }
... ...
... ... @@ -63,8 +63,10 @@
63 63 <uni-list-item title="撤销数量kg">
64 64 <template v-slot:footer>
65 65 <uni-easyinput type="digit" v-model="item.revokeQuantity" placeholder="请输入撤销数量kg"
66   - :inputBorder="false" @input="onRevokeQuantityInput($event, item, idx)"
67   - @blur="onRevokeQuantityBlur(item, idx)" />
  66 + :inputBorder="false"
  67 + @input="onTwoDecimalInput($event, item, idx, 'revokeQuantity')"
  68 + @blur="onTwoDecimalBlur(item, idx, 'revokeQuantity')"
  69 + />
68 70 </template>
69 71 </uni-list-item>
70 72 </uni-list>
... ... @@ -209,6 +211,49 @@ export default {
209 211 if (isNaN(num) || num < 0) { item.revokeQuantity = '0'; if (typeof idx === 'number') this.$set(this.items, idx, { ...item }); return }
210 212 if (typeof idx === 'number') this.$set(this.items, idx, { ...item })
211 213 },
  214 + // 限制输入为2位小数
  215 + onTwoDecimalInput(val, item, idx, field) {
  216 + let v = String(val != null ? val : (item && item[field]) || '')
  217 + v = v.replace(/[^0-9.]/g, '')
  218 + v = v.replace(/(\..*)\./g, '$1')
  219 +
  220 + // Restrict to 2 decimal places
  221 + const decimalIndex = v.indexOf('.')
  222 + if (decimalIndex !== -1 && v.length > decimalIndex + 3) {
  223 + v = v.substring(0, decimalIndex + 3)
  224 + }
  225 +
  226 + if (v.startsWith('.')) v = '0' + v
  227 +
  228 + // If the value was modified (truncated or cleaned)
  229 + if (String(val) !== v) {
  230 + // Hack: Temporarily set the dirty value to trigger Vue update mechanism
  231 + // This ensures that when we set the clean value back, Vue detects a change
  232 + item[field] = val
  233 + if (typeof idx === 'number') this.$set(this.items, idx, { ...item })
  234 +
  235 + // Then revert to the clean value asynchronously
  236 + setTimeout(() => {
  237 + item[field] = v
  238 + if (typeof idx === 'number') this.$set(this.items, idx, { ...item })
  239 + }, 0)
  240 + } else {
  241 + item[field] = v
  242 + if (typeof idx === 'number') this.$set(this.items, idx, { ...item })
  243 + }
  244 + },
  245 + onTwoDecimalBlur(item, idx, field) {
  246 + let v = String((item && item[field]) || '')
  247 + const num = Number(v)
  248 + if (isNaN(num) || num < 0) {
  249 + item[field] = '0'
  250 + } else {
  251 + if (v.endsWith('.')) {
  252 + item[field] = v.slice(0, -1)
  253 + }
  254 + }
  255 + if (typeof idx === 'number') this.$set(this.items, idx, { ...item })
  256 + },
212 257 toggleViewCollapse() {
213 258 this.collapsedView = !this.collapsedView
214 259 }
... ...