#
whycq
2023-12-01 d8e6f395fea1419c73f6b6f0a2ddd75eac3eed84
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
<template>
    <view>
        <view class="main">
            <view class="inner1">{{attribute.lable}}</view>
            <view class="put inner2">
                <uni-icons class="p-icon"
                    type="scan" 
                    size="16" 
                    color="#a6a6a6" 
                    @click="scanCode"
                    v-show="attribute.scanCode"
                    >
                </uni-icons>
                <input class="p-input" 
                    type="text" 
                    :placeholder="placeholder" 
                    v-model="zzz" 
                    :focus="focusData" 
                    @input="change"
                    >
                    
                <uni-icons class="p-icon" 
                    type="closeempty" 
                    size="16" 
                    color="#b9b9b9" 
                    v-show="data.length"
                    @click="clear">
                    
                </uni-icons>
            </view>
            <view class="inner3" v-show="btn">
                <button class="m-btn" size="mini" @click="clickBtn">{{btnName}}</button>
            </view>
        </view>
    </view>
</template>
 
<script>
    export default {
        name:"x-input",
        data() {
            return {
                data:'',
                focusData: false
            };
        },
        props: {
            attribute: {
                type: Object,
                default() {
                    return {}
                }
            },
            index: {
                type: Number,
                default: 0
            },
            lable: {
                type: String,
                default: ''
            },
            name: {
                type: String,
                default: ''
            },
            btn: {
                type: Boolean,
                default: false
            },
            btnName: {
                type: String,
                default: 'button'
            },
            placeholder: {
                type: String,
                default: '扫码 / 录入'
            },
            value: {
                type: [String,Number],
                default: ''
            },
            v: {
                type: [String,Number],
                default: ''
            },
            lenCheck: {
                type: [Number],
                default: null
            },
            focus: {
                type: Boolean,
                default: false
            }
        },
        watch: {
            data(val) {
                // if (!this.lenCheck) {
                //     this.$emit('input',val)
                //     return
                // }
                // if (val.length != this.lenCheck) {
                //     setTimeout(()=>{
                //         this.data = ''
                //         this.$emit('input','')
                //     },10)
                // } else {
                //     this.$emit('input',val)
                // }
            },
            value(val) {
                this.data = val
            },
            focus(f) {
                this.focusData = !f
                setTimeout(()=>{
                    this.focusData = f
                },10)
            },
            zzz(val) {
                // this.v = val
            }
            
        },
        created() {
            this.data = this.value
            this.focusData = this.focus
        },
        methods: {
            change() {
                let _this = this
                console.log(`值改变了: ${this.zzz}`);
                // if (this.data.length > 8) {
                //     this.data = 66666
                // }
                this.$emit('change')
            },
            clear() {
                this.data = ''
                console.log(this.attribute);
            },
            clickBtn() {
                this.$emit('clickBtn');
            },
            inputVal() {
                this.$emit('inputVal',[this.data,this.name]);
            },
            scanCode() {
                let _this = this
                uni.scanCode({
                    onlyFromCamera: true,
                    success(res) {
                        _this.$parent.scanCode(res.result)
                        _this.data = res.result
                        console.log('扫到了');
                        console.log(res);
                    }
                })
            }
        }
    }
</script>
 
<style scoped>
    .main {
        display: flex;
        align-items: center;
        min-height: 50px;
        background-color: #fff;
    }
    .put {
        display: flex;
        flex-shrink: 0;
    }
    
    .inner1 {
        width: 55px;
        padding-left: 8px;
        color: #606164;
        font-weight: 900;
        font-family:'Helvetica Neue';
    }
    .inner2 {
        background-color: #f8f8f8;
        flex: 1;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 5px;
        margin-right: 32rpx;
        color: #606266;
    }
    .p-input {
        flex:1;
        padding: 4px;
    }
    .p-icon {
        margin-left: 4px;
        margin-right: 4px;
    }
    .inner3 {
        width: 90px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    .m-btn {
        background-color: #00aeec;
        color: #FFF;
    }
    .m-btn:active {
        background-color: #55bbff;
        color: #FFF;
    }
 
</style>