schangxiang@126.com
2024-08-28 6667b0cc7e221402fd50582151457fcf9ac38622
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
<template>
    <view class="scan-input-form-item-compontent">
        <view class="p-form-label" v-if="label">{{label}}:</view>
        <view class="input-row">
            <view class="mask" @tap.stop="" v-if="disabled"></view>
            <view class="input-view">
                <u-input ref="uinput" :focus="inputFocus" :clearable="clearable" border="none" :type="type"
                    :placeholder="placeholder" v-model.trim="innerValue" @clear="onClear" @blur="onBlur"
                    @change="onChange"
                    @confirm="onConfirm" />
            </view>
            <!-- <view class="scan-view">
                <view @tap.stop="onScan"><u-icon name="scan" color="#F18201" :size="32"></u-icon></view>
            </view>
            <view class="btn-view" v-if="hasSearch">
                <view class="search-btn" @tap.stop="onSearch">搜</view>
            </view> -->
        </view>
        <view class="msg-row" v-if="msg" :class="[msgType==='info'?'info-type':'']">{{msg}}</view>
    </view>
</template>
 
<script>
    
    export default {
        name: 'ScanInputFormItemCompontent',
        // emits: ['input', 'search', 'clear', 'blur', 'confirm'],
        props: {
            type: {
                type: String,
                default: 'text'
            },
            label: {
                type: String,
                default: ''
            },
            placeholder: {
                type: String,
                default: '请输入...'
            },
            msg: {
                type: String,
                default: ''
            },
            msgType: {
                type: String,
                default: 'error'
            },
            value: {
                type: [String, Number, null],
                default: ''
            },
            hasSearch: {
                type: Boolean,
                default: true
            },
            disabled: {
                type: Boolean,
                default: false
            },
            clearable: {
                type: Boolean,
                default: true
            },
            inputFocus: {
                type: Boolean,
                default: true
            },
            // codeLength:{
            //     type: Number,
            //     default: 1
            // }
        },
        data() {
            return {
                innerValue: '',
                confirmType:'handle'
            }
        },
        watch: {
            value(newVal, oldVal) {
                if (newVal !== this.innerValue) {
                    this.innerValue = newVal
                }
            },
            innerValue(newVal, oldVal) {
                if (newVal !== this.value) {
                    this.$emit('input', newVal)
                }
                if(newVal&&this.confirmType=='auto') {
                    this.$emit('search', newVal)
                    this.confirmType='handle'
                }
            }
        },
 
        methods: {
            
            onScan() {
                uni.scanCode({
                    success: function(res) {
                        this.innerValue = res.result;
                    },
                    fail: function() {
                        console.log('scanCode fail')
                    }
                })
            },
            onSearch() {
                this.$emit('search', this.innerValue)
            },
            onClear() {
                this.innerValue = null;
                this.$emit('clear')
            },
            onBlur() {
                this.$emit('blur', this.innerValue)
            },
            onChange(val) {
                //debugger
                //alert(val);
                this.$emit('search', val)
            },
            onConfirm(val) {
                //debugger
                /*
                if(val!=this.innerValue) {
                    this.confirmType='auto'
                }
                
                if(val) {
                    this.$emit('search', val)
                }
                //*/
            },
        },
        created() {
            this.innerValue = this.value
        },
 
    }
</script>
 
<style scoped lang="scss">
    .scan-input-form-item-compontent {
        width: 100%;
 
        .p-form-label {
            font-size: 32rpx;
            color: $u-tips-color;
            padding-bottom: 12rpx;
            padding-left: 20rpx;
        }
 
        .input-row {
            width: 100%;
            height: 90rpx;
            overflow: hidden;
            background-color: $uni-bg-color;
            display: flex;
            align-items: center;
            position: relative;
 
            .scan-view,
            .btn-view {
                flex-shrink: 0;
            }
 
            .scan-view {
                display: flex;
                align-items: center;
                justify-content: center;
                padding-right: 10rpx;
            }
 
            .input-view {
                flex-grow: 1;
                padding-left: 20rpx;
            }
 
            .btn-view {
                width: 70rpx;
                height: 100%;
                padding: 20rpx;
                padding-left: 0rpx;
                box-sizing: border-box;
 
                .search-btn {
                    height: 100%;
                    width: 100%;
                    border-radius: 8rpx;
                    background: linear-gradient(157.342820970935deg, rgba(194, 128, 255, 1) -20%, rgba(194, 128, 255, 1) -19%, rgba(132, 0, 255, 1) 119%);
                    display: flex;
                    align-items: center;
                    justify-content: center;
                    color: $uni-bg-color;
                    font-size: 26rpx;
                }
            }
 
            &>.mask {
                position: absolute;
                left: 0;
                top: 0;
                width: 100%;
                height: 100%;
                z-index: 100;
                background-color: #000;
                opacity: 0.25;
            }
        }
 
        .msg-row {
            padding: 6rpx 20rpx 0 20rpx;
            line-height: 1.3;
            font-size: 24rpx;
            color: $u-error;
 
            &.info-type {
                color: $color-blue;
            }
        }
    }
</style>