Add to shopping cart function wepy

Source: Internet
Author: User

1. There is a button to add to the shopping cart first

<View wx: If = "{(detaildata. boughtnum <detaildata. buy_limit) & detaildata. stock_num> 0 }}"> <button class = "nav-detail add-car" open-type = "getuserinfo" bindgetuserinfo = "addcar" plain = "true"> Add to shopping cart </button> <button open-type = "getuserinfo" class = "nav-Detail go-buy" bindgetuserinfo = "tobuy" plain = "true"> buy now </button> </View>

2. Actions after clicking

Async addcar () {var self = this; let result = await API. shoppingcardlist ({}). then (RES => res) if (result. data. code == 200) {self. carlist = result. data. data. onsale self. carlistnum = result. data. data. onsale. length> 0? String (result. data. data. onsale. length): 0 self. $ apply (); If (self. carlist. length> 0) {// when there is data in the shopping cart list, determine whether the shopping cart has this item for (VAR I = 0; I <self. carlist. length; I ++) {If (self. carlist [I]. prdid = self. prdid) {// If (parseint (self. carlist [I]. buy_num)> = self. detaildata. buy_limit_remain | parseint (self. carlist [I]. buy_num)> = self. detaildata. buy_limit) {// determines whether the purchase quantity of the item in the shopping cart has reached the upper limit of self. $ parent. toasttips ('you have reached the limit per person purchase ', 'None') return ;}}// you can continue to purchase self. addincar ();} else if (result. data. code = 204) {// No record self. carlist = [] self. $ apply (); self. addincar ();} else if (result. data. code = 401) {// store the source wx. setstoragesync ('prodetailsource', 'addbuy') // self. $ broadcast ('userlogin ')}}

3. Add a function to the shopping cart

// Add the shopping cart addincar () {var self = This; const add2shoppingcard = API. add2shoppingcard (self. prdid, 1); add2shoppingcard. then (result) => {If (result. data. code == 200) {This. $ parent. globaldata. is_shoppingcard_update = true; self. $ parent. toasttips ('added successfully, in shopping cart', 'None') self. getcarlist ()} else if (result. data. code = 401) {// store the source wx. setstoragesync ('prodetailsource', 'addbuy') // self. $ broadcast ('userlogin ')}}). catch (ERR) => {});}

You can search for small apps for page effects.

Add to shopping cart function wepy

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.