| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886 |
- // index.js
- let myPro = require("../../utils/wxRequest.js");
- let util = require("../../utils/util.js");
- // 点击计时器
- let clickScrollTimer;
- Page({
- data: {
- customTop: getApp().globalData.customTop,
- setBgHeight: getApp().globalData.setBgHeight, // 导航条高度
- imgUrl: getApp().globalData.imgUrl,
- keywords: '',
- showGoodsSpec: false, // 规格弹层
- showShopCar: false, // 购物车弹层
- store: null, // 所在门店
- loading: false, // 全局loading
- fare_type: 1, // 0外卖 1自提 默认自提
- showOpenLocation: false, // 开启定位提醒
- good_list: null,
- cartList: null,
- // showSelectFare: false, // 配送方式弹层
- showTopCate: false,
- toViewErji: null,
- totalNums: 0,
- totalPrice: 0,
- totalMemberPrice: 0,
- activeErjiId: 0,
- checkedSpecNums: 0,
- isClickToScroll: false, // 通过点击滚动产品列表 true 滚动事件中不赋值,false 时赋值
- activeCateId: '',
- toViewErji: '',
- activeErjiId: '',
- toView: '',
- currentCate: '',
- showErjiCate: false,
- tableId: null
- },
- onLoad: function (options) {
- // Do some initialize when page load.
- let that = this;
- if (options.tableId) {
- that.setData({
- tableId: options.tableId
- })
- }
- },
- onShow: function () {
- // Do something when page show.
- let that = this;
- that.setData({
- showGoodsSpec: false, // 规格弹层
- showShopCar: false, // 购物车弹层
- });
- // 获取配送方式
- if(wx.getStorageSync('fare_type')){
- that.setData({
- fare_type: wx.getStorageSync('fare_type')
- })
- }else{
- // 未获取到,需主动存一下,默认自提
- wx.setStorage({
- key: "fare_type",
- data: '1'
- })
- };
- // 单店开是否开定位,都需要把商品调出来
- getApp().getLocal(function(){
- that.afterAuthLocation();
- // 拒绝定位时,提醒去开启
- if(getApp().globalData.location_auth == -1){
- console.log('拒绝定位');
- that.setData({
- showOpenLocation: true
- });
- }
- });
- },
- onReady: function () {
- // Do something when page ready.
- let that = this;
- // 滚动区域高度计算
- wx.getSystemInfo({
- success: function(res){
- let height = res.windowHeight;
- // console.log('总height',height)
- const query = wx.createSelectorQuery();
- query.select('.store_wrap').boundingClientRect();
- query.select('.heji_wrap').boundingClientRect();
- // query.select('.erji_cate').boundingClientRect();
- query.exec((res) =>{
- // 分别取出节点的高度
- let storeWrapH = res[0].height; // 门店选择的高度 px
- let hejiWrapH = res[1].height; // 底部合计的高度 px
- // let erjiCateH = res[2].height; // 顶部分类固定宽
- // let scrollH = height - storeWrapH - hejiWrapH - erjiCateH;
- let scrollH = height - storeWrapH - hejiWrapH;
- that.setData({
- storeWrapH: storeWrapH,
- scrollH: scrollH,
- guigeH: height*0.5
- });
- // console.log('scrollH',scrollH)
- // console.log('门店高度',that.data.storeWrapH);
- });
- }
- });
- },
- onHide: function () {
- // Do something when page hide.
- // console.log('hide')
- let that = this;
- // return;
- // 主动模拟selectClassesClick
- clearTimeout(clickScrollTimer);
- let item = that.data.good_cate[0];
- that.setData({
- isClickToScroll: true,
- activeCateId: item.id,
- toView: 'erji' + (item.children && item.children.length != 0 ? item.children[0].id : item.id), //不能数字开头,所以开头加了productItem
- activeErjiId: item.children && item.children.length != 0 ? item.children[0].id : item.id,
- toViewYiji: 'yijicate'+item.id
- });
- // console.log('toView',that.data.toView);
- // console.log('activeErjiId',that.data.activeErjiId);
- let good_cate = that.data.good_cate;
- // 循环当前分类
- for(let i in good_cate){
- if(good_cate[i].id == item.id){
- that.setData({
- currentCate: good_cate[i]
- })
- }
- }
- },
- onUnload: function () {
- // Do something when page close.
- },
- onPullDownRefresh: function () {
- // Do something when pull down.
-
- },
- onReachBottom: function () {
- // Do something when page reach bottom.
- },
- onPageScroll: function () {
- // Do something when page scroll
- },
- onResize: function () {
- // Do something when page resize
- },
- // 获取购物车商品
- getCartsList(){
- let that = this;
- myPro.wxRequest("user/v3/carts/list","GET",{}).then(res=>{
- // 在首页只体现普通商品
- let list = res.result.list;
- that.setData({
- cartGoods: list,
- totalNums: res.result.total_num,
- totalPrice: res.result.money
- });
- // 同步商品列表
- that.updateTotalGoods();
- }).catch(err=>{
- console.log('报错信息',err);
- wx.showToast({
- title: err,
- icon: "none"
- });
- })
- },
- // 店铺列表(只拿最近的)
- getStoreList(lat,lng){
- let that = this;
- let data = {
- lat: lat ? lat : getApp().globalData.lat,
- lng: lng ? lng : getApp().globalData.lng,
- page: 1,
- size: 10
- };
- myPro.wxRequest("user/store/list","GET",data,true).then(res=>{
- let storeList = res.result;
- // 有门店
- if(storeList && storeList.length != 0){
- let currentStore = storeList[0];
- that.setData({
- store: currentStore
- });
- // 营业时间的判断
- // that.checkBusinessTime();
- // 存下门店
- wx.setStorage({
- key: "store",
- data: JSON.stringify(that.data.store),
- });
- // 获取店内商品
- that.getGoodsList(function(){
- // 登录状态
- if(getApp().globalData.token){
- getApp().globalData.loadingCount = 0; // 主动关
- that.getCartsList();
- }
- });
- }else{
- wx.showToast({
- title: "门店暂未营业",
- icon: "none"
- });
- }
- }).catch(err=>{
- console.log('报错信息',err);
- wx.showToast({
- title: err,
- icon: "none",
- });
- });
- },
- // 拨打店铺电话
- onMakePhone(){
- let that = this;
- wx.makePhoneCall({
- phoneNumber: that.data.store.phone
- });
- },
- // 获取商品分类及商品
- getGoodsList(callback){
- let that = this;
- let params = {
- store_id: that.data.store.id
- };
- myPro.wxRequest("user/v3/index","GET",params).then(res=>{
- let list = res.result.good;
- // 回调
- if(callback){
- callback();
- };
- that.setData({
- good_cate: res.result.good_cate,
- good_list: list,
- activeCateId: res.result.good_cate[0].id, //默认左侧第一个选中
- currentCate: res.result.good_cate[0], // 当前分类(结构为一级分类+二级分类)
- toView: 'erji' + res.result.good_cate[0].id
- });
- // console.log('左侧第一个分类',that.data.activeCateId);
- // console.log('右侧第一个内容',that.data.toView);
- // 一级节点
- that.data.good_list.forEach(item=>{
- // 添加节点的布局位置的查询请求
- wx.createSelectorQuery().select('#yiji' + item.good_cate_id).boundingClientRect(rect => {
- item.offsetTop = rect.top;
- item.height = rect.height;
- // console.log('rect',rect)
- // console.log('item',item);
- }).exec()
- // 二级节点
- if(item.children){
- item.children.forEach(erjiItem=>{
- wx.createSelectorQuery().select('#erji' + erjiItem.good_cate_id).boundingClientRect(rect => {
- erjiItem.offsetTop = rect.top;
- erjiItem.height = rect.height;
- // console.log('rect',rect)
- // console.log('item',item);
- }).exec()
- })
- }
- });
- // console.log('商品列表带节点',that.data.good_list);
- }).catch(err=>{
- console.log('报错信息',err)
- wx.showToast({
- title: err,
- icon: "none",
- });
- });
- },
- // 左侧菜单栏切换事件
- selectClassesClick: function(e) {
- let that = this
- // return;
- console.log('e===',e);
- clearTimeout(clickScrollTimer);
- let item = e.currentTarget.dataset.item;
- that.setData({
- isClickToScroll: true,
- activeCateId: item.id,
- toView: 'erji' + (item.children && item.children.length != 0 ? item.children[0].id : item.id), //不能数字开头,所以开头加了productItem
- activeErjiId: item.children && item.children.length != 0 ? item.children[0].id : item.id,
- toViewYiji: 'yijicate'+ item.id
- });
- // console.log('toView',that.data.toView);
- // console.log('activeErjiId',that.data.activeErjiId);
- let good_cate = that.data.good_cate;
- // 循环当前分类
- for(let i in good_cate){
- if(good_cate[i].id == item.id){
- that.setData({
- currentCate: good_cate[i]
- })
- }
- }
- // console.log('当前fenlei',that.data.currentCate);
- },
- // 监听右边商品列表滑动
- scrollProductList(e){
- let that = this;
- let good_cate = that.data.good_cate;
- let scrollTop = e.detail.scrollTop;
- if(scrollTop!=0){
- that.setData({
- showErjiCate: true
- })
- }
- // return;
- // console.log('isClickToScroll',that.data.isClickToScroll);
- // console.log('e.detail.scrollTop',scrollTop);
- if(!that.data.isClickToScroll){
- that.data.good_list.forEach(item=>{
- // console.log('item',item);
- // console.log('item.offsetTop',item.offsetTop );
- // console.log('item.height',item.height);
- if (scrollTop >= (item.offsetTop - that.data.storeWrapH) && e.detail.scrollTop <= (item.offsetTop - that.data.storeWrapH + item.height)){
- that.setData({
- activeCateId: item.good_cate_id,
- toViewYiji: 'yijicate'+item.good_cate_id
- });
- // console.log('左侧分类1111',item.good_cate_id)
- good_cate.forEach(cateItem=>{
- if(cateItem.id == item.good_cate_id){
- that.setData({
- currentCate: cateItem
- })
- }
- });
- // console.log('当前分类',that.data.currentCate);
- if(item.children){
- item.children.forEach(erjiItem=>{
- if(scrollTop >= erjiItem.offsetTop-180 && scrollTop<= erjiItem.offsetTop+erjiItem.height-180){
- that.setData({
- activeErjiId: erjiItem.good_cate_id,
- toViewErji: 'erjiCate'+erjiItem.good_cate_id
- })
- }
- })
- };
- return;
- }
- })
- }
- else{
- clickScrollTimer = setTimeout(function() {
- that.setData({
- isClickToScroll: false
- });
- },300)
- }
- // console.log('当前分类',that.data.currentCate)
- // console.log('左侧分类',that.data.activeCateId);
- // console.log('二级分类',that.data.activeErjiId);
- // console.log('右侧分类',that.data.toView);
- },
- // 点击某个二级菜单
- onErjiCate(event){
- // console.log('二级event',event)
- let that = this;
- let good_cate = that.data.good_cate;
- let item = event.currentTarget.dataset.item;
- // console.log('item',item);
- // return;
- that.setData({
- toView: 'erji'+item.id,
- activeErjiId: item.id,
- activeCateId: item.parentid,
- toViewErji: 'erjiCate'+item.id
- });
- // 循环当前分类
- // for(let i in good_cate){
- // if(good_cate[i].id == item.parentid){
- // that.setData({
- // currentCate: good_cate[i]
- // })
- // }
- // }
- // console.log('toView',that.data.toView);
- // console.log('当前的一级分类',that.data.currentCate)
- },
- // 查看规格
- onGoodsSpec(event){
- let that = this;
- let item = event.currentTarget.dataset.item;
- if(item.status != 1){
- // 如果商品售罄
- wx.showToast({
- title: "此商品已售罄",
- icon: "none"
- })
- return;
- };
- let checkedSpec = null;
- // 有规格
- if(item.good_specs && item.good_specs.length != 0){
- let specsArr = item.good_specs;
- for(let i in specsArr){
- if(i == 0){
- specsArr[i].is_checked = true; // 规格默认选中第一项
- checkedSpec = specsArr[i];
- }else{
- specsArr[i].is_checked = false;
- }
- }
- }else{
- // 无规格
- item['member_price'] = item.base_member_price;
- checkedSpec = item;
- }
- // console.log('当前商品',item);
- // console.log('当前选中规格',checkedSpec);
- that.setData({
- showGoodsSpec: true,
- currentGoods: item, // 当前商品
- checkedSpec: checkedSpec, // 当前选中规格
- checkedSpecNums: checkedSpec.nums ? checkedSpec.nums : 0
- });
- },
- // 更改商品规格弹层的商品数量
- onChangeSpecNum(event){
- let that = this;
- let nums = event.detail;
- that.setData({
- checkedSpecNums: nums
- });
- // 更新购物车
- let oldCartGoods = that.data.cartGoods;
- let item = event.currentTarget.dataset.item;
- // console.log('item',item);
- // console.log('购物车',oldCartGoods);
- if(that.isAddCart(item)){
- console.log('在')
- // 在购物车
- // return;
- let params = {};
- // 有规格id
- if(item.good_id){
- for(let i in oldCartGoods){
- if(oldCartGoods[i].good_id == item.good_id && oldCartGoods[i].good_specs_id == item.id){
- params.id = oldCartGoods[i].id; // 购物车ID
- break;
- }
- };
- }else{
- // 无规格id
- for(let i in oldCartGoods){
- if( oldCartGoods[i].good_id == item.id && !oldCartGoods[i].good_specs_id){
- params.id = oldCartGoods[i].id; // 购物车ID
- break;
- }
- }
- };
- if(nums != 0){
- params.nums = nums;
- // 修改数量
- myPro.wxRequest("user/v3/carts/editnum","POST",params).then(res=>{
- that.getCartsList();
- }).catch(err=>{
- console.log('报错信息',err);
- wx.showToast({
- title: err,
- icon: "none"
- })
- })
- }else{
- // 删除
- myPro.wxRequest("user/v3/carts/remove","POST",params).then(res=>{
- that.getCartsList();
- }).catch(err=>{
- console.log('报错信息',err);
- wx.showToast({
- title: err,
- icon: "none"
- })
- })
- }
- }else{
- console.log('不在');
- // return;
- let params = {
- good_id: item.good_id ? item.good_id : item.id,
- nums: nums,
- is_add: 0 // 是否为活动加购商品(1是 0否)
- };
- // 有规格id(加一个无规格的看看)
- if(item.good_id){
- params.good_specs_id = item.id;
- };
- // 添加购物车
- myPro.wxRequest("user/v3/carts/create","POST",params).then(res=>{
- that.getCartsList();
- }).catch(err=>{
- console.log('报错信息',err);
- wx.showToast({
- title: err,
- icon: "none"
- })
- })
- }
- },
- // 切换规格
- onChangeSpecGoods(event){
- let that = this;
- // console.log('event====',event);
- let currentSpecs = event.currentTarget.dataset.specs;
- let oldCartGoods = that.data.cartGoods;
- let checkedSpec = null;
- let checkedSpecNums = 0;
- // 同步选中状态
- let currentGoods = that.data.currentGoods;
- let specsArr = currentGoods.good_specs;
- for(let j in specsArr){
- if(specsArr[j].id == currentSpecs.id){
- specsArr[j].is_checked = true;
- if(that.isAddCart(specsArr[j])){
- // 同步购物车
- for(let i in oldCartGoods){
- if(oldCartGoods[i].good_id == currentSpecs.good_id && oldCartGoods[i].good_specs_id == currentSpecs.id){
- specsArr[j].nums = oldCartGoods[i].nums;
- checkedSpecNums = oldCartGoods[i].nums;
- // console.log('进来了==')
- break;
- }
- };
- }else{
- specsArr[j].nums = 0;
- checkedSpecNums = 0;
- };
- checkedSpec = specsArr[j];
- // break;
- }else{
- specsArr[j].is_checked = false;
- }
- };
- that.setData({
- currentGoods: currentGoods,
- checkedSpec: checkedSpec,
- checkedSpecNums: checkedSpecNums
- });
- // console.log('全规格',specsArr);
- // console.log('当前规格',checkedSpec);
- },
- // 关闭规格
- closeGoodsSpec(){
- let that = this;
- that.setData({
- showGoodsSpec: false
- });
- },
- // 计算价格和数量
- computedGoods(){
- let that = this;
- let list = that.data.cartGoods;
- let totalNums = 0;
- let totalPrice = 0;
- let totalMemberPrice = 0;
- for(let i in list){
- if(list[i].nums != 0){
- totalNums += parseInt(list[i].nums);
- totalPrice += parseFloat(list[i].total_prices);
- totalMemberPrice += parseFloat(list[i].total_member_prices);
- }
- };
- that.setData({
- totalNums: totalNums,
- totalPrice: totalPrice,
- totalMemberPrice: totalMemberPrice
- });
- // 同步商品列表
- // that.updateTotalGoods();
- },
- // 去结算
- toPay(){
- let that = this;
- // 未开启 不允许进入下一步
- if(getApp().globalData.location_auth == -1){
- wx.showToast({
- title: "地理位置未授权,请您授权定位后重试",
- icon: "none"
- })
- return;
- };
- // 验证登录
- getApp().verifyLogin(function(loginStatus){
- // console.log('登录状态',loginStatus)
- if(loginStatus){
- if(!that.data.totalNums){
- wx.showToast({
- title: "请先选择商品",
- icon: "none"
- });
- return;
- };
- // 验证是否能下单,如果不能给提示并进购物车(因为可能是购物车有商品,但未勾选)
- let params = {
- token: getApp().globalData.token
- };
- wx.request({
- url: getApp().globalData.api + "user/v3/order/createlist",
- data: params,
- success: function(res) {
- if(res.data.code != 200){
- wx.showToast({
- title: res.data.msg,
- icon: "none",
- duration: 3000
- });
- setTimeout(function(){
- wx.navigateTo({
- url: "/pages/shopcart/index"
- });
- },1000)
- }else{
- wx.navigateTo({
- url: "/pages/create-order/index"
- });
- }
- }
- });
- };
- })
- },
- // 取消授权提醒
- onCloseLocation(){
- let that = this;
- that.setData({
- showOpenLocation: false
- });
- },
- // 同意去打开地理位置
- onConfirmLocation(){
- // console.log('触发====');
- let that = this;
- wx.openSetting({
- success: function (res) {
- console.log(res)
- let authSetting = res.authSetting;
- if(authSetting["scope.userLocation"]){
- // 开启
- getApp().getLocal(function(){
- that.afterAuthLocation();
- });
- }
- }
- })
- },
- // 允许定位后的操作(或 拒绝定位,但选了默认店铺)
- afterAuthLocation(lat,lng){
- let that = this;
- // 外卖流程,需要验证是否登录
- if(that.data.fare_type == 0){
- getApp().verifyLogin(function(loginstatus){
- if(loginstatus){
- console.log('登录状态',loginstatus)
- try {
- wx.getStorage({
- key: 'checkedAddress',
- success: function(res){
- // console.log('res.data',res.data);
- let checkedAddress = JSON.parse(res.data);
- that.setData({
- checkedAddress: checkedAddress
- });
- // 按地址算
- that.getStoreList(that.data.checkedAddress.lat,that.data.checkedAddress.lnt);
- },
- fail: function(){
- wx.showToast({
- title: "请先选择收货地址",
- icon: "none",
- });
- setTimeout(function(){
- wx.navigateTo({
- url: '/pages/user/address/list/index'
- });
- },1000)
- }
- })
- }
- catch(err){
- console.log('报错信息',err)
- }
- }
- })
- }else{
- that.getStoreList();
- }
- console.log('定位成功');
- },
- // 切换配送方式
- changeFareType(event){
- // console.log(event);
- let that = this;
- let fare_type = event.currentTarget.dataset.type; // 0外卖 1自提
- let store = that.data.store;
- // 判断门店是否支持此配送方式
- if(fare_type == 0 && store.is_delivery != 1){
- wx.showToast({
- title: '门店暂不支持外卖',
- icon: 'none'
- });
- return;
- };
- if(fare_type == 1 && store.is_ziti != 1){
- wx.showToast({
- title: '门店暂不支持自提',
- icon: 'none'
- });
- return;
- };
- // 支持
- // if(that.data.showSelectFare){
- // that.setData({
- // showSelectFare: false
- // })
- // };
- // 切换时实现: 自取选门店,外卖选地址
- // 为每次选外卖时重选地址,清掉checkedAddress
- wx.removeStorageSync('checkedAddress');
- // 更新
- that.setData({
- fare_type: fare_type
- });
- wx.setStorage({
- key: "fare_type",
- data: that.data.fare_type
- });
- // 切到外卖
- if(fare_type == 0){
- // 选地址
- wx.navigateTo({
- url: '/pages/user/address/list/index'
- });
- };
- },
- // 关闭提醒
- closeShowTips(){
- let that = this;
- that.setData({
- showTips: false
- })
- },
- // 关闭选配送方式(用不到了)
- closeSelectFare(){
- let that = this;
- that.setData({
- showSelectFare: false
- })
- },
- // 计算每个商品的总数量
- updateTotalGoods(){
- let that = this;
- let oldCartGoods = that.data.cartGoods;
- // console.log('购物车',oldCartGoods);
- let list = that.data.good_list;
- list.forEach( item=> {
- if(item.children){
- // 有二级
- let erjiGoods = item.children;
- erjiGoods.forEach(erjiItem => {
- let goodsList = erjiItem.goodList;
- goodsList.forEach(goods=>{
- goods.cartNums = 0;
- oldCartGoods.forEach(oldGoods=>{
- if(!oldGoods.is_add){
- // 有规格
- if(goods.good_specs && goods.good_specs.length != 0){
- let specsArr = goods.good_specs;
- specsArr.forEach(goodsSpec=>{
- if(oldGoods.good_id == goodsSpec.good_id && oldGoods.good_specs_id == goodsSpec.id){
- goodsSpec.nums = oldGoods.nums;
- goods.cartNums += oldGoods.nums;
- }
- })
- }else{
- // 无规格
- if(oldGoods.good_id == goods.id){
- goods.nums = oldGoods.nums;
- }
- }
- }
- })
- })
- })
- }else{
- // 无二级
- let goodsList = item.goodList;
- goodsList.forEach(goods=>{
- goods.cartNums = 0
- oldCartGoods.forEach(oldGoods=>{
- if(!oldGoods.is_add){
- // 有规格
- if(goods.good_specs && goods.good_specs.length != 0){
- let specsArr = goods.good_specs;
- specsArr.forEach(goodsSpec=>{
- if(oldGoods.good_id == goodsSpec.good_id && oldGoods.good_specs_id == goodsSpec.id){
- goodsSpec.nums = oldGoods.nums;
- goods.cartNums += oldGoods.nums;
- }
- })
- }else{
- // 无规格
- if(oldGoods.good_id == goods.id){
- goods.nums = oldGoods.nums;
- }
- }
- }
- })
- })
- }
- })
- that.setData({
- good_list: list
- });
- // console.log('重组商品',list);
- },
- // 核实商品是否存在于购物车
- isAddCart(item){
- let that = this;
- let oldCartGoods = that.data.cartGoods;
- let is_have = false;
- // console.log('购物车',oldCartGoods);
- // console.log('操作商品',item);
- // 检测购物车是否有此商品
- for(let i in oldCartGoods){
- if(item.good_id){
- // 有规格
- console.log(item.id,oldCartGoods[i].good_specs_id);
- if(item.id == oldCartGoods[i].good_specs_id && !oldCartGoods[i].is_add){
- is_have = true;
- break;
- }
- }else{
- if(item.id == oldCartGoods[i].good_id && !oldCartGoods[i].is_add){
- is_have = true;
- break;
- }
- }
- };
- return is_have;
- },
- // 进入购物车页面
- goShopCart(){
- let that = this;
- wx.navigateTo({
- url: '/pages/shopcart/index'
- })
- },
- // 营业时间判断(弃用 改成多段时间了, 前端判断没意义了)
- checkBusinessTime(){
- let that = this;
- let store = that.data.store;
- // console.log('store',that.data.store,store.status);
- if(store.status != 1){
- wx.showToast({
- title: "门店暂未营业",
- icon: "none",
- duration: 3000
- });
- return;
- };
- let currentTime = new Date();
- let year = currentTime.getFullYear();
- let month = currentTime.getMonth()+1;
- let day = currentTime.getDate();
- let endDay = currentTime.getDate();
- if(store.end_at.split(":")[0] < store.begin_at.split(":")[0]){
- endDay = endDay+1;
- };
- let storeBeginAt = new Date(year+'/'+month+'/'+day+' '+store.begin_at);
- let storeEndAt = new Date(year+'/'+month+'/'+endDay+' '+store.end_at);
- if(storeBeginAt.getTime() > currentTime.getTime() || storeEndAt.getTime() < currentTime.getTime()){
- wx.showToast({
- title: "门店暂未营业",
- icon: "none",
- duration: 3000
- });
- };
- }
- });
|