change
This commit is contained in:
@@ -1,34 +1,135 @@
|
|||||||
<template>
|
<template>
|
||||||
<input
|
<input
|
||||||
class="filter_input"
|
|
||||||
type="number"
|
type="number"
|
||||||
:value="value"
|
:value="displayValue"
|
||||||
:placeholder="placeholder"
|
@input="handleInput"
|
||||||
@input="onInput"
|
@blur="handleBlur"
|
||||||
@confirm="onInput"
|
:class="inputClass"
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
export default {
|
export default {
|
||||||
|
name: "NumberInput",
|
||||||
props: {
|
props: {
|
||||||
value: {
|
value: [Number, String],
|
||||||
type: [Number, String],
|
inputClass: {
|
||||||
default: '',
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
// 输入模式:integer(纯整数), decimal(纯小数), mixed(混合)
|
||||||
|
mode: {
|
||||||
|
type: String,
|
||||||
|
default: "mixed",
|
||||||
|
validator: (v) => ["integer", "decimal", "mixed"].includes(v),
|
||||||
|
},
|
||||||
|
// 小数位数限制
|
||||||
|
decimalLength: {
|
||||||
|
type: Number,
|
||||||
|
default: 2,
|
||||||
|
},
|
||||||
|
// 最小值
|
||||||
|
min: {
|
||||||
|
type: Number,
|
||||||
|
default: 0,
|
||||||
|
},
|
||||||
|
// 最大值
|
||||||
|
max: {
|
||||||
|
type: Number,
|
||||||
|
default: Infinity,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
displayValue: this.value?.toString() || "",
|
||||||
|
};
|
||||||
|
},
|
||||||
|
watch: {
|
||||||
|
value(newVal) {
|
||||||
|
this.displayValue = newVal?.toString() || "";
|
||||||
},
|
},
|
||||||
placeholder: String
|
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
onInput(event) {
|
handleInput(e) {
|
||||||
// 获取输入值
|
let value = e.detail.value;
|
||||||
const value = event.detail ? event.detail.value : event.target.value;
|
|
||||||
// 格式化输入值
|
// 1. 过滤非法字符
|
||||||
let formattedValue = value.replace(/[^0-9.]/g, '')
|
let filtered = value.replace(/[^\d.]/g, "");
|
||||||
formattedValue = parseFloat(formattedValue)
|
|
||||||
formattedValue = formattedValue > 0 ? formattedValue : ''
|
// 2. 处理多余的小数点
|
||||||
this.$emit('input', formattedValue);
|
if (this.mode === "integer") {
|
||||||
event.target.value = formattedValue
|
filtered = filtered.replace(/\./g, ""); // 整数模式删除所有小数点
|
||||||
}
|
} else {
|
||||||
|
const firstDotIndex = filtered.indexOf(".");
|
||||||
|
if (firstDotIndex !== -1) {
|
||||||
|
// 只保留第一个小数点
|
||||||
|
filtered =
|
||||||
|
filtered.substring(0, firstDotIndex + 1) +
|
||||||
|
filtered.substring(firstDotIndex + 1).replace(/\./g, "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. 处理前导0
|
||||||
|
if (filtered.startsWith("0") && filtered.length > 1 && !filtered.startsWith("0.")) {
|
||||||
|
filtered = filtered.replace(/^0+/, "0").replace(/^0([^.])/, "$1");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. 处理开头的小数点
|
||||||
|
if (filtered.startsWith(".")) {
|
||||||
|
if (this.mode === "integer") {
|
||||||
|
filtered = "";
|
||||||
|
} else {
|
||||||
|
filtered = "0" + filtered;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.displayValue = filtered;
|
||||||
|
},
|
||||||
|
|
||||||
|
handleBlur() {
|
||||||
|
let value = this.displayValue;
|
||||||
|
|
||||||
|
// 空值处理
|
||||||
|
if (value === "" || value === ".") {
|
||||||
|
this.$emit("input", "");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理结尾的小数点
|
||||||
|
if (value.endsWith(".")) {
|
||||||
|
value = value.slice(0, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 转换为数字
|
||||||
|
const numValue = Number(value);
|
||||||
|
|
||||||
|
// 小数位数处理
|
||||||
|
let processedValue = value;
|
||||||
|
if (this.mode !== "integer" && value.includes(".")) {
|
||||||
|
const parts = value.split(".");
|
||||||
|
if (parts[1].length > this.decimalLength) {
|
||||||
|
processedValue = `${parts[0]}.${parts[1].slice(0, this.decimalLength)}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 范围校验
|
||||||
|
let finalNum = Number(processedValue);
|
||||||
|
if (finalNum < this.min) finalNum = this.min;
|
||||||
|
if (finalNum > this.max) finalNum = this.max;
|
||||||
|
|
||||||
|
// 更新值
|
||||||
|
this.displayValue = finalNum.toString();
|
||||||
|
this.$emit("input", finalNum);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.number-input {
|
||||||
|
border: 1px solid #ddd;
|
||||||
|
padding: 8px 12px;
|
||||||
|
border-radius: 4px;
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|||||||
34
components/NumberInput0.vue
Normal file
34
components/NumberInput0.vue
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
<template>
|
||||||
|
<input
|
||||||
|
class="filter_input"
|
||||||
|
type="number"
|
||||||
|
:value="value"
|
||||||
|
:placeholder="placeholder"
|
||||||
|
@input="onInput"
|
||||||
|
@confirm="onInput"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
props: {
|
||||||
|
value: {
|
||||||
|
type: [Number, String],
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
placeholder: String
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
onInput(event) {
|
||||||
|
// 获取输入值
|
||||||
|
const value = event.detail ? event.detail.value : event.target.value;
|
||||||
|
// 格式化输入值
|
||||||
|
let formattedValue = value.replace(/[^0-9.]/g, '')
|
||||||
|
formattedValue = parseFloat(formattedValue)
|
||||||
|
formattedValue = formattedValue > 0 ? formattedValue : ''
|
||||||
|
this.$emit('input', formattedValue);
|
||||||
|
event.target.value = formattedValue
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
|
</script>
|
||||||
@@ -106,10 +106,12 @@
|
|||||||
onShow() {
|
onShow() {
|
||||||
if (this.$store.getters.publicObj !== '') {
|
if (this.$store.getters.publicObj !== '') {
|
||||||
this.currentData = this.$store.getters.publicObj
|
this.currentData = this.$store.getters.publicObj
|
||||||
|
this.$store.dispatch('setPublicObj', '')
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created () {
|
created () {
|
||||||
this._getPdaSect()
|
this._getPdaSect()
|
||||||
|
this._getPdaStruct(e)
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
toJump () {
|
toJump () {
|
||||||
@@ -131,7 +133,7 @@
|
|||||||
},
|
},
|
||||||
async _getPdaStruct (e) {
|
async _getPdaStruct (e) {
|
||||||
try {
|
try {
|
||||||
let res = await getPdaStruct(e)
|
let res = await getPdaStruct(this.index)
|
||||||
if (res) {
|
if (res) {
|
||||||
this.options2 = res.data
|
this.options2 = res.data
|
||||||
} else {
|
} else {
|
||||||
@@ -162,7 +164,7 @@
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
let res = await checkoutbillcallMaterial(this.index, this.index2, this.currentData.material_code, this.index4)
|
let res = await checkoutbillcallMaterial(this.val1, this.index2, this.currentData.material_code, this.index4)
|
||||||
if (res.code === '200') {
|
if (res.code === '200') {
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: res.message,
|
title: res.message,
|
||||||
|
|||||||
@@ -28,6 +28,7 @@
|
|||||||
<uni-data-select v-model="index4" :localdata="options4" @change="selectChange4"></uni-data-select>
|
<uni-data-select v-model="index4" :localdata="options4" @change="selectChange4"></uni-data-select>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
<view v-if="index4 === '1'">
|
||||||
<view class="zd-row border-bottom">
|
<view class="zd-row border-bottom">
|
||||||
<view class="zd-col-7">
|
<view class="zd-col-7">
|
||||||
<span class="filter_label">物料信息</span>
|
<span class="filter_label">物料信息</span>
|
||||||
@@ -65,10 +66,15 @@
|
|||||||
<span class="filter_label">物料数量</span>
|
<span class="filter_label">物料数量</span>
|
||||||
</view>
|
</view>
|
||||||
<view class="zd-col-17">
|
<view class="zd-col-17">
|
||||||
<NumberInput v-model="val3" />
|
<!-- <NumberInput v-model="val3" /> -->
|
||||||
|
<NumberInput
|
||||||
|
v-model="val3"
|
||||||
|
mode="integer"
|
||||||
|
/>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<view class="zd-row submit-bar">
|
<view class="zd-row submit-bar">
|
||||||
<button class="zd-col-6 button-default" @tap="clearUp">清空</button>
|
<button class="zd-col-6 button-default" @tap="clearUp">清空</button>
|
||||||
@@ -80,11 +86,13 @@
|
|||||||
<script>
|
<script>
|
||||||
import NavBar from '@/components/NavBar.vue'
|
import NavBar from '@/components/NavBar.vue'
|
||||||
import SearchBox from '@/components/SearchBox.vue'
|
import SearchBox from '@/components/SearchBox.vue'
|
||||||
|
import NumberInput from '@/components/NumberInput.vue'
|
||||||
import {checkoutbillBackMaterial} from '@/utils/getData4.js'
|
import {checkoutbillBackMaterial} from '@/utils/getData4.js'
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
NavBar,
|
NavBar,
|
||||||
SearchBox
|
SearchBox,
|
||||||
|
NumberInput
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
@@ -104,6 +112,7 @@
|
|||||||
onShow() {
|
onShow() {
|
||||||
if (this.$store.getters.publicObj !== '') {
|
if (this.$store.getters.publicObj !== '') {
|
||||||
this.currentData = this.$store.getters.publicObj
|
this.currentData = this.$store.getters.publicObj
|
||||||
|
this.$store.dispatch('setPublicObj', '')
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created () {
|
created () {
|
||||||
|
|||||||
Reference in New Issue
Block a user