cashier-ipad/pagesCreateOrder/index/components/weigh.vue

354 lines
8.1 KiB
Vue

<template>
<view class="">
<up-overlay :show="overlayshow" @click="overlayshow = false">
<view class="boxoverlay" v-if="form && form.goods">
<view class="rect" @tap.stop>
<view class="title">
<view> {{ form.goods.name }} </view>
<view class="" @click="overlayshow = false">
<up-icon name="close" color="#93969b" size="20"></up-icon>
</view>
</view>
<view class="inputtop">
<view class="dj">
<view class="text">单价</view>
<view class="jg"
>¥{{
is_time_discount ? returnLimitPrice() : form.goods.lowPrice
}}/{{ form.goods.unitName }}</view
>
</view>
<view class="inputdj">
<view>重量</view>
<view class="inputdjbox">
<view class="inputdisplay">{{ currentInput }}</view>
<text>{{ form.goods.unitName }}</text>
</view>
</view>
</view>
<view class="keyboard">
<button
v-for="(num, index) in numberButtons"
:key="index"
@click="handleClick(num)"
>
{{ num }}
</button>
<button @click="deleteLast">←</button>
</view>
<view class="classmoney">
{{ totalMoney }}
</view>
<view class="classconfirm" @click="clickconfirm"> 确认 </view>
</view>
</view>
</up-overlay>
</view>
</template>
<script setup>
import { onLoad, onShow } from "@dcloudio/uni-app";
import { BigNumber } from "bignumber.js";
import {
reactive,
computed,
ref,
watch,
defineExpose,
defineEmits,
inject,
} from "vue";
const yskUtils = inject("yskUtils");
const shopInfo = uni.getStorageSync("shopInfo");
const shopUserInfo = uni.getStorageSync("shopUserInfo");
const emit = defineEmits(["refresh"]);
const currentInput = ref("");
const numberButtons = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "."];
const handleClick = (value) => {
// 首位不能输入0
if (currentInput.value === "") {
if (value === "0") {
return;
}
}
if (value === "." && currentInput.value.indexOf(".") !== -1) {
return; // 如果已经存在小数点,不再添加
}
if (value === "." && currentInput.value === "") {
currentInput.value = "0.";
} else {
currentInput.value += value;
}
// 限制小数点后两位
const parts = currentInput.value.split(".");
if (parts.length > 1 && parts[1].length > 2) {
currentInput.value = currentInput.value.slice(0, -1);
}
};
const deleteLast = () => {
currentInput.value = currentInput.value.slice(0, -1);
};
const clickconfirm = () => {
// 首位不能输入0
if (currentInput.value === "") {
uni.showToast({
title: "请输入",
icon: "none",
});
return false;
}
console.log(currentInput.value, "称重数量");
emit(
"weighgoodsUpdate",
form.foodsindex,
form.index,
true,
undefined,
currentInput.value,
is_time_discount.value
);
overlayshow.value = false;
};
//显示
const overlayshow = ref(false);
const form = reactive({});
const open = (foodsindex, index, goods) => {
console.log(goods);
currentInput.value = "";
Object.assign(form, {
foodsindex,
index,
goods,
});
overlayshow.value = true;
};
const props = defineProps({
limitTimeDiscount: {
type: Object,
default: () => {},
},
});
const is_time_discount = computed(() => {
if (!props.limitTimeDiscount || !props.limitTimeDiscount.id) {
return false;
}
const isCanuse = yskUtils.limitUtils.canUseLimitTimeDiscount(
form.goods,
props.limitTimeDiscount,
shopInfo,
shopUserInfo,
"id"
);
console.log("isCanuse");
return isCanuse;
});
function returnLimitPrice() {
const price = yskUtils.limitUtils.returnPrice({
goods: form.goods,
shopInfo: shopInfo,
limitTimeDiscountRes: props.limitTimeDiscount,
shopUserInfo: shopUserInfo,
idKey: "id",
});
return price;
}
const totalMoney = computed(() => {
if(!currentInput.value) return 0
if (is_time_discount.value) {
return BigNumber(returnLimitPrice())
.times(currentInput.value)
.decimalPlaces(2, BigNumber.ROUND_UP)
.toNumber();
}
return BigNumber(form.goods.lowPrice)
.times(currentInput.value)
.decimalPlaces(2, BigNumber.ROUND_UP)
.toNumber();
});
defineExpose({
open,
});
</script>
<style lang="scss" scoped>
page {
background: #f9f9f9;
}
.boxoverlay {
width: 100%;
display: flex;
align-items: center;
justify-content: center;
height: 100%;
.rect {
padding: 32rpx 28rpx;
width: 30%;
background-color: #fff;
border-radius: 18rpx;
.title {
display: flex;
justify-content: space-between;
align-items: center;
padding-bottom: 20rpx;
font-size: 40rpx;
border-bottom: 1rpx solid #ccc;
}
.inputtop {
margin-top: 20rpx;
width: 100%;
display: flex;
justify-content: space-between;
align-items: center;
flex-wrap: wrap;
.dj {
width: 32%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: flex-start;
.text {
font-weight: 300;
font-size: 24rpx;
}
.jg {
margin-top: 16rpx;
background-color: #e8f4ff;
color: #1890ff;
height: 60rpx;
line-height: 60rpx;
padding: 0 20rpx;
font-size: 24rpx;
color: #1890ff;
border-radius: 10rpx;
}
}
.inputdj {
width: 66%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: flex-start;
font-weight: 300;
font-size: 24rpx;
.inputdjbox {
margin-top: 16rpx;
width: 100%;
display: flex;
justify-content: space-between;
align-items: center;
border: 1rpx solid #ccc;
border-radius: 10rpx;
padding-left: 20rpx;
height: 60rpx;
line-height: 60rpx;
background: #fff;
.inputdisplay {
width: auto;
}
text {
border: 1rpx solid #ccc;
border-radius: 10rpx;
border-radius: 10rpx;
padding: 0 20rpx;
background: #f5f7fa;
color: #a7aaaf;
}
}
}
}
.keyboard {
margin-top: 20rpx;
display: flex;
justify-content: space-between;
align-items: center;
flex-wrap: wrap;
button {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
width: 28%;
margin: 10rpx;
}
.keyboard-button {
width: 28%;
margin: 10rpx;
border: none;
border-radius: 5rpx;
box-shadow: 0 0 5rpx rgba(0, 0, 0, 0.3), 0 0 10rpx rgba(0, 0, 0, 0.2);
cursor: pointer;
transition: all 0.3s ease;
}
// .keyboard-button:hover {
// box-shadow: 0 0 10rpx rgba(255, 0, 0, 0.5), 0 0 20px rgba(255, 0, 0, 0.3);
// transform: translateY(-2rpx);
// }
.dot-button {
// background-color: #FFC107;
}
.clear-button {
// background-color: #FF5733;
}
.clear-button:hover {
box-shadow: 0 0 10px rgba(255, 87, 51, 0.5),
0 0 20px rgba(255, 87, 51, 0.3);
}
.delete-button {
// background-color: #33FF57;
}
.delete-button:hover {
// box-shadow: 0 0 10px rgba(51, 255, 87, 0.5), 0 0 20px rgba(51, 255, 87, 0.3);
}
}
.classmoney {
margin-top: 16rpx;
width: 100%;
font-size: 40rpx;
text-align: left;
color: #ff5152;
font-weight: 600;
}
.classconfirm {
width: 100%;
margin: 30rpx auto 0 auto;
border-radius: 16rpx;
text-align: center;
background: #1890ff;
color: #fff;
padding: 10rpx 0;
}
}
}
</style>