PageSourceSearch

https://www.ababbb.com/wp-content/themes/b2/Assets/fontend/carts.js?ver=4.2.6

js ababbb.com collected 2026-10-06 13:15:42 UTC 13,293 bytes, 413 lines download raw bytes

1var carts = new Vue({
2    el:'#carts-list',
3    data:{
4        picked:[],
5        comment:'',
6        address:{
7            addresses:{}
8        },
9        showAddress:false,
10        total:0,
11        dataLength:0,
12        pickedAll:false,
13        step:1,
14        //地址编辑
15        showAddressBox:false,
16        pickedAddress:'',
17        addressEditData:{
18            'address':'',
19            'name':'',
20            'phone':'',
21            'province':'',
22            'city':'',
23            'county':''
24        },
25        editAddressKey:'',
26        coupons:'',
27        pickedCoupon:[],
28        couponTotal:0,
29        //邮箱
30        pickedEmail:'',
31        showEmailBox:false,
32        showEmail:false,
33        getLocked:false,
34        id:0
35    },
36    computed:{
37        data(){
38            
39            if(b2GetQueryVariable('id')){
40                
41                return this.$store.state._carts
42            }else{
43                
44                return this.$store.state.carts
45            }
46        }
47    },
48    mounted(){
49        this.id = b2GetQueryVariable('id'),
50        count = b2GetQueryVariable('count');
51
52        if(count && count <= 0){
53            Qmsg['warning'](b2_global.js_text.global.buy_count_error,{html:true});
54            return
55        }
56
57        if(this.id){
58            this.getItems(this.id,b2GetQueryVariable('index'))
59        }else{
60            this.getCarts()
61        }
62    },
63    methods:{
64        showEmeilBoxAction(){
65            if(!b2token){
66                login.show = true
67                return
68            }
69            this.showEmailBox = true 
70        },
71        showAddressBoxAction(){
72            if(!b2token){
73                login.show = true
74                return
75            }
76            this.showAddressBox = true 
77        },
78        init(){
79            if(Object.keys(this.data).length > 0){
80                Object.keys(this.data).forEach((key)=>{
81                    this.picked.push(key)
82                    if(this.data[key].commodity === 1){
83                        this.showAddress = true
84                    }
85                    this.total += Calc.Mul(this.data[key].price.current_price,this.data[key].count);
86                    this.dataLength++
87                    this.pickedAll = true
88                });
89
90                this.getCoupons()
91                this.getAddress()
92                this.getEmail()
93            }
94        },
95        getCarts(){
96            if(this.getLocked == true) return
97            this.getLocked = true
98            this.$http.get(b2_rest_url+'getMyCarts').then((res)=>{
99                console.log(res.data)
100                if(res.data.length == 0){
101                    this.$store.commit('setcartsData',{})
102                }else{
103                    this.$store.commit('setcartsData',res.data)
104                }
105                this.init()
106                this.getLocked = false
107            })
108        },
109        getCoupons(){
110            if(!b2token){
111                return
112            }
113
114            let ids = {
115                'ids':this.picked
116            }
117            this.$http.post(b2_rest_url+'getCouponsByPostId',Qs.stringify(ids)).then((res)=>{
118                this.coupons = res.data
119                if(this.pickedCoupon.length > 0){
120                    for (let i = 0; i < this.pickedCoupon.length; i++) {
121                        if(this.coupons.hasOwnProperty(this.pickedCoupon[i]) === false){
122                            this.pickedCoupon.splice(i,1)
123                        }
124                    }
125                }
126            })
127        },
128        couponClass(item){
129            if(item.expiration_date.expired) return 'stamp04'
130            if(item.products.length > 0) return 'stamp01'
131            if(item.cats.length > 0) return 'stamp02'
132            return 'stamp03'
133        },
134        pickedCouponArg(id){
135            if(this.pickedCoupon.indexOf(id) !== -1){
136                this.pickedCoupon.splice(this.pickedCoupon.indexOf(id),1)
137            }else{
138                this.pickedCoupon.push(id)
139            }
140        },
141        couponTotalReset(){
142            this.couponTotal = 0;
143            for (let i = 0; i < this.pickedCoupon.length; i++) {
144                this.couponTotal = Calc.Add(this.coupons[this.pickedCoupon[i]].money,this.couponTotal)  
145            }
146        },
147        totalPay(){
148            let total = Calc.Sub(this.total,this.couponTotal);
149            if(total < 0) return 0
150            return total
151        },
152        getItems(id,index){
153            if(this.getLocked == true) return
154            this.getLocked = true
155            let ids = {
156                ids:[id],
157                index:index,
158                return:{
159                    'images':0,
160                    'attrs':0
161                }
162            }
163
164            this.$http.post(b2_rest_url+'getShopItemsData',Qs.stringify(ids)).then((res)=>{
165                let data = res.data
166                data[id].count = b2GetQueryVariable('count')
167
168                this.$store.commit('set_cartsData',res.data)
169                this.init()
170                this.getLocked = false
171            })
172            
173        },
174        getEmail(){
175            this.$http.post(b2_rest_url+'getEmail').then(res=>{
176                if(res.data.status != 403){
177                    this.pickedEmail = res.data
178                }
179            })
180        },
181        getAddress(){
182            this.$http.post(b2_rest_url+'getAddresses').then(res=>{
183                if(Object.keys(res.data.addresses).length > 0){
184                    this.address = res.data
185                    this.pickedAddress = this.address.default
186                }
187            })
188        },
189        mul(price,count){
190            return Calc.Mul(price,count,2)
191        },
192        countAdd(key){
193            if(this.data[key].count >= this.data[key].stock.total) return
194            if(this.picked.indexOf(key) !== -1){
195                this.total = Calc.Add(this.total,this.data[key].price.current_price)
196            }
197            this.data[key].count++
198        },
199        countSub(key){
200            if(this.data[key].count <=1 ) return
201            if(this.picked.indexOf(key) !== -1){
202                this.total = Calc.Sub(this.total,this.data[key].price.current_price)
203            }
204            this.data[key].count--
205        },
206        totalMoney(){
207            return Calc.Add(this.total,0,2);
208        },
209        totalReset(){
210            this.showAddress = false
211            this.showEmail = false
212            this.total = 0
213            console.log(this.picked,this.data)
214            for (let i = 0; i < this.picked.length; i++) {
215                if(this.data[this.picked[i]].commodity === 1){
216                    this.showAddress = true
217                }
218
219                if(this.data[this.picked[i]].commodity === 0){
220                    this.showEmail = true
221                }
222                
223                this.total += Calc.Mul(this.data[this.picked[i]].price.current_price,this.data[this.picked[i]].count);
224            }
225        },
226        allPicked(){
227            if(this.data != 0 && this.data != null){
228                Object.keys(this.data).forEach((key)=>{
229                    if(this.picked.indexOf(key) === -1){
230                        this.picked.push(key)
231                    }
232                });
233            }
234        },
235        //关闭弹窗
236        close(){
237            this.showAddressBox = false
238            this.showEmailBox = false
239        },
240        emptyAddress(){
241            if(this.address === '') return false
242
243            if(!this.data) return false
244            
245            if(this.pickedAddress === '') return false
246
247            return true
248        },
249        deleteAddress(key){
250            var r = confirm(b2_global.js_text.global.delete_address);
251            if (r == true) {
252                this.$http.post(b2_rest_url+'deleteAddress','key='+key).then(res=>{
253                    if(res.data){
254                        this.address.addresses = res.data.address;
255                        if(key === this.address.default){
256                            this.address.default = res.data.default
257                        }
258                        if(this.pickedAddress === key){
259                            this.pickedAddress = res.data.default
260                        }
261                    }
262                }).catch(err=>{
263                    Qmsg['warning'](err.response.data.message,{html:true});
264                })
265            } 
266            return
267        },
268        pickedAddressAc(key){
269            this.pickedAddress = key
270            this.close()
271        },
272        editAddress(key){
273            this.editAddressKey = key
274            this.addressEditData = this.address.addresses[key]
275        },
276        addNewAddress(){
277            this.editAddressKey = uuid(8, 16);
278            this.addressEditData = []
279        },
280        saveAddress(){
281            this.$http.post(b2_rest_url+'saveAddress','address='+this.addressEditData.address+'&name='+this.addressEditData.name+'&phone='+this.addressEditData.phone+'&key='+this.editAddressKey).then(res=>{
282                this.address.addresses = res.data.address;
283                this.$nextTick(()=>{
284                    this.pickedAddressAc(res.data.key)
285                    this.editAddressKey = ''
286                    this.key = ''
287                })
288                
289            }).catch(err=>{
290
291                Qmsg['warning'](err.response.data.message,{html:true});
292            })
293        },
294        //只显示选中商品
295        pickedProducts(key){
296            if(this.picked.indexOf(key) !== -1) return true
297            return false
298        },
299        //支付
300        pay(){
301            if(!b2token){
302                login.show = true
303                return
304            }
305
306            if(this.showAddress === true && this.pickedAddress === ''){
307
308
309                Qmsg['warning'](b2_global.js_text.global.add_address,{html:true});
310                
311                return
312            }
313
314            if(this.showEmail === true && this.pickedEmail == ''){
315
316                Qmsg['warning'](b2_global.js_text.global.add_email,{html:true});
317                return
318            }
319
320            this.step = 2
321            let data = {
322                'products':this.getPickedProducts(),
323                'content':this.comment,
324                'address':this.showAddress ? this.pickedAddress : '',
325                'coupons':this.pickedCoupon,
326                'email':this.pickedEmail ? this.pickedEmail : ''
327            }
328            
329            b2DsBox.data = {
330                'title':b2_global.js_text.global.buy,
331                'order_price':this.totalPay(),
332                'order_type':'g',
333                'post_id':0,
334                'order_value':JSON.stringify(data),
335            }
336            b2DsBox.show = true;
337        },
338        getPickedProducts(){
339            let data = [];
340            Object.keys(this.data).forEach((key)=>{
341                if(this.picked.indexOf(key) !== -1){
342                    data.push({'id':key,'count':this.data[key]['count'],'index':this.data[key]['index']})
343                }
344            });
345
346            return data;
347        },
348        deleteCarts(id){
349            this.$https.post(b2_rest_url+'deleteMyCarts','id='+id).then(res=>{
350
351                if(res.data.length == 0){
352                    this.$store.commit('setcartsData',{})
353                }else{
354                    this.$store.commit('setcartsData',res.data)
355                }
356
357                setTimeout(() => {
358                    this.totalReset()
359                }, 500);
360                
361            })
362        },
363        deleteCartsItem(key){
364            for (let i = 0; i < this.picked.length; i++) {
365                if(this.picked[i] == key){
366                    this.$delete(this.picked,i);
367                }
368            }
369            this.deleteCarts(key)   
370        },
371        deleteAll(){
372            this.picked = []
373            Object.keys(this.data).forEach((key)=>{
374                this.deleteCarts(key)
375            });
376        },
377        orderPage(){
378            if(b2token){
379                return this.$store.state.userData.link+'/orders'
380            }
381        },
382        buyDisabeld(){
383            if(this.showAddress === true && !this.pickedAddress){
384                return true
385            } 
386
387            return false;
388        }
389    },
390    watch:{
391        pickedCoupon(val){
392            this.couponTotalReset()
393        },
394        pickedAll(val){
395            if(val){
396                this.allPicked()
397            }else{
398                if(this.picked.length === this.dataLength){
399                    this.picked = []
400                }
401            }
402        },
403        picked(val){
404            if(val.length !== this.dataLength){
405                this.pickedAll = false
406            }else{
407                this.pickedAll = true
408            }
409            this.getCoupons()
410            this.totalReset()
411        }
412    }
413})

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.