diff --git a/package.json b/package.json index fbdf21d..b022099 100644 --- a/package.json +++ b/package.json @@ -75,6 +75,7 @@ "uview-plus": "^3.4.28", "vue": "3.4.21", "vue-i18n": "9.1.9", + "weixin-js-sdk": "^1.6.5", "wot-design-uni": "^1.11.1", "z-paging": "^2.8.4" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e292633..c0b6570 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -44,6 +44,9 @@ importers: vue-i18n: specifier: 9.1.9 version: 9.1.9(vue@3.4.21(typescript@5.8.3)) + weixin-js-sdk: + specifier: ^1.6.5 + version: 1.6.5 wot-design-uni: specifier: ^1.11.1 version: 1.11.1(vue@3.4.21(typescript@5.8.3)) @@ -5963,6 +5966,9 @@ packages: webpack-virtual-modules@0.6.2: resolution: {integrity: sha512-66/V2i5hQanC51vBQKPH4aI8NMAcBW59FVBs+rC7eGHupMyfn34q7rZIE+ETlJ+XTevqfUhVVBgSUNSW2flEUQ==} + weixin-js-sdk@1.6.5: + resolution: {integrity: sha512-Gph1WAWB2YN/lMOFB/ymb+hbU/wYazzJgu6PMMktCy9cSCeW5wA6Zwt0dpahJbJ+RJEwtTv2x9iIu0U4enuVSQ==} + whatwg-encoding@1.0.5: resolution: {integrity: sha512-b5lim54JOPN9HtzvK9HFXvBma/rnfFeqsic0hSpjtDbVxR3dJKLc+KB4V6GgiGOvl7CY/KNh8rxSo9DKQrnUEw==} @@ -13178,6 +13184,8 @@ snapshots: webpack-virtual-modules@0.6.2: {} + weixin-js-sdk@1.6.5: {} + whatwg-encoding@1.0.5: dependencies: iconv-lite: 0.4.24 diff --git a/src/pages/banquet/combo/index.vue b/src/pages/banquet/combo/index.vue index e355a9b..1a36c66 100644 --- a/src/pages/banquet/combo/index.vue +++ b/src/pages/banquet/combo/index.vue @@ -21,16 +21,14 @@ body { - - - - @@ -55,41 +53,28 @@ body { searchIconColor="#909399" color="#606266" placeholderColor="#909399" searchIcon="search" margin="10rpx" maxlength="-1" height="60rpx" @change="searchSP()"> - - - - - - - - - --> + + + + + + + + + - - + + - - - - + + + + + @@ -128,17 +117,24 @@ body { - + + {{ orderInfo.is_set ? '修改餐标' : '设置餐标' }} + + + + + - 已选{{this.menu_list.length}}餐,合计¥213213元 + 已选{{ this.set_num }}餐,合计¥{{ totalPrice }}元 { - if (res.confirm) { - // 删除数组 - const index = this.currentTab; // 假设 currentTab 是您想要删除的餐项的索引 - if (index !== undefined && index >= 0 && index < this.menu_list.length) { - this.menu_list.splice(index, 1); - } + useModal().showModal('success', { + title: '删除提示', + content: '确定删除' + this.menu_name + '吗?', + showCancel: true, + confirmText: '确定', + cancelText: '取消', + success: (res) => { + if (res.confirm) { + // 删除数组 + const index = this.currentTab; // 假设 currentTab 是您想要删除的餐项的索引 + if (index !== undefined && index >= 0 && index < this.menu_list.length) { + this.menu_list.splice(index, 1); + } - // CommonApi.commonPost('/api/user/deleteAddress', { id: id }).catch((res) => { - // if (res.code === 1) { - // // this.propShowAddress = false; - // this.getAddressInfoListData(); - // } else { - // uni.$u.toast(res.msg); - // } - // }); - } - else if (res.cancel) { - // console.log('用户点击取消'); - } - }, - }); + // CommonApi.commonPost('/api/user/deleteAddress', { id: id }).catch((res) => { + // if (res.code === 1) { + // // this.propShowAddress = false; + // this.getAddressInfoListData(); + // } else { + // uni.$u.toast(res.msg); + // } + // }); + } + else if (res.cancel) { + // console.log('用户点击取消'); + } + }, + }); }, @@ -266,7 +379,7 @@ export default defineComponent({ this.$nextTick(() => { this.handleClickCategory(this.currentTab) this.menu_name = this.menu_list[this.currentTab].name; // 更新 menu_name - this.orderInfo = this.menu_list[this.currentTab].orderInfo; // 更新 orderInfo + // this.orderInfo = this.menu_list[this.currentTab].orderInfo; // 更新 orderInfo }); }, @@ -277,8 +390,8 @@ export default defineComponent({ if (valid) { this.menu_list[this.currentTab].is_set = 1; this.menu_list[this.currentTab].orderInfo = this.orderInfo; + this.editCart() // this.menu_list[this.currentTab].orderInfo.columns = this.columns[this.currentTab].value; - // this.menu_list[this.currentTab].orderInfo.total_price = this.totalPrice; this.close(); } @@ -293,16 +406,19 @@ export default defineComponent({ handleSubmit () { this.propShowOrder = true; }, - + //提交订单 handleConfirm () { // console.log(value) - var id = 1; - uni.navigateTo({ - url: `/pages/banquet/combo/detail?id=${id}` - }); + + console.log(this.set_num); + + // var id = 1; + // uni.navigateTo({ + // url: `/pages/banquet/combo/detail?id=${id}` + // }); }, - + formatter (day) { const date = new Date(day.date) @@ -328,30 +444,74 @@ export default defineComponent({ }, handleTimeConfirm (res) { - console.log(res.value) - this.orderInfo.time = res.value + // console.log(res.value) + this.orderInfo.date = res.value }, //分类切换 handleClickCategory (index: number) { + // console.log(index); + // this.categoryIndex = index; + // this.tabList = this.categoryList[index].children; + // this.handleChildrenClick(0); + this.getCategoryList(); - console.log(index); - this.categoryIndex = index; - this.tabList = this.categoryList[index].children; - this.handleChildrenClick(0); }, handleChildrenClick (index: number) { this.childrenIndex = index; - this.search.category_id = this.tabList[index].id; + // this.search.category_id = this.tabList[this.childrenIndex].id; this.$refs.pagingRefSP?.reload(); }, + //购物车验证 + getCartCheck () { + CommonApi.commonPost('/api/banquet/order/check', { server_user_id: this.search.server_user_id }).catch((res) => { + var num = 0; + var is_set_cart = 0; + var newCartList = []; + this.set_num = 0; + if (res.code === 1) { + for (let val in res.data.cart_list) { + // console.log(res.data.cart_list[val][0]); + num++; + is_set_cart = res.data.cart_list[val][0].banquet_date ? 1 : 0; // 餐标已设置 日期 + if (is_set_cart) { + this.set_num += 1; + } + newCartList.push({ + name: '第' + num + '餐', orderInfo: { + id: 0, + is_set: is_set_cart, + date: new Date(res.data.cart_list[val][0].banquet_date).getTime(), + columns: res.data.cart_list[val][0].banquet_time ? res.data.cart_list[val][0].banquet_time : '早上', + number: res.data.cart_list[val][0].table_number ? res.data.cart_list[val][0].table_number : 1, + } + }) + this.menu_list[val].orderInfo.is_set = is_set_cart; + } + //更新购物车餐标--获取已填数据 + if (num > 0 && newCartList[this.currentTab]) { + this.orderInfo = newCartList[this.currentTab].orderInfo; // 更新 orderInfo --已填值 + } else { + this.orderInfo = this.menu_list[this.currentTab].orderInfo; // 更新 orderInfo --默认值 + } + this.totalPrice = res.data.total_price; + } else { + // uni.$u.toast(res.msg); + } + }); + }, getCategoryList () { - CommonApi.commonGet('/api/dishes/category').catch((res) => { + CommonApi.commonGet('/api/banquet/dishes/category', { + server_user_id: this.search.server_user_id, + index: this.currentTab + }).catch((res) => { if (res.code === 1) { - this.categoryList = res.data; - this.handleClickCategory(0) + // this.categoryList = res.data; + this.tabList = res.data; + this.search.category_id = this.tabList[0].id; + this.getCartCheck() // 检查购物车 } else { uni.$u.toast(res.msg); } @@ -364,9 +524,11 @@ export default defineComponent({ }, //列表分页 changeSP (pageNo: number) { + this.search.category_id = this.tabList[this.childrenIndex] ? this.tabList[this.childrenIndex].id : 0; // console.log(pageNo); this.search.page = pageNo; - CommonApi.commonGet('/api/dishes/dishes', this.search).catch((res) => { + this.search.index = this.currentTab; + CommonApi.commonGet('/api/banquet/dishes/list', this.search).catch((res) => { if (res.code === 1) { // this.matchedItems_sp = res.data; this.$refs.pagingRefSP?.complete(res.data); @@ -386,18 +548,66 @@ export default defineComponent({ }, //加入购物车 - addCart (id) { - CommonApi.commonPost('/api/cart/add', { - buy_now: false, - dishes_id: id, + addCart (e) { + console.log(e); + CommonApi.commonPost('/api/banquet/cart/add', { + server_user_id: this.search.server_user_id, + index: this.currentTab, + dishes_id: e.id, + number: e.cart_count, }).catch((res) => { if (res.code === 1) { - uni.$u.toast('加入购物车成功'); + //等于0 删除商品 + if (e.cart_count === 0) { + this.delCart(e.cart_id) + } + this.getCategoryList() // 更新购物车 + this.searchSP() // 更新列表 } else { uni.$u.toast(res.msg); } }); - } + }, + delCart (id) { + CommonApi.commonPost('/api/banquet/cart/delete', { + id: id, + }).catch((res) => { + if (res.code === 1) { + uni.$u.toast('删除成功'); + this.getCartCheck() // 检查购物车 + } else { + uni.$u.toast(res.msg); + } + }); + }, + + editCart () { + CommonApi.commonPost('/api/banquet/cart/edit', { + server_user_id: this.search.server_user_id, + index: this.currentTab, + date: this.formatDate(this.orderInfo.date), + time: this.orderInfo.columns, + number: this.orderInfo.number, + + }).catch((res) => { + if (res.code === 1) { + uni.$u.toast('设置餐标成功'); + this.getCartCheck() // 检查购物车 + } else { + uni.$u.toast(res.msg); + } + }); + }, + // 时间戳转换为 Y-m-d 格式 + formatDate (timestamp: number) { + const date = new Date(timestamp); + const year = date.getFullYear(); + const month = String(date.getMonth() + 1).padStart(2, '0'); + const day = String(date.getDate()).padStart(2, '0'); + const formattedDate = `${year}-${month}-${day}`; + console.log('格式化后的日期:', formattedDate); + return formattedDate; + }, }, diff --git a/src/pages/banquet/cook/detail.vue b/src/pages/banquet/cook/detail.vue index 178a213..16ca1d8 100644 --- a/src/pages/banquet/cook/detail.vue +++ b/src/pages/banquet/cook/detail.vue @@ -1,9 +1,5 @@