From 36a7c2ff68db9f5773fa7b8dc2a63f77cf774af2 Mon Sep 17 00:00:00 2001 From: taiwan Date: Mon, 28 Feb 2022 10:02:30 +0800 Subject: [PATCH] 服务卡项秒杀 --- packageA/pages/cart2_ser/cart2_ser.js | 12 ++++++++++++ packageA/pages/goodsInfo/goodsInfo.js | 376 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------- packageA/pages/goodsInfo/goodsInfo.wxml | 143 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------- packageA/pages/goodsInfo/goodsInfo.wxss | 42 ++++++++++++++++++++++++++++++++++++++++++ pages/index/index/index.wxml | 32 +++++++++++++++++--------------- 5 files changed, 559 insertions(+), 46 deletions(-) diff --git a/packageA/pages/cart2_ser/cart2_ser.js b/packageA/pages/cart2_ser/cart2_ser.js index 34a44ab..1250ec1 100644 --- a/packageA/pages/cart2_ser/cart2_ser.js +++ b/packageA/pages/cart2_ser/cart2_ser.js @@ -249,6 +249,11 @@ Page({ t.data.data.original_img = oo.imghost + t.data.data.imgUrl; t.data.data['buynum'] = gg.goods_num; t.data.data.shop_price = gd.money; + + if(th.data.postdata.prom_type == 1) { + let postdata = th.data.postdata; + t.data.data.shop_price = postdata.prom_price; + }; th.setData({ bn_goods: t.data.data, @@ -510,6 +515,12 @@ Page({ // 'price': th.data.formData.order_amount, 'pickup_id': gg.pick_id, 'pickup_keyid': gg.keyid, + 'prom_type': this.data.postdata.prom_type, //促销活动类型 + 'prom_id': this.data.postdata.prom_id, //促销活动id + }; + + if(this.data.postdata.prom_type == 1) { + goods.price = this.data.postdata.prom_price; }; //--导购分享过来的id-- @@ -525,6 +536,7 @@ Page({ } }) } + console.log('goooooooooooooooooods', goods); item.list.push(goods); } diff --git a/packageA/pages/goodsInfo/goodsInfo.js b/packageA/pages/goodsInfo/goodsInfo.js index 7793881..2d5da23 100644 --- a/packageA/pages/goodsInfo/goodsInfo.js +++ b/packageA/pages/goodsInfo/goodsInfo.js @@ -205,22 +205,18 @@ Page({ hui_condition:null, sto_sele_name_1:'',//分享的门店名称 + // 秒杀 + prom_st: 1, + prom_r_null: 0, }, //------初始化加载---------- onLoad: function(t) { - - // ===> 小程序页面分享到朋友圈时使用 - if(!getApp().is_Single_page()){ - return false; - } - // <=== - - - self = this; - this.data.options = t; // { goods_id: ...} - + + this.setData({ + options: t, + }); var ee = this, that = ee, @@ -385,7 +381,7 @@ Page({ var ser_card=th.data.data; //--如果默认门店不在等级卡的默认们店以内 if(ser_card.storageId!=null && ser_card.storageId!="" && ser_card.storageId.indexOf(ee.keyid)==-1){ - ee.is_no_dis=1; + ee.is_no_dis=1; } var appd=getApp().globalData; @@ -454,6 +450,7 @@ Page({ }); }, + //------------程序初始化入口------------- async init(gid) { var ee = this, @@ -494,6 +491,58 @@ Page({ // }) + // ----> 秒杀 + let prom_type = this.data.options.prom_type; + + let goods_id = this.data.options.goods_id; + if(!goods_id) goods_id = this.data.data.goods_id; + + if(prom_type) { // 进入商品详情页地址传参有带goods_id、prom_type、prom_id参数, 即从秒杀入口进入 + let prom_id = this.data.options.prom_id; + this.check_prom(goods_id, prom_type, prom_id); + } else { // 从非秒杀入口进入,地址不带prom_type、prom_id参数 + getApp().request.promiseGet('/api/weshop/activitylist/getGoodActInfo', { + data: { + store_id: os.stoid, + goodsidlist: goods_id, + is_detail: 1, + goods_type: 1, + user_id: oo.user_id, + } + }).then(res => { + if (res.data.code == 0) { + let result = res.data.data; + let resLength = result.length; + if(resLength == 1) { // 如果数组长度为1,则直接显示当前活动 + let goods_id = this.data.options.goods_id; + let prom_type = result[0].prom_type; + let prom_id = result[0].act_id; + this.setData({ + 'options.prom_type': prom_type, + }); + this.check_prom(goods_id, prom_type, prom_id); + } else if(resLength > 1) { //如果数组长度大于1,表示当前商品参加多个活动,以列表形式显示多活动 + this.setData({ + actList: res.data.data, + }); + }; + + console.log('!!!!!!~~~~~~~~~prom~~~~~~~~~~!!!!!!'); + // this.setData({ + // prom, + // }); + + }; + }); + }; + // <---- 秒杀 + + + + + + + //------是否收藏---------- await getApp().request.promiseGet("/api/weshop/goodscollect/page", { data: { @@ -517,8 +566,6 @@ Page({ store_id: os.stoid, service_id: gid }, - //failRollback: !0, - }).then(res => { console.log('get评价统计数量', res.data.data); var t = res; @@ -538,7 +585,7 @@ Page({ categories3 = dd; } - }) + }); //----获取详情页的评价---- await getApp().request.promiseGet("/api/weshop/serviceComment/pageComment", { @@ -553,7 +600,7 @@ Page({ }).then(res => { console.log('get详情页评价', res.data.data); fir_com = res.data.data.pageData; - }) + }); if (fir_com) { for (var ind in fir_com) { @@ -561,7 +608,7 @@ Page({ if (fir_com[ind].img) fir_com[ind].img = ut.unserialize(fir_com[ind].img); if (fir_com[ind].weapp_img) fir_com[ind].weapp_img = JSON.parse(fir_com[ind].weapp_img); } - } + }; this.getTaohe(); @@ -600,6 +647,7 @@ Page({ var ee = this,gid = this.data.gid, i = getApp().request; this.data.is_timer = 1; this.wait_for_store_config(); + i.get("/api/weshop/serviceCard/get/" + o.stoid + "/" + ee.data.gid, { failRollback: !0, @@ -676,6 +724,8 @@ Page({ this.data.enterAddressPage && (this.data.enterAddressPage = !1); this.get_sto(); + + }, enterAddress: function() { @@ -689,6 +739,7 @@ Page({ clearInterval(i); } }, + onHide: function() { this.data.is_timer = 0; for(var i = 1; i < 100; i++) { @@ -702,6 +753,7 @@ Page({ activeCategoryId: e }), 1 == e ? this.tabGoodsContent() : 2 == e && this.tabComment(); }, + tabClick2: function(t) { this.setData({ activeCategoryId2: t.currentTarget.id @@ -735,7 +787,7 @@ Page({ //商品详情的时候调用 tabGoodsContent: function() { var th = this, - i = getApp().request; + i = getApp().request; this.setData({ activeCategoryId: 1 }); @@ -749,7 +801,7 @@ Page({ var action= t.currentTarget.dataset.action; if(!ind) ind = t.currentTarget.dataset.openspecmodal_ind; - th.setData({ + th.setData({ open_ind_store: ind }); @@ -770,8 +822,16 @@ Page({ newd['pick_name'] = th.data.sto_sele_name; newd['guide_id'] = getApp().globalData.guide_id; newd['guide_type']=0; + + if(this.data.prom_type && this.data.prom_type == 1) { + newd['prom_type'] = this.data.prom_type; + newd['prom_id'] = this.data.prom_id; + newd['prom_price'] = this.data.prom_price; + } + + // console.log('newd++++++++', newd); th.buyNow(newd); - }else{ + } else { var newd = { service_id: th.data.data.id, @@ -881,7 +941,8 @@ Page({ }, openSpecModel: function(t) { - var th=this; + // console.log('****ttttttt***', t); + var th=this; var open_store = t.currentTarget.dataset.ind; this.setData({ store: 0, @@ -2749,7 +2810,278 @@ Page({ }; }; }); - } + }, + + + + + //---小于10的格式化函数---- + // timeFormat(param) { + // return param < 10 ? '0' + param : param; + // }, + + //----倒计时函数----- + countDown(time, prom_st) { + if (!this.data.is_timer) return false; + var th = this; + // 获取当前时间,同时得到活动结束时间数组 + var endTime = time; + var newTime = ut.gettimestamp(); + // 对结束时间进行处理渲染到页面 + var obj = null; + // 如果活动未结束,对时间进行处理 + if (endTime - newTime > 0) { + var time = (endTime - newTime); + // 获取天、时、分、秒 + var day = parseInt(time / (60 * 60 * 24)); + var hou = parseInt(time % (60 * 60 * 24) / 3600); + var min = parseInt(time % (60 * 60 * 24) % 3600 / 60); + var sec = parseInt(time % (60 * 60 * 24) % 3600 % 60); + obj = { + day: this.timeFormat(day), + hou: this.timeFormat(hou), + min: this.timeFormat(min), + sec: this.timeFormat(sec) + } + } else { + if (th.data.prom_st == 0) { + //var endTime2 = new Date(th.data.prom_end_time).getTime(); + var endTime2 = th.data.prom_act.end_time; + th.setData({ + prom_time_text: '距结束还剩:', + prom_st: 1 + }) + setTimeout(function () { + th.countDown(endTime2) + }, 1000); + return false; + + } else { + //活动已结束,全部设置为'00' + obj = { + day: '00', + hou: '00', + min: '00', + sec: '00' + } + th.setData({ + prom_time_text: '活动已经结束:', + prom_st: 3 + }) + th.setData({ + djs: obj + }); + return false; + } + } + + th.setData({ + djs: obj + }); + setTimeout(function () { + th.countDown(endTime) + }, 1000); + }, + + + get_normal(gid) { + this.setData({ + prom_type: 0, + isshow: 1, + }); + // this.get_sku(os.stoid, this.data.data, gid); + // this.get_sto(); + // this.check_is_youhui(gid, 1); + this.data.is_normal = 1; + }, + + + + + //--------检查是否活动,活动是否开始,或者是否结束------- + async check_prom(gid, prom_type, prom_id) { + console.log('check_prom'); + var ee = this, th = ee; + var user_id = getApp().globalData.user_id; + if (!user_id) user_id = 0; + + // if (prom_type == 3 || prom_type == 0 || prom_type == 5 || prom_type == 7 || prom_type == 9 || prom_type == 10) { + // this.setData({ + // prom_type: 0, isshow: 1, + // }); + // return false; + // } + + + + // if (prom_type == 1 && prom_id == 0) { + // this.setData({ + // prom_type: 0, isshow: 1, + // }); + + // //获取门店 + // this.get_sto(); + // this.get_sku(o.stoid, this.data.data, gid); + // this.check_has_flash(); + // this.data.is_normal = 1; + // this.check_is_youhui(gid, 1); + // return false; + // } + + //if (prom_type != 3 && prom_type!=0){ + //---判断秒杀---- + if (prom_type == 1 && prom_id > 0) { + //-------判断活动是否抢光--------- + await getApp().request.promiseGet("/api/weshop/activitylist/getActLen/" + os.stoid + "/" + prom_type + "/" + prom_id, { + 1: 1 + }).then(res => { + var em = res; + if (res.data.code == 0) { + // console.log('!!!!!!res!!!!', res); + if (res.data.data <= 0) ee.setData({ + prom_r_null: 1 + }); + //拿取价格并且判断时间-- + getApp().request.get("/api/ms/flash_sale/getNew/" + os.stoid + "/" + user_id + "/" + prom_id, { + success: function (t) { + // console.log('!!!!!!t!!!!', t); + if (t.data.code != 0) { + ee.get_normal(gid); + return false; + } + //----已经结束----- + if (t.data.data.is_end == 1) { + ee.get_normal(gid); + return false; + } + //----已经过期----- + var now = ut.gettimestamp(); + if (t.data.data.end_time < now) { + ee.get_normal(gid); + return false; + } + /*-- 还没有开始预热的也不显示 --*/ + if (t.data.data.show_time > now) { + ee.get_normal(gid); + return false; + } + + var t_gd = ee.data.data; + var prom_end_time = ut.formatTime(t.data.data.end_time, "yyyy-MM-dd hh:mm:ss"); + var prom_start_time = ut.formatTime(t.data.data.start_time, "yyyy-MM-dd hh:mm:ss"); + + ee.setData({ + 'data.shop_price': t.data.data.user_price, + prom_price: t.data.data.user_price, + prom_type: 1, + prom_id: prom_id, + prom_buy_limit: t.data.data.buy_limit, + prom_act: t.data.data, + prom_end_time: prom_end_time, + prom_start_time: prom_start_time, + isshow: 1, + }); + + ee.get_sto(); + var newTime = ut.gettimestamp(); + var endTime2 = t.data.data.end_time; + var endTime1 = t.data.data.start_time; + if (endTime1 > newTime) { + ee.setData({ + prom_time_text: '距秒杀开始还有', + prom_st: 0, + }) + ee.countDown(endTime1, 0); + } else { + if (endTime2 > newTime) { + ee.setData({ + prom_time_text: '距秒杀结束还有', + prom_st: 1 + }) + ee.countDown(endTime2); + } + } + + //如果是进行中的话 + // if (endTime1 < newTime) { + // //-- 获取秒杀活动的多少规格 -- + // ee.get_more_flahs(function (list) { + // if (list && list.length > 1) { + + // var n_item = list[0]; + // var ind = list.findIndex(function (ele) { + // return ele.goods_id == ee.data.data.goods_id; + // }) + // if (ind < 0) return false; + // if (ind > 0) { + // n_item = JSON.parse(JSON.stringify(list[ind])); + // list.splice(ind, 1); + // list.unshift(n_item); + // } + + // ee.data.sele_g.viplimited = n_item.viplimited; + // ee.data.data.viplimited = n_item.viplimited; + + // var gb = 1; + // //-- 显示多规格 -- + // for (let i in list) { + // let item = list[i]; + // var gg = ""; + // if (item.goods_spec == "null" || item.goods_spec == null) item.goods_spec = ""; + // if (item.goods_color == "null" || item.goods_color == null) item.goods_color = ""; + + // if (item.goods_spec != "" && item.goods_color != "") { + // gg = item.goods_spec + "/" + item.goods_color; + // } else if (item.goods_spec != "" || item.goods_color != "") { + // gg = item.goods_spec + item.goods_color; + // } else { + // gg = "规格" + gb; + // gb++; + // } + // item.gg = gg; + // item.prom_id = item.prom_id; + // item.prom_type = 1; + // } + + // ee.setData({ + // sku_g: list, + // }); + + // } + // }) + // } + + } + }); + } + }) + } + + }, + + + + viewFlash(e) { + let prom_type = e.currentTarget.dataset.promtype; + let prom_id = e.currentTarget.dataset.promid; + let goods_id = this.data.data.goods_id; + let url = `/packageA/pages/goodsInfo/goodsInfo?goods_id=${goods_id}&prom_type=${prom_type}&prom_id=${prom_id}`; + // console.log('url~~~~', url); + getApp().goto(url); + }, + + + + + + + + + + + + + diff --git a/packageA/pages/goodsInfo/goodsInfo.wxml b/packageA/pages/goodsInfo/goodsInfo.wxml index 231982d..f18ca5e 100644 --- a/packageA/pages/goodsInfo/goodsInfo.wxml +++ b/packageA/pages/goodsInfo/goodsInfo.wxml @@ -51,6 +51,7 @@ + @@ -63,6 +64,30 @@ + + + + + + + + + + 距活动开始还有 + 距活动结束还有 + + + {{djs.day}} + + + {{djs.hou}} + + {{djs.min}} + + {{djs.sec}} + + + @@ -73,6 +98,9 @@ + + + {{filters.toFix(data.shop_price,2)}} {{data.goods_name}} @@ -124,6 +152,41 @@ + + + + + + + 秒杀{{index+1}} + + + + + + + {{item.act_name}} + + + + + + + + + + + @@ -238,7 +301,7 @@ - + @@ -439,11 +502,63 @@ - + - 加入购物车 - 立即购买 + + + + + + 加入购物车 + 立即抢购 + + + + + + 单独购买 + 即将开始 + + + 即将开始 + + + + + + + + 单独购买 + 已抢光 + + 已抢光 + + + + + 单独购买 + 活动已经结束 + + + 活动已经结束 + + + + + + + + 加入购物车 + 立即购买 + + + + + + + + @@ -558,10 +673,20 @@ 加入购物车 - - {{sele_g.offline_price?"券后购买":"立即购买"}} - + + + + {{sele_g.offline_price?"券后购买":"立即购买"}} + + + + + + {{sele_g.offline_price?"券后购买":"立即购买"}} + + diff --git a/packageA/pages/goodsInfo/goodsInfo.wxss b/packageA/pages/goodsInfo/goodsInfo.wxss index 500f8d6..c8d39ff 100644 --- a/packageA/pages/goodsInfo/goodsInfo.wxss +++ b/packageA/pages/goodsInfo/goodsInfo.wxss @@ -2907,3 +2907,45 @@ button.custom-service::after{ .del { text-decoration: line-through; } + + + + +.tick { + position: relative; +} + +.tick:before { + content: ''; + display: inline-block; + vertical-align: middle; + margin-top: -4rpx; + margin-right: 12rpx; + width: 22rpx; + height: 22rpx; + background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABYAAAAWCAMAAADzapwJAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAABCUExURUdwTPInDPInDPgoDfMnDPYqEvInDPInDPInDP87NPUoDv8vEvMoDPInDPIoDPMnDvInDPInDPInDPIoDPQoDfInDEON4KMAAAAVdFJOUwD45yawG4zz3gQ0DmLOfECQZpPlS54kMQ4AAAC0SURBVBjTbZFREoMgDERDS0xQQNHu/a/alEGtaIYfHrBhs0S1pujVifo40VkhC+BUHSDzQTlBhjHY8bjogXmDZ+orJKwXwMUeUoa/0PeGbH8Q4Y5CJopYOjosiOQxdpRGk1UXOkrBKdkimtN8UrKrJBVXdzsllSYSjR/0J9JaGn81WluWtonYKQ0op51P3M2L2bmZN9n8MKoVqTph/RsseyjfYxAkfgot/82CpuJVLOLSIv4Cd5AJ37BgpFwAAAAASUVORK5CYII=) no-repeat; + background-size: 22rpx auto; +} + +.details::after { + content: ''; + position: absolute; + right: 0; + top: 0; + bottom: 0; + margin: auto; + display: inline-block; + width: 40rpx; + height: 40rpx; + background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAAoBAMAAAB+0KVeAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAAVUExURUdwTIyMjCYmJiYmJi0tLY+PjyYmJidnOsIAAAAGdFJOUwDt6aYcSSEXj/YAAAA8SURBVCjPY2AYBTQBLEbKDhiCTmlpKggeq2AAiDJLS0tGcBkFBUActbS0JAY4F6sgVu1YLcLnpFFAFQAATwgLKVhjC9UAAAAASUVORK5CYII=); + background-repeat: no-repeat; + background-size: 40rpx auto; +} + +.lh2 { + line-height: 2; +} + +.huise { + background: gray +} diff --git a/pages/index/index/index.wxml b/pages/index/index/index.wxml index 766039d..2d0812a 100644 --- a/pages/index/index/index.wxml +++ b/pages/index/index/index.wxml @@ -172,21 +172,23 @@ - - - - - - - - - {{aitem.goods_name}} - - - {{aitem.price}} - ¥{{aitem.market_price}} - - + + + + + + + + + {{aitem.goods_name}} + + + {{aitem.price}} + ¥{{aitem.market_price}} + + + +