单品改价

This commit is contained in:
duan
2024-12-03 16:19:48 +08:00
parent 74d644c46b
commit c4f43a0626
5 changed files with 166 additions and 75 deletions

View File

@@ -639,7 +639,7 @@
}
},
{
"pageId": "PAGES_ADD_TEMP_CUISINE",
"pageId": "PAGES_CHOOSE_ADD_TEMP_CUISINE",
"path": "add-temp-cuisine/add-temp-cuisine",
"style": {
"navigationBarTitleText": "添加临时菜"

View File

@@ -125,9 +125,12 @@
reactive,
onMounted,
ref,
onBeforeMount
onBeforeMount,
} from 'vue';
import {onLoad} from '@dcloudio/uni-app'
import {
onLoad,
onShow
} from '@dcloudio/uni-app'
const units = reactive({
list: [],
current: ''
@@ -188,6 +191,7 @@
},
}
let timer = null
function submit() {
refform.value.validate(res => {
console.log(res)
@@ -234,7 +238,7 @@
page: 0,
size: 600
})
const arr = returnAllCategory(res.content).map(v => {
const arr = forList(res.content).map(v => {
return {
...v,
value: v.id
@@ -244,24 +248,40 @@
for (let i in arr) {
category[i] = arr[i]
}
console.log(category);
}
function forList(arr) {
let arrs = []
arr.forEach(ele => {
arrs.push(ele)
if (ele.childrenList.length) {
ele.childrenList.forEach(res => {
arrs.push(res)
})
}
})
return arrs
}
async function init() {
getTbShopUnit()
getCategory()
}
onMounted(() => {
// onMounted(() => {
// init()
// })
onLoad((opt) => {
Object.assign(option, opt)
setTimeout(() => {
init()
}, 600)
})
onBeforeMount(() => {
clearInterval(timer)
})
const option = reactive({
})
onLoad((opt)=>{
Object.assign(option,opt)
})
</script>
<style lang="scss" scoped>

View File

@@ -1,9 +1,9 @@
<template>
<my-model ref="model" :title="title" iconColor="#000" @close="resetForm">
<template #desc>
<view class="u-m-t-48 tab">
<!-- <view class="u-m-t-48 tab">
<my-tabs :list="tabs" @change="tabsChange"></my-tabs>
</view>
</view> -->
<view class="u-text-left u-p-30 ">
<template v-if="!current">
<view>
@@ -46,19 +46,22 @@
</view>
</template>
<view class="u-m-t-48">
<view class="u-font-24">
<text class="color-999">当前单品价格{{price}}</text>
</view>
<view class="u-font-24">
<text class="color-999">打折原因</text>
<text class="color-red">*</text>
</view>
<view class="u-flex u-m-t-24">
<view class="u-flex" v-for="(item,index) in causes" :key="index">
<button @tap="changeCauses(item)" class="tag u-m-r-20"
<button @tap="changeCauses(item,index)" class="tag u-m-r-20"
:class="{active:item.checked}">{{item.name}}</button>
</view>
</view>
</view>
<view class="u-m-t-32 u-flex ">
<uni-easyinput type="textarea" v-model="value" placeholder="自定义内容"></uni-easyinput>
<uni-easyinput type="textarea" v-model="form.note" placeholder="自定义内容"></uni-easyinput>
</view>
</view>
@@ -101,9 +104,7 @@
function changeCauses(item) {
item.checked = !item.checked
}
const discounts = [95, 90, 85, 80]
const causes = reactive([{
@@ -120,6 +121,11 @@
}
])
function changeCauses(item, index) {
item.checked = !item.checked
form.notes = causes
}
function discountInput(e) {
if (e.detail.value >= 100) {
nextTick(() => {
@@ -127,6 +133,7 @@
})
}
}
function discountMoneyInput(e) {
const max = 100
if (e.detail.value >= max) {
@@ -142,7 +149,7 @@
const tabs = ['打折', '减免']
let current = ref(0)
let current = ref(1)
function tabsChange(i) {
console.log(i);
@@ -163,6 +170,7 @@
form.price = newval
form.currentPrice = newval
})
function resetForm() {
Object.assign(form, {
...$form
@@ -182,7 +190,8 @@
function confirm() {
const {
discount,discountMoney
discount,
discountMoney
} = form
if (current.value === 0 && discount === '') {
return uni.showToast({
@@ -196,8 +205,8 @@
title: '请输入有效减免价格!'
})
}
close()
emits('confirm', form)
close()
}
defineExpose({
open,

View File

@@ -154,6 +154,11 @@
custom-style="background-color: #E6F0FF; border-color: #E6F0FF; color: #318AFE;"
size="small" text="打包" inverted type="success" />
</view>
<view class="u-m-r-20 u-flex" v-if="item.isPrint">
<uni-tag
custom-style="background-color: #E6F0FF; border-color: #E6F0FF; color: #318AFE;"
size="small" text="打印" inverted type="success" />
</view>
<view>
{{item.name}}
</view>
@@ -174,7 +179,8 @@
<text
class="line-th color-999">{{formatPrice(item.salePrice*item.number) }}</text>
<view class="u-absolute" style="right: 0;bottom: 100%;">
<text class="font-bold">{{formatPrice(item.memberPrice*item.number) }}</text>
<text
class="font-bold">{{formatPrice(item.memberPrice*item.number) }}</text>
</view>
</template>
<template v-else>
@@ -196,9 +202,10 @@
</template>
<scroll-view class="u-m-t-32" scroll-x="true" v-if="index==goods.sel">
<view class=" u-flex no-wrap ">
<!-- <view class="u-flex u-m-r-20 u-m-b-20">
<button class="tag" hover-class="hover-class" @tap="showModel('discount')">单品打折</button>
</view> -->
<view class="u-flex u-m-r-20 ">
<button class="tag" hover-class="hover-class"
@tap="showModel('discount',index)">单品打折</button>
</view>
<view class="u-flex u-m-r-20 ">
<!-- <button class="tag" hover-class="hover-class" @tap="showModel('giveFood')">赠菜</button> -->
<button class="tag" hover-class="hover-class"
@@ -208,10 +215,14 @@
<button class="tag" hover-class="hover-class"
@tap="toggleGoodsItemKey(item,index,'isPack')">{{item.isPack?'取消打包':'打包'}}</button>
</view>
<!-- <view class="u-flex u-m-r-20 u-m-b-20">
<view class="u-flex u-m-r-20 ">
<button class="tag" hover-class="hover-class"
@tap="toggleWait(item)">{{item.isWait?'取消等叫':'等叫'}}</button>
</view> -->
</view>
<view class="u-flex u-m-r-20 ">
<button class="tag" hover-class="hover-class"
@tap="toggisPrint(item)">{{item.isPrint?'免厨打':'打印'}}</button>
</view>
<view class="u-flex u-m-r-20 ">
<button class="tag" hover-class="hover-class"
@tap="showModel('remark',index)">单品备注</button>
@@ -278,8 +289,7 @@
</view>
</view>
<model-discount title="菜品打折/减免" :ref="setModel" name="discount" :price="allPrice"></model-discount>
<model-discount title="菜品减免" :ref="setModel" name="discount" :price="modelData.data.salePrice" @confirm="discountconfirm"></model-discount>
<give-food title="赠菜" :ref="setModel" name="giveFood"></give-food>
<one-remark @confirm="goodsOneRemarkConfirm" title="单品备注" :ref="setModel" name="remark"></one-remark>
<edit-discount title="优惠金额" :ref="setModel" name="editMoney" :price="allPrice"></edit-discount>
@@ -351,7 +361,24 @@
return Number(n).toFixed(2)
}
// 单品打折
async function discountconfirm(form) {
console.log(form, '调试111111')
let str = ''
if (form.notes) {
form.notes.forEach(ele => {
if (ele.checked) {
str = str + ele.name + ','
}
})
}
let obj = {
saleAmount: form.discountMoney,
note: str + form.note,
cartId: modelData.data.id
}
const res = await Api.$updatePrice(obj)
}
//用餐人数
const userNumbers = reactive({
@@ -423,11 +450,40 @@
}
}
//等叫
function toggleWait(item) {
async function toggleWait(item) {
item.isWait = !item.isWait
let obj = {
cartId: item.id,
isGift: item.isGift,
isPack: item.isPack,
isPrint: item.isPrint,
isWaitCall: item.isWait,
masterId: option.masterId,
num: item.number, // 0会删除此商品
productId: item.productId,
skuId: item.skuId,
vipUserId: '',
}
let res = await Api.$updateCart(obj)
}
// 打印
async function toggisPrint(item) {
item.isPrint = !item.isPrint
let obj = {
cartId: item.id,
isGift: item.isGift,
isPack: item.isPack,
isPrint: item.isPrint,
isWaitCall: item.isWait,
masterId: option.masterId,
num: item.number, // 0会删除此商品
productId: item.productId,
skuId: item.skuId,
vipUserId: '',
}
let res = await Api.$updateCart(obj)
}
const eatTypes = reactive({
list: [{
@@ -479,7 +535,6 @@
function watchChooseuser() {
uni.$off('choose-user')
uni.$on('choose-user', (data) => {
console.log(data);
user.value = data
setUser()
})
@@ -523,6 +578,12 @@
const isVip = computed(() => {
return $shop.value.isMemberPrice && user.value && user.value.id && user.value.isVip
})
const discountSaleAmount=computed(()=>{
return goods.list.filter((v) => v.discountSaleAmount && v.discountSaleAmount > 0)
.reduce((a, b) => {
return a + b.number * b.discountSaleAmount;
}, 0);
})
const goodsPrice = computed(() => {
const goodsTotalPrice = goods.list.reduce((prve, cur) => {
const memberPrice = cur.memberPrice ? cur.memberPrice : cur.salePrice
@@ -530,10 +591,10 @@
const tpackFee = cur.isPack ? cur.packFee * 1 : 0
return prve + (cur.isGift ? 0 : tPrice) + tpackFee
}, 0)
return (goodsTotalPrice || 0).toFixed(2)
return ((goodsTotalPrice-discountSaleAmount.value) || 0).toFixed(2)
})
const allPrice = computed(() => {
console.log(goodsPrice.value);
console.log(goodsPrice.value,'调试2121');
const n = goodsPrice.value * 1 + $seatFee.totalAmount
return n.toFixed(2)
// const goodsTotalPrice = goods.list.reduce((prve, cur) => {
@@ -542,17 +603,18 @@
// return (goodsTotalPrice + ($seatFee.totalAmount || 0)).toFixed(2)
})
const youhui = computed(() => {
let goodsTotalPrice=0
if (user.value && user.value.id && user.value.isVip) {
const goodsTotalPrice = goods.list.reduce((prve, cur) => {
goodsTotalPrice = goods.list.reduce((prve, cur) => {
const tPrice = cur.salePrice * cur.number
const tpackFee = cur.isPack ? cur.packFee * 1 : 0
return prve + tPrice + tpackFee
}, 0)
return goodsTotalPrice - allPrice.value
} else {
return 0
return (discountSaleAmount.value)
}
return goodsTotalPrice
return (goodsTotalPrice+discountSaleAmount.value*1).toFixed(2)
})
function setGoodsItem(key, val) {

View File

@@ -671,7 +671,7 @@
}
function toLinshi() {
go.to('PAGES_ADD_TEMP_CUISINE',{
go.to('PAGES_CHOOSE_ADD_TEMP_CUISINE',{
masterId:data.masterId,
tableId:data.table.tableId,
vipUserId:option.vipUserId?option.vipUserId:'',