1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093 |
- var app = getApp();
- var WxParse = require('../../lib/wxParse/wxParse.js');
- var util = require('../../utils/util.js');
- var api = require('../../config/api.js');
- var goodsUtil = require('../../utils/goods.js');
- Page({
- data: {
- winHeight: "",
- id: 0,
- referrer: 0,
- goods: {},
- gallery: [],
- attribute: [],
- issueList: [],
- comment: [],
- brand: {},
- specificationList: [],
- productList: [],
- relatedGoods: [],
- cartGoodsCount: 0,
- userHasCollect: 0,
- crashList: {},
- number: 1,
- checkedSpecText: '请选择规格数量',
- openAttr: false,
- openAttrByOrder: false,
- noCollectImage: "/static/images/icon_collect.png",
- hasCollectImage: "/static/images/icon_collect_checked.png",
- collectBackImage: "/static/images/icon_collect.png",
- showNavList: false,
- stockNum: null,
- cartNumber: 0,
- autoplay: false,
- defaultFreight: 0,
- current: 0, //banner当前的index
- isPlay: true,
- indexNum: 0,
- windowWidth: 0,
- leftWidth: 0,
- startX: 0,
- curr_id: '',
- videoHiddenName: true,
- imgHiddenName: false,
- page: 1,
- size: 3,
- detailContent: '',
- storeId: '',
- detailStoreId: '',
- promId: '',
- merchSn: '',
- openTicketAttr: false,
- ticketDiscountList: [],
- detailTicketDiscountList: [],
- discountSize: 9999, //查看全部
- discountDetailSize: 3, //详情查看部分
- campDetailSize: 1, //详情查看部分
- detailStoreCampMinusList: [],
- storeCampMinusList: []
- },
- onLoad: function(options) {
- // 页面初始化 options为页面跳转所带来的参数
- //由渠道推广生成的小程序码带来的参数,格式:商品id&门店id&推广id&用户id
- // options.scene = "1181115&20&1&26";
- // options.scene = "1181167&12&5&26";
- // options.scene = "1181133&12&6&26";
- // options.scene = "1181133&12&&26";
- var paramView = '';
- if (options.scene) {
- paramView = 'indexGoods';
- var scene = decodeURIComponent(options.scene);
- console.log("scene is ", scene);
- var scanArray = scene.split('&');
- var id = scanArray[0];
- var storeId = scanArray[1];
- var promId = scanArray[2];
- var referrer = scanArray[3];
- console.log("id is ", id);
- console.log("storeId is ", storeId);
- console.log("promId is ", promId);
- console.log("referrer is ", referrer);
- this.setData({
- id: id,
- storeId: storeId,
- promId: promId,
- referrer: referrer
- });
- if (storeId) {
- wx.setStorageSync('storeId', storeId);
- wx.setStorageSync('isShareGoods', 'true'); //商品详情是由用户分享进入的
- }
- } else {
- //由列表页、与普通用户分享点进来带来的参数,商品id,门店id;商品id,门店id,分享用户
- this.setData({
- id: parseInt(options.id)
- });
- if (options.paramView){
- paramView = options.paramView;
- }
- if (options.storeId) {
- this.setData({
- storeId: options.storeId
- });
- wx.setStorageSync('storeId', options.storeId);
- }
- if (options.referrer) {
- this.setData({
- referrer: options.referrer
- });
- wx.setStorageSync('isShareGoods', 'true');
- } else {
- wx.removeStorageSync('isShareGoods'); //由列表页、与普通用户分享点进来则清除是否分享缓存
- }
- }
- var that = this;
- if (wx.getStorageSync('userInfo') && wx.getStorageSync('token')){
- // 高度自适应
- wx.getSystemInfo({
- success: function (res) {
- var clientHeight = res.windowHeight,
- clientWidth = res.windowWidth,
- rpxR = 750 / clientWidth;
- var calc = clientHeight * rpxR - 100;
- // console.log(calc);
- that.setData({
- winHeight: calc,
- windowWidth: res.windowWidth
- });
- }
- });
- } else {
- // wx.navigateTo({
- // url: '/pages/auth/btnAuth/btnAuth',
- // })
- // wx.navigateTo({
- // url: '/pages/ucenter/userLogin/userLogin?view=' + paramView
- // })
- }
- },
- onShow: function () {
- let that = this;
- if (wx.getStorageSync('token')) {
- console.log(wx.getStorageSync('userInfo'))
- console.log(wx.getStorageSync('token'))
- util.request(api.checkToken, {
- token: wx.getStorageSync('token'),
- isRefusedLogin: wx.getStorageSync('isRefusedLogin'),
- userId: wx.getStorageSync('userId')+'',
- storeId: parseInt(wx.getStorageSync('storeId'))
- }, 'POST').then(function (res) {
- if (res.data.errno == 401) {
- //token失效
- console.log('token失效')
- } else {
- //token未失效
- }
- });
- }
- // 页面显示
- if (wx.getStorageSync('token')) {
- if (wx.getStorageSync('storeId')) {
- //保存商户、门店、token信息到redis
- util.request(api.ChooseStoreId, {
- storeId: wx.getStorageSync('storeId'),
- merchSn: wx.getStorageSync('merchSn'),
- isRefusedLogin: wx.getStorageSync('isRefusedLogin')
- }, 'POST').then(function (res) {
- if (res.errno === 0) {
- wx.setStorageSync('storeId', wx.getStorageSync('storeId'));
- wx.setStorageSync('merchSn', wx.getStorageSync('merchSn'));
- that.reLoad();
- that.getGoodsInfo();
- if(wx.getStorageSync('userInfo')){
- util.request(api.CartGoodsCount, {
- storeId: wx.getStorageSync('storeId')
- }).then(function (res) {
- if (res.errno === 0) {
- that.setData({
- cartGoodsCount: res.data.cartTotal.goodsCount
- });
- }
- });
- }
- }
- });
- }
- }
- },
- onReady: function() {
- let that = this;
- this.videoContext = wx.createVideoContext('myVideo');
- // 页面渲染完成
- // wx.setClipboardData({
- // data: '/pages/goods/goods?id=' + that.data.id,
- // success: function (res) {
- // wx.getClipboardData({
- // success: function (res) {
- // // console.log(res.data) // data
- // }
- // })
- // }
- // })
- },
- toggleNav() {
- this.setData({
- showNavList: !this.data.showNavList
- })
- },
- switchNav(event) {
- let name = event.currentTarget.dataset.name;
- wx.switchTab({
- url: `/pages/${name}/${name}`,
- });
- },
- //小程序里的转义方法
- escape2Html: function(str) {
- var arrEntities = {
- 'lt': '<',
- 'gt': '>',
- 'nbsp': ' ',
- 'amp': '&',
- 'quot': '"'
- };
- return str.replace(/&(lt|gt|nbsp|amp|quot);/ig, function(all, t) {
- return arrEntities[t];
- });
- },
- //调用在需要的地方直接调用即可。如:this.escape2Html(contents)
- getGoodsInfo: function() {
- wx.showLoading({
- title: '加载中...',
- });
- setTimeout(function() {}, 350)
- let that = this;
- const regex = new RegExp('<img', 'gi');
- console.log('分享的storeId' + wx.getStorageSync('storeId'))
- // console.log('promId' + that.data.promId)
- util.request(api.GoodsDetail, {
- id: that.data.id,
- referrer: that.data.referrer,
- merchSn: wx.getStorageSync('merchSn'),
- storeId: wx.getStorageSync('storeId'),
- promId: that.data.promId
- }).then(function(res) {
- if (res.errno === 0) {
- that.setData({
- goods: res.data.info,
- gallery: res.data.gallery,
- attribute: res.data.attribute,
- issueList: res.data.issue,
- comment: res.data.comment,
- brand: res.data.brand,
- specificationList: res.data.specificationList,
- productList: res.data.productList,
- userHasCollect: res.data.userHasCollect,
- stockNum: res.data.stockNum,
- defaultFreight: res.data.defaultFreight,
- checkedSpecText: res.data.specificationList[0].valueList[0].value,
- detailContent: that.escape2Html(res.data.info.goods_desc).replace(regex, `<img style="width: 100%;"`),
- detailStoreId: res.data.info.storeId,
- merchSn: res.data.info.merchSn
- });
- if (res.data.cartNumber){
- that.setData({
- cartNumber: res.data.cartNumber
- });
- }
- if (wx.getStorageSync('userInfo')){
- that.getDetailTicketDiscountList();
- that.getDetailStoreCampMinusList();
- }
- if (res.data.userHasCollect == 1) {
- that.setData({
- 'collectBackImage': that.data.hasCollectImage
- });
- } else {
- that.setData({
- 'collectBackImage': that.data.noCollectImage
- });
- }
- // WxParse.wxParse('goodsDetail', 'html', res.data.info.goods_desc, that);
- that.getGoodsRelated();
- // that.getGoodsCrashList();
- //
- let _specificationList = that.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
- });
- }
- wx.hideLoading();
- });
- if (null != that.data.referrer && that.data.referrer > 0) {
- //转发获取优惠券
- util.request(api.GoodsTransferCoupon, {
- goods_id: that.data.id,
- referrer: that.data.referrer,
- send_type: 2
- }).then(function(res) {
- });
- }
- //商品列表图
- util.request(api.GoodsGallery, {
- goods_id: that.data.id
- }).then(function(res) {
- if (res.errno === 0) {
- that.setData({
- gallery: res.data
- })
- }
- });
- },
- // getGoodsCrashList: function () {
- // let that = this;
- // util.request(api.GoodsCrashList, { goodsId: that.data.id }).then(function (res) {
- // if (res.errno === 0) {
- // that.setData({
- // crashList: res.data,
- // });
- // that.data.crashList.length;
- // }
- // });
- // },
- clickSkuValue: function(event) {
- let that = this;
- let specNameId = event.currentTarget.dataset.nameId;
- let specValueId = event.currentTarget.dataset.valueId;
- //
- let _specificationList = this.data.specificationList;
- for (let i = 0; i < _specificationList.length; i++) {
- if (_specificationList[i].specification_id == specNameId) {
- for (let j = 0; j < _specificationList[i].valueList.length; j++) {
- if (_specificationList[i].valueList[j].id == specValueId) {
- //如果已经选中,则反选
- if (_specificationList[i].valueList[j].checked) {
- _specificationList[i].valueList[j].checked = false;
- } else {
- _specificationList[i].valueList[j].checked = true;
- }
- } else {
- _specificationList[i].valueList[j].checked = false;
- }
- }
- }
- }
- this.setData({
- 'specificationList': _specificationList
- });
- //重新计算spec改变后的信息
- goodsUtil.changeSpecInfo(that);
- },
- //购物车增加
- addNumber2: function(e) {
- let that = this;
- var goodsId = e.currentTarget.dataset.goodsId;
- var productId = e.currentTarget.dataset.productId;
- var hotGoods = that.data.hotGoods;
- util.request(api.CartAdd, {
- goodsId: goodsId,
- productId: productId,
- number: 1
- }, 'POST').then(function(res) {
- if (res.errno === 0 && null != res.data) {
- util.request(api.CartGoodsCount, {
- storeId: wx.getStorageSync('storeId')
- }).then(function(res) {
- if (res.errno === 0) {
- that.setData({
- cartGoodsCount: res.data.cartTotal.goodsCount
- });
- }
- });
- wx.showToast({
- title: '添加成功',
- icon: 'success',
- mask: true
- });
- } else {
- wx.showToast({
- title: res.errmsg,
- icon: 'none'
- })
- }
- });
- },
- onHide: function() {
- // 页面隐藏
- },
- onUnload: function() {
- // 页面关闭
- },
- switchAttrPop: function() {
- this.setData({
- openAttr: !this.data.openAttr,
- openAttrByOrder: false,
- openTicketAttr: false,
- openCampMinusAttr: false
- })
- },
- hideSwitchAttrPop: function() {
- this.setData({
- openAttr: false,
- openAttrByOrder: false,
- openTicketAttr: false,
- openCampMinusAttr: false
- })
- },
- switchAttrPopByOrder: function () {
- this.setData({
- openAttr: false,
- openAttrByOrder: !this.data.openAttrByOrder,
- openTicketAttr: false,
- openCampMinusAttr: false
- })
- },
- reLoad: function() {
- let that = this;
- 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) {
- // console.log("用户信息更新成功");
- }
- },
- fail: function(err) {
- console.log("failed");
- }
- });
- }
- }
- },
- changeProperty: function(e) {
- var propertyName = e.currentTarget.dataset.propertyName;
- console.log(propertyName);
- },
- closeAttrOrCollect: function() {
- let that = this;
- //添加或是取消收藏
- util.request(api.CollectAddOrDelete, {
- typeId: 0,
- valueId: this.data.id
- }, "POST")
- .then(function(res) {
- let _res = res;
- if (_res.errno == 0) {
- if (_res.data.type == 'add') {
- that.setData({
- 'collectBackImage': that.data.hasCollectImage
- });
- wx.showToast({
- title: "收藏成功",
- mask: true
- });
- } else {
- that.setData({
- 'collectBackImage': that.data.noCollectImage
- });
- wx.showToast({
- title: "收藏取消",
- mask: true
- });
- }
- } else {
- wx.showToast({
- image: '/static/images/icon_error.png',
- title: _res.errmsg,
- mask: true
- });
- }
- });
- },
- openCartPage: function() {
- if (wx.getStorageSync('userInfo')){
- wx.switchTab({
- url: '/pages/cart/cart',
- });
- }else{
- wx.showModal({
- title: '授权提示',
- content: '用户未授权',
- confirmText: '确定授权',
- cancelText: '不授权',
- success(res) {
- if (res.confirm) {
- wx.navigateTo({
- url: '/pages/ucenter/userLogin/userLogin?view=goodsView'
- })
- } else if (res.cancel) {
- // console.log('用户点击取消')
- }
- }
- });
- }
- },
- addToCart: function () {
- var that = this;
- if (!wx.getStorageSync('userInfo')) {
- // wx.showToast({
- // image: '/static/images/icon_error.png',
- // title: '用户未授权'
- // });
- wx.showModal({
- title: '授权提示',
- content: '用户未授权',
- confirmText: '确定授权',
- cancelText: '不授权',
- success(res) {
- if (res.confirm) {
- wx.navigateTo({
- url: '/pages/ucenter/userLogin/userLogin?view=goodsView'
- })
- } else if (res.cancel) {
- // console.log('用户点击取消')
- }
- }
- });
- return;
- }
- if (that.data.openAttr == false) {
- //打开规格选择窗口
- that.setData({
- openAttr: !that.data.openAttr,
- openAttrByOrder: false,
- number: 1
- });
- } else {
- //提示选择完整规格
- if (!goodsUtil.isCheckedAllSpec(that)) {
- return false;
- }
- if (that.data.number + that.data.cartNumber > that.data.stockNum) {
- // wx.showToast({
- // title: '库存不足',
- // mask: true
- // });
- if (that.data.cartNumber == that.data.stockNum){
- wx.showToast({
- title: '不能再加了,购物车中已加入库存' + that.data.cartNumber + '个',
- icon: 'none'
- })
- }else{
- util.showErrorToast('库存不足');
- }
- // util.showErrorToast('库存不足');
- //找不到对应的product信息,提示没有库存
- return false;
- }
- // console.log(that.data.productList)
- // //根据选中的规格,判断是否有对应的sku信息
- let checkedProduct = goodsUtil.getCheckedProductItem(goodsUtil.getCheckedSpecKey(that), that);
- // console.log(goodsUtil.getCheckedSpecKey(that))
- if (!checkedProduct || checkedProduct.length <= 0) {
- wx.showToast({
- title: '库存不足',
- icon: 'none'
- });
- //找不到对应的product信息,提示没有库存
- return false;
- }
- //验证库存
- // if (checkedProduct.goods_number < this.data.number) {
- // //找不到对应的product信息,提示没有库存
- // return false;
- // }
- //添加到购物车
- util.request(api.CartAdd, {
- goodsId: this.data.goods.id,
- number: this.data.number,
- productId: checkedProduct[0].id,
- promId: that.data.promId
- }, "POST")
- .then(function(res) {
- let _res = res;
- if (_res.errno == 0) {
- wx.showToast({
- title: '添加成功'
- });
- that.setData({
- openAttr: !that.data.openAttr,
- openAttrByOrder: false,
- cartGoodsCount: _res.data.cartTotal.goodsCount
- });
- if (that.data.userHasCollect == 1) {
- that.setData({
- 'collectBackImage': that.data.hasCollectImage
- });
- } else {
- that.setData({
- 'collectBackImage': that.data.noCollectImage
- });
- }
- } else {
- wx.showToast({
- title: _res.errmsg,
- icon: 'none'
- })
- that.hideSwitchAttrPop();
- // that.setData({
- // stockNum: 0
- // });
- }
- });
- }
- },
- cutNumber: function() {
- this.setData({
- number: (this.data.number - 1 > 1) ? this.data.number - 1 : 1
- });
- },
- addNumber: function() {
- this.setData({
- number: this.data.number + 1
- });
- },
- onShareAppMessage: function() {
- var that = this;
- // console.log("url:" + that.data.goods.list_pic_url);
- var userId = wx.getStorageSync('userId');
- console.log("userId:" + userId);
- console.log("detailStoreId:" + that.data.detailStoreId);
- console.log("merchSn:" + that.data.merchSn);
- console.log("promId:" + that.data.promId);
- var requestUrl = "";
- if (that.data.promId) {
- requestUrl = '/pages/goods/goods?scene=' + that.data.id + '&' + that.data.detailStoreId + '&' + that.data.promId +
- '&' + wx.getStorageSync('userId');
- } else {
- requestUrl = '/pages/goods/goods?id=' + that.data.id + '&&referrer=' + wx.getStorageSync('userId') +
- '&&storeId=' + that.data.detailStoreId +
- '&&merchSn=' + that.data.merchSn;
- }
- // console.log("requestUrl:" + requestUrl);
- return {
- title: '商品详情',
- desc: null != that.data.goods.name ? that.data.goods.name : "商品详情",
- imageUrl: that.data.goods.list_pic_url,
- path: requestUrl,
- success: function(res) {
- // console.log("转发成功");
- console.log("转发成功12:" + that.data.promId);
- if (that.data.promId) {
- //转发成功记录推广信息转发次数
- wx.request({
- url: api.GoodsSaveTransNum,
- data: {
- referrer: wx.getStorageSync('userId'),
- storeId: that.data.detailStoreId,
- promId: that.data.promId
- },
- method: 'POST',
- header: {
- 'Content-Type': 'application/json'
- },
- success: function(wxRes) {
- console.log("转发成功");
- }
- });
- }
- },
- fail: function(res) {
- console.log("转发失败");
- }
- }
- },
- //购物车增加
- addCrashNumber: function(e) {
- let that = this;
- var goodsId = e.currentTarget.dataset.goodsId;
- var productId = e.currentTarget.dataset.productId;
- util.request(api.CartAdd, {
- 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.id == goodsId) {
- val.cart_num = res.data;
- hotGoods[index] = val;
- that.setData({
- hotGoods: hotGoods
- });
- }
- }, that);
- }
- });
- },
- previewPic(e) {
- let url = e.currentTarget.dataset.url;
- let urls = [];
- urls[0] = url;
- wx.previewImage({
- urls
- })
- },
- switchNav(event) {
- wx.switchTab({
- url: '/pages/index/index'
- });
- },
- //触摸事件start
- touchStart(e) {
- let startX = e.changedTouches[0].pageX
- this.setData({
- startX: startX
- })
- console.log("startX:" + startX);
- },
- //触摸事件end
- touchEnd(e) {
- let _self = this;
- let windowWidth = this.data.windowWidth;
- let moveWidth = e.changedTouches[0].pageX - this.data.startX;
- let defineWidth = windowWidth / 20;
- let rankList = this.data.gallery;
- let index_now = e.currentTarget.dataset.index;
- if (moveWidth >= defineWidth) {
- //上一张
- let transWidth = (index_now - 1) * (-this.data.windowWidth);
- if (index_now >= 1) {
- this.setData({
- indexNum: index_now - 1,
- rankList: rankList,
- leftWidth: transWidth
- })
- }
- } else if (moveWidth <= (0 - defineWidth)) {
- //下一张
- this.videoContext.pause();
- let transWidth = (index_now + 1) * (-this.data.windowWidth);
- if (index_now < rankList.length - 1) {
- this.setData({
- indexNum: index_now + 1,
- rankList: rankList,
- leftWidth: transWidth
- })
- }
- } else {
- //console.log('不能修改样式')
- }
- },
- videoPlay(e) {
- // if (this.data.curr_id == e.currentTarget.dataset.id) {
- // this.setData({
- // curr_id: 0,
- // })
- // } else {
- // this.setData({
- // curr_id: e.currentTarget.dataset.id,
- // })
- // }
- this.setData({
- imgHiddenName: true,
- videoHiddenName: false
- })
- this.videoContext.play();
- },
- //触摸事件start
- touchStart2(e) {
- },
- touchEnd2(e) {
- this.setData({
- curr_id: 0,
- imgHiddenName: false,
- videoHiddenName: true
- })
- this.videoContext.pause();
- },
- getGoodsRelated: function() {
- let that = this;
- util.request(api.GoodsRelated, {
- id: that.data.id,
- page: that.data.page,
- size: that.data.size
- }).then(function(res) {
- if (res.errno === 0) {
- let goodsList = that.data.relatedGoods.concat(res.data.goodsList);
- that.setData({
- relatedGoods: goodsList,
- });
- }
- });
- },
- onReachBottom() {
- var that = this;
- wx.showLoading({
- title: '加载中...',
- })
- that.setData({
- page: that.data.page + 1
- });
- that.getGoodsRelated();
- },
- switchTicketPop: function() {
- this.setData({
- openTicketAttr: !this.data.openTicketAttr,
- openAttr: false,
- openAttrByOrder: false,
- openCampMinusAttr: false
- })
- if (this.data.openTicketAttr) {
- if (wx.getStorageSync('userInfo')) {
- this.getTicketDiscountList();
- }
- }
- },
- // hideSwitchTicketPop: function () {
- // this.setData({
- // openTicketAttr: false,
- // openAttr: false
- // })
- // },
- /**
- * 领取优惠券
- */
- getUserCoupon(event) {
- var that = this;
- let tickDiscId = event.currentTarget.dataset.couponId;
- let storeTopicId = event.currentTarget.dataset.storeTopicId;
- let storeId = that.data.storeId;
- util.request(api.getUserCoupon, {
- tickDiscId: tickDiscId,
- storeTopicId: storeTopicId,
- storeId: storeId
- }, 'POST').then(function(res) {
- if (res.errno === 0) {
- wx.showToast({
- title: '领取成功'
- });
- that.setData({
- discStatus: 0
- });
- if (wx.getStorageSync('userInfo')) {
- this.getTicketDiscountList();
- }
- } else {
- wx.showToast({
- title: res.errmsg,
- icon: 'none'
- })
- }
- });
- },
- /**
- * 查询商品所支持的优惠券列表
- */
- getTicketDiscountList() {
- let that = this;
- util.request(api.DiscountByGoodsIdList, {
- storeId: that.data.storeId,
- goodsId: that.data.id,
- size: that.data.discountSize
- }).then(function(res) {
- if (res.errno === 0) {
- that.setData({
- ticketDiscountList: res.data
- });
- }
- });
- },
- /**
- * 查看优惠券列表,详情页展示
- */
- getDetailTicketDiscountList() {
- let that = this;
- util.request(api.DiscountByGoodsIdList, {
- storeId: that.data.storeId,
- goodsId: that.data.id,
- size: that.data.discountDetailSize
- }).then(function(res) {
- if (res.errno === 0) {
- that.setData({
- detailTicketDiscountList: res.data
- });
- }
- });
- },
- /**
- * 查看满减满折列表
- */
- getStoreCampMinusList() {
- let that = this;
- util.request(api.StoreCampMinusByGoodsIdList, {
- storeId: that.data.storeId,
- goodsId: that.data.id,
- size: that.data.discountSize
- }).then(function(res) {
- if (res.errno === 0) {
- that.setData({
- storeCampMinusList: res.data
- });
- let storeCampMinusList = that.data.storeCampMinusList
- for (let i = 0; i < storeCampMinusList.length; i++) {
- if (storeCampMinusList[i].campMinusType == '00' && storeCampMinusList[i].minusMode == '00') {
- that.setData({
- minusList0000: true
- });
- }
- if (storeCampMinusList[i].campMinusType == '01' && storeCampMinusList[i].minusMode == '00') {
- that.setData({
- minusList0100: true
- });
- }
- if (storeCampMinusList[i].campMinusType == '00' && storeCampMinusList[i].minusMode == '10') {
- that.setData({
- minusList0010: true
- });
- }
- if (storeCampMinusList[i].campMinusType == '01' && storeCampMinusList[i].minusMode == '10') {
- that.setData({
- minusList0110: true
- });
- }
- if (storeCampMinusList[i].campMinusType == '10') {
- that.setData({
- minusList10: true
- });
- }
- if (storeCampMinusList[i].campMinusType == '11') {
- that.setData({
- minusList11: true
- });
- }
- }
- }
- });
- },
- /**
- * 查看满减满折列表,详情页展示
- */
- getDetailStoreCampMinusList() {
- let that = this;
- util.request(api.StoreCampMinusByGoodsIdList, {
- storeId: that.data.storeId,
- goodsId: that.data.id,
- size: that.data.campDetailSize
- }).then(function(res) {
- if (res.errno === 0) {
- that.setData({
- detailStoreCampMinusList: res.data
- });
- }
- });
- },
- switchCampMinusPop: function() {
- this.setData({
- openCampMinusAttr: !this.data.openCampMinusAttr,
- openTicketAttr: false,
- openAttrByOrder: false,
- openAttr: false
- })
- if (this.data.openCampMinusAttr) {
- this.getStoreCampMinusList();
- }
- },
- hideSwitchCampMinusPop: function() {
- this.setData({
- openCampMinusAttr: false,
- openTicketAttr: false,
- openAttrByOrder: false,
- openAttr: false
- })
- },
- selectCampMinus(event) {
- var that = this;
- let campId = event.currentTarget.dataset.campId;
- let campName = event.currentTarget.dataset.campName;
- wx.navigateTo({
- url: '../ucenter/campMinus/campMinus?campMinusId=' + campId + '&&storeId=' + that.data.storeId + '&&campName=' + campName + "&&isShare=1"
- })
- },
- checkoutOrder: function () {
- if (!wx.getStorageSync('userInfo')) {
- // wx.showToast({
- // image: '/static/images/icon_error.png',
- // title: '用户未授权'
- // });
- wx.showModal({
- title: '授权提示',
- content: '用户未授权',
- confirmText: '确定授权',
- cancelText: '不授权',
- success(res) {
- if (res.confirm) {
- wx.navigateTo({
- url: '/pages/ucenter/userLogin/userLogin?view=goodsView'
- })
- } else if (res.cancel) {
- // console.log('用户点击取消')
- }
- }
- });
- return;
- }
- //获取已选择的商品
- let that = this;
- util.request(api.getCurUser, {
- userInfo: app.globalData.userInfo
- }, 'POST').then(function(res) {
- if (res.errno === 0) {
- // console.log('that.data.mobile:' + res.data.mobile);
- if (res.data.mobile == '' || res.data.mobile == null) {
- wx.showModal({
- title: '',
- confirmColor: '#b4282d',
- showCancel: false,
- content: '您的手机号码未绑定,请先绑定手机号再进行购买',
- success: function(res) {
- if (res.confirm) {
- wx.navigateTo({
- url: '../../pages/auth/newuser/newuser'
- });
- }
- }
- });
- } else {
- if (that.data.openAttrByOrder == false) {
- //打开规格选择窗口
- that.setData({
- openAttrByOrder: !that.data.openAttrByOrder,
- openAttr: false,
- number: 1
- });
- } else {
- //提示选择完整规格
- if (!goodsUtil.isCheckedAllSpec(that)) {
- return false;
- }
- if (that.data.number > that.data.stockNum) {
- util.showErrorToast('库存不足');
- return false;
- }
- // //根据选中的规格,判断是否有对应的sku信息
- let checkedProduct = goodsUtil.getCheckedProductItem(goodsUtil.getCheckedSpecKey(that), that);
- //找不到对应的product信息,提示没有库存
- if (!checkedProduct || checkedProduct.length <= 0) {
- wx.showToast({
- title: '库存不足',
- icon: 'none'
- });
- return false;
- }
- wx.navigateTo({
- url: '../shopping/checkout/checkout?checkCart=00&&goodsId=' + that.data.id + '&&number=' + that.data.number
- })
- }
- }
- }
- });
- },
- })
|