-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstock-in.wpy
140 lines (139 loc) · 3.55 KB
/
stock-in.wpy
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
<style lang="scss">
.btn-wrap{
display: flex;
justify-content: space-between;
}
.stock-in-btn{
width: 300rpx;
}
.scan-item {
overflow:hidden;
text-overflow:ellipsis;
white-space:nowrap;
}
.picker{
.desc{
float: right;
color: #808080;
}
}
.result-wrap{
flex: 1;
overflow-y: auto;
}
</style>
<template>
<view class="container">
<toast></toast>
<view class="section">
<picker @change="PickerChange" value="{{storageIndex}}" range="{{storage}}" range-key="name">
<view class="picker">
当前选择:{{curStore.name}} <text class="desc">库存:{{curStore.store.length}}/{{curStore.size}}</text>
</view>
</picker>
</view>
<view class="section">
已扫描:{{scanResults.length}}
</view>
<view class="section result-wrap">
<repeat for="{{scanResultLines}}" key="data">
<swipe-delete :swipeData="item" @delItem.user="deleteScanItem">
<view class="scan-item">{{item.data}}</view>
</swipe-delete>
</repeat>
</view>
<view class="section btn-wrap">
<button class="stock-in-btn" type="primary" @tap="submit">一键入库</button>
<button class="stock-in-btn" @tap="scanCode">点击扫码</button>
</view>
</view>
</template>
<script>
/* global wx */
import wepy from 'wepy'
import swipeDelete from 'wepy-swipe-delete'
import Toast from 'wepy-com-toast'
export default class StockIn extends wepy.page {
config = {
navigationBarTitleText: '入库'
}
components = {
'swipe-delete': swipeDelete,
toast: Toast
}
data = {
storage: wx.getStorageSync('storage'),
storageIndex: 0,
scanResults: [],
scanResultLines: []
}
computed = {
curStore () {
return this.storage[this.storageIndex]
},
curStoreLeft () {
return this.curStore && this.curStore.size - this.curStore.store.length
}
}
watch = {
scanResults (n, o) {
console.log(n)
this.scanResultLines = n.map(d => {
return {
data: d,
style: 0
}
})
}
}
onLoad () {
}
methods = {
PickerChange (e) {
this.storageIndex = e.detail.value
},
scanCode () {
if (this.scanResults.length >= this.curStoreLeft) {
this.toast('当前库位已经装不下更多了~')
} else {
wx.scanCode({
success: res => {
this.toast('success')
const result = res.result
console.log('scan res:', res)
if (~this.findScanItemIndex(result)) {
this.toast('已存在')
} else {
this.scanResults.push(result)
wx.vibrateLong && wx.vibrateLong()
}
this.$apply()
}
})
}
},
deleteScanItem (item) {
const index = this.findScanItemIndex(item.data)
this.scanResults.splice(index, 1)
},
submit () {
if (this.scanResults.length < 1) {
this.toast('您还没有添加商品')
} else {
this.storage[this.storageIndex].store.push(...this.scanResults)
this.scanResults = []
wx.setStorageSync('storage', this.storage)
this.toast('入库成功')
}
}
}
findScanItemIndex (result) {
return this.scanResults.findIndex(d => d === result)
}
toast (txt) {
this.$invoke('toast', 'show', {
title: txt
})
}
}
</script>