| | |
| | | import { |
| | | fetchHome |
| | | } from '../../services/home/home'; |
| | | import moment from 'moment' |
| | | import { |
| | | loginInfo |
| | | } from '../../assets/js/login'; |
| | |
| | | value: false |
| | | }, |
| | | loading: true, |
| | | showStateMenu: false, // 新年公告弹窗 |
| | | }, |
| | | onShow() { |
| | | this.setData({ |
| | |
| | | this.getShoppingCartList() |
| | | } |
| | | this.init(); |
| | | // const stateMenu = wx.getStorageSync('stateMenu') |
| | | // if (stateMenu == 'true') { |
| | | // this.setData({ |
| | | // showStateMenu: true |
| | | // }) |
| | | // wx.setStorageSync('stateMenu', 'false') |
| | | // } |
| | | }, |
| | | |
| | | closeStateMenu() { |
| | | this.setData({ |
| | | showStateMenu: false |
| | | }) |
| | | }, |
| | | onLoad() { |
| | | this.getBannerList() |
| | | const systInfo = wx.getSystemInfoSync(); |
| | |
| | | // 首页测试登录功能,后续注释 |
| | | // 检查登录状态 |
| | | const token = wx.getStorageSync(app.config.tokenKey) |
| | | if (!token) { |
| | | loginInfo(app, (data) => { |
| | | // 如果不是第一次登录,会执行回调 |
| | | if (data) { |
| | | this.init(); |
| | | this.registe() |
| | | } else { |
| | | this.init(); |
| | | } |
| | | }) |
| | | } |
| | | // if (!token) { |
| | | // loginInfo(app, (data) => { |
| | | // // 如果不是第一次登录,会执行回调 |
| | | // if (data) { |
| | | // this.init(); |
| | | // this.registe() |
| | | // } else { |
| | | // this.init(); |
| | | // } |
| | | // }) |
| | | // } |
| | | |
| | | }, |
| | | onReachBottom() {}, |
| | |
| | | }) |
| | | }) |
| | | }, |
| | | async addCart(e) { |
| | | addCart(e) { |
| | | const { |
| | | info |
| | | } = e.currentTarget.dataset; |
| | | if (wx.getStorageSync(app.config.tokenKey)) { |
| | | if (info.isbuy) { |
| | | wx.showToast({ |
| | | title: "该商品已购买", |
| | | icon: 'none', |
| | | duration: 1000 |
| | | const token = wx.getStorageSync(app.config.tokenKey) |
| | | if (token) { |
| | | this.addCartFun(info) |
| | | } else { |
| | | if (!token) { |
| | | loginInfo(app, (data) => { |
| | | // 如果不是第一次登录,会执行回调 |
| | | if (data) { |
| | | this.addCartFun(info) |
| | | this.registe() |
| | | } else { |
| | | this.addCartFun(info) |
| | | } |
| | | }) |
| | | } else { |
| | | let query = { |
| | | start: 0, |
| | | size: 999, |
| | | filterList: [], |
| | | searchList: [] |
| | | } |
| | | try { |
| | | if ( |
| | | this.data.shoppingCartGetId.includes( |
| | | info.defaultSaleMethodId |
| | | ) |
| | | ) { |
| | | wx.showToast({ |
| | | title: "该商品已在购物车,请勿重复添加", |
| | | icon: 'none', |
| | | } |
| | | } |
| | | }, |
| | | // 剥离加入购物车方法登陆前后公用 |
| | | addCartFun(info) { |
| | | if (info.isbuy) { |
| | | wx.showToast({ |
| | | title: "该商品已购买", |
| | | icon: 'none', |
| | | duration: 1000 |
| | | }) |
| | | } else { |
| | | try { |
| | | if ( |
| | | this.data.shoppingCartGetId.includes( |
| | | info.defaultSaleMethodId |
| | | ) |
| | | ) { |
| | | wx.showToast({ |
| | | title: "该商品已在购物车,请勿重复添加", |
| | | icon: 'none', |
| | | duration: 1000 |
| | | }) |
| | | } else { |
| | | let query = { |
| | | requests: [{ |
| | | saleMethodId: info.defaultSaleMethodId, |
| | | storeEventId: null, |
| | | agentCode: '电子书' |
| | | }] |
| | | } |
| | | app.MG.store.addShoppingCart(query).then(res => { |
| | | if (res) wx.showToast({ |
| | | title: "添加成功", |
| | | icon: 'success', |
| | | duration: 1000 |
| | | }) |
| | | } else { |
| | | let query = { |
| | | requests: [{ |
| | | saleMethodId: info.defaultSaleMethodId, |
| | | storeEventId: null, |
| | | agentCode: '电子书' |
| | | }] |
| | | } |
| | | const addRes = await app.MG.store.addShoppingCart(query) |
| | | if (addRes) { |
| | | wx.showToast({ |
| | | title: "添加成功", |
| | | icon: 'success', |
| | | duration: 1000 |
| | | }) |
| | | } |
| | | this.getShoppingCartList() |
| | | } |
| | | |
| | | } catch (error) { |
| | | console.error('出错了:', error) |
| | | }) |
| | | } |
| | | } catch (error) { |
| | | console.error('出错了:', error) |
| | | } |
| | | } |
| | | }, |
| | |
| | | success(res) { |
| | | console.log(res); |
| | | if (res.errMsg == "scanCode:ok" && res.path || res.result) { |
| | | let path = res.path || res.result |
| | | wx.redirectTo({ |
| | | url: '/' + path, |
| | | }) |
| | | if (res.path) { |
| | | let path = res.path || res.result |
| | | wx.redirectTo({ |
| | | url: '/' + path, |
| | | }) |
| | | } else { |
| | | wx.redirectTo({ |
| | | url: '/pages/scanResult/index?result=' + res.result, |
| | | }) |
| | | } |
| | | } |
| | | } |
| | | }) |