123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308 |
- var app = getApp();
- var WxParse = require('../../lib/wxParse/wxParse.js');
- var util = require('../../utils/util.js');
- var api = require('../../config/api.js');
- var user = require('../../utils/user.js');
- Page({
- data: {
- plusNum:'0',
- chooseSkuVisible:false,
- activeSku:0,
- countSalesNumber:'',
- recGoodsList:[],
- goodsComment:[],
- goodsBuyTime:{
- },
- buyToastShow:false,
- checkedSku:{
- specifications:[''],
- id:'',
- retailPrice:'',
- counterPrice:'',
- },
- currentSku:{
- specifications:[''],
- id:'',
- retailPrice:'',
- counterPrice:'',
- price:'',
- },
- recGoodsNum:'',
- selfPayShow: false,
- selfPayCheck: false,
- spreadPayShow: false,
- spreadPayChecked: false,
- canShare: false,
- id: 0,
- goods: {},
- groupon: [], //该商品支持的团购规格
- grouponLink: {}, //参与的团购
- attribute: [],
- issueList: [],
- comment: [],
- //brand: {},
- specificationList: [],
- productList: [],
- relatedGoods: [],
- cartGoodsCount: 0,
- userHasCollect: 0,
- number: 1,
- checkedSpecText: '规格数量选择',
- tmpSpecText: '请选择规格数量',
- checkedSpecPrice: 0,
- openAttr: false,
- openShare: false,
- collect: false,
- shareImage: '',
- isGroupon: false, //标识是否是一个参团购买
- soldout: false,
- canWrite: false, //用户是否获取了保存相册的权限
- name_height: 58, //根据名称长度 设置高度
- userInfo: {},
- hasLogin: false,
- shareId: 0, //options传递过来的参数 表示是打开哪个分享
- wxShareId: 0, //如果要分享此商品的分享id
- addressInfo: {},
- rId: 0, //分享人id,
- selfDiscount: 0,
- spreadDiscount: 0,
- referee: {
- self: 0,
- share: 0,
- },
- myqr_show: false, //我的分享二维码
- myqr_url: null, //分享海报及推广语言
- myqr_ads: '',
- myqr_blur: 100, //背景模糊值
- myqr_bottom_btn: 'fixed', //底部功能按钮
- activited: false, //是否活动中
- activityPrice: 0, //活动价格
- activityTime: 24 * 3600 + 3246, //活动倒计时总计时间 (整型 秒)
- activityDay: 0, //活动天数
- activityHour: 0, //活动小时
- activityMinute: 0, //活动分钟
- activitySecond: 0, //活动秒
- activityTimer: null, //定时器
- fraId: '' //加盟商id
- },
- // 页面分享
- onShareAppMessage: function () {
- let that = this;
- if (!app.globalData.hasLogin) {
- wx.navigateTo({
- url: "/pages/auth/login/login"
- });
- return;
- }
- //获取分享id 用来追踪链接
- //引荐人和非引荐人的 链接不同
- let fraId = wx.getStorageSync('fraId');
- let imgUrl = that.data.goods.shareWxUrl ? that.data.goods.shareWxUrl : that.data.goods.gallery[0];
- var path = '/pages/goods/goods?id=' + that.data.id + '&rId=' + that.data.userInfo.id;
-
- if (that.data.userInfo.isDis) { //是引荐人
- path = '/pages/goods/goods?id=' + that.data.id + '&shareId=' + that.data.wxShareId;
- }
- if(fraId){
- path = path+ '&fraId=' + fraId;
- }
- this.hidePoster();
- return {
- title: that.data.goods.name + "\n" + that.data.myqr_ads,
- path: path,
- imageUrl: imgUrl
- }
- },
- goCustomerService() { //跳转微信客服
- console.info('goCustomerService')
- wx.openCustomerServiceChat({
- extInfo: {
- url: 'https://work.weixin.qq.com/kfid/kfc1fcfae84340d5125'
- },
- corpId: 'ww034f0b524f8ead00',
- success(res) {},
- fail(res) {
- console.info(res)
- }
- })
- },
- shareFriendOrCircle: function () {
- if (!app.globalData.hasLogin) {
- wx.navigateTo({
- url: "/pages/auth/login/login"
- });
- return;
- }
- //分享 弹出图片
- let that = this;
- wx.removeStorageSync(String(that.data.goods.id));
- //取出本地缓存中的分享图
- // let sUrl=wx.getStorageSync(String(that.data.goods.id));
- // if(sUrl!=null&&sUrl!=""){//获取过的分享图 不需要再次获取
- // that.setData({
- // myqr_url:sUrl,
- // myqr_show:true,
- // myqr_blur:5
- // });
- // return;
- // }
- wx.showLoading({
- title: '生成中',
- });
- util.request(api.QrGoodsCodeCreate, {
- goodsId: that.data.goods.id
- }).then(function (res) {
- wx.hideLoading();
- if (res.errno == 0) {
- that.setData({
- myqr_url: res.data.imgUrl,
- myqr_show: true,
- myqr_blur: 5
- });
- //保存分享图url到本地缓存
- // wx.setStorageSync(String(that.data.goods.id),res.data.imgUrl);
- } else if (res.errno == 501) {
- wx.navigateTo({
- url: "/pages/auth/login/login"
- });
- } else {
- wx.showToast({
- title: res.errmsg,
- duration: 5000
- })
- }
- });
- //var that = this;
- /*if (this.data.openShare === false) {
- this.setData({
- openShare: !this.data.openShare
- });
- } else {
- return false;
- }*/
- },
- /**活动剩余时间 格式化 */
- handleActivityTime() {
- let that = this;
- let interval = setInterval(function () {
- if (that.data.activityTime <= 1) return;
- let activityTime = that.data.activityTime;
- let day = parseInt(activityTime / (24 * 60 * 60));
- let hour = parseInt(activityTime % (24 * 60 * 60) / 3600);
- console.info(activityTime % (24 * 60 * 60) % 3600)
- let minte = parseInt(activityTime % (24 * 60 * 60) % 3600 / 60);
- let second = parseInt(activityTime % (24 * 60 * 60) % 3600 % 60);
- that.setData({
- activityDay: day,
- activityHour: (hour < 10 ? ("0" + hour.toString()) : hour.toString()),
- activityMinute: (minte < 10 ? ("0" + minte.toString()) : minte.toString()),
- activitySecond: (second < 10 ? ("0" + second.toString()) : second.toString()),
- activityTime: activityTime - 1
- })
- }, 1000);
- that.setData({
- activityTimer: interval
- })
- },
- handleSetting: function (e) {
- var that = this;
- // console.log(e)
- if (!e.detail.authSetting['scope.writePhotosAlbum']) {
- wx.showModal({
- title: '警告',
- content: '不授权无法保存',
- showCancel: false
- })
- that.setData({
- canWrite: false
- })
- } else {
- wx.showToast({
- title: '保存成功'
- })
- that.setData({
- canWrite: true
- })
- }
- },
- // 保存分享图
- saveShare: function () {
- let that = this;
- wx.showLoading({
- title: '图片保存中',
- });
- console.log(that.data);
- wx.downloadFile({
- url: that.data.myqr_url,
- success: function (res) {
- console.log(res)
- wx.saveImageToPhotosAlbum({
- filePath: res.tempFilePath,
- success: function (res) {
- wx.hideLoading();
- wx.showModal({
- title: '存图成功',
- content: '图片成功保存到相册了,可以分享到朋友圈了',
- showCancel: false,
- confirmText: '好的',
- confirmColor: '#a78845',
- success: function (res) {
- if (res.confirm) {
- console.log('用户点击确定');
- that.setData({
- myqr_show: false,
- myqr_blur: 0
- });
- }
- }
- })
- },
- fail: function (res) {
- wx.hideLoading();
- wx.showModal({
- title: '警告',
- content: '不授权无法保存',
- showCancel: false
- })
- that.setData({
- myqr_show: false,
- myqr_blur: 0
- });
- }
- })
- },
- fail: function (res) {
- wx.hideLoading();
- console.log(res);
- }
- })
- },
- //从分享的团购进入
- getGrouponInfo: function (grouponId) {
- let that = this;
- util.request(api.GroupOnJoin, {
- grouponId: grouponId
- }).then(function (res) {
- if (res.errno === 0) {
- that.setData({
- grouponLink: res.data.groupon,
- id: res.data.goods.id
- });
- //获取商品详情
- that.getGoodsInfo();
- }
- });
- },
- getReferee: function () {
- let that = this;
- util.request(api.GoodsDetail, {
- id: that.data.id,
- rId: that.data.rId
- }).then(res => {
- if (res.errno === 0) {
- if (res.data.referee.self != null && res.data.referee.self > 0) {
- res.data.referee.self = res.data.referee.self.toFixed(2);
- res.data.referee.share = res.data.referee.share.toFixed(2);
- }
- that.setData({
- referee: res.data.referee
- });
- console.info(res.data.referee)
- if (JSON.stringify(res.data.referee) == "{}") {
- that.setData({
- referee: {
- self: 0,
- share: 0,
- isReferee: false
- }
- });
- }
- //是引荐人 更新userinfo数据(因为如果后台将客户标记为引荐人 此userinfo是取缓存数据 不会更新状态)
- if (that.data.referee != null && that.data.referee.isReferee) {
- let userInfo = that.data.userInfo;
- userInfo.isDis = true;
- that.setData({
- userInfo: userInfo
- })
- wx.setStorageSync('userInfo', userInfo);
- }
- }
- });
- },
- // 获取商品信息
- getGoodsInfo: function () {
- console.info('1-》getGoodsInfo start');
- let that = this;
- util.request(api.GoodsDetail, {
- id: that.data.id,
- rId: that.data.rId
- }).then(function (res) {
- console.info('2-》getGoodsInfo end');
- console.info(res);
- if (res.errno === 0) {
- let _specificationList = res.data.specificationList
- // 如果仅仅存在一种货品,那么商品页面初始化时默认checked
- if (_specificationList.length == 1) {
- if (_specificationList[0].valueList.length == 1) {
- _specificationList[0].valueList[0].checked = true
- console.info(res.data.info);
- // 如果仅仅存在一种货品,那么商品价格应该和货品价格一致
- // 这里检测一下
- let _productPrice = res.data.productList[0].price;
- let _goodsPrice = res.data.info.retailPrice;
- if (_productPrice != _goodsPrice) {
- console.error('商品数量价格和货品不一致');
- }
- that.setData({
- checkedSpecText: _specificationList[0].valueList[0].value,
- tmpSpecText: '已选择:' + _specificationList[0].valueList[0].value,
- });
- }
- }
- console.info('3-》getGoodsInfo count end');
- //设置显示名称的控件高度
- let height = 56;
- if (res.data.info.name.length > 17 & res.data.info.name.length < 36)
- height = 76;
- else if (res.data.info.name.length >= 36)
- height = 116;
- // console.info(res.data.share);
-
- let goodsComment=res.data.goodsComment;
- let list=[];
- goodsComment.forEach(item=>{
- let obj=item;
- if(item.commentImgs){
- let img=item.commentImgs.split(',');
- if(img.length>=1){
- obj.commentImg=img[0];
- }else{
- obj.commentImg=''
- }
- }
-
- list.push(obj)
- });
-
- that.setData({
- goods: res.data.info,
- // attribute: res.data.attribute,
- // issueList: res.data.issue,
- // comment: res.data.comment,
- //brand: res.data.brand,
- specificationList: res.data.specificationList,
- productList: res.data.productList,
- //productList: res.data.info.products,
- userHasCollect: res.data.userHasCollect,
- shareImage: res.data.shareImage,
- checkedSpecPrice: res.data.info.retailPrice,
- // canShare: res.data.share,
- name_height: height,
- wxShareId: res.data.shareId,
- activited: res.data.activited,
- activityTime: res.data.activityTime,
- activityPrice: res.data.activityPrice,
- countSalesNumber:res.data.countSalesNumber,
- recGoodsList:res.data.recGoodsList,
- recGoodsNum:res.data.recGoodsList.length,
- goodsComment:list,
- goodsBuyTime:res.data.goodsBuyTime,
- checkedSku:res.data.productList[0],
- currentSku:res.data.productList[0],
- buyToastShow:true
- });
- // setTimeout(()=>{
- // that.setData({
- // buyToastShow:true
- // })
- // },500);
- // setTimeout(()=>{
- // that.setData({
- // buyToastShow:false
- // })
- // },3500);
- if (res.data.activited)
- that.handleActivityTime()
- //如果是通过分享的团购参加团购,则团购项目应该与分享的一致并且不可更改
- /* if (that.data.isGroupon) {
- let groupons = that.data.groupon;
- for (var i = 0; i < groupons.length; i++) {
- if (groupons[i].id != that.data.grouponLink.rulesId) {
- groupons.splice(i, 1);
- }
- }
- groupons[0].checked = true;
- //重设团购规格
- that.setData({
- groupon: groupons
- });
- }*/
- if (res.data.userHasCollect == 1) {
- that.setData({
- collect: true
- });
- } else {
- that.setData({
- collect: false
- });
- }
- WxParse.wxParse('goodsDetail', 'html', res.data.info.detail, that);
- //获取推荐商品
- // that.getGoodsRelated();
- }
- });
- },
- // 获取推荐商品
- getGoodsRelated: function () {
- let that = this;
- util.request(api.GoodsRelated, {
- id: that.data.id,
- shopId: this.data.addressInfo.shopId
- }).then(function (res) {
- if (res.errno === 0) {
- that.setData({
- relatedGoods: res.data.list,
- });
- }
- });
- },
- // 团购选择
- clickGroupon: function (event) {
- let that = this;
- //参与团购,不可更改选择
- if (that.data.isGroupon) {
- return;
- }
- let specName = event.currentTarget.dataset.name;
- let specValueId = event.currentTarget.dataset.valueId;
- let _grouponList = this.data.groupon;
- for (let i = 0; i < _grouponList.length; i++) {
- if (_grouponList[i].id == specValueId) {
- if (_grouponList[i].checked) {
- _grouponList[i].checked = false;
- } else {
- _grouponList[i].checked = true;
- }
- } else {
- _grouponList[i].checked = false;
- }
- }
- this.setData({
- groupon: _grouponList,
- });
- },
- // 规格选择
- clickSkuValue: function (event) {
- let that = this;
- let specName = event.currentTarget.dataset.name;
- let specValueId = event.currentTarget.dataset.valueId;
- //判断是否可以点击
- //TODO 性能优化,可在wx:for中添加index,可以直接获取点击的属性名和属性值,不用循环
- let _specificationList = this.data.specificationList;
- for (let i = 0; i < _specificationList.length; i++) {
- if (_specificationList[i].name === specName) {
- 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改变后的信息
- this.changeSpecInfo();
- //重新计算哪些值不可以点击
- },
- //获取选中的团购信息
- getCheckedGrouponValue: function () {
- let checkedValues = {};
- let _grouponList = this.data.groupon;
- for (let i = 0; i < _grouponList.length; i++) {
- if (_grouponList[i].checked) {
- checkedValues = _grouponList[i];
- }
- }
- return checkedValues;
- },
- //获取选中的规格信息
- getCheckedSpecValue: function () {
- let checkedValues = [];
- let _specificationList = this.data.specificationList;
- for (let i = 0; i < _specificationList.length; i++) {
- let _checkedObj = {
- name: _specificationList[i].name,
- valueId: 0,
- valueText: ''
- };
- for (let j = 0; j < _specificationList[i].valueList.length; j++) {
- if (_specificationList[i].valueList[j].checked) {
- _checkedObj.valueId = _specificationList[i].valueList[j].id;
- _checkedObj.valueText = _specificationList[i].valueList[j].value;
- }
- }
- checkedValues.push(_checkedObj);
- }
- return checkedValues;
- },
- //判断规格是否选择完整
- isCheckedAllSpec: function () {
- return !this.getCheckedSpecValue().some(function (v) {
- if (v.valueId == 0) {
- return true;
- }
- });
- },
- getCheckedSpecKey: function () {
- let checkedValue = this.getCheckedSpecValue().map(function (v) {
- return v.valueText;
- });
- return checkedValue;
- },
- // 规格改变时,重新计算价格及显示信息
- changeSpecInfo: function () {
- let checkedNameValue = this.getCheckedSpecValue();
- //设置选择的信息
- let checkedValue = checkedNameValue.filter(function (v) {
- if (v.valueId != 0) {
- return true;
- } else {
- return false;
- }
- }).map(function (v) {
- return v.valueText;
- });
- if (checkedValue.length > 0) {
- this.setData({
- tmpSpecText: checkedValue.join(' ')
- });
- } else {
- this.setData({
- tmpSpecText: '请选择规格数量'
- });
- }
- if (this.isCheckedAllSpec()) {
- this.setData({
- checkedSpecText: this.data.tmpSpecText
- });
- // 规格所对应的货品选择以后
- let checkedProductArray = this.getCheckedProductItem(this.getCheckedSpecKey());
- if (!checkedProductArray || checkedProductArray.length <= 0) {
- this.setData({
- soldout: true
- });
- console.error('规格所对应货品不存在');
- return;
- }
- let checkedProduct = checkedProductArray[0];
- if (checkedProduct.number > 0) {
- this.setData({
- checkedSpecPrice: checkedProduct.price,
- soldout: false
- });
- } else {
- this.setData({
- checkedSpecPrice: this.data.goods.retailPrice,
- soldout: true
- });
- }
- } else {
- this.setData({
- checkedSpecText: '规格数量选择',
- checkedSpecPrice: this.data.goods.retailPrice,
- soldout: false
- });
- }
- },
- // 获取选中的产品(根据规格)
- getCheckedProductItem: function (key) {
- return this.data.productList.filter(function (v) {
- if (v.specifications.toString() == key.toString()) {
- return true;
- } else {
- return false;
- }
- });
- },
- onLoad: function (options) {
- console.log(options);
- // if (app.globalData.hasLogin) {
- // let userInfo = wx.getStorageSync('userInfo');
- // app.globalData.userInfo=userInfo;
- // this.setData({
- // userInfo: userInfo,
- // hasLogin: true
- // });
- // }
- // 页面初始化 options为页面跳转所带来的参数
- var addressInfo = wx.getStorageSync('addressInfo');
- if (addressInfo) {
- this.setData({
- addressInfo: addressInfo
- })
- }
- if (options.rId) {
- this.setData({
- rId: parseInt(options.rId)
- })
- }
- if (options.grouponId) {
- this.setData({
- isGroupon: true,
- });
- this.getGrouponInfo(options.grouponId);
- }
- if (options.shareId) {
- this.setData({
- shareId: parseInt(options.shareId)
- })
- }
- console.info(this.data.shareId)
- if (options.id) {
- this.setData({
- id: parseInt(options.id)
- });
- this.getGoodsInfo();
- }
-
- if(options.fraId){
- wx.setStorageSync('fraId',options.fraId);
- }
- // let that = this;
- // wx.getSetting({
- // success: function (res) {
- // console.log(res)
- // //不存在相册授权
- // if (!res.authSetting['scope.writePhotosAlbum']) {
- // wx.authorize({
- // scope: 'scope.writePhotosAlbum',
- // success: function () {
- // that.setData({
- // canWrite: true
- // })
- // },
- // fail: function (err) {
- // that.setData({
- // canWrite: false
- // })
- // }
- // })
- // } else {
- // that.setData({
- // canWrite: true
- // });
- // }
- // }
- // })
- },
- onShow: function () {
- // 页面显示
- if (app.globalData.hasLogin) {
- let userInfo = wx.getStorageSync('userInfo');
- app.globalData.userInfo = userInfo;
- this.setData({
- userInfo: userInfo,
- hasLogin: true
- });
- }
- // this.getReferee();
- // 已登陆并且是引荐人展示自购推广
- if (this.data.hasLogin && this.data.userInfo.isDis) {
- // this.setData({
- // selfDiscount:0,
- // spreadDiscount:0,
- // })
- }
- },
- //添加或是取消收藏
- addCollectOrNot: function () {
- let that = this;
- util.request(api.CollectAddOrDelete, {
- type: 0,
- valueId: this.data.id
- }, "POST")
- .then(function (res) {
- if (that.data.userHasCollect == 1) {
- that.setData({
- collect: false,
- userHasCollect: 0
- });
- } else {
- that.setData({
- collect: true,
- userHasCollect: 1
- });
- }
- });
- },
- //立即购买(先自动加入购物车)appType=0:先买后约 appType=1:立即预约
- addFast: function (event) {
- let appType = event.currentTarget.dataset.type;
- var that = this;
- // 如果是安心包只能购买一个
- console.log(this.data.goods);
- // 如果是中介类,跳转到信息收集页面
- if (this.data.goods.type == 2) {
- app.globalData.infoGoods = {
- name: this.data.goods.name,
- brief: this.data.goods.brief,
- picUrl: this.data.goods.picUrl,
- type: this.data.goods.type
- };
- wx.navigateTo({
- url: '/pages/goods/infoCollect/infoCollect'
- });
- return false;
- }
- // if (this.data.openAttr == false) {
- // //打开规格选择窗口
- // this.setData({
- // openAttr: !this.data.openAttr
- // });
- // } else {
- //提示选择完整规格
- // if (!this.isCheckedAllSpec()) {
- // util.showErrorToast('请选择完整规格');
- // return false;
- // }
- //根据选中的规格,判断是否有对应的sku信息
- // let checkedProductArray = this.getCheckedProductItem(this.getCheckedSpecKey());
-
- // if (!checkedProductArray || checkedProductArray.length <= 0) {
- // //找不到对应的product信息,提示没有库存
- // util.showErrorToast('没有库存');
- // return false;
- // }
- // let checkedProduct = checkedProductArray[0];
-
- //验证库存
- // if (checkedProduct.number <= 0) {
- // util.showErrorToast('没有库存');
- // return false;
- // }
- //验证团购是否有效
- let checkedGroupon = this.getCheckedGrouponValue();
- //立即购买
- util.request(api.CartFastAdd, {
- goodsId: this.data.goods.id,
- number: this.data.number,
- // productId: checkedProduct.id,
- productId: this.data.checkedSku.id,
- shareId: this.data.shareId,
- unitIncreaseNumber:this.data.plusNum
- }, "POST")
- .then(res => {
- if (res.errno == 0) {
- // 如果storage中设置了cartId,则是立即购买,否则是购物车购买
- try {
- wx.setStorageSync('cartId', res.data);
- wx.setStorageSync('grouponRulesId', checkedGroupon.id);
- wx.setStorageSync('grouponLinkId', that.data.grouponLink.id);
- // 支付结果页面展示图片用
- app.globalData.infoGoods = {
- name: this.data.goods.name,
- brief: this.data.goods.brief,
- picUrl: this.data.goods.picUrl,
- type: this.data.goods.type
- };
- //存储客户按钮选择的预约动作
- wx.setStorageSync('appType', appType ? appType : '');
- if (that.data.shareId > 0)
- wx.navigateTo({
- url: '/pages/checkout/checkout?shareId=' + that.data.shareId
- })
- else
- wx.navigateTo({
- url: '/pages/checkout/checkout'
- })
- } catch (e) {
- console.info(e)
- }
- } else {
- util.showErrorToast(res.errmsg);
- }
- });
- //}
- },
- //添加到购物车
- addToCart: function () {
- var that = this;
- if (this.data.openAttr == false) {
- //打开规格选择窗口
- this.setData({
- openAttr: !this.data.openAttr
- });
- } else {
- //提示选择完整规格
- if (!this.isCheckedAllSpec()) {
- util.showErrorToast('请选择完整规格');
- return false;
- }
- //根据选中的规格,判断是否有对应的sku信息
- let checkedProductArray = this.getCheckedProductItem(this.getCheckedSpecKey());
- // if (!checkedProductArray || checkedProductArray.length <= 0) {
- // //找不到对应的product信息,提示没有库存
- // util.showErrorToast('没有库存');
- // return false;
- // }
- let checkedProduct = checkedProductArray[0];
- //验证库存
- // if (checkedProduct.number <= 0) {
- // util.showErrorToast('没有库存');
- // return false;
- // }
- //添加到购物车
- util.request(api.CartAdd, {
- goodsId: this.data.goods.id,
- number: this.data.number,
- productId: checkedProduct.id
- }, "POST")
- .then(function (res) {
- let _res = res;
- if (_res.errno == 0) {
- wx.showToast({
- title: '添加成功'
- });
- that.setData({
- openAttr: !that.data.openAttr,
- cartGoodsCount: _res.data
- });
- //显示tab购物车缓存
- //user.cartadd(that.data.number);
- if (that.data.userHasCollect == 1) {
- that.setData({
- collect: true
- });
- } else {
- that.setData({
- collect: false
- });
- }
- } else {
- util.showErrorToast(_res.errmsg);
- }
- });
- }
- },
- cutNumber: function () {
- this.setData({
- number: (this.data.number - 1 > 1) ? this.data.number - 1 : 1
- });
- },
- addNumber: function () {
- // 如果是安心包只能购买一个
- console.log(this.data.goods);
- if (this.data.goods.goodsSn == '1036016') {
- wx.showToast({
- title: '此款商品只能购买一个',
- icon: 'none',
- duration: 2000
- });
- } else {
- this.setData({
- number: this.data.number + 1
- });
- }
- },
- onHide: function () {
- // 页面隐藏
- clearInterval(this.data.activityTimer);
- },
- onUnload: function () {
- // 页面关闭
- clearInterval(this.data.activityTimer);
- },
- switchAttrPop: function () {
- if (this.data.openAttr == false) {
- this.setData({
- openAttr: !this.data.openAttr
- });
- }
- },
- closeAttr: function () {
- this.setData({
- openAttr: false,
- });
- },
- closeShare: function () {
- this.setData({
- openShare: false,
- });
- },
- openCartPage: function () {
- wx.switchTab({
- url: '/pages/tabBar/cart/cart'
- });
- },
- onReady: function () {
- // 页面渲染完成
- },
- qrtouchstart: function () {
- this.setData({
- myqr_blur: 100,
- myqr_show: false
- });
- },
- copyToHM() {
- let copyLink = this.data.goods.copyLink;
- console.log(copyLink);
- if (copyLink != undefined && copyLink != '') {
- wx.setClipboardData({
- data: copyLink,
- success(res) {
- wx.getClipboardData({
- success(res) {
- console.log(res.data) // data
- }
- })
- }
- });
- } else {
- wx.showToast({
- title: '该商品暂未配置盒马链接',
- icon: 'none'
- })
- }
- },
- onSelfPayChange(e) {
- console.log(e);
- this.setData({
- selfPayChecked: e.detail,
- });
- },
- onSpreadPayChange(e) {
- console.log(e);
- this.setData({
- spreadPayChecked: e.detail,
- });
- },
- cancelSelfPay() {
- let selfPayChecked = this.data.selfPayChecked;
- if (selfPayChecked == true) {
- wx.setStorageSync('selfPayChecked', true);
- }
- this.setData({
- selfPayShow: false,
- });
- },
- cancelSpreadPay() {
- let spreadPayChecked = this.data.spreadPayChecked;
- if (spreadPayChecked == true) {
- wx.setStorageSync('spreadPayChecked', true);
- }
- this.setData({
- spreadPayShow: false,
- });
- },
- goSelfPay() {
- let selfPayChecked = wx.getStorageSync('selfPayChecked');
- if (selfPayChecked != true) {
- this.setData({
- selfPayShow: true,
- });
- } else {
- this.addFast();
- }
- },
- goSpread() {
- let spreadPayChecked = wx.getStorageSync('spreadPayChecked');
- console.log(spreadPayChecked);
- if (spreadPayChecked != true) {
- this.setData({
- spreadPayShow: true,
- });
- } else {
- // wx.navigateTo({
- // url: '/pages/goods/goodsPoster/goodsPoster?goodsId='+this.data.goods.id,
- // })
- this.createPoster();
- }
- },
- posterCopy() {
- let that = this
- wx.setClipboardData({
- data: that.data.myqr_ads,
- success: function (res) {
- wx.getClipboardData({
- success: function (res) {
- wx.showToast({
- title: '文案复制成功',
- icon: 'success',
- duration: 2000
- });
- // that.hidePoster();
- }
- })
- }
- })
- },
- hidePoster() {
- this.setData({
- myqr_show: false,
- myqr_blur: 100,
- myqr_bottom_btn: 'fixed'
- })
- },
- createPoster() {
- wx.showLoading({
- title: '生成中',
- })
- wx.pageScrollTo({
- scrollTop: 0
- })
- if (this.data.myqr_url != null) {
- wx.hideLoading();
- this.setData({
- myqr_show: true,
- myqr_blur: 25,
- myqr_bottom_btn: 'unset'
- })
- return;
- }
- util.request(api.QrGoodsCodeCreate, {
- goodsId: this.data.goods.id
- }).then(res => {
- wx.hideLoading();
- if (res.errno == 0) {
- this.setData({
- myqr_url: res.data.imgUrl,
- myqr_ads: res.data.ads,
- myqr_show: true,
- myqr_blur: 25,
- myqr_bottom_btn: 'unset'
- })
- } else {
- util.showErrorToast("未设置分享图")
- }
- });
- },
- goSaveQrcode: function () { //保存二维码图片
- let that = this;
- console.info(that.data.myqr_url);
- wx.downloadFile({
- url: that.data.myqr_url,
- success: function (res) {
- if (res.statusCode === 200) {
- let img = res.tempFilePath;
- wx.saveImageToPhotosAlbum({
- filePath: img,
- success(res) {
- that.goCloseMyqr('个人专属二维码图片已保存到您的相册');
- },
- fail(res) {
- that.goCloseMyqr('网络或授权问题 图片保存失败 请重试');
- }
- })
- } else
- that.goCloseMyqr('网络或授权问题 图片保存失败 请重试');
- },
- fail(res) {
- that.goCloseMyqr('网络或授权问题 图片保存失败 请重试');
- }
- })
- },
- goCloseMyqr: function (msg) { //关闭分享图片的弹层
- this.hidePoster();
- if (msg) {
- wx.showToast({
- title: msg,
- icon: 'none',
- duration: 3000
- })
- }
- },
- reSelfPay() {
- let selfPayChecked = this.data.selfPayChecked;
- if (selfPayChecked == true) {
- wx.setStorageSync('selfPayChecked', true);
- }
- this.setData({
- selfPayShow: false,
- });
- this.addFast();
- },
- reSpread() {
- let spreadPayChecked = this.data.spreadPayChecked;
- if (spreadPayChecked == true) {
- wx.setStorageSync('spreadPayChecked', true);
- }
- this.setData({
- spreadPayShow: false,
- });
- this.createPoster();
- // wx.navigateTo({
- // url: '/pages/goods/goodsPoster/goodsPoster?goodsId='+this.data.goods.id,
- // })
- },
- goMemberCenter() {
- if (!app.globalData.hasLogin) {
- wx.navigateTo({
- url: "/pages/auth/login/login"
- });
- return;
- } else {
- wx.navigateTo({
- url: "/pages/member/memberCenter/memberCenter"
- });
- }
- },
- onSkuClose(){
- this.setData({
- chooseSkuVisible:false
- });
- },
- showSkuPopup(){
- this.setData({
- chooseSkuVisible:true,
- currentSku:this.data.checkedSku,
- activeSku:this.data.checkedSku.id
- });
- },
- selectSku(e){
- let id=e.currentTarget.dataset.id;
- let index=e.currentTarget.dataset.index;
- this.setData({
- activeSku:id,
- currentSku:this.data.productList[index],
-
- });
- },
- confSku(){
- this.setData({
- checkedSku:this.data.currentSku,
- chooseSkuVisible:false
- });
- },
- goWholeEval(){
- wx.navigateTo({
- url: '/pages/goods/wholeEvaluation/wholeEvaluation?id='+this.data.id,
- })
- },
- bindGoodsNumInput(e){
- this.setData({
- plusNum:e.detail.value
- })
- },
- minusNum(){
- if(this.data.plusNum==0){
- return false;
- }else{
- let result=Number(this.data.plusNum)-1;
- this.setData({
- plusNum:(result==0?'0':result)
- });
- }
- },
- addNum(){
-
- let result=Number(this.data.plusNum)+1;
- this.setData({
- plusNum:result
- });
-
- },
- })
|