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