| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 | 
							- const _Http = getApp().globalData.http;
 
- let downCount = {};
 
- Page({
 
-     data: {
 
-         loading: true,
 
-         list: [],
 
-         results: [], //选中结果
 
-         sa_brandid: null, //当前选中品牌id
 
-         sum: 0, //价格合
 
-         yfsum: 0, //运费合
 
-     },
 
-     onLoad(options) {
 
-         this.getList()
 
-     },
 
-     /* 提交 */
 
-     submit() {
 
-         console.log("提交订单")
 
-     },
 
-     /* 获取列表 */
 
-     getList() {
 
-         _Http.basic({
 
-             "id": 20220924095302,
 
-             "content": {
 
-                 nocache: true,
 
-                 "pageNumber": 1,
 
-                 "pageSize": getApp().globalData.num + 5,
 
-                 "where": {
 
-                     "condition": ""
 
-                 }
 
-             }
 
-         }).then(res => {
 
-             console.log('购物车列表', res)
 
-             if (res.msg != '成功') return wx.showToast({
 
-                 title: res.msg,
 
-                 icon: "none"
 
-             })
 
-             this.setData({
 
-                 list: res.data,
 
-                 loading: false
 
-             });
 
-             if (wx.getStorageSync('shopping')) {
 
-                 this.setData({
 
-                     ...wx.getStorageSync('shopping')
 
-                 })
 
-                 this.computeSum();
 
-             }
 
-         })
 
-     },
 
-     /* 切换选中项 */
 
-     changeResults(e, my = false) {
 
-         const {
 
-             item
 
-         } = my ? e : e.currentTarget.dataset;
 
-         let results = this.data.results,
 
-             sa_brandid = this.data.sa_brandid;
 
-         if (sa_brandid && sa_brandid != item.sa_brandid) return;
 
-         if (results.length == 0) {
 
-             results.push(item.sa_shoppingcartid);
 
-             sa_brandid = item.sa_brandid;
 
-         } else {
 
-             let index = results.findIndex(v => v == item.sa_shoppingcartid)
 
-             if (index == -1) {
 
-                 results.push(item.sa_shoppingcartid);
 
-             } else {
 
-                 results.splice(index, 1);
 
-                 if (results.length == 0) sa_brandid = null;
 
-             }
 
-         };
 
-         this.setData({
 
-             results,
 
-             sa_brandid
 
-         })
 
-         this.computeSum();
 
-     },
 
-     /* 计算总价 */
 
-     computeSum() {
 
-         let results = this.data.results,
 
-             sum = 0,
 
-             yfsum = 0,
 
-             deteleList = [];
 
-         if (results.length) results.forEach((v, i) => {
 
-             let item = this.data.list.find(va => va.sa_shoppingcartid == v);
 
-             if (item) {
 
-                 sum += (item.qty * item.gradeprice).toFixed(2) - 0;
 
-             } else {
 
-                 deteleList.push(i)
 
-             }
 
-         });
 
-         if (deteleList.length) deteleList.forEach(v => {
 
-             results.splice(v, 1);
 
-         });
 
-         wx.setStorageSync('shopping', {
 
-             results,
 
-             sa_brandid: this.data.sa_brandid
 
-         })
 
-         this.setData({
 
-             sum,
 
-             yfsum,
 
-             results
 
-         })
 
-     },
 
-     /* 删除产品 */
 
-     deteleItem(e) {
 
-         const {
 
-             item
 
-         } = e.currentTarget.dataset;
 
-         _Http.basic({
 
-             "id": 20220924095202,
 
-             "content": {
 
-                 "sa_shoppingcartids": [item.sa_shoppingcartid]
 
-             }
 
-         }).then(res => {
 
-             if (res.msg != '成功') return wx.showToast({
 
-                 title: res.msg,
 
-                 icon: "none"
 
-             });
 
-             this.setData({
 
-                 list: this.data.list.filter(v => v.sa_shoppingcartid != item.sa_shoppingcartid)
 
-             })
 
-             if (this.data.results.some(v => v == item.sa_shoppingcartid)) this.changeResults({
 
-                 item
 
-             }, true);
 
-         })
 
-     },
 
-     /* 步进器调整 */
 
-     stepperChange(e) {
 
-         const {
 
-             index
 
-         } = e.currentTarget.dataset;
 
-         let item = this.data.list[index];
 
-         item.qty = e.detail;
 
-         this.setData({
 
-             [`list[${index}]`]: item
 
-         })
 
-         this.computeSum();
 
-         clearTimeout(downCount['count' + index])
 
-         downCount['count' + index] = setTimeout(() => {
 
-             _Http.basic({
 
-                 "id": 20220924104302,
 
-                 "content": {
 
-                     "sa_shoppingcartid": item.sa_shoppingcartid,
 
-                     "qty": item.qty
 
-                 },
 
-             }, false).then(res => {
 
-                 console.log("修改数量", res)
 
-             })
 
-         }, 2000)
 
-     },
 
- })
 
 
  |