InventoryInfo.js
2.76 KB
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
// components/InventoryInfo/InventoryInfo.js
Component({
/**
* 组件的属性列表
*/
properties: {
// 是否显示弹窗
show: {
type: Boolean,
value: false,
observer: 'onShowChange'
},
// 库存信息数据
inventoryData: {
type: Object,
value: {},
observer: 'onDataChange'
},
// 自定义标题
title: {
type: String,
value: '库存信息'
}
},
/**
* 组件的初始数据
*/
data: {
// 弹窗显示状态
isShowing: false,
// 缓存的数据
dataList:[]
},
/**
* 组件的方法列表
*/
methods: {
/**
* 显示弹窗
*/
showPopup() {
this.setData({
isShowing: true
});
},
/**
* 隐藏弹窗
*/
hidePopup() {
this.setData({
isShowing: false
});
},
/**
* 关闭弹窗事件处理
*/
onClose() {
this.hidePopup();
// 触发关闭事件
this.triggerEvent('close');
},
/**
* 复制文本到剪贴板
*/
copyText(e) {
const { text } = e.currentTarget.dataset;
wx.setClipboardData({
data: text,
success: () => {
wx.showToast({
title: '复制成功',
icon: 'success',
duration: 1500
});
},
fail: () => {
wx.showToast({
title: '复制失败',
icon: 'none',
duration: 1500
});
}
});
},
/**
* 监听show属性变化
*/
onShowChange(newVal, oldVal) {
if (newVal !== oldVal) {
this.setData({
isShowing: newVal
});
}
},
/**
* 监听数据变化
*/
onDataChange(newVal, oldVal) {
if (newVal && typeof newVal === 'object') {
const dataList = Object.keys(newVal).map(key => ({
key: key,
value: newVal[key],
label: this.getFieldLabel(key)
}));
this.setData({
dataList: dataList
},()=>{
console.log(this.data.dataList)
});
}
},
/**
* 获取字段值(支持格式化)
*/
getFieldLabel(field) {
const fieldMap = {
upgradeGoodsCommodityCode: 'UID',
upgradeGoodsCustomCode: '商品编码',
specification: '规格值',
stock: '库存总数'
};
return fieldMap[field] || field;
},
/**
* 获取字段值
*/
getFieldValue(field) {
const data = this.data.cachedData;
return data ? data[field] : '';
}
},
/**
* 组件生命周期函数
*/
lifetimes: {
attached() {
// 组件创建完成后执行
},
detached() {
// 组件销毁时执行
}
},
/**
* 外部样式类
*/
externalClasses: [
'custom-class'
]
});