diff --git a/common/js/api.js b/common/js/api.js index 7438067..c019c09 100644 --- a/common/js/api.js +++ b/common/js/api.js @@ -8,9 +8,18 @@ export default { loginapplogin(data) { //APP登录(登录即注册) return uni.api.post("/login/app/login", data); }, + productqueryShop(data) { //通过桌码获取店铺信息 + return uni.api.get("/product/queryShop", data); + }, productqueryProduct(data) { //获取商品信息 return uni.api.post("/product/queryProduct", data, false); }, + cartAdd(data) { //添加到购物车 + return uni.api.post("/product/addCart", data); + }, + cleanCart(data) { //清空购物车 + return uni.api.post("/product/cleanCart", data); + }, // 下单详情 getproductorderConfirm(data) { return uni.api.get("/product/orderConfirm", data); diff --git a/framework/11-api.js b/framework/11-api.js index 41289bb..85aeba0 100644 --- a/framework/11-api.js +++ b/framework/11-api.js @@ -102,6 +102,7 @@ async function request(options) { let res = await uni.pro.request(options); // #endif if (res.code != 0) { + console.log(options) if (res.code == -4) { uni.showToast({ // title: '', diff --git a/pages.json b/pages.json index b45f432..44c2a66 100644 --- a/pages.json +++ b/pages.json @@ -173,13 +173,6 @@ "navigationBarTextStyle": "white" } }, - { - "path": "pages/order_food/goodsList_swiper", - "style": { - "navigationStyle": "custom", - "navigationBarTextStyle": "white" - } - }, { "path": "pages/make/list", "style": { diff --git a/pages/index/components/diamond.vue b/pages/index/components/diamond.vue index 84c895b..afbd065 100644 --- a/pages/index/components/diamond.vue +++ b/pages/index/components/diamond.vue @@ -58,7 +58,8 @@ let tableCode = this.getQueryString(decodeURIComponent(res.result), 'code') uni.cache.set('tableCode', tableCode) if (tableCode) { - uni.pro.navigateTo('order_food/order_food') + // uni.pro.navigateTo('order_food/order_food') + uni.pro.navigateTo('order_food/goodsList_scroll') } } }); diff --git a/pages/order_food/goodsList.vue b/pages/order_food/goodsList.vue deleted file mode 100644 index 8105b1d..0000000 --- a/pages/order_food/goodsList.vue +++ /dev/null @@ -1,92 +0,0 @@ - - - - - diff --git a/pages/order_food/goodsList_scroll.vue b/pages/order_food/goodsList_scroll.vue index 8e7063f..9b86515 100644 --- a/pages/order_food/goodsList_scroll.vue +++ b/pages/order_food/goodsList_scroll.vue @@ -9,14 +9,14 @@ src="https://czg-qr-order.oss-cn-beijing.aliyuncs.com/orderfood/shuangyu1.png" mode="aspectFill"> - {{ shopList.storeInfo.shopName }} + {{ shopInfo.storeInfo.shopName }} - 距离您12.44KM + 距离您{{ shopInfo.distance }} - 营业时间:{{ shopList.storeInfo.businessStartDay +'至'+ shopList.storeInfo.businessEndDay +' '+ shopList.storeInfo.businessTime }} + 营业时间:{{ shopInfo.storeInfo.businessStartDay +'至'+ shopInfo.storeInfo.businessEndDay +' '+ shopInfo.storeInfo.businessTime }} 查看 @@ -29,10 +29,10 @@ - + - 厚乳酪冰镇拿铁 + {{ item.name }} 本店回头客第4名 @@ -66,7 +66,7 @@ - {{item.name}} @@ -74,7 +74,7 @@ - + {{item.name}} @@ -186,7 +186,7 @@ - {{ shopList.storeInfo.shopName }} + {{ shopInfo.storeInfo.shopName }} @@ -195,22 +195,22 @@ 营业时间: - {{ shopList.storeInfo.businessStartDay +'至'+ shopList.storeInfo.businessEndDay +' '+ shopList.storeInfo.businessTime }} + {{ shopInfo.storeInfo.businessStartDay +'至'+ shopInfo.storeInfo.businessEndDay +' '+ shopInfo.storeInfo.businessTime }} 商家地址: - {{ shopList.storeInfo.address }} + {{ shopInfo.storeInfo.address }} - + 商家电话: - {{ shopList.storeInfo.phone }} + {{ shopInfo.storeInfo.phone }} 商家公告 公告: - {{ shopList.storeInfo.detail }} + {{ shopInfo.storeInfo.detail }} @@ -298,13 +298,13 @@ heightnav: '' ,//点击获取的距离 showShopInfo: false, //店铺信息弹窗是否显示 showShopsku: false, //多规格弹窗是否显示 + skuId: null, // 多规格ID cartLists: {}, //购物车 cartLists_count: 0, - shopList: { - storeInfo:{ - shopName: "", - } - }, //店铺信息 + shopInfo: {}, //店铺信息 + shopProductList: { + + }, //商品信息 specifications: { }, // 规格信息 @@ -350,7 +350,6 @@ this.scrollTopSize = res.top; //元素距离顶部的距离 this.scrollHeight = this.scrollHeight - this.heightnav // console.log(this.scrollHeight, 111) - this.getListData(); }) } }) @@ -376,6 +375,7 @@ this.fixedtrue = true }, onShow() { + console.log(uni.cache.get('token')) if (!uni.cache.get('token')) { uni.login({ provider: 'weixin', @@ -395,7 +395,7 @@ .miniAppOpenId) uni.cache.set('userInfo', res.data.userInfo); uni.$on('message', this.getMessage) - this.productqueryShopIdByTableCode() //获取shop User id + this.productqueryShop(); } }, fail: (err) => {} @@ -405,11 +405,91 @@ }); } else { uni.$on('message', this.getMessage) - this.productqueryShopIdByTableCode() //获取shop User id + this.productqueryShop(); } }, methods: { + /** + * socket初始化 + */ + handlemessage() { + this.socketTicket ? this.socketTicket.Close() : null //调用前先判断是否有socket正在进行 先关闭后链接 + this.socketTicket = new webSocketUtils(`${uni.conf.baseUrlwws}`, 5000, { + tableId: uni.cache.get('tableCode'), + shopId: uni.cache.get('shopUser'), + userId: uni.cache.get('userInfo').id, + "type": "connect", + }) + }, + + /** + * 通过桌码获取店铺信息 + */ + async productqueryShop () { + let res = await this.api.productqueryShop({ + code: uni.cache.get('tableCode'), + lng: uni.cache.get('getLocationstorage').lng, + lat: uni.cache.get('getLocationstorage').lat, + }) + console.log(res) + if (res.code == 0) { + uni.cache.set('shopUser', res.data.storeInfo.id) + this.handlemessage() //监听websocket返回 + this.shopInfo = res.data; + this.productqueryProduct() //list 数据 + } else { + setTimeout(() => { + uni.pro.switchTab('index/index') + }, 1000) + } + + }, + + /** + * 获取商品数据 + */ + async productqueryProduct() { + let res = await this.api.productqueryProduct({ + // code: uni.cache.get('tableCode'), + "shopId": uni.cache.get('shopUser'), + productGroupId: '' + }) + if (res.code == 0) { + this.shopProductList = res.data; + + if ( this.cartLists.data.length >= 0 ) { + var summedArray = this.cartLists.data.reduce((acc, current) => { + const existing = acc.find(item => item.productId === current.productId); + if (existing) { + existing.number += current.number; + } else { + acc.push({ + ...current + }) + } + return acc; + }, []); + console.log(summedArray) + // 购物车总数据与列表页面互通 + this.shopProductList.productInfo.forEach((item) => { + return item.products.filter(e => { + e.cartNumber = 0; + return summedArray.find(i => { + if (e.id == i.productId) { + e.cartNumber = i.number + } + }) + }) + }) + } + console.log(this.shopProductList) + // this.$nextTick(() => { + // this.countTitleTopNum(); + // }); + } + }, + /** * 商品数量增加/减少 * @param {Object} item @@ -422,7 +502,8 @@ if (b == '单规格') { //没有规格为空 this.skuidname = [] } - this.hodgepodge(item, 1, a) //获取skuid /1添加购物车 + let cartNumber = a == '+' ? item.cartNumber+1 : item.cartNumber-1; + this.hodgepodge(item, 1, a, cartNumber) //获取skuid /1添加购物车 }, /** @@ -449,6 +530,16 @@ */ addShopping ( item, index, index1, a, b ) { console.log(item) + let params = { + "skuId": this.skuId, + "num": item.cartNumber + this.amountcartNumber, //数量 + "type": a == '+' ? 1 : 0, + "productId": item.id, //商品id + "shopId": uni.cache.get('shopUser'), + "userId": uni.cache.get('userInfo').id, + "tableId": uni.cache.get('tableCode'), + } + this.addCart(params) }, /** @@ -476,6 +567,58 @@ } }, + + /** + * 添加到购物车 + */ + async addCart ( data ) { + let res = await this.api.cartAdd(data) + if ( res.code == 0) { + this.showShopsku = false; + this.$set(this, 'amountcartNumber', 1) + } + }, + + /** + * 清空购物车 + */ + async cartclear() { + let res = await this.api.cleanCart({ + "shopId": uni.cache.get('shopUser'), + "tableId": uni.cache.get('tableCode'), + }) + }, + + + /** + * 商品数量\购物车数量处理 + */ + setNumber () { + // 处理购物车相同id的情况下 数量相加 + var summedArray = this.cartLists.data.reduce((acc, current) => { + const existing = acc.find(item => item.productId === current.productId); + if (existing) { + existing.number += current.number; + } else { + acc.push({ + ...current + }) + } + return acc; + }, []); + // 购物车总数据与列表页面互通 + this.shopProductList.productInfo.forEach((item) => { + return item.products.filter(e => { + e.cartNumber = 0; + return summedArray.find(i => { + if (e.id == i.productId) { + e.cartNumber = i.number + } + }) + }) + }) + }, + /** * 结算直接生成订单 */ @@ -488,7 +631,7 @@ return false } uni.navigateTo({ - url: '/pages/order/confirm_order?storeInfo=' + JSON.stringify(this.shopList.storeInfo) + url: '/pages/order/confirm_order?storeInfo=' + JSON.stringify(this.shopInfo.storeInfo) }); // let data = { @@ -513,41 +656,6 @@ this.showShopInfo = true; }, - /** - * 单独获取他的shopUserid - */ - async productqueryShopIdByTableCode() { - let res = await this.api.productqueryShopIdByTableCode({ - code: uni.cache.get('tableCode') - }) - if (res.code == 0) { - uni.cache.set('shopUser', res.data) - this.handlemessage() //监听websocket返回 - this.productqueryProduct() //list 数据 - } else { - setTimeout(() => { - uni.pro.switchTab('index/index') - }, 1000) - } - }, - - /** - * 获取店铺数据 - */ - async productqueryProduct() { - let res = await this.api.productqueryProduct({ - code: uni.cache.get('tableCode'), - productGroupId: '' - }) - if (res.code == 0) { - this.shopList = res.data; - console.log(this.shopList) - // this.$nextTick(() => { - // this.countTitleTopNum(); - // }); - } - }, - /** * 多规格选择 @@ -591,7 +699,8 @@ this.skuidname.splice(index, 1, e) //替换skuidname的数据 this.hodgepodge(item, 2) }, - async hodgepodge(item, a, c) { //此接口去获取商品id !!!赋值库存 数量 价格等 + + async hodgepodge(item, a, c, num) { //此接口去获取商品id !!!赋值库存 数量 价格等 try { let res = await this.api.productqueryProductSku({ shopId: uni.cache.get('shopUser'), @@ -609,45 +718,34 @@ this.salePrice = res.data.salePrice // 价格 let data = null; if (a == 1) { //1添加购物车 2是websocket返回这个商品的价格(应为不同的多规格商品返回不同的价格) - data = { //定义socket数据传参 - "nickName": this.userInfo.nickName, - "barrageavatar": this.userInfo.headImg, - 'name': item.name, + let params = { "skuId": res.data.id, - "num": c == '-' ? -1 : 1, //数量 - "type": "addcart", //“addcart:添加购物车,create0rder:生成订单,clearCart:庆康购物车”, + "num": num, //数量 + "type": c == '+' ? 1 : 0, "productId": item.id, //商品id "shopId": uni.cache.get('shopUser'), - "userId": uni.cache.get('userInfo').id - }; + "userId": uni.cache.get('userInfo').id, + "tableId": uni.cache.get('tableCode'), + } + this.addCart(params); } else { - data = { //查询这个商品的价格 - "name": item.name, - "skuId": res.data.id, - "num": '', //数量 - "type": "sku", //“addcart:添加购物车,create0rder:生成订单,clearCart:庆康购物车”, - "productId": item.id, //商品id - "shopId": uni.cache.get('shopUser'), - "userId": uni.cache.get('userInfo').id - }; - this.$set(this, 'amountcartNumber', 1) + this.skuId = res.data.id; this.showShopsku = true //打开弹框 } - this.datasocket = data; - uni.$u.debounce(this.socketSendMsg(data), 500) + this.$set(this, 'amountcartNumber', 1) + // this.datasocket = data; + // uni.$u.debounce(this.socketSendMsg(data), 500) } } catch (e) {} }, - - - + /** * 获取消息 * @param {Object} msg */ getMessage(msg) { //wss 回显数据 - console.log(msg) + console.log(msg.type) if (msg == 1) { // 网络在连接 this.fixedtrue = true return false @@ -672,58 +770,26 @@ switch (msg.type) { case 'sku': // sku 数量 查询这个商品的价格和数量 // this.$set(this, 'amountcartNumber', msg.amount) - this.productqueryProduct() //list 数据 - break; - case 'clearCart': - this.cartLists = msg - this.productqueryProduct() //list 数据 - this.skuidname = [] - this.showCart = false - setTimeout(() => { - uni.showToast({ - title: msg.msg, - icon: "none", - }) - }, 500) + // this.productqueryProduct() //list 数据 break; case 'order': this.skuidname = [] this.showCart = false this.cartLists = msg - this.productqueryProduct() //list 数据 + // this.productqueryProduct() //list 数据 break; case 'addCart': //初始化add this.cartLists = msg - this.productqueryProduct() //list 数据 break; case 'addcart': this.cartLists = msg - console.log(msg, 1111) - this.productqueryProduct() //list 数据 try { - if (msg.data.length != 0) { - let nums = 0 - msg.data.forEach((item, index, arr) => { //初始化skuidname的数据 选择第一个 - if (item.skuId == this.skuidsearch) { - nums = item.number - } - }) - // this.$set(this, 'amountcartNumber', nums) - } else { - this.$set(this, 'amountcartNumber', 1) + //购物车为空的情况 + if ( msg.data.length == 0) { + this.showCart = false; } - } catch (e) { - //TODO handle the exception - } - try { - this.barrageavatar = msg.reqData.headImg - /*插入一条弹幕*/ - this.$refs.lBarrage.add( - `${msg.reqData.nickName?msg.reqData.nickName:'微信用户'}${msg.reqData.num==-1?'取消了':'添加了'}${msg.reqData.name}(${msg.reqData.num})` - ); - } catch (e) { - //TODO handle the exception - } + this.setNumber() + } catch (e) {} break; } this.cartListsdatashow = this.cartLists.data.length == 0 ? false : true @@ -740,23 +806,16 @@ //TODO handle the exception } }, - handlemessage() { - this.socketTicket ? this.socketTicket.Close() : null //调用前先判断是否有socket正在进行 先关闭后链接 - this.socketTicket = new webSocketUtils(`${uni.conf.baseUrlwws}`, 5000, { - tableId: uni.cache.get('tableCode'), - shopId: uni.cache.get('shopUser'), - userId: uni.cache.get('userInfo').id, - "type": "connect", - }) - }, + // 数据处理 socketSendMsg(data) { if (this.socketTicket) { - console.log(data) this.socketTicket.send(data); } }, + + // 导航栏高度 去计算列表页的高度 Topdistance(e) { diff --git a/pages/order_food/goodsList_swiper.vue b/pages/order_food/goodsList_swiper.vue deleted file mode 100644 index 76c11f6..0000000 --- a/pages/order_food/goodsList_swiper.vue +++ /dev/null @@ -1,323 +0,0 @@ - - - - - diff --git a/pages/order_food/order_food - 副本 (2).vue b/pages/order_food/order_food - 副本 (2).vue deleted file mode 100644 index 26cfe4a..0000000 --- a/pages/order_food/order_food - 副本 (2).vue +++ /dev/null @@ -1,1380 +0,0 @@ - - - - - \ No newline at end of file diff --git a/pages/order_food/order_food.vue b/pages/order_food/order_food.vue index 03f2dfa..195ecde 100644 --- a/pages/order_food/order_food.vue +++ b/pages/order_food/order_food.vue @@ -307,7 +307,7 @@ this.tableCode = this.getQueryString(decodeURIComponent(e.q), 'code') uni.cache.set('tableCode', this.tableCode) } - uni.cache.set('types', 'types'); + this.$nextTick(() => { this.countTitleTopNum(); //导航栏 }); diff --git a/pages/order_food/order_goods.vue b/pages/order_food/order_goods.vue deleted file mode 100644 index 04a0aba..0000000 --- a/pages/order_food/order_goods.vue +++ /dev/null @@ -1,765 +0,0 @@ - - - - - \ No newline at end of file