| | |
| | | // pages/digitalCourses/index.js |
| | | import { |
| | | loginInfo |
| | | } from '../../assets/js/login'; |
| | | const app = getApp() |
| | | import { |
| | | setSessionGuid, |
| | |
| | | }); |
| | | } |
| | | this.getCourseTypeListList() |
| | | this.getShoppingCartList() |
| | | const token = wx.getStorageSync(app.config.tokenKey) |
| | | if (token) this.getShoppingCartList() |
| | | }, |
| | | |
| | | /** |
| | |
| | | }) |
| | | }, |
| | | addCart(e) { |
| | | const { |
| | | item |
| | | } = e.currentTarget.dataset; |
| | | wx.showToast({ |
| | | title: "建设中", |
| | | icon: 'none', |
| | | duration: 1000 |
| | | }) |
| | | if (wx.getStorageSync(app.config.tokenKey)) { |
| | | let query = { |
| | | start: 0, |
| | | size: 999, |
| | | filterList: [], |
| | | searchList: [] |
| | | } |
| | | try { |
| | | if ( |
| | | this.data.shoppingCartGetId.includes( |
| | | item.defaultSaleMethodId |
| | | ) |
| | | ) { |
| | | wx.showToast({ |
| | | title: "该课程已在购物车,请勿重复添加", |
| | | icon: 'none', |
| | | duration: 1000 |
| | | }) |
| | | } else { |
| | | let query = { |
| | | requests: [{ |
| | | saleMethodId: item.defaultSaleMethodId, |
| | | storeEventId: null, |
| | | agentCode: '数字课程' |
| | | }] |
| | | } |
| | | const addRes = app.MG.store.addShoppingCart(query) |
| | | if (addRes) { |
| | | const addFun = () => { |
| | | const { |
| | | item |
| | | } = e.currentTarget.dataset; |
| | | wx.showToast({ |
| | | title: "建设中", |
| | | icon: 'none', |
| | | duration: 1000 |
| | | }) |
| | | if (wx.getStorageSync(app.config.tokenKey)) { |
| | | let query = { |
| | | start: 0, |
| | | size: 999, |
| | | filterList: [], |
| | | searchList: [] |
| | | } |
| | | try { |
| | | if ( |
| | | this.data.shoppingCartGetId.includes( |
| | | item.defaultSaleMethodId |
| | | ) |
| | | ) { |
| | | wx.showToast({ |
| | | title: "添加成功", |
| | | icon: 'success', |
| | | title: "该课程已在购物车,请勿重复添加", |
| | | icon: 'none', |
| | | duration: 1000 |
| | | }) |
| | | } else { |
| | | let query = { |
| | | requests: [{ |
| | | saleMethodId: item.defaultSaleMethodId, |
| | | storeEventId: null, |
| | | agentCode: '数字课程' |
| | | }] |
| | | } |
| | | const addRes = app.MG.store.addShoppingCart(query) |
| | | if (addRes) { |
| | | wx.showToast({ |
| | | title: "添加成功", |
| | | icon: 'success', |
| | | duration: 1000 |
| | | }) |
| | | } |
| | | this.getShoppingCartList() |
| | | } |
| | | this.getShoppingCartList() |
| | | } catch (error) { |
| | | console.error('出错了:', error) |
| | | } |
| | | } catch (error) { |
| | | console.error('出错了:', error) |
| | | } |
| | | } |
| | | |
| | | const token = wx.getStorageSync(app.config.tokenKey) |
| | | if (token) { |
| | | addFun() |
| | | } else { |
| | | loginInfo(app, (data) => { |
| | | if (data) { |
| | | this.getShoppingCartList() |
| | | } |
| | | }) |
| | | } |
| | | }, |
| | | |
| | | }) |