单品改价

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: ''
@@ -187,11 +190,12 @@
}]
},
}
let timer=null
let timer = null
function submit() {
refform.value.validate(res => {
console.log(res)
if(!res){
if (!res) {
$temporaryDishes({
"useType": option.useType,
"masterId": option.masterId,
@@ -200,15 +204,15 @@
"categoryId": category[categoryCurrent.value].id,
"price": form.price,
"num": form.num,
unit:units.list[units.current].id,
unit: units.list[units.current].id,
"note": form.note,
"vipUserId": option.vipUserId
}).then(r=>{
}).then(r => {
uni.$emit('add:cashCai')
clearInterval(timer)
timer=setTimeout(()=>{
timer = setTimeout(() => {
uni.navigateBack()
},500)
}, 500)
})
}
}).catch(err => {
@@ -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,23 +248,39 @@
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(() => {
init()
// onMounted(() => {
// init()
// })
onLoad((opt) => {
Object.assign(option, opt)
setTimeout(() => {
init()
}, 600)
})
onBeforeMount(()=>{
onBeforeMount(() => {
clearInterval(timer)
})
const option=reactive({
})
onLoad((opt)=>{
Object.assign(option,opt)
const option = reactive({
})
</script>

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">打折原因</text>
<text class="color-red">*</text>
</view>
<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>
@@ -86,7 +89,7 @@
import myTabs from '@/components/my-components/my-tabs.vue'
const props = defineProps({
price: {
type: [Number,String],
type: [Number, String],
default: 0
},
title: {
@@ -98,12 +101,10 @@
default: []
}
})
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,8 +133,9 @@
})
}
}
function discountMoneyInput(e) {
const max=100
const max = 100
if (e.detail.value >= max) {
nextTick(() => {
form.discountMoney = 100
@@ -142,7 +149,7 @@
const tabs = ['打折', '减免']
let current = ref(0)
let current = ref(1)
function tabsChange(i) {
console.log(i);
@@ -158,11 +165,12 @@
const form = reactive({
...$form
})
watch(()=>props.price,(newval)=>{
watch(() => props.price, (newval) => {
console.log(newval);
form.price=newval
form.currentPrice=newval
form.price = newval
form.currentPrice = newval
})
function resetForm() {
Object.assign(form, {
...$form
@@ -182,22 +190,23 @@
function confirm() {
const {
discount,discountMoney
discount,
discountMoney
} = form
if (current.value===0&& discount==='') {
if (current.value === 0 && discount === '') {
return uni.showToast({
icon: 'none',
title: '请输入有效折扣!'
})
}
if (current.value===1&& discountMoney==='') {
if (current.value === 1 && discountMoney === '') {
return uni.showToast({
icon: 'none',
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>
@@ -251,7 +262,7 @@
<view class="font-bold u-font-32">{{formatPrice(youhui) }}</view>
</view>
</view>
<view class="u-flex price u-m-l-32">
<view class="">实收金额</view>
<view class="font-bold u-font-32">{{formatPrice(allPrice) }}</view>
@@ -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()
})
@@ -520,20 +575,26 @@
totalNumber: 0,
totalAmount: 0,
})
const isVip=computed(()=>{
return $shop.value.isMemberPrice&& user.value&&user.value.id&&user.value.isVip
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
const tPrice = (isVip.value? memberPrice:cur.salePrice) * cur.number
const memberPrice = cur.memberPrice ? cur.memberPrice : cur.salePrice
const tPrice = (isVip.value ? memberPrice : cur.salePrice) * cur.number
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) => {
@@ -541,18 +602,19 @@
// }, 0)
// return (goodsTotalPrice + ($seatFee.totalAmount || 0)).toFixed(2)
})
const youhui=computed(()=>{
if(user.value&&user.value.id&&user.value.isVip){
const goodsTotalPrice = goods.list.reduce((prve, cur) => {
const youhui = computed(() => {
let goodsTotalPrice=0
if (user.value && user.value.id && user.value.isVip) {
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 goodsTotalPrice - allPrice.value
} else {
return (discountSaleAmount.value)
}
return goodsTotalPrice
return (goodsTotalPrice+discountSaleAmount.value*1).toFixed(2)
})
function setGoodsItem(key, val) {
@@ -573,16 +635,16 @@
records,
seatFee
} = await Api.getCart(par)
let useType=''
let useType = ''
if (seatFee && seatFee.useType) {
useType=seatFee.useType
useType = seatFee.useType
$storageManage.useType(useType)
}else{
useType=records[0].info[0].useType
} else {
useType = records[0].info[0].useType
$storageManage.useType(useType)
}
console.log(useType);
eatTypes.active =useType == 'takeout' ? useType : useType.replace(
eatTypes.active = useType == 'takeout' ? useType : useType.replace(
/-after|-before/g, '');
goods.list = getNowCart(records)
if (seatFee && seatFee.totalNumber) {

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:'',