feat: 代客下单更新,修复店铺列表编辑展示问题
This commit is contained in:
@@ -7,33 +7,42 @@
|
||||
<div class="color-red u-font-18 font-600">¥{{ form.money }}</div>
|
||||
<!-- <el-input :value="form.money" disabled> </el-input> -->
|
||||
</el-form-item>
|
||||
<el-form-item label="减免金额">
|
||||
<el-input
|
||||
<el-form-item label="优惠类型" v-if="shopUser.isShopAdmin">
|
||||
<el-radio-group v-model="discountType">
|
||||
<el-radio-button label="金额" :value="0"></el-radio-button>
|
||||
<el-radio-button label="折扣" :value="1"></el-radio-button>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
<el-form-item label="减免金额" v-if="discountType == 0">
|
||||
<el-input-number
|
||||
v-model="form.reduceMoney"
|
||||
clearable
|
||||
autofocus
|
||||
type="number"
|
||||
@keyup.enter="init('reduceMoney')"
|
||||
@blur="init('reduceMoney')"
|
||||
@change="init('reduceMoney')"
|
||||
>
|
||||
<template #append>元</template>
|
||||
</el-input>
|
||||
</el-input-number>
|
||||
</el-form-item>
|
||||
<el-form-item label="优惠折扣">
|
||||
<el-input
|
||||
|
||||
<el-form-item label="优惠折扣" v-if="discountType == 1">
|
||||
<el-input-number
|
||||
v-model="form.discount"
|
||||
:step="1"
|
||||
step-strictly
|
||||
type="number"
|
||||
@keyup.enter="init('discount')"
|
||||
@blur="init('discount')"
|
||||
@change="init('discount')"
|
||||
>
|
||||
<template #append>%</template>
|
||||
</el-input>
|
||||
</el-input-number>
|
||||
<span>%</span>
|
||||
</el-form-item>
|
||||
<el-form-item label="实收金额">
|
||||
<el-input
|
||||
v-model="form.curretnMoney"
|
||||
type="number"
|
||||
clearable
|
||||
disabled
|
||||
@keyup.enter="init('curretnMoney')"
|
||||
@blur="init('curretnMoney')"
|
||||
>
|
||||
@@ -49,7 +58,11 @@
|
||||
</div>
|
||||
</el-dialog>
|
||||
</template>
|
||||
<script>
|
||||
<script setup>
|
||||
import { useUserStore } from "@/store/modules/user";
|
||||
import { ElMessage } from "element-plus";
|
||||
const shopUser = useUserStore();
|
||||
|
||||
function toFixedNoRounding(num) {
|
||||
// 转换为字符串
|
||||
var numStr = num.toString();
|
||||
@@ -62,99 +75,103 @@ function toFixedNoRounding(num) {
|
||||
// 拼接回数字字符串并返回
|
||||
return parts.join(".");
|
||||
}
|
||||
//折扣类型
|
||||
const discountType = ref(1);
|
||||
|
||||
export default {
|
||||
props: {
|
||||
title: {
|
||||
type: String,
|
||||
default: "优惠金额",
|
||||
},
|
||||
value: {
|
||||
type: [String, Number],
|
||||
default: 0,
|
||||
},
|
||||
const props = defineProps({
|
||||
title: {
|
||||
type: String,
|
||||
default: "优惠金额",
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
form: {
|
||||
money: 0,
|
||||
discount: 100,
|
||||
reduceMoney: 0,
|
||||
curretnMoney: 0,
|
||||
},
|
||||
number: "0",
|
||||
show: false,
|
||||
};
|
||||
value: {
|
||||
type: [String, Number],
|
||||
default: 0,
|
||||
},
|
||||
methods: {
|
||||
init(key) {
|
||||
const { money, reduceMoney, discount, curretnMoney } = this.form;
|
||||
if (key == "reduceMoney") {
|
||||
if (reduceMoney < 0) {
|
||||
this.$message.error("减免金额不能小于0");
|
||||
this.form.reduceMoney = 0;
|
||||
}
|
||||
if (reduceMoney > money) {
|
||||
this.$message.error("减免金额不能大于总金额");
|
||||
this.form.reduceMoney = money;
|
||||
}
|
||||
this.form.curretnMoney = (money - this.form.reduceMoney).toFixed(2);
|
||||
this.form.discount = toFixedNoRounding(((this.form.curretnMoney / money) * 100).toFixed(3));
|
||||
return;
|
||||
}
|
||||
if (key == "discount") {
|
||||
if (discount < 0) {
|
||||
this.$message.error("折扣不能小于0");
|
||||
this.form.discount = 0;
|
||||
}
|
||||
if (discount > 100) {
|
||||
this.$message.error("折扣不能大于100");
|
||||
this.form.discount = 100;
|
||||
}
|
||||
this.form.curretnMoney = ((money * this.form.discount) / 100).toFixed(2);
|
||||
this.form.reduceMoney = ((money * (100 - this.form.discount)) / 100).toFixed(2);
|
||||
return;
|
||||
}
|
||||
if (key == "curretnMoney") {
|
||||
if (curretnMoney < 0) {
|
||||
this.$message.error("实收金额不能小于0");
|
||||
this.form.curretnMoney = 0;
|
||||
}
|
||||
if (curretnMoney > money) {
|
||||
this.$message.error("实收金额不能大于总金额");
|
||||
this.form.curretnMoney = this.form.money;
|
||||
}
|
||||
this.form.reduceMoney = (money - this.form.curretnMoney).toFixed(2);
|
||||
this.form.discount = toFixedNoRounding(((this.form.curretnMoney / money) * 100).toFixed(3));
|
||||
return;
|
||||
}
|
||||
this.form.curretnMoney = ((money * discount) / 100).toFixed(2);
|
||||
this.form.reduceMoney = (money - this.form.curretnMoney).toFixed(2);
|
||||
},
|
||||
changeKey(key, val) {
|
||||
this[key] = val;
|
||||
},
|
||||
});
|
||||
|
||||
confirm() {
|
||||
console.log(this.form.discount / 100);
|
||||
this.$emit("confirm", this.form);
|
||||
this.close();
|
||||
},
|
||||
open(data) {
|
||||
console.log(data);
|
||||
this.form.money = data.amount * 1;
|
||||
this.form.discount = data.discount ? toFixedNoRounding(data.discount.toFixed(3)) : 100;
|
||||
this.show = true;
|
||||
this.init();
|
||||
},
|
||||
close() {
|
||||
this.show = false;
|
||||
},
|
||||
const state = reactive({
|
||||
form: {
|
||||
money: 0,
|
||||
discount: 100,
|
||||
reduceMoney: 0,
|
||||
curretnMoney: 0,
|
||||
},
|
||||
mounted() {
|
||||
this.number = `${this.value}`;
|
||||
},
|
||||
};
|
||||
number: "0",
|
||||
show: false,
|
||||
});
|
||||
const { form, number, show } = toRefs(state);
|
||||
function init(key) {
|
||||
const { money, reduceMoney, discount, curretnMoney } = form.value;
|
||||
if (key == "reduceMoney") {
|
||||
if (reduceMoney < 0) {
|
||||
ElMessage.error("减免金额不能小于0");
|
||||
form.value.reduceMoney = 0;
|
||||
}
|
||||
if (reduceMoney > money) {
|
||||
ElMessage.error("减免金额不能大于总金额");
|
||||
form.value.reduceMoney = money;
|
||||
}
|
||||
form.value.curretnMoney = (money - form.value.reduceMoney).toFixed(2);
|
||||
form.value.discount = toFixedNoRounding(((form.value.curretnMoney / money) * 100).toFixed(3));
|
||||
return;
|
||||
}
|
||||
if (key == "discount") {
|
||||
if (discount < 0) {
|
||||
ElMessage.error("折扣不能小于0");
|
||||
form.value.discount = 0;
|
||||
}
|
||||
if (discount > 100) {
|
||||
ElMessage.error("折扣不能大于100");
|
||||
form.value.discount = 100;
|
||||
}
|
||||
form.value.curretnMoney = (money * (form.value.discount / 100)).toFixed(2);
|
||||
form.value.reduceMoney = ((money * (100 - form.value.discount)) / 100).toFixed(2);
|
||||
return;
|
||||
}
|
||||
if (key == "curretnMoney") {
|
||||
if (curretnMoney < 0) {
|
||||
ElMessage.error("实收金额不能小于0");
|
||||
form.value.curretnMoney = 0;
|
||||
}
|
||||
if (curretnMoney > money) {
|
||||
ElMessage.error("实收金额不能大于总金额");
|
||||
form.value.curretnMoney = form.value.money;
|
||||
}
|
||||
form.value.reduceMoney = (money - form.value.curretnMoney).toFixed(2);
|
||||
form.value.discount = toFixedNoRounding(((form.value.curretnMoney / money) * 100).toFixed(3));
|
||||
return;
|
||||
}
|
||||
form.value.curretnMoney = ((money * discount) / 100).toFixed(2);
|
||||
form.value.reduceMoney = (money - form.value.curretnMoney).toFixed(2);
|
||||
}
|
||||
|
||||
const emits = defineEmits(["confirm"]);
|
||||
function confirm() {
|
||||
console.log(form.value);
|
||||
if (discountType.value == 1) {
|
||||
emits("confirm", { discount: form.value.discount });
|
||||
} else {
|
||||
emits("confirm", { discountAmount: form.value.reduceMoney });
|
||||
}
|
||||
close();
|
||||
}
|
||||
function open(data) {
|
||||
console.log(data);
|
||||
form.value.money = data.amount * 1;
|
||||
form.value.discount = data.discount ? toFixedNoRounding(data.discount.toFixed(3)) : 100;
|
||||
show.value = true;
|
||||
init();
|
||||
}
|
||||
function close() {
|
||||
show.value = false;
|
||||
}
|
||||
onMounted(() => {
|
||||
number.value = `${props.value}`;
|
||||
});
|
||||
defineExpose({
|
||||
close,
|
||||
open,
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
|
||||
Reference in New Issue
Block a user