1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030 |
- const util = require('../../utils/util.js');
- const api = require('../../config/api.js');
- const user = require('../../services/user.js');
- //获取应用实例
- const app = getApp();
- Page({
- data: {
- groupGoods: [],
- hotGoods: [],
- topics: [],
- brands: [],
- floorGoods: [],
- banner: [],
- channel: [],
- groupBanner: {},
- storeName: '',
- showPop: false, //活动弹窗
- couponVo: {},
- storeId: '',
- page: 1,
- size: 3,
- list: [],
- openAttr: false,
- isMapShow: '', //第三方商户是否启用地图显示
- isStartLocation: null, // 是否授权地理位置获取权限
- isSystemLocation: null // 手机系统设置中定位是否开启
- },
- onLoad: function(options) {
- let that = this;
- wx.clearStorageSync();
- // console.log('http://120.76.26.84:80/group1/M00/00/03/rBJEdVv1LDWAAjsfABCztmpupr8780.mp4')
- // console.log(wx.getFileSystemManager().readFile())
- wx.setStorageSync("navUrl", "/pages/index/index");
- // options.scene = 148;
- // options.scene = 93;
- // options.scene = 38;
- // options.scene = 67;
- // options.scene = 28;
- // options.scene = 8;
- // 目前共分四种情况进入小程序
- if (options.scene) {
- // 是否通过扫门店码进入小程序首页
- // console.log("have scene");
- var scene = decodeURIComponent(options.scene);
- console.log("scene is ", scene);
- that.setData({
- storeId: scene
- });
- wx.removeStorageSync('storeId');
- wx.setStorageSync('storeId', scene);
- console.log('扫门店码进入小程序首页,storeId(scene):', scene)
- //扫门店码进入的小程序首页则清除是否分享缓存
- // 20210908 add by scott chen
- wx.setStorageSync('isScanShopEntry', 'true'); // 通过扫门店码进入
- wx.removeStorageSync('isShareIndexEntry'); // 通过分享首页进入
- wx.removeStorageSync('isShareGoodEntry'); // 通过分享商品进入
- wx.removeStorageSync('isDirectEntry'); // 直接进入
- //清除是否分享商品标识缓存
- wx.removeStorageSync('isShareGood');
- } else if (options.shareIndex) {
- // 是否通过分享首页进入小程序首页
- // console.log("have shareIndex");
- var shareIndex = decodeURIComponent(options.shareIndex);
- console.log("shareIndex is ", shareIndex);
- that.setData({
- storeId: shareIndex
- });
- wx.removeStorageSync('storeId');
- wx.setStorageSync('storeId', shareIndex);
- console.log('分享门店首页进入小程序首页,storeId(shareIndex):', shareIndex)
- wx.setStorageSync('isShareIndexEntry', 'true'); // 通过分享首页进入
- wx.removeStorageSync('isScanShopEntry'); // 通过扫门店码进入
- wx.removeStorageSync('isShareGoodEntry'); // 通过分享商品进入
- wx.removeStorageSync('isDirectEntry'); // 直接进入
- //清除是否分享商品标识缓存
- wx.removeStorageSync('isShareGood');
- } else {
- // 是否通过分享商品进入,或直接进入小程序
- // 是否分享过商品进入,isShareGoods标识是通过商品分享进入goods页面后,生成的标记;
- if (wx.getStorageSync('isShareGoods') == 'true') {
- // 商品分享一定会有storeId编号
- if(!wx.getStorageSync('storeId')) {
- console.log('商品分享进入首页,从商品页获取缓存的storeId不存在。');
- }
- console.log('商品分享进入首页,从商品页获取缓存的storeId:', wx.getStorageSync('storeId'));
- that.setData({
- storeId: wx.getStorageSync('storeId')
- });
- wx.setStorageSync('isShareGoodEntry', 'true'); // 通过分享商品进入
- wx.removeStorageSync('isScanShopEntry'); // 通过扫门店码进入
- wx.removeStorageSync('isShareIndexEntry'); // 通过分享首页进入
- wx.removeStorageSync('isDirectEntry'); // 直接进入
- } else {
- //直接进入小程序主页,则清除storeId,通过当前位置获取附近门店
- wx.removeStorageSync('storeId');
- that.setData({
- storeId: '',
- storeName: ''
- });
- console.log('直接进入小程序,storeId:', that.data.storeId)
- wx.setStorageSync('isDirectEntry', 'true'); // 直接进入
- wx.removeStorageSync('isScanShopEntry'); // 通过扫门店码进入
- wx.removeStorageSync('isShareIndexEntry'); // 通过分享首页进入
- wx.removeStorageSync('isShareGoodEntry'); // 通过分享商品进入
- //清除是否分享商品标识缓存
- wx.removeStorageSync('isShareGood');
- }
- }
- console.log('isScanShopEntry-0:', wx.getStorageSync('isScanShopEntry'))
- console.log('isShareIndexEntry-0:', wx.getStorageSync('isShareIndexEntry'))
- console.log('isShareGoodEntry-0:', wx.getStorageSync('isShareGoodEntry'))
- console.log('isDirectEntry-0:', wx.getStorageSync('isDirectEntry'))
- wx.getLocation({
- success: function(location) {
- // do nothing
- // console.log('获取用户位置成功,获取附近门店');
- },
- fail: function() {
- // console.log('获取用户位置失败');
- wx.hideLoading();
- // 判断获取地理位置失败的原因
- // 获取配置信息
- wx.getSetting({
- success: function(res) {
- if (!res.authSetting['scope.userLocation']) {
- // 是否授权地理位置获取权限
- wx.showModal({
- title: '',
- content: '检测到您没有开启获取地理位置权限,是否开启',
- confirmText: '确定',
- success: function(resConfirm) {
- if (resConfirm.confirm) {
- wx.openSetting();
- } else {
- that.setData({
- isStartLocation: false
- });
- }
- }
- })
- } else {
- // 已授权地理位置获取权限,但依然未获取到定位
- // 用户未在手机系统设置中打开定位
- wx.showModal({
- title: '',
- content: '请在系统设置中打开定位服务',
- confirmText: '确定',
- showCancel: false,
- success: function(resConfirm2) {
- that.setData({
- isSystemLocation: false
- });
- }
- })
- }
- }
- })
- }
- });
- },
- onReady: function() {
- // 页面渲染完成
- },
- onShow: function() {
- // 页面显示
- let that = this;
- wx.setStorageSync("navUrl", "/pages/index/index");
- wx.setStorageSync("isLocationIndex", "false"); //购物车是否已跳转登录页,到首页重置字段为false未跳转
- if (!wx.getStorageSync('isRefusedLogin')) {
- // 是否拒绝授权
- if (wx.getStorageSync('userInfo') && wx.getStorageSync('token')) {
- console.log('缓存是否授权为空,用户已授权:' + wx.getStorageSync('isRefusedLogin'))
- wx.setStorageSync('isRefusedLogin', 'false'); //授权
- } else {
- console.log('缓存是否授权为空,用户未授权:' + wx.getStorageSync('isRefusedLogin'))
- wx.setStorageSync('isRefusedLogin', 'true'); //拒绝授权
- }
- } else {
- console.log('授权不为空,isRefusedLogin:' + wx.getStorageSync('isRefusedLogin'))
- wx.setStorageSync('isRefusedLogin', wx.getStorageSync('isRefusedLogin'));
- }
- console.log('是否拒绝授权,isRefusedLogin', wx.getStorageSync('isRefusedLogin'));
-
- // 判断isMapShow,是否同步门店,没有storeId的,要同步
- that.syncNearbyStore();
- /*if(wx.getStorageSync('isDirectEntry') == 'true') {
- // 直接进入小程序,或分享首页进入,同步
- that.syncNearbyStore();
- } else if(wx.getStorageSync('isScanShopEntry') == 'true'
- || wx.getStorageSync('isShareGoodEntry') == 'true'
- || wx.getStorageSync('isShareIndexEntry' == 'true')) {
- // 扫门店码,商品分享,首页分享,判断当前门店码判断isMapShow是否开启
- if (!wx.getStorageSync('storeId')) {
- // 判断条件成立,如发生丢失storeId的问题,为保持容错,加载附近门店
- wx.showModal({
- title: '',
- content: '<>通过扫门店码进入,仍然加载附近门店<>',
- confirmText: '确定',
- showCancel: true,
- cancelText: '取消',
- success: function(resConfirm2) {
- // 加载附近门店
- this.syncNearbyStore();
- }
- })
- } else {
- this.syncNearbyStore();
- // isMapShow是否开启
- // 门店及所属第三方商户信息
- // function callback() {
- // // 商户地图是否显示 0:否 1:是
- // if(that.data.isMapShow == '1') {
- // this.syncNearbyStore();
- // }
- // };
- // this.getStoreByIdWithMerch(callback);
- }
- } else {
- // do nothing
- console.log('进入小程序标识异常,onShow() 判断isMapShow,是否同步门店,无进入条件');
- }*/
- // if (wx.getStorageSync('userInfo') && wx.getStorageSync('token')) {
- // } else {
- // // console.log('拒绝授权:' + wx.getStorageSync('isRefusedLogin'))
- // if (wx.getStorageSync('isRefusedLogin') != 'true') {
- // wx.navigateTo({
- // url: '/pages/auth/btnAuth/btnAuth',
- // })
- // }
- // }
- },
- onHide: function() {
- // 页面隐藏
- },
- onUnload: function() {
- // 页面关闭
- },
- showCouponPop() {
- let that = this;
- this.setData({
- showPop: false
- });
- // wx.showToast({
- // title: '恭喜获取优惠券一张' + that.data.couponVo.name,
- // duration: 2000
- // });
- wx.showModal({
- title: '获取优惠券一张',
- showCancel: false,
- content: that.data.couponVo.name
- })
- },
- onShareAppMessage: function() {
- var that = this;
- // console.log('分享:' + that.data.storeId)
- return {
- title: '中网跨境电商主页',
- desc: '中网跨境电商主页',
- path: '/pages/index/index?shareIndex=' + that.data.storeId
- }
- },
- // 获取门店及商户信息
- // 此时 storeId已经保存到本地缓存中
- getStoreByIdWithMerch: function(callback) {
- let that = this;
- util.request(api.StoreByIdWithMerch, {
- storeId: wx.getStorageSync('storeId'),
- }).then((res) => {
- if (res.errno == '0') {
- if(res.data) {
- let storeVo = res.data.storeVo;
- let storeWithThirdMerchBizVo = res.data.storeWithThirdMerchBizVo;
- that.setData({
- storeId: storeWithThirdMerchBizVo.id,
- storeName: storeWithThirdMerchBizVo.storeName,
- isMapShow: storeWithThirdMerchBizVo.isMapShow
- })
- console.log('获取第三方商户及门店信息,storeId:', storeWithThirdMerchBizVo.id)
- console.log('获取第三方商户及门店信息,storeName:', storeWithThirdMerchBizVo.storeName)
- console.log('获取第三方商户及门店信息,isMapShow:', storeWithThirdMerchBizVo.isMapShow)
- wx.setStorageSync('storeId', storeWithThirdMerchBizVo.id);
- wx.setStorageSync('storeName', storeWithThirdMerchBizVo.storeName);
- wx.setStorageSync('isMapShow', storeWithThirdMerchBizVo.isMapShow);
- wx.setStorageSync('storeVo', JSON.stringify(storeVo));
- }
- if(callback){
- callback();
- }
- }
-
- }).catch((error) => {
- })
- },
- // 同步附近门店
- syncNearbyStore: function() {
- let that = this;
- // console.log(wx.getStorageSync('merchSn'));
- //获取附件门店信息
- wx.getLocation({
- success: function(location) {
- // console.log(location)
- that.loadNearbyStore(location);
- },
- fail: function() {
- wx.hideLoading();
- wx.getSetting({
- success: function(res) {
- if (!res.authSetting['scope.userLocation']) {
- that.setData({
- isStartLocation: false
- });
- } else {
- //用户已授权,但是获取地理位置失败,提示用户去系统设置中打开定位
- that.setData({
- isSystemLocation: false
- });
- }
- }
- });
- }
- });
- },
- /**
- * 定位确定授权加载附近门店信息
- * 分不同情况,加载附近门店信息
- */
- loadNearbyStore: function(location) {
- let that = this;
- that.setData({
- isStartLocation: true,
- isSystemLocation: true
- });
- var lng = location.longitude;
- var lat = location.latitude;
- wx.setStorageSync('location', JSON.stringify({
- lng,
- lat
- }));
- console.log('定位加载附近门店时,storeId:', wx.getStorageSync('storeId'))
- util.request(api.NearbyList, {
- longitude: lng,
- latitude: lat,
- storeId: wx.getStorageSync('storeId'),
- thirdPartyMerchCode: ''
- }).then((res) => {
- let nlist = res.data;
- // wx.removeStorageSync('nearStoreList');
- // wx.removeStorageSync('storeId');
- // wx.removeStorageSync('storeVo');
- // wx.setStorageSync('storeId', storeId);
- if (!wx.getStorageSync('currentCategory')) {
- wx.removeStorageSync('currentCategory');
- }
- if (!nlist.length) {
- wx.removeStorageSync('nearStoreList');
- } else {
- wx.setStorageSync('nearStoreList', JSON.stringify(nlist));
- }
- let param = {}
- // 区分情况,对原有门店编号及名称进行覆盖
- if (wx.getStorageSync('isDirectEntry') == 'true') {
- // 直接进入小程序
- if (!nlist.length) {
- wx.removeStorageSync('storeVo');
- wx.removeStorageSync('mapIndexStoreId');
- that.setData({
- storeName: '附近暂无门店',
- storeId: ''
- })
- } else {
- // 更新
- that.setData({
- storeId: nlist[0].id,
- storeName: nlist[0].storeName
- })
- }
- wx.setStorageSync('storeId', that.data.storeId);
- param.id = nlist[0].id;
- param.merchSn = nlist[0].merchSn;
- } else if(wx.getStorageSync('isScanShopEntry') == 'true'
- || wx.getStorageSync('isShareIndexEntry') == 'true'
- || wx.getStorageSync('isShareGoodEntry') == 'true') {
- // 不能使用附近门店编码storeId替代原有的storeId
- param.id = wx.getStorageSync('storeId');
- param.merchSn = nlist[0].merchSn;
- }
- wx.setStorageSync('mapIndexStoreId', nlist[0].id);
- // 获取门店及第三方商户对应的信息
- that.getStoreByIdWithMerch(that.checkLoginTokenByUpd(param));
- // that.checkLoginTokenByUpd(param);
- // wx.setStorageSync('storeVo', JSON.stringify(nlist[0]));
- })
- },
- /**
- * 校验token是否失效,失效则更新新token
- */
- checkLoginTokenByUpd: function (param){
- var that = this;
- // token验证
- util.request(api.checkToken, {
- token: wx.getStorageSync('token'),
- isRefusedLogin: wx.getStorageSync('isRefusedLogin'),
- userId: wx.getStorageSync('userId')+'',
- storeId: parseInt(param.storeId)
- }, 'POST').then(function (res) {
- if (res.data.errno == 401) {
- // token在服务端失败
- console.log('checkLoginTokenByUpd() res.data.errmsg:', res.data.errmsg)
- console.log('checkLoginTokenByUpd() token:', wx.getStorageSync('token'))
- wx.getSetting({
- success: (setRes) => {
- if (setRes.authSetting['scope.userInfo'] == undefined) {
- wx.setStorageSync('isRefusedLogin', 'true');//未授权
- wx.request({
- url: api.AuthLoginSaveToken,
- data: {
- storeId: param.storeId,
- merchSn: param.merchSn
- },
- method: 'POST',
- header: {
- 'Content-Type': 'application/json',
- 'isRefusedLogin': wx.getStorageSync('isRefusedLogin')
- },
- success: function (wxRes) {
- // console.log(wxRes)
- if (wxRes.data.errno === 0) {
- //存储信息
- wx.setStorageSync('token', wxRes.data.data.token);
- console.log('checkLoginTokenByUpd() loginSaveToken 微信用户未授权,获取到一个新的token:' + wx.getStorageSync('token'))
- that.chooseStore(param.id, param.merchSn);
- }
- },
- fail: function (err) {
- console.log("checkLoginTokenByUpd() loginSaveToken failed");
- }
- });
- } else {
- console.log('微信用户点击授权操作,过了一段时间token失效,更新token')
- wx.login({
- success: function (loginRes) {
- if (loginRes.code) {
- //登录远程服务器
- wx.request({
- url: api.AuthLoginSaveToken,
- data: {
- code: loginRes.code,
- userInfo: wx.getStorageSync('userInfo'),
- storeId: wx.getStorageSync('storeId'),
- merchSn: param.merchSn
- },
- method: 'POST',
- header: {
- 'Content-Type': 'application/json'
- },
- success: function (wxRes) {
- // console.log(wxRes)
- if (wxRes.data.errno === 0) {
- //存储用户信息
- wx.setStorageSync('userInfo', wxRes.data.data.userInfo);
- wx.setStorageSync('token', wxRes.data.data.token);
- wx.setStorageSync('userId', wxRes.data.data.userId);
- wx.setStorageSync('isRefusedLogin', 'false');//允许授权
- console.log("checkLoginTokenByUpd() loginSaveToken token失效,更新token,登录成功");
- that.chooseStore(param.id, param.merchSn);
- }
- },
- fail: function (err) {
- console.log("checkLoginTokenByUpd() loginSaveToken failed");
- }
- });
- } else {
- console.log("checkLoginTokenByUpd() loginSaveToken !loginRes.code failed");
- }
- },
- fail: function (err) {
- console.log("checkLoginTokenByUpd() wx.login() failed");
- }
- });
- }
- }
- });
- } else {
- console.log('checkLoginTokenByUpd() checkToken token未失效');
- // console.log(res)
- that.chooseStore(param.id, param.merchSn);
- }
- });
- },
- // 更新门店Id
- chooseStore: function(storeId, merchSn) {
- let that = this;
- console.log('chooseStore(),storeId:', storeId,)
- util.request(api.ChooseStoreId, {
- storeId: storeId,
- merchSn: merchSn,
- isRefusedLogin: wx.getStorageSync('isRefusedLogin')
- }, 'POST').then(function (res) {
- if (res.errno === 0) {
- if(wx.getStorageSync('isScanShopEntry') == 'true'
- || wx.getStorageSync('isShareIndexEntry') == 'true'
- || wx.getStorageSync('isShareGoodEntry') == 'true'){
- // 通过扫门店码,分享首页,分享商品等进入,不更新
- } else if(wx.getStorageSync('isDirectEntry') == 'true') {
- // 直接进入,更新
- that.setData({
- storeId: storeId,
- });
- console.log('更新了门店编号,storeId:', storeId)
- wx.setStorageSync('storeId', storeId);
- }
- wx.setStorageSync('merchSn', merchSn);
- console.log('chooseStore() token:',res.data.token)
- wx.setStorageSync('token', res.data.token);
- console.log('isScanShopEntry-1:', wx.getStorageSync('isScanShopEntry'))
- console.log('isShareIndexEntry-1:', wx.getStorageSync('isShareIndexEntry'))
- console.log('isShareGoodEntry-1:', wx.getStorageSync('isShareGoodEntry'))
- console.log('isDirectEntry-1:', wx.getStorageSync('isDirectEntry'))
- if (wx.getStorageSync('userInfo') && wx.getStorageSync('token')) {
- that.reLoad();
- } else {
- wx.setStorageSync('isLoadGoods', '0'); //1:代表每次点首页都会重新加载商品,0:否
- }
- that.getIndexData();
- that.enableActivity();
- that.getGroupData();
- }
- });
- },
- reLoad: function() {
- let that = this;
- // console.log(wx.getStorageSync('userId'));
- // console.log(wx.getStorageSync('storeId'));
- // console.log(wx.getStorageSync('merchSn'));
- if (wx.getStorageSync('storeId')) {
- if (wx.getStorageSync('userId')) {
- wx.request({
- url: api.updateLoginUser,
- data: {
- userId: wx.getStorageSync('userId'),
- storeId: wx.getStorageSync('storeId'),
- merchSn: wx.getStorageSync('merchSn')
- },
- method: 'POST',
- header: {
- 'Content-Type': 'application/json'
- },
- success: function(wxRes) {
- if (wxRes.data.errno === 0) {
- that.setData({
- isMapShow: wxRes.data.data.isMapShow
- });
- // console.log(wxRes.data.data.isLoadGoods);
- wx.setStorageSync('isLoadGoods', wxRes.data.data.isLoadGoods);
- wx.setStorageSync('thirdPartyMerchCode', wxRes.data.data.thirdPartyMerchCode);
- // console.log(that.data.isMapShow)
- // console.log("用户信息更新成功");
- }
- },
- fail: function(err) {
- console.log("reLoad()::api.updateLoginUser: failed");
- }
- });
- }
- }
- },
- getIndexData: function() {
- setTimeout(function() {}, 350)
- wx.showLoading({
- title: '加载中...',
- })
- let that = this;
- util.request(api.IndexUrl,
- {storeId: wx.getStorageSync('storeId')}
- ).then(function(res) {
- if (res.errno === 0) {
- // console.log(res.data.banner);
- that.setData({
- // newGoods: res.data.newGoodsList,
- // hotGoods: res.data.hotGoodsList,
- // topics: res.data.topicList,
- // brand: res.data.brandList,
- // floorGoods: res.data.categoryList,
- banner: res.data.banner,
- // groupBanner: res.data.groupBanner,
- channel: res.data.channel
- });
- //当切换了门店地图(mapIndexStoreId);或由用户分享进入的商品详情页,再切换进入的首页(isShareGoodEntry:true)
- if (wx.getStorageSync('storeId') != wx.getStorageSync('mapIndexStoreId')
- || wx.getStorageSync('isShareGoodEntry') == 'true'
- || that.data.hotGoods.length == 0
- || wx.getStorageSync('isLoadGoods') == '1') {
- that.setData({
- hotGoods: [],
- page: 1
- });
- that.getGoodsList();
- if (wx.getStorageSync('isLoadGoods') == '1') {
- util.request(api.UpdateStoreLoadGoods, {
- storeId: wx.getStorageSync('storeId')
- }).then(function(res) {});
- }
- wx.setStorageSync('isShareGoodEntry', 'false');
- }
- }
- wx.hideLoading();
- });
- },
- getGoodsList: function() {
- let that = this;
- util.request(api.GoodsHot).then(function(res) {
- if (res.errno == 0) {
- util.request(api.HotGoodsList, {
- isHot: 1,
- page: that.data.page,
- size: that.data.size,
- categoryId: 0
- })
- .then(function(res) {
- if (res.errno == 0) {
- let goodsList = that.data.hotGoods.concat(res.data.goodsList);
- that.setData({
- hotGoods: goodsList,
- list: res.data.goodsList
- });
- }
- });
- wx.hideLoading();
- }
- });
- },
- getGroupData: function() {
- let that = this;
- util.request(api.GroupList).then(function(res) {
- if (res.errno === 0) {
- that.setData({
- groupGoods: res.data.data,
- });
- }
- });
- },
- handleStore() {
- console.log('进入 handleStore()');
- wx.navigateTo({
- url: '../map/map',
- })
- },
- goSearch() {
- wx.navigateTo({
- url: '../search/search',
- })
- },
- goCatalog: function(e) {
- let url = '';
- // console.log('dataset.goodsBizType:' + e.currentTarget.dataset.goodsBizType);
- app.globalData.appGoodsBizType = e.currentTarget.dataset.goodsBizType;
- // console.log('appgoodsBizType1:' + app.globalData.appGoodsBizType);
- wx.setStorageSync('isSwitchCatalog', 'true'); //主页跳转至分类页加载商品,
- wx.switchTab({
- url: '/pages/catalog/catalog',
- });
- },
- onReachBottom: function() {
- if (this.data.bottomLoadDone === true || this.data.bottomLoading === true) {
- return false;
- }
- this.setData({
- bottomLoading: true
- });
- // this.getFloorCategory();
- },
- //购物车减少
- cutNumber: function(e) {
- let that = this;
- var goodsId = e.currentTarget.dataset.goodsId;
- var productId = e.currentTarget.dataset.productId;
- var hotGoods = that.data.hotGoods;
- // hotGoods.forEach(function (val, index, arr) {
- // if (val.product_id == productId) {
- // val.cart_num = val.cart_num - 1;
- // if (val.cart_num >= 0) {
- // hotGoods[index] = val;
- // }
- // }
- // });
- // that.setData({ hotGoods: hotGoods });
- util.request(api.CartMinus, {
- goodsId: goodsId,
- productId: productId,
- number: 1
- }, 'POST').then(function(res) {
- if (res.errno === 0 && null != res.data) {
- var hotGoods = that.data.hotGoods;
- hotGoods.forEach(function(val, index, arr) {
- if (val.product_id == productId) {
- val.cart_num = res.data;
- hotGoods[index] = val;
- that.setData({
- hotGoods: hotGoods
- });
- }
- }, that);
- }
- });
- },
- //购物车增加
- addNumber: function(e) {
- let that = this;
- var goodsId = e.currentTarget.dataset.goodsId;
- var productId = e.currentTarget.dataset.productId;
- var hotGoods = that.data.hotGoods;
- // hotGoods.forEach(function (val, index, arr) {
- // if (val.product_id == productId) {
- // val.cart_num = val.cart_num + 1;
- // hotGoods[index] = val;
- // }
- // });
- // that.setData({ hotGoods: hotGoods });
- util.request(api.CartAdd, {
- goodsId: goodsId,
- productId: productId,
- number: 1
- }, 'POST').then(function(res) {
- if (res.errno === 0 && null != res.data) {
- hotGoods.forEach(function(val, index, arr) {
- res.data.cartList.forEach(function(cartVal, cartIndex, cartArr) {
- if (val.product_id == cartVal.product_id) {
- val.cart_num = cartVal.number;
- hotGoods[index] = val;
- }
- });
- that.setData({
- hotGoods: hotGoods
- });
- }, that);
- wx.showToast({
- title: '添加成功'
- })
- } else {
- wx.showToast({
- title: res.errmsg,
- icon: 'none'
- })
- }
- });
- },
- // 查询是否有活动
- enableActivity: function() {
- let that = this;
- let couponIds = wx.getStorageSync('couponIds');
- if (!couponIds) {
- couponIds = new Array();
- }
- // util.request(api.EnableActivity, { couponIds: couponIds }).then(function (res) {
- // // if (res.errno === 0 && null != res.data.showCoupon) {
- // // if (couponIds.contains(res.data.showCoupon.id)) {
- // // return;
- // // }
- // // couponIds.push(res.data.showCoupon.id);
- // // wx.setStorageSync('couponIds', couponIds);
- // // that.setData({
- // // couponVo: res.data.showCoupon,
- // // showPop: true
- // // });
- // // } else
- // if (res.errno === 0 && null != res.data.takeCoupon && null != res.data.takeCoupon.id) {
- // that.setData({
- // couponVo: res.data.takeCoupon,
- // showPop: true
- // });
- // }
- // });
- },
- // 商品扫码
- scanGoodsCode: function(e) {
- var that = this;
- var code;
- var value;
- var substrValue;
- var scanType;
- // 调起客户端扫码界面进行扫码
- wx.scanCode({
- // 是否只能从相机扫码
- onlyFromCamera: true,
- // 扫码类型, barCode:一维码, qrCode:二维码
- scanType: ['barCode', 'qrCode'],
- success: function(res) {
- that.code = "结果:" + res.result + ",路径:" + res.path + ",编码:" + res.rawData;
- that.value = res.result;
- that.scanType = res.scanType;
- that.setData({
- goodsCode: that.code
- });
- if (that.scanType == 'QR_CODE') { //二维码
- that.substrValue = that.value.substring(0, 5);
- that.value = that.value.substring(5, that.value.length);
- // var goodId = that.value.substring(18, that.value.length);
- var scanArray = that.value.split('&');
- // console.log(scanArray.length);
- if (scanArray.length < 2) {
- wx.showModal({
- title: '',
- content: '您所扫描的商品无效',
- showCancel: false
- });
- return;
- }
- var goodId = scanArray[0].substring(18, that.value.length);
- var storeId = scanArray[1].substring(8, that.value.length);
- // console.log("storeId:" + storeId);
- // console.log("goodId:" + goodId);
- if (that.substrValue != 'emato') { //../goods/goods?id=&merchSn=
- wx.showModal({
- title: '',
- content: '您所扫描的商品无效',
- showCancel: false,
- success: function(res) {
- if (res.confirm) {
- console.log('用户点击确定')
- } else if (res.cancel) {
- console.log('用户点击取消')
- }
- }
- });
- return;
- }
- if (storeId != wx.getStorageSync('storeId')) {
- wx.showModal({
- title: '扫描结果',
- content: '该商品不属于当前门店',
- showCancel: false
- });
- return;
- }
- util.request(api.GoodsDetail, {
- id: goodId,
- storeId: storeId,
- referrer: ''
- }).then(function(res) {
- if (res.errno === 0) {
- // console.log(res);
- // 跳转页面
- setTimeout(function() {
- wx.navigateTo({
- url: that.value,
- success: function(e) {
- console.log('跳转成功');
- },
- fail: function(e) {
- console.log('跳转失败');
- }
- })
- }, 350)
- } else {
- wx.showModal({
- title: '扫描结果',
- content: '商品不存在',
- showCancel: false
- });
- }
- });
- } else { //其他码
- //弹框显示结果
- wx.showModal({
- title: '扫描结果',
- content: that.value,
- showCancel: false
- });
- }
- },
- fail: function() {
- // 显示提示框
- wx.showToast({
- title: '扫码失败',
- icon: 'none',
- // 提示的延迟时间
- duration: 3000
- })
- }
- })
- },
- imgOnLoad: function(e) {
- let that = this;
- // console.log('图片加载完成');
- // var realthumb = e.target.dataset.thumb;
- // let list = that.data.list
- // for (var i = 0; i < list.length; i++) {
- // if (list[i].thumb == realthumb) {
- // list[i].loaded = true
- // }
- // that.setData({
- // list: list
- // })
- // }
- },
- switchAttrPop: function() {
- this.setData({
- openAttr: !this.data.openAttr
- })
- },
- hideSwitchAttrPop: function() {
- this.setData({
- openAttr: false
- })
- },
- //购物车增加
- addCart: function(e) {
- let that = this;
- that.setData({
- number: 1
- });
- var goodsId = e.currentTarget.dataset.goodsId;
- var retailPrice = e.currentTarget.dataset.retailPrice;
- util.request(api.GoodsSku, {
- goodsId: goodsId
- }).then(function(res) {
- if (res.errno === 0 && null != res.data) {
- that.setData({
- goodsVo: res.data.goodsVo,
- specificationList: res.data.specificationList,
- productList: res.data.productList,
- openAttr: !that.data.openAttr,
- retailPrice: retailPrice,
- stockNum: res.data.stockNum,
- cartNumber: res.data.cartNumber,
- checkedSpecText: res.data.specificationList[0].valueList[0].value
- });
- //
- let _specificationList = res.data.specificationList;
- for (let i = 0; i < _specificationList.length; i++) {
- if (_specificationList[i].valueList.length == 1) {
- //如果已经选中,则反选
- _specificationList[i].valueList[0].checked = true;
- }
- }
- that.setData({
- 'specificationList': _specificationList
- });
- }
- });
- },
- shows: function(e) {
- // wx.redirectTo({
- // url: '/pages/images/images'
- // })
- // wx.navigateTo({
- // url: '../ucenter/campMinus/campMinus?campMinusId=' + 9 + '&&storeId=' + 8 + '&&campName=' + '满200减50' + "&&isShare=1"
- // })
- wx.redirectTo({
- url: '/pages/checkVideo/checkVideo'
- })
- },
- onReachBottom() {
- var that = this;
- if (that.data.list.length > 0) {
- // console.log(that.data.list)
- wx.showLoading({
- title: '加载中...',
- })
- }
- that.setData({
- page: that.data.page + 1
- });
- that.getGoodsList();
- }
- })
|