()
| 9 | totalCounter: 0 |
| 10 | }, |
| 11 | onLoad() { |
| 12 | // 1.第一次加载数据 |
| 13 | this.setData({ |
| 14 | cartList: app.globalData.cartList |
| 15 | }) |
| 16 | |
| 17 | // 2.设置回调 |
| 18 | app.addCartCallback = () => { |
| 19 | this.setData({ |
| 20 | cartList: app.globalData.cartList |
| 21 | }) |
| 22 | this.changeData() |
| 23 | } |
| 24 | |
| 25 | // 3.设置修改某个商品的回调 |
| 26 | app.changeGoodsState = (index, goods) => { |
| 27 | // 1.修改某一项的选中状态 |
| 28 | this.setData({ |
| 29 | [`cartList[${index}]`]: goods |
| 30 | }) |
| 31 | |
| 32 | // 2.修改全部选中的状态 |
| 33 | const selectAll = !this.data.cartList.find(item => !item.checked) |
| 34 | this.setData({ |
| 35 | isSelectAll: selectAll |
| 36 | }) |
| 37 | this.changeData() |
| 38 | } |
| 39 | }, |
| 40 | onShow() { |
| 41 | wx.setNavigationBarTitle({ |
| 42 | title: `购物车(${this.data.cartList.length})`, |
nothing calls this directly
no outgoing calls
no test coverage detected