12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406 |
- // pages/prod/prod.js
- const app = getApp()
- var http = require('../../utils/http.js');
- var config = require('../../utils/config.js');
- var util = require('../../utils/util.js');
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- shopId: 1,
- shopName: '',
- picDomain: config.picDomain,
- indicatorDots: true,
- indicatorColor: '#f2f2f2',
- indicatorActiveColor: '#FF941A',
- isAuthInfo: true,
- autoplay: true,
- interval: 3000,
- duration: 1000,
- prodNum: 1,
- totalCartNum: 0,
- groupActivityId: 0,
- pic: "",
- imgs: '',
- prodName: '',
- price: 0,
- actPrice: 0,
- content: '',
- prodId: 0,
- brief: '',
- skuId: 0,
- popupShow: false,
- // 是否获取过用户领取过的优惠券id
- loadCouponIds: false,
- skuShow: false,
- skuGroupShow: false,
- commentShow: false,
- couponList: [],
- skuList: [],
- skuGroup: {},
- findSku: true,
- defaultSku: undefined,
- detaultGroupSku: undefined,
- selectedProp: [],
- selectedPropObj: {},
- selectedProperties: "",
- propKeys: [],
- allProperties: [],
- prodCommData: {},
- prodCommPage: {
- current: 0,
- pages: 0,
- records: []
- },
- littleCommPage: [],
- evaluate: -1,
- isCollection: false,
- shareShow: false,
- isDist: false, //是否分销员
- isDistProd: false, //是否分销商品
- distributionCardNo: "", //分销员卡号
- wxCodeShow: false, //是否显示二维码弹层
- shareWxCode: "", //分享二维码图片路径
- groupActivity: {}, // 团购活动
- endOfGroupTime: {}, // 距离团购活动结束还剩多久
- joinGroupList: [], // 可加入的团列表
- skuShowType: 0, // sku的显示类型 0普通sku 1拼团sku
- totalStocks: 0, // 活动剩余库存
- hasMaxNum: false, // 是否限购
- maxNum: 0, // 限购数量
- joinGroupListTimer: '',
- endOfGroupTimer: '',
- scene: '',
- prodDiscountList: [], // 商品促销活动列表
- phoneNumber: '', //客服电话
- showBacktop: false, //回到顶部显隐
- showDiscountPopup: false, //促销弹窗显隐
- videoContext: '', // 视频组件
- isPlaying: false, // 视频是否播放中
- currentSwiper: 0, // 当前轮播index
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- console.log(options)
- //根据Ticket获取保存的内容(pc团购扫码 || 分销)
- if (options.scene) {
- this.setData({
- scene: options.scene,
- })
- this.getContent() //根据Ticket获取保存的内容
- }
- if(options.shopid){
- this.setData({
- shopId: Number(options.shopid) ,
- });
- }
- // 加载商品信息
- if (options.prodid) {
- this.setData({
- prodId: options.prodid,
- });
- this.executionFunction() //所有需要加载的函数
- }
- if (options.cardno && options.type == 2) {
- // this.bindDistUser(options.cardno)
- this.setData({
- distributionCardNo: options.cardno,
- })
- }
- this.getCartCount() //请求购物车数量
- },
- /**
- * 执行函数
- */
- executionFunction: function () {
- // 加载评论数据
- this.getProdCommData();
- // 加载评论项
- this.getLittleProdComm();
- // 获取商品是否被收藏信息
- this.getCollection();
- // 查询分销开关是否开启
- this.getDistInfo();
- //加载商品数据
- this.getProdInfo();
- // 获取商品所有促销活动
- this.getPordDiscountList()
- },
- /**
- * 根据Ticket获取保存的内容
- */
- getContent: function () {
- http.request({
- url: "/qrcodeTicket/getContent",
- method: "GET",
- data: {
- ticket: this.data.scene
- },
- callBack: (res) => {
- console.log(res)
- var content = JSON.parse(res.content);
- var ids = JSON.parse(content.content)
- if (res.type == 1) { //pc团购二维码跳转
- this.setData({
- prodId: ids.prodId,
- groupActivityId: ids.groupActivityId
- })
- this.executionFunction() //所有需要加载的函数
- } else if (res.type == 2) { //分销员二维码跳转
- this.setData({
- prodId: ids.shareProdId,
- distributionCardNo: ids.cardNo
- })
- this.executionFunction() //所有需要加载的函数
- }
- }
- })
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- clearTimeout(this.data.endOfGroupTimer)
- },
- /**
- * 分销绑定用户
- */
- // bindDistUser(cardno) {
- // var params = {
- // url: "/p/distribution/bindUser",
- // method: "post",
- // data: cardno,
- // callBack:res=>{
- // console.log('绑定分销员',res)
- // }
- // }
- // http.request(params)
- // },
- /**
- * 查询分销相关信息
- */
- getDistInfo() {
- //查询分销开关是否开启
- http.request({
- url: "/p/distribution/distributionBasicSet/canDistribution",
- method: "GET",
- dontTrunLogin: true,
- // data: {
- // shopId: this.data.shopId,
- // },
- callBack: (res) => {
- if (res == 1) {
- this.getIsDistInfo();
- }
- }
- })
- },
- /**
- * 查询用户 是否为分销员
- */
- getIsDistInfo() {
- http.request({
- url: "/p/distribution/user/distributionUserInfo",
- method: "GET",
- callBack: (res) => {
- console.log('是否分销员', res)
- if (res && res.state == 1) {
- this.setData({
- isDist: true
- });
- this.getIsDistProd();
- wx.setStorageSync("distCardNo", res.cardNo);
- }
- }
- })
- },
- /**
- * 查询是否为分销商品
- */
- getIsDistProd() {
- http.request({
- url: "/p/distribution/prod/isDistributionProd",
- method: "GET",
- data: {
- prodId: this.data.prodId,
- },
- callBack: (res) => {
- console.log('是否分销商品', res)
- if (res) {
- this.setData({
- isDistProd: true
- });
- }
- }
- })
- },
- /**
- * 获取商品是否被收藏信息
- */
- getCollection() {
- wx.showLoading();
- var params = {
- url: "/p/user/collection/isCollection",
- method: "GET",
- dontTrunLogin: true,
- data: {
- prodId: this.data.prodId
- },
- callBack: (res) => {
- this.setData({
- isCollection: res
- })
- wx.hideLoading();
- }
- };
- http.request(params);
- },
- /**
- * 添加或者取消收藏商品
- */
- addOrCannelCollection() {
- util.checkAuthInfo(() => {
- var params = {
- url: "/p/user/collection/addOrCancel",
- method: "POST",
- data: this.data.prodId,
- callBack: (res) => {
- this.setData({
- isCollection: !this.data.isCollection
- })
- wx.showToast({
- title: res ? '已添加收藏' : '已取消收藏',
- duration: 3000,
- icon: 'none',
- })
- setTimeout(() => {
- wx.hideToast()
- }, 3000)
- }
- };
- http.request(params);
- })
- },
- // 获取商品信息
- getProdInfo() {
- wx.showLoading();
- var params = {
- url: "/prod/prodInfo",
- method: "GET",
- data: {
- prodId: this.data.prodId,
- platform:1,
- shopId:this.data.shopId
- // userType: 0
- },
- callBack: (res) => {
- let pic = ''
- var imgStrs = res.imgs;
- if(imgStrs){
- var imgs = imgStrs.split(",");
- }
- var content = res.content?util.formatHtml(res.content):'';
- if(res.pic){
- pic = res.pic.split(',')
- res.pic = pic[0]
- }
- this.setData({
- imgs: imgs,
- content: content,
- price: res.price,
- prodName: res.prodName,
- prodId: res.prodId,
- brief: res.brief,
- totalStocks: res.totalStocks,
- // skuId: res.skuId
- skuList: res.skuList,
- pic: res.pic,
- // shopId: res.shopId,
- video: res.video,
- prodType: res.prodType
- });
- if (res.video) {
- this.getVideoInfo()
- }
- // 团购商品
- if (res.prodType === 1) {
- this.setData({
- groupActivityId: res.activityId
- });
- this.getGroupActivity();
- this.getJoinGroupList();
- }
- // 获取优惠券
- this.getCouponList();
- // 组装sku
- this.groupSkuProp(res.skuList);
- this.getShopInfo();
- wx.hideLoading();
- },
- errCallBack: (err) => {
- console.log(err)
- if (err.statusCode == 400) {
- wx.showModal({
- title: '提示',
- content: err.data,
- showCancel: false,
- success: (res) => {
- if (res.confirm) {
- wx.navigateBack({
- delta: 1
- })
- }
- }
- })
- }
- }
- };
- http.request(params);
- },
- /**
- * 获取店铺信息
- */
- getShopInfo() {
- http.request({
- url: "/shop/headInfo",
- method: "GET",
- data: {
- shopId: this.data.shopId,
- },
- callBack: (res) => {
- this.setData({
- shopName: res.shopName,
- shopLogo: res.shopLogo,
- phoneNumber: res.tel
- })
- }
- })
- },
- getProdCommData() {
- http.request({
- url: "/prod/prodCommData",
- method: "GET",
- data: {
- prodId: this.data.prodId,
- },
- callBack: (res) => {
- this.setData({
- prodCommData: res
- })
- }
- })
- },
- // 获取部分评论
- getLittleProdComm() {
- if (this.data.prodCommPage.records.length) {
- return;
- }
- this.getProdCommPage();
- },
- getMoreCommPage(e) {
- this.getProdCommPage();
- },
- // 获取分页获取评论
- getProdCommPage(e) {
- if (e) {
- if (e.currentTarget.dataset.evaluate === this.data.evaluate) {
- return;
- }
- this.setData({
- prodCommPage: {
- current: 0,
- pages: 0,
- records: []
- },
- evaluate: e.currentTarget.dataset.evaluate
- })
- }
- http.request({
- url: "/prod/prodCommPageByProd",
- method: "GET",
- data: {
- prodId: this.data.prodId,
- size: 10,
- current: this.data.prodCommPage.current + 1,
- evaluate: this.data.evaluate
- },
- callBack: (res) => {
- res.records.forEach(item => {
- if (item.pics) {
- item.pics = item.pics.split(',')
- }
- })
- let records = this.data.prodCommPage.records
- records = records.concat(res.records)
- this.setData({
- prodCommPage: {
- current: res.current,
- pages: res.pages,
- records: records
- }
- })
- // 如果商品详情中没有评论的数据,截取两条到商品详情页商品详情
- if (!this.data.littleCommPage.length) {
- this.setData({
- littleCommPage: records.slice(0, 2)
- })
- }
- }
- })
- },
- /**
- * 评论小图点击事件(点击图片显示大图)
- */
- clickImg: function (e) {
- const current = e.currentTarget.dataset.index //获取当前点击的 图片 url
- const pics = e.currentTarget.dataset.pics
- wx.previewImage({
- current: pics[current],
- urls: pics
- })
- },
- getCouponList() {
- http.request({
- url: "/coupon/listByProdId",
- method: "GET",
- data: {
- prodId: this.data.prodId,
- shopId: this.data.shopId,
- },
- callBack: (res) => {
- this.setData({
- couponList: res
- })
- }
- })
- },
- /**
- * 团购商品详情信息
- */
- getGroupActivity() {
- http.request({
- url: "/groupProd/info",
- method: "GET",
- data: {
- prodId: this.data.prodId,
- groupActivityId: this.data.groupActivityId,
- },
- callBack: (res) => {
- if (res.success) {
- this.setData({
- groupActivity: res.obj,
- maxNum: res.obj.maxNum,
- hasMaxNum: res.obj.hasMaxNum
- })
- this.setDefaultGroupSku();
- this.groupActivityCountdown(res.obj)
- } else {
- this.setData({
- groupActivityId: null
- });
- }
- }
- })
- },
- // 团购倒计时
- groupActivityCountdown(groupActivity) {
- let endOfGroupTime;
- // activityStatus 1 未开始
- if (groupActivity.activityStatus === 1) {
- endOfGroupTime = util.endOfStartTime(util.dateToTimestamp(groupActivity.startTime), new Date().getTime())
- } else {
- endOfGroupTime = util.endOfStartTime(new Date().getTime(), util.dateToTimestamp(groupActivity.endTime))
- }
- this.setData({
- endOfGroupTime: endOfGroupTime,
- endOfGroupTimer: setTimeout(() => this.groupActivityCountdown(groupActivity), 1000)
- })
- },
- // 可加入的拼团列表
- getJoinGroupList() {
- http.request({
- url: "/groupProd/joinGroupList",
- method: "GET",
- data: {
- prodId: this.data.prodId,
- groupActivityId: this.data.groupActivityId,
- showSize: 3
- },
- callBack: (res) => {
- this.setData({
- joinGroupList: res
- })
- this.joinGroupListCountdown(res)
- }
- })
- },
- joinGroupListCountdown(joinGroupList) {
- joinGroupList.forEach(item => {
- item.endOfGroupTime = util.endOfStartTime(new Date().getTime(), util.dateToTimestamp(item.endTime))
- })
- this.setData({
- joinGroupList: joinGroupList,
- joinGroupListTimer: setTimeout(() => this.joinGroupListCountdown(joinGroupList), 1000)
- })
- },
- //根据sku的属性 分组
- groupSkuProp: function (skuList) {
- // var skuList = this.data.skuList;
- if (skuList.length == 1 && skuList[0].properties == "") {
- this.setData({
- defaultSku: skuList[0]
- });
- this.setDefaultGroupSku();
- return;
- }
- var skuGroup = {};
- var allProperties = [];
- var propKeys = [];
- this.setData({
- selectedPropObj: {}
- });
- for (var i = 0; i < skuList.length; i++) {
- var defaultSku = this.data.defaultSku;
- var isDefault = false;
- if (!defaultSku && skuList[i].price == this.data.price) { //找到和商品价格一样的那个SKU,作为默认选中的SKU
- defaultSku = skuList[i];
- isDefault = true;
- this.setData({
- defaultSku: defaultSku
- });
- }
- var properties = skuList[i].properties; //版本:公开版;颜色:金色;内存:64GB
- allProperties.push(properties);
- var propList = properties.split(";"); // ["版本:公开版","颜色:金色","内存:64GB"]
- var selectedPropObj = this.data.selectedPropObj;
- for (var j = 0; j < propList.length; j++) {
- var propval = propList[j].split(":"); //["版本","公开版"]
- var props = skuGroup[propval[0]]; //先取出 版本对应的值数组
- //如果当前是默认选中的sku,把对应的属性值 组装到selectedProp
- if (isDefault) {
- propKeys.push(propval[0]);
- selectedPropObj[propval[0]] = propval[1];
- }
- if (props == undefined) {
- props = []; //假设还没有版本,新建个新的空数组
- props.push(propval[1]); //把 "公开版" 放进空数组
- } else {
- if (!this.array_contain(props, propval[1])) { //如果数组里面没有"公开版"
- props.push(propval[1]); //把 "公开版" 放进数组
- }
- }
- skuGroup[propval[0]] = props; //最后把数据 放回版本对应的值
- }
- this.setData({
- selectedPropObj: selectedPropObj,
- propKeys: propKeys
- });
- }
- this.parseSelectedObjToVals();
- this.setData({
- skuGroup: skuGroup,
- allProperties: allProperties
- });
- this.setDefaultGroupSku();
- },
- //将已选的 {key:val,key2:val2}转换成 [val,val2]
- parseSelectedObjToVals: function () {
- var selectedPropObj = this.data.selectedPropObj;
- var selectedProperties = "";
- var selectedProp = [];
- for (var key in selectedPropObj) {
- selectedProp.push(selectedPropObj[key]);
- selectedProperties += key + ":" + selectedPropObj[key] + ";";
- }
- selectedProperties = selectedProperties.substring(0, selectedProperties.length - 1);
- this.setData({
- selectedProp: selectedProp,
- selectedProperties: selectedProperties
- });
- var findSku = false;
- for (var i = 0; i < this.data.skuList.length; i++) {
- if (this.data.skuList[i].properties == selectedProperties) {
- findSku = true;
- this.setData({
- defaultSku: this.data.skuList[i]
- });
- break;
- }
- }
- this.setData({
- findSku: findSku
- });
- this.setDefaultGroupSku();
- },
- //点击选择规格
- toChooseItem: function (e) {
- var ok = e.currentTarget.dataset.ok;
- if (ok == 0) {
- return;
- }
- var val = e.currentTarget.dataset.val;
- var key = e.currentTarget.dataset.key;
- var selectedPropObj = this.data.selectedPropObj;
- selectedPropObj[key] = val;
- this.setData({
- selectedPropObj: selectedPropObj
- });
- this.parseSelectedObjToVals();
- },
- //判断数组是否包含某对象
- array_contain: function (array, obj) {
- for (var i = 0; i < array.length; i++) {
- if (array[i] == obj) //如果要求数据类型也一致,这里可使用恒等号===
- return true;
- }
- return false;
- },
- /**
- * 设置选中的拼团sku
- */
- setDefaultGroupSku() {
- if (this.data.groupActivityId) {
- var groupSkuList = this.data.groupActivity.groupSkuList;
- if (groupSkuList) {
- for (var i = 0; i < groupSkuList.length; i++) {
- if (groupSkuList[i].properties == this.data.selectedProperties) {
- this.setData({
- detaultGroupSku: groupSkuList[i]
- });
- break;
- }
- }
- }
- }
- },
- /**
- * 去凑团
- */
- toSpellGroupDetail(e) {
- const groupTeamId = e.currentTarget.dataset.groupteamid
- util.checkAuthInfo(() => {
- wx.navigateTo({
- url: '/pages/spellGroupDetails/spellGroupDetails?groupTeamId=' + groupTeamId,
- })
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- this.videoContext = wx.createVideoContext('myVideo')
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- this.getCartCount()
- if (this.data.prodType == 1) {
- this.getJoinGroupList()
- }
- },
- getCartCount: function () {
- var params = {
- url: "/p/shopCart/prodCount",
- method: "GET",
- dontTrunLogin: true,
- data: {platform:1},
- callBack: (res) => {
- if (res > 0) {
- // wx.setTabBarBadge({
- // index: 2,
- // text: res + "",
- // })
- var app = getApp();
- app.globalData.totalCartCount = res;
- } else {
- // wx.removeTabBarBadge({
- // index: 2
- // })
- var app = getApp();
- app.globalData.totalCartCount = 0;
- }
- this.setData({
- totalCartNum: res
- })
- }
- };
- http.request(params);
- },
- /**
- * 阻止滚动
- */
- preventScorll() {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 跳转到首页
- */
- toHomePage: function () {
- wx.switchTab({
- url: '/pages/index/index',
- })
- },
- /**
- * 跳转到购物车
- */
- toCartPage: function () {
- wx.switchTab({
- url: '/pages/basket/basket',
- })
- },
- handleContact: function (e) {
- console.log(e.detail, '----路径')
- console.log(e.detail.query, '----参数')
- // this.get_register()
- },
- /**
- * 创建商户
- * @param {*} event
- */
- // get_register: function () {
- // let url='https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wxc032a09413289004&secret=453c5047ae43288f1d015d48df32a5c0'
- // wx.request({
- // url:url,
- // method: 'GET',
- // data: {},
- // header: {
- // 'content-type': 'application/json' // 默认值
- // },
- // success(res) {
- // // console.log(res.data.access_token)
- // wx.request({
- // url: 'https://api.weixin.qq.com/cgi-bin/business/register?access_token='+res.data.access_token,
- // method: 'POST',
- // data: {
- // account_name: "test_shopname",
- // nickname: "苹果",
- // icon_media_id: "png",
- // transfer_to_commkf: true
- // },
- // header: {
- // 'content-type': 'application/json' // 默认值
- // },
- // success(res) {
- // console.log(res.data)
- // }
- // })
- // }
- // })
- // },
- /**
- * 加入购物车
- */
- addToCart: function (event) {
- let skuList = this.data.skuList[0]
- console.log(333333,skuList);
- if (skuList.weight > 20000) {
- wx.showToast({
- title: "商品超过20kg,太重咯~",
- icon: "none"
- })
- return;
- }
- if(this.data.totalStocks<0){
- wx.showToast({
- title: "该商品暂无库存~",
- icon: "none"
- })
- return;
- }
- if (this.data.isPlaying) {
- this._stopPlay()
- }
- if (!this.data.skuShow) {
- this.setData({
- skuShow: true
- })
- return
- }
- wx.showLoading({
- mask: true
- });
- // 查看是否授权
- util.checkAuthInfo(this.callChangeItem)
- },
- callChangeItem() {
- wx.showLoading({
- mask: true
- });
- http.request({
- url: "/p/shopCart/changeItem",
- method: "POST",
- data: {
- basketId: 0,
- count: this.data.prodNum,
- prodId: this.data.prodId,
- shopId: this.data.shopId,
- shopName: this.data.shopName,
- skuId: this.data.defaultSku.skuId,
- distributionCardNo: this.data.distributionCardNo,
- platform:1
- },
- callBack: (res) => {
- this.setData({
- totalCartNum: this.data.totalCartNum + this.data.prodNum,
- skuShow: false,
- });
- wx.hideLoading();
- wx.showToast({
- title: "加入购物车成功",
- icon: "none"
- })
- }
- });
- },
- /**
- * 立即购买
- */
- buyNow: function () {
- let skuList = this.data.skuList[0]
- if (skuList.weight > 20000) {
- wx.showToast({
- title: "商品超过20kg,太重咯~",
- icon: "none"
- })
- return;
- }
- if(this.data.totalStocks<0){
- wx.showToast({
- title: "该商品暂无库存~",
- icon: "none"
- })
- return;
- }
- if (this.data.isPlaying) {
- this._stopPlay()
- }
- if (!this.data.skuShow) {
- this.setData({
- skuShow: true
- })
- return
- }
- wx.showLoading({
- mask: true
- });
- // 查看是否授权
- util.checkAuthInfo(this._buyNowData(this))
- },
- /**
- * 立即购买参数配置
- */
- _buyNowData(ctx) {
- wx.setStorageSync("orderItem", JSON.stringify({
- prodId: ctx.data.prodId,
- skuId: ctx.data.defaultSku.skuId,
- prodCount: ctx.data.prodNum,
- shopId: ctx.data.shopId,
- distributionCardNo: ctx.data.distributionCardNo
- }));
- wx.navigateTo({
- url: '/pages/submit-order/submit-order?orderEntry=1',
- })
- },
- /**
- * 减数量
- */
- onCountMinus: function () {
- var prodNum = this.data.prodNum;
- if (prodNum > 1) {
- this.setData({
- prodNum: prodNum - 1
- });
- }
- },
- /**
- * 加数量
- */
- onCountPlus: function () {
- var prodNum = this.data.prodNum;
- // 判断是否限购
- if (this.data.hasMaxNum) {
- if (prodNum < this.data.totalStocks && prodNum < this.data.maxNum) {
- this.setData({
- prodNum: prodNum + 1
- });
- } else {
- wx.showToast({
- title: '限购' + this.data.maxNum + '件',
- icon: 'none',
- })
- }
- } else {
- if (prodNum < this.data.totalStocks) {
- this.setData({
- prodNum: prodNum + 1
- });
- } else {
- wx.showToast({
- title: '库存不足!',
- icon: 'none'
- })
- }
- }
- },
- /**
- * 用户点击转发
- */
- onShareAppMessage: function (res) {
- if (res.from === 'button') {
- var cardno = wx.getStorageSync("distCardNo");
- return {
- title: this.data.prodName,
- path: '/pages/prod/prod?prodid=' + this.data.prodId + '&cardno=' + cardno + '&type=' + this.data.shareType,
- imageUrl: this.data.pic,
- }
- } else {
- return {
- title: this.data.prodName,
- path: '/pages/prod/prod?prodid=' + this.data.prodId
- }
- }
- },
- /**
- * 优惠券
- */
- showPopup: function () {
- if (this.data.loadCouponIds) {
- this.setData({
- popupShow: true
- });
- return;
- }
- http.request({
- url: "/p/myCoupon/listCouponIds",
- method: "GET",
- data: {},
- callBack: (couponIds) => {
- var couponList = this.data.couponList;
- couponList.forEach(coupon => {
- if (couponIds && couponIds.length) {
- // 领取该优惠券数量
- var couponLimit = 0;
- couponIds.forEach(couponId => {
- if (couponId == coupon.couponId) {
- couponLimit++;
- }
- });
- // 小于用户领取优惠券上限,可以领取优惠券
- if (couponLimit < coupon.limitNum) {
- coupon.canReceive = true;
- } else {
- coupon.canReceive = false;
- }
- } else {
- coupon.canReceive = true;
- }
- });
- this.setData({
- couponList: couponList,
- popupShow: true,
- loadCouponIds: true
- })
- }
- })
- },
- showSku: function (e) {
- if (e.currentTarget.dataset.alonebuy == 1) {
- this.setData({
- skuShow: true,
- skuShowType: 0
- });
- } else {
- if (this.data.groupActivityId) {
- this.setData({
- skuShow: true,
- skuShowType: 1
- });
- } else {
- this.setData({
- skuShow: true,
- skuShowType: 0
- });
- }
- }
- },
- showGroupSku: function () {
- if (this.data.isPlaying) {
- this._stopPlay()
- }
- this.setData({
- skuShow: true,
- skuShowType: 1
- });
- },
- showComment: function () {
- this.setData({
- commentShow: true
- });
- },
- closePopup: function () {
- this.setData({
- popupShow: false,
- skuShow: false,
- commentShow: false
- });
- },
- /**
- * 赚字浮层
- */
- onShowShare: function (e) {
- if (this.data.isPlaying) {
- this._stopPlay()
- }
- this.setData({
- shareShow: true,
- shareType: e.currentTarget.dataset.type,
- });
- },
- /**
- * 回到顶部
- */
- backToTop: function () {
- wx.pageScrollTo({
- scrollTop: 0
- })
- },
- /**
- * 监听页面滚动
- */
- onPageScroll: function (e) {
- if (e.scrollTop > 80) {
- this.setData({
- showBacktop: true
- })
- } else if (e.scrollTop < 80) {
- this.setData({
- showBacktop: false
- })
- }
- },
- closeEarn: function () {
- this.setData({
- shareShow: false
- })
- },
- toDistCenterPage: function () {
- wx.navigateTo({
- url: '/pages/dis-center/dis-center',
- })
- },
- /**
- * 生成小程序二维码
- */
- genWeixinCode() {
- wx.showLoading({
- mask: true
- })
- var cardNo = wx.getStorageSync("distCardNo");
- var content = JSON.stringify({
- shareProdId: this.data.prodId,
- cardNo: cardNo,
- })
- http.request({
- url: "/qrcodeTicket/miniQrCode",
- method: "GET",
- responseType: 'arraybuffer',
- data: {
- content: content,
- type: 2
- },
- callBack: (res) => {
- this.setData({
- wxCodeShow: true,
- shareShow: false,
- shareWxCode: "data:image/jpg;base64," + wx.arrayBufferToBase64(res)
- });
- wx.hideLoading();
- }
- })
- console.log('分销员id:' + cardNo)
- },
- /**
- * 关闭二维码弹窗
- */
- closeCodePopup() {
- this.setData({
- wxCodeShow: false
- });
- },
- /**
- * 保存图片至相册
- */
- downloadImg() {
- var ths = this
- var imgSrc = this.data.shareWxCode.slice(22); //base64编码
- var save = wx.getFileSystemManager();
- save.writeFile({
- filePath: wx.env.USER_DATA_PATH + '/分享商品-' + this.data.prodName + '.png',
- data: imgSrc,
- encoding: 'base64',
- success: res => {
- wx.saveImageToPhotosAlbum({
- filePath: wx.env.USER_DATA_PATH + '/分享商品-' + this.data.prodName + '.png',
- success: function (res) {
- wx.showToast({
- title: '保存成功',
- })
- ths.setData({
- wxCodeShow: false
- })
- },
- fail: function (err) {
- wx.showModal({
- title: '提示',
- content: '保存图片需要授予存储权限',
- success: modalRes => {
- if (modalRes.confirm) {
- wx.openSetting({
- success(settingdata) {
- if (settingdata.authSetting['scope.writePhotosAlbum']) {
- console.log('用户权限成功')
- } else {
- console.log('用户取消权限')
- }
- }
- })
- }
- }
- })
- }
- })
- // console.log(res)
- },
- fail: err => {
- // console.log(err)
- }
- })
- },
- /**
- * 获取用户信息
- */
- onGotUserInfo: function (e) {
- if (e.detail.errMsg != "getUserInfo:fail auth deny") {
- this.setData({
- isAuthInfo: true
- });
- http.updateUserInfo();
- }
- },
- /**
- * 确认开团
- */
- groupConfirmOrder: function (e) {
- if (!this.data.findSku) {
- return;
- }
- wx.showLoading({
- mask: true
- });
- this.setData({
- teamId: e.currentTarget.dataset.teamid
- })
- // 查看是否授权
- util.checkAuthInfo(this._groupConfirmParams)
- },
- // 拼团确认订单参数
- _groupConfirmParams() {
- wx.setStorageSync("groupOrderItem", JSON.stringify({
- groupSkuId: this.data.detaultGroupSku.groupSkuId, // this.data.groupSkuId,
- prodCount: this.data.prodNum, // this.data.prodNum,
- groupTeamId: this.data.teamId // this.data.groupTeamId
- }));
- wx.navigateTo({
- url: '/pages/groupConfirmOrder/groupConfirmOrder',
- })
- },
- /**
- * 跳转到店铺页
- */
- toShopPage: function () {
- wx.navigateTo({
- url: '/pages/shopPage/shopPage?shopId=' + this.data.shopId,
- })
- },
- /**
- * 通过商品id获取商品所有促销活动
- */
- getPordDiscountList() {
- http.request({
- url: "/marking/discount/getDiscountByProdId",
- method: "GET",
- data: {
- prodId: this.data.prodId
- },
- callBack: res => {
- this.setData({
- prodDiscountList: res
- })
- }
- })
- },
- /**
- * 促销活动弹窗
- */
- clickDiscount: function () {
- var showDiscountPopup = !this.data.showDiscountPopup
- this.setData({
- showDiscountPopup
- })
- },
- /**
- * 页面从前台变为后台时执行
- */
- onHide: function () {
- this.setData({
- isCollection: false,
- skuShow: false,
- })
- clearTimeout(this.data.joinGroupListTimer)
- },
- /**
- * 视频信息
- */
- getVideoInfo() {
- wx.showLoading()
- wx.request({
- url: this.data.video + '?avinfo',
- success: res => {
- wx.hideLoading()
- let time = Number(res.data.format.duration).toFixed(0)
- this.setData({
- videoDuration: time < 60 ? '00′' + time + '″' : ((parseInt(time / 60) < 10 ? '0' + parseInt(time / 60) : parseInt(time / 60)) + '′' + (time % 60 < 10 ? '0' + time % 60 : time % 60) + '″')
- })
- }
- })
- },
- /**
- * 视频播放/停止按钮
- */
- videoOper() {
- if (this.data.isPlaying) {
- this._stopPlay()
- } else {
- this._startPlay()
- }
- },
- /**
- * 视频播放结束时
- */
- playEnd() {
- this._stopPlay()
- },
- _startPlay() {
- this.setData({
- isPlaying: true,
- })
- this.videoContext.play()
- this.videoContext.seek(0)
- },
- _stopPlay() {
- this.setData({
- isPlaying: false
- })
- this.videoContext.stop()
- this.videoContext.seek(0)
- },
- })
|