菜品不可销售状态修改

This commit is contained in:
GaoHao
2025-04-21 13:29:37 +08:00
parent acad1cd067
commit 27a8d6894e
13 changed files with 176 additions and 34 deletions

View File

@@ -32,15 +32,13 @@
<view class="u-flex" style="flex-shrink: 0;">
<view class="font-bold red u-m-r-32">{{formatPrice(item.lowPrice*item.number) }}</view>
<view class="u-flex" @tap="updateNumber(false,index,item)">
<image src="/pagesCreateOrder/static/images/icon-reduce-black.svg" class="icon" mode="">
</image>
<image src="/pagesCreateOrder/static/images/icon-reduce-black.svg" class="icon" mode="" />
</view>
<view class="u-m-l-30 u-m-r-30 color-333">
{{item.number.toFixed(2)}}
</view>
<view class="u-flex" @tap="updateNumber(true,index,item)">
<image src="/pagesCreateOrder/static/images/icon-add-black.svg" class="icon" mode="">
</image>
<view class="u-flex" @tap="updateNumber(true,index,item)" >
<image src="/pagesCreateOrder/static/images/icon-add-black.svg" class="icon " :class="{'grayscale': item.type == 'package'&&item.groupType == 1}" mode="" />
</view>
</view>
@@ -253,6 +251,9 @@
function updateNumber(isAdd, index, goods) {
const step = isAdd ? 1 : -1
const newval = goods.number + step
if(goods.type == 'package'&&goods.groupType == 1&&isAdd){
return
}
const par = {
num: newval,
index: index,
@@ -294,7 +295,9 @@
width: 40rpx;
height: 40rpx
}
.grayscale{
filter: opacity(60%)
}
.mask {
@include fixedAll;
background: rgba(51, 51, 51, 0.5);

View File

@@ -2,7 +2,7 @@
<view class="u-relative u-flex item">
<up-image :src="data.coverImg" mode="aspectFill" :width="img.width" :height="img.height"></up-image>
<view class="info u-flex u-row-between u-col-top u-flex-col">
<view class="info u-flex u-row-between u-col-top u-flex-col" >
<view >
<view >
<text class="up-line-1">{{data.name}}</text>
@@ -14,8 +14,7 @@
<view class="btnweigh">称重</view>
</template>
</view>
<view class="u-flex">
<template v-if="!isSellout">
<view class="u-flex" v-if="!isSellout">
<template v-if="data.type == 'sku'||data.groupType==1">
<button class="btn" hover-class="btn-hover-class" @tap="emitEvent('chooseGuige')">选规格</button>
</template>
@@ -35,27 +34,35 @@
</template>
</view>
</template>
</template>
<template v-else>
<view class=" u-m-t-16">
已售罄
</view>
</template>
</view>
<template v-if="isSellout">
<view class="isSellout" v-if="data.isSale == 0" >
<image class="isSellout_icon" src="/pagesCreateOrder/static/images/no-toDown.svg" mode=""></image>
</view>
<view class="isSellout" v-else-if="!isProductAvailable(data.days,data.startTime,data.endTime)" >
<image class="isSellout_icon" src="/pagesCreateOrder/static/images/no-saleTime.svg" mode=""></image>
</view>
<view class="isSellout" v-else-if="data.isSoldStock == 1" >
<image class="isSellout_icon" src="/pagesCreateOrder/static/images/no-sold.svg" mode=""></image>
</view>
<view class="isSellout" v-else-if="data.isStock == 1 && data.stockNumber <= 0" >
<image class="isSellout_icon" src="/pagesCreateOrder/static/images/no-stock.svg" mode=""></image>
</view>
</template>
</view>
</view>
</template>
<script setup>
import {
computed,
toRef,
toRefs,
watch
} from 'vue';
import { computed, toRef } from 'vue';
import util from '../util.js';
import dayjs from "dayjs";
import isBetween from "dayjs/plugin/isBetween.js";
dayjs.extend(isBetween)
const props = defineProps({
img: {
type: Object,
@@ -98,10 +105,42 @@
return false
}
return (
item.isPauseSale || (item.type !== "sku" && item.isStock == 1 && item.stockNumber <= 0)
(item.isStock == 1 && item.stockNumber <= 0) || item.isSoldStock == 1 || item.isSale == 0 || !isProductAvailable(item.days,item.startTime,item.endTime)
);
})
// 判断商品是否在可售时间内
function isProductAvailable(sellDaysStr, startTimeStr, endTimeStr) {
// 将后端返回的字符串转换为数组
const sellDays = sellDaysStr.split(',');
    const now = dayjs();
    const days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
const currentDay = days[now.day()];
    const currentTime = now.format('HH:mm:ss');
// console.log('当前日期:', currentDay);
// console.log('可售日期列表:', sellDays);
    // 检查当前周几是否在可售周几列表中
    if (!sellDays.includes(currentDay)) {
        // console.log('当前日期不在可售日期列表中');
        return false;
    }
    const startTime = dayjs(`${now.format('YYYY-MM-DD')} ${startTimeStr}`);
    let endTime = dayjs(`${now.format('YYYY-MM-DD')} ${endTimeStr}`);
// 处理跨天情况
    if (endTime.isBefore(startTime)) {
        endTime = endTime.add(1, 'day');
    }
// console.log('当前时间:', now.format('YYYY-MM-DD HH:mm:ss'));
    // console.log('开始时间:', startTime.format('YYYY-MM-DD HH:mm:ss'));
    // console.log('结束时间:', endTime.format('YYYY-MM-DD HH:mm:ss'));
    const isInRange = now.isBetween(startTime, endTime, null, '[)');
    // console.log('当前时间是否在可售时间范围内:', isInRange);
    return isInRange;
}
const emits = defineEmits(['add', 'reduce', 'chooseGuige','tapweigh'])
@@ -174,4 +213,20 @@
overflow: hidden;
}
}
.isSellout{
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
background-color: rgba(0, 0, 0, 0.6);
display: flex;
justify-content: center;
align-items: center;
.isSellout_icon{
height: 60%;
width: 60%;
}
}
</style>