修改商品增加编辑售价时不自动填充会员价

This commit is contained in:
2025-11-14 10:05:43 +08:00
parent 17e63a2400
commit a3cbe7576e

View File

@@ -2,71 +2,133 @@
<el-form ref="ruleFormRef" label-width="150px" class="demo-ruleForm" status-icon> <el-form ref="ruleFormRef" label-width="150px" class="demo-ruleForm" status-icon>
<el-form-item label="规格属性"> <el-form-item label="规格属性">
<el-table :data="skuList" border> <el-table :data="skuList" border>
<el-table-column :label="item.label" :prop="item.value" v-for="(item, index) in props.specTableHeaders" <el-table-column
:key="index"> :label="item.label"
</el-table-column> :prop="item.value"
v-for="(item, index) in props.specTableHeaders"
:key="index"
></el-table-column>
<el-table-column prop="salePrice"> <el-table-column prop="salePrice">
<template #header> <template #header>
<span>售价</span> <span>售价</span>
<el-icon style="margin-left: 10px;" color="#409EFC" class="no-inherit" @click="batchNumber('salePrice')"> <el-icon
style="margin-left: 10px"
color="#409EFC"
class="no-inherit"
@click="batchNumber('salePrice')"
>
<EditPen /> <EditPen />
</el-icon> </el-icon>
</template> </template>
<template v-slot="scope"> <template v-slot="scope">
<el-input-number size="default" v-model="scope.row.salePrice" @change="priceFormat(scope.row, 'salePrice')" <el-input-number
@blur="priceFormat(scope.row, 'salePrice')" controls-position="right" :disabled="isSyncStatus()"></el-input-number> size="default"
v-model="scope.row.salePrice"
@change="priceFormat(scope.row, 'salePrice')"
@blur="priceFormat(scope.row, 'salePrice')"
controls-position="right"
:disabled="isSyncStatus()"
></el-input-number>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column prop="originPrice"> <el-table-column prop="originPrice">
<template #header> <template #header>
<span>原价</span> <span>原价</span>
<el-icon style="margin-left: 10px;" color="#409EFC" class="no-inherit" @click="batchNumber('originPrice')"> <el-icon
style="margin-left: 10px"
color="#409EFC"
class="no-inherit"
@click="batchNumber('originPrice')"
>
<EditPen /> <EditPen />
</el-icon> </el-icon>
</template> </template>
<template v-slot="scope"> <template v-slot="scope">
<el-input-number @change="priceFormat(scope.row, 'originPrice')" v-model="scope.row.originPrice" <el-input-number
@blur="priceFormat(scope.row, 'originPrice')" controls-position="right" :disabled="isSyncStatus()"></el-input-number> @change="priceFormat(scope.row, 'originPrice')"
v-model="scope.row.originPrice"
@blur="priceFormat(scope.row, 'originPrice')"
controls-position="right"
:disabled="isSyncStatus()"
></el-input-number>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column prop="costPrice"> <el-table-column prop="costPrice">
<template #header> <template #header>
<span>成本价</span> <span>成本价</span>
<el-icon style="margin-left: 10px;" color="#409EFC" class="no-inherit" @click="batchNumber('costPrice')"> <el-icon
style="margin-left: 10px"
color="#409EFC"
class="no-inherit"
@click="batchNumber('costPrice')"
>
<EditPen /> <EditPen />
</el-icon> </el-icon>
</template> </template>
<template v-slot="scope"> <template v-slot="scope">
<el-input-number @change="priceFormat(scope.row, 'costPrice')" v-model="scope.row.costPrice" <el-input-number
@blur="priceFormat(scope.row, 'costPrice')" controls-position="right" :disabled="isSyncStatus()"></el-input-number> @change="priceFormat(scope.row, 'costPrice')"
v-model="scope.row.costPrice"
@blur="priceFormat(scope.row, 'costPrice')"
controls-position="right"
:disabled="isSyncStatus()"
></el-input-number>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column prop="memberPrice"> <el-table-column prop="memberPrice">
<template #header> <template #header>
<span>会员价</span> <span>会员价</span>
<el-icon style="margin-left: 10px;" color="#409EFC" class="no-inherit" @click="batchNumber('memberPrice')"> <el-icon
style="margin-left: 10px"
color="#409EFC"
class="no-inherit"
@click="batchNumber('memberPrice')"
>
<EditPen /> <EditPen />
</el-icon> </el-icon>
</template> </template>
<template v-slot="scope"> <template v-slot="scope">
<el-input-number @change="priceFormat(scope.row, 'memberPrice')" v-model="scope.row.memberPrice" <el-input-number
@blur="priceFormat(scope.row, 'memberPrice')" controls-position="right" :disabled="isSyncStatus()"></el-input-number> @change="priceFormat(scope.row, 'memberPrice')"
v-model="scope.row.memberPrice"
@blur="priceFormat(scope.row, 'memberPrice')"
controls-position="right"
:disabled="isSyncStatus()"
></el-input-number>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="起售数量" prop="suitNum"> <el-table-column label="起售数量" prop="suitNum">
<template #header> <template #header>
<span>起售数量</span> <span>起售数量</span>
<el-icon style="margin-left: 10px;" color="#409EFC" class="no-inherit" @click="batchNumber('suitNum')"> <el-icon
style="margin-left: 10px"
color="#409EFC"
class="no-inherit"
@click="batchNumber('suitNum')"
>
<EditPen /> <EditPen />
</el-icon> </el-icon>
</template> </template>
<template v-slot="scope"> <template v-slot="scope">
<el-input-number @change="priceFormat(scope.row, 'suitNum')" v-model="scope.row.suitNum" <el-input-number
@blur="priceFormat(scope.row, 'suitNum')" :min="0" controls-position="right" @change="priceFormat(scope.row, 'suitNum')"
v-if="props.info.type == 'weigh'" :disabled="isSyncStatus()"></el-input-number> v-model="scope.row.suitNum"
<el-input-number @change="priceFormat(scope.row, 'suitNum')" v-model="scope.row.suitNum" @blur="priceFormat(scope.row, 'suitNum')"
@blur="priceFormat(scope.row, 'suitNum')" :min="1" controls-position="right" :disabled="isSyncStatus()" v-else></el-input-number> :min="0"
controls-position="right"
v-if="props.info.type == 'weigh'"
:disabled="isSyncStatus()"
></el-input-number>
<el-input-number
@change="priceFormat(scope.row, 'suitNum')"
v-model="scope.row.suitNum"
@blur="priceFormat(scope.row, 'suitNum')"
:min="1"
controls-position="right"
:disabled="isSyncStatus()"
v-else
></el-input-number>
</template> </template>
</el-table-column> </el-table-column>
</el-table> </el-table>
@@ -75,60 +137,66 @@
<el-dialog title="批量修改" width="400px" v-model="showBatchModal"> <el-dialog title="批量修改" width="400px" v-model="showBatchModal">
<el-form :model="batchNumberForm"> <el-form :model="batchNumberForm">
<el-form-item> <el-form-item>
<el-input-number @change="priceFormat(batchNumberForm, 'batchNumber')" <el-input-number
@blur="priceFormat(batchNumberForm, 'batchNumber')" v-model="batchNumberForm.batchNumber" @change="priceFormat(batchNumberForm, 'batchNumber')"
controls-position="right" style="width: 100%" :disabled="isSyncStatus()"></el-input-number> @blur="priceFormat(batchNumberForm, 'batchNumber')"
v-model="batchNumberForm.batchNumber"
controls-position="right"
style="width: 100%"
:disabled="isSyncStatus()"
></el-input-number>
</el-form-item> </el-form-item>
</el-form> </el-form>
<template #footer> <template #footer>
<span class="dialog-footer"> <span class="dialog-footer">
<el-button @click="showBatchModal = false"> </el-button> <el-button @click="showBatchModal = false"> </el-button>
<el-button type="primary" @click="batchNumberFormConfirm"> <el-button type="primary" @click="batchNumberFormConfirm"> </el-button>
</el-button>
</span> </span>
</template> </template>
</el-dialog> </el-dialog>
</template> </template>
<script setup> <script setup>
import { ref } from 'vue' import { ref } from "vue";
import { isSyncStatus } from "@/utils/index"; import { isSyncStatus } from "@/utils/index";
const ruleFormRef = ref(null) const ruleFormRef = ref(null);
let batchNumberKey = ref(null) let batchNumberKey = ref(null);
let batchNumberForm = reactive({ let batchNumberForm = reactive({
batchNumber: 0, batchNumber: 0,
}) });
let skuList = ref([]) let skuList = ref([]);
let showBatchModal = ref(false) let showBatchModal = ref(false);
const props = defineProps({ const props = defineProps({
info: { info: {
type: Object, type: Object,
default: () => { default: () => {
return {} return {};
} },
}, },
list: { list: {
type: Array, type: Array,
default: () => { default: () => {
return [] return [];
} },
}, },
specTableHeaders: { specTableHeaders: {
type: Array, type: Array,
default: () => { default: () => {
return [] return [];
} },
} },
}) });
onMounted(() => { onMounted(() => {
skuList.value = props.list skuList.value = props.list;
}) });
watch(() => props.list, (newval) => { watch(
skuList.value = newval () => props.list,
}, { deep: true }) (newval) => {
skuList.value = newval;
},
{ deep: true }
);
// 批量修改规格 // 批量修改规格
function batchNumber(key) { function batchNumber(key) {
batchNumberKey.value = key; batchNumberKey.value = key;
@@ -139,26 +207,28 @@ function batchNumberFormConfirm() {
skuList.value.map((item, index) => { skuList.value.map((item, index) => {
let newitem = { ...item }; let newitem = { ...item };
newitem[batchNumberKey.value] = batchNumberForm.batchNumber; newitem[batchNumberKey.value] = batchNumberForm.batchNumber;
skuList.value[index] = { ...newitem } skuList.value[index] = { ...newitem };
}); });
showBatchModal.value = false; showBatchModal.value = false;
batchNumberForm.batchNumber = 0; batchNumberForm.batchNumber = 0;
} }
function getdata() { function getdata() {
return skuList.value return skuList.value;
} }
function priceFormat(item, key) { function priceFormat(item, key) {
// 输入售价其他行为0值时候同样回填售价值 // 输入售价其他行为0值时候同样回填售价值
// 原价 originPrice // 原价 originPrice
if (key == 'salePrice' && item.originPrice == 0) { if (key == "salePrice" && item.originPrice == 0) {
item.originPrice = item.salePrice; item.originPrice = item.salePrice;
} }
// 会员价 memberPrice // 会员价 memberPrice
if (key == 'salePrice' && item.memberPrice == 0) { /*
if (key == "salePrice" && item.memberPrice == 0) {
item.memberPrice = item.costPrice; item.memberPrice = item.costPrice;
} }
*/
// 成本价 costPrice // 成本价 costPrice
if (key == 'salePrice' && item.costPrice == 0) { if (key == "salePrice" && item.costPrice == 0) {
item.costPrice = item.originPrice; item.costPrice = item.originPrice;
} }
nextTick(() => { nextTick(() => {
@@ -167,32 +237,31 @@ function priceFormat(item, key) {
const newval = formatPrice(item[key], min, max, true); const newval = formatPrice(item[key], min, max, true);
if (typeof newval !== "number") { if (typeof newval !== "number") {
item[key] = newval.value; item[key] = newval.value;
ElMessage.warning(`请输入${min}${max}范围内的数字`) ElMessage.warning(`请输入${min}${max}范围内的数字`);
} }
}) });
} }
// 格式化价格函数,将价格限定在指定的最小值和最大值范围内,并保留两位小数。 // 格式化价格函数,将价格限定在指定的最小值和最大值范围内,并保留两位小数。
const formatPrice = (price, min = -Infinity, max = 100000000, returnIsArea = false) => { const formatPrice = (price, min = -Infinity, max = 100000000, returnIsArea = false) => {
if (price === undefined || price === null || price === '') { if (price === undefined || price === null || price === "") {
return 0 return 0;
} }
// 将价格转换为浮点数并保留两位小数 // 将价格转换为浮点数并保留两位小数
const newval = parseFloat((Math.floor(price * 100) / 100).toFixed(2)) const newval = parseFloat((Math.floor(price * 100) / 100).toFixed(2));
// 如果价格大于最大值,返回最大值 // 如果价格大于最大值,返回最大值
if (newval > max) { if (newval > max) {
return returnIsArea ? { value: max, error: true } : max return returnIsArea ? { value: max, error: true } : max;
} }
// 如果价格小于最小值,返回最小值 // 如果价格小于最小值,返回最小值
if (newval < min) { if (newval < min) {
return returnIsArea ? { value: min, error: true } : min return returnIsArea ? { value: min, error: true } : min;
} }
// 如果价格小于最小值,返回最小值 // 如果价格小于最小值,返回最小值
if (newval < min) { if (newval < min) {
return min return min;
} }
// 返回格式化后的价格 // 返回格式化后的价格
return newval return newval;
} };
defineExpose({ getdata }) defineExpose({ getdata });
</script> </script>