cart_collect_temp.js
5.33 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
165
166
167
168
169
170
171
172
var regeneratorRuntime = require('../../utils/runtime.js');
var os = getApp().globalData.setting
Component({
properties: {
// 这里定义了数据列表属性,列表显示数据
all_collocation_list: {
type: Array,
value: null
},
// 是不是购物车
is_cart: {
type: Boolean,
value: false
},
// 购物车的索引
cart_index: {
type: Number,
value: 0
},
//主商品物流方式
distr_t: {
type: Number,
value: 0
},
sales_rules: {
type: Number,
value: 1
},
pick:{
type: Number,
value: 1
},
appoint_pick_keyid:{
type: String,
value: ''
}
},
/*** 页面的初始数据***/
data: {
imgUrl: getApp().globalData.setting.imghost,
},
methods: {
async select_coll(e) {
var th=this;
var index = e.currentTarget.dataset.index;
var itr = this.properties.all_collocation_list[index];
var ob = {
index: index,
selected: !itr.selected
}
if(this.properties.is_cart){
ob.is_cart =1;
ob.cart_index =this.properties.cart_index;
}
if(th.data.sales_rules>1){
var isok = 1;
await th.check_store_num(itr.goods_id, th.data.pick, 1, function (res){
isok = res;
})
if(!isok){
wx.showToast({
title: itr.goods_name+"商品库存不足",
icon: 'none',
duration: 2000
})
return false;
}
}
this.triggerEvent('childFun', ob);
if(!ob.selected) {
var txt = "all_collocation_list[" + index + "].selected"
this.setData({[txt]: ob.selected})
}
},
//图片失败,默认图片
bind_bnerr3: function (e) {
var _errImg = e.target.dataset.errorimg;
var _Img = e.target.dataset.img;
if (_Img != undefined) {
var _errObj = {};
_errObj[_errImg] = "/public/images/default_goods_image_240.gif";
this.setData(_errObj) //注意这里的赋值方式,只是将数据列表中的此项图片路径值替换掉 ;
}
},
//---确认线下门店的数量足不足---
async check_store_num(goods_id, pick, goods_num, func) {
var lock = 0, pick_no, plist, erpwareid;
var lock_rq={ store_id: os.stoid, wareId: goods_id, storageId: pick, pageSize: 1000 };
if(this.data.sales_rules==3){
lock_rq.appoint_pick_keyid=this.data.appoint_pick_keyid;
delete lock_rq.storageId
}
//先读取门店的lock
await getApp().request.promiseGet("/api/weshop/order/ware/lock/page", {
data: lock_rq
}).then(res => {
if (res.data.code == 0 && res.data.data.total > 0) {
for (var i in res.data.data.pageData)
lock += res.data.data.pageData[i].outQty;
}
})
if(this.data.sales_rules==2) {
//先获取门店的编号
await getApp().request.promiseGet("/api/weshop/pickup/get/" + os.stoid + "/" + pick, {
}).then(res => {
if (res.data.code == 0) {
pick_no = res.data.data.pickup_no;
}
})
}
//先获取商品的线下库存
await getApp().request.promiseGet("/api/weshop/goods/get/" + os.stoid + "/" + goods_id, {
}).then(res => {
if (res.data.code == 0) {
erpwareid = res.data.data.erpwareid;
}
})
var sto_rq={ storageNos: pick_no, wareIds: encodeURIComponent(erpwareid), storeId: os.stoid, pageSize: 2000 };
if(this.data.sales_rules==3){
sto_rq.storageIds=this.data.appoint_pick_keyid;
delete sto_rq.storageNos
}
//读取线下的门店库存
await getApp().request.promiseGet("/api/weshop/goods/getWareStorages", {
data: sto_rq
}).then(res => {
if (res.data.code == 0 && res.data.data.total > 0) {
plist = res.data.data.pageData[0];
}
})
var isok = 1;
if (!plist || goods_num > plist.CanOutQty - lock) {
isok = 0;
}
func(isok);
},
set_sele(index){
var txt = "all_collocation_list[" + index + "].selected"
this.setData({[txt]: 1})
},
//-- 清理所有的选择 --
clear_sele(){
var all_collocation_list=this.data.all_collocation_list;
for (let i = 0; i <all_collocation_list.length ; i++) {
all_collocation_list[i].selected=0;
}
this.setData({all_collocation_list})
}
}
})