From 71b86f2bc57d003de0a87e4f985d527dc5dd2b5f Mon Sep 17 00:00:00 2001 From: KangKang0928 <443456429@qq.com> Date: Wed, 21 Aug 2024 16:05:34 +0800 Subject: [PATCH] add --- .../logistics-template/index.vue | 75 ++++-- .../logistics-template/popup/add-template.vue | 231 ++++++++++++++---- 2 files changed, 242 insertions(+), 64 deletions(-) diff --git a/src/views/modules/logistics-fare/logistics-template/index.vue b/src/views/modules/logistics-fare/logistics-template/index.vue index 4c5ee4e..bb40d54 100644 --- a/src/views/modules/logistics-fare/logistics-template/index.vue +++ b/src/views/modules/logistics-fare/logistics-template/index.vue @@ -16,14 +16,19 @@ v-model="searchForm.name" > - 搜索 + 搜索 添加运费模板 - + @@ -49,11 +54,14 @@ export default { }) .then((res) => { console.log(res); - this.$refs.oTable.complete(res.data.data.data,Number(res.data.data.total)); + this.$refs.oTable.complete( + res.data.data.data, + Number(res.data.data.total) + ); }) - .catch(err=>{ + .catch((err) => { this.$refs.oTable.complete(false); - }) + }); }, addFareTemplate() { this.$refs.addTemplate.toggle().add(); @@ -66,26 +74,59 @@ export default { type: "jsx", render: (row) => { console.log(row); - this.$api.mer_admin.getShippingTemplateInfo(row.id) + this.$api.mer_admin.getShippingTemplateInfo(row.id).then((res) => { + console.log(res); + // this.$set(row,tableData,); + }); + const appointMapper = { + 0: "(全国包邮)", + 1: "(部分包邮)", + 2: "(自定义运费)", + }; + + const edit = () => { + this.$api.mer_admin + .getShippingTemplateInfo(row.id) + .then((res) => { + console.log(res); + this.$refs.addTemplate.toggle().update(res.data.data); + }); + }; + const copy = () => { + this.$api.mer_admin + .getShippingTemplateInfo(row.id) + .then((res) => { + console.log(res); + this.$refs.addTemplate.toggle().copy(res.data.data); + }); + }; + const remove = () => { + this.$api.mer_admin.removeShippingTemplate(row.id) .then(res=>{ - console.log(res); - // this.$set(row,tableData,); + this.$refs.oTable.refresh(); }) - const appointMapper={ - 0:'(全国包邮)', - 1:'(部分包邮)', - 2:'(自定义运费)' - } + }; return (
-
{row.name}{appointMapper[row.appoint]}
+
+ {row.name} + {appointMapper[row.appoint]} +
最后编辑时间:{row.updateTime}
- 复制模板 - 修改 - 删除 + + 复制模板 + + + 修改 + + + + 删除 + +
diff --git a/src/views/modules/logistics-fare/logistics-template/popup/add-template.vue b/src/views/modules/logistics-fare/logistics-template/popup/add-template.vue index 7b5c80a..375ead1 100644 --- a/src/views/modules/logistics-fare/logistics-template/popup/add-template.vue +++ b/src/views/modules/logistics-fare/logistics-template/popup/add-template.vue @@ -65,7 +65,11 @@ export default { place: "", //场地 }; }, - mounted() {}, + mounted() { + window.onbeforeunload = function (e) { + return "还有未保存的数据,确定离开此页吗?"; + }; + }, methods: { computedCityOptions() { function filterTree(tree, filterArray) { @@ -110,25 +114,77 @@ export default { } else { this.modalConfig.show = false; } - if (e) { - console.log(e); - this.init(cloneDeep(e.row)); - } + //回显数据 + const refillData = (e) => { + let _data = cloneDeep(e); + console.log("_data", _data); + + //默认运费回显 + _data.shippingTemplatesRegionList = + [_data.shippingTemplatesRegionResultList?.[0]] || + BASE_DATA.shippingTemplatesRegionList; + //指定城市设置运费 + _data.shippingTemplatesRegionListAppend = + _data.shippingTemplatesRegionResultList + ?.slice(1, _data.shippingTemplatesRegionResultList.length) + ?.map((item) => { + item.cityCodes = item.cityCodes.split(","); + return item; + }) || BASE_DATA.shippingTemplatesRegionListAppend; + //指定包邮条件 + _data.shippingTemplatesConditionList = + _data.shippingTemplatesConditionResultList?.map((item) => { + item.cityCodes = item.cityCodes.split(","); + // item.conditionType= + if (item.price && item.number) { + item.conditionType = "件数+金额"; + } else if (item.price && !item.number) { + item.conditionType = "金额"; + } else if (!item.price && item.number) { + item.conditionType = "件数"; + } + return item; + }) || BASE_DATA.shippingTemplatesConditionList; + + //计价方式 + _data.calculateMethod = { + 1: "按件数", + 2: "按重量", + 3: "按体积", + }[_data.groups]; + + //运费配置 + _data.fareConfig = { + 0: "全国包邮", + 2: "自定义运费", + }[_data.appoint]; + + //模板名称 + _data.templateName = _data.name; + + this.modalData = _data; + }; return { - add: (item) => { - console.log(item); + add: () => { this.$nextTick(() => { this.modalData = JSON.parse(JSON.stringify(BASE_DATA)); }); this.isAdd = true; + this.modalConfig.title = "添加运费模板"; }, - update: (row) => { - this.modalData = row; + update: (e) => { this.isAdd = false; + refillData(e); + this.modalConfig.title = "编辑运费模板"; + }, + copy: (e) => { + this.isAdd = true; + refillData(e); + this.modalConfig.title = "添加运费模板"; + this.modalData.templateName += "(复制)"; }, }; }, - init(row) {}, }, computed: { modalCols() { @@ -310,7 +366,7 @@ export default {
{ console.log(this.modalData); if (this.isAdd) { - this.$api.mer_admin.addShippingTemplate({ - linkId: JSON.parse(sessionStorage.getItem("userInfo")).shopId, - defaults: 0,//默认值,待确认 - sort: 0,//默认值,待确认 - type:2,//默认值,待确认 - name: this.modalData.templateName, - groups: { - 按重量: 2, - 按件数: 1, - 按体积: 3, - }[this.modalData.calculateMethod], - appoint: { - 全国包邮: 0, - 自定义运费: 2, - }[this.modalData.fareConfig], - shippingTemplatesRegionList: - this.modalData.fareConfig == "全国包邮" - ? null - : [ - ...this.modalData.shippingTemplatesRegionList, - ...JSON.parse( + this.$api.mer_admin + .addShippingTemplate({ + linkId: JSON.parse(sessionStorage.getItem("userInfo")).shopId, + defaults: 0, //默认值,待确认 + sort: 0, //默认值,待确认 + type: 2, //默认值,待确认 + name: this.modalData.templateName, + groups: { + 按重量: 2, + 按件数: 1, + 按体积: 3, + }[this.modalData.calculateMethod], + appoint: { + 全国包邮: 0, + 自定义运费: 2, + }[this.modalData.fareConfig], + shippingTemplatesRegionList: + this.modalData.fareConfig == "全国包邮" + ? null + : [ + ...this.modalData.shippingTemplatesRegionList, + ...JSON.parse( + JSON.stringify( + this.modalData.shippingTemplatesRegionListAppend.map( + (item) => { + item.cityCodes = item.cityCodes.join(","); + return item; + } + ) + ) + ), + ], + shippingTemplatesConditionList: + this.modalData.fareConfig == "全国包邮" + ? null + : JSON.parse( JSON.stringify( - this.modalData.shippingTemplatesRegionListAppend.map( + this.modalData.shippingTemplatesConditionList.map( (item) => { item.cityCodes = item.cityCodes.join(","); + //过滤 + if (item.conditionType == "件数") { + item.price = null; + } else if (item.conditionType == "金额") { + item.number = null; + } return item; } ) ) ), - ], - shippingTemplatesConditionList: - this.modalData.fareConfig == "全国包邮" - ? null - : JSON.parse( - JSON.stringify( - this.modalData.shippingTemplatesConditionList.map( - (item) => { - item.cityCodes = item.cityCodes.join(","); - return item; - } + }) + .then((res) => { + this.toggle(); + this.$emit("refresh"); + }); + } else { + //编辑 + this.$api.mer_admin + .updateShippingTemplate({ + id: this.modalData.id, + linkId: JSON.parse(sessionStorage.getItem("userInfo")).shopId, + defaults: 0, //默认值,待确认 + sort: 0, //默认值,待确认 + type: 2, //默认值,待确认 + name: this.modalData.templateName, + groups: { + 按重量: 2, + 按件数: 1, + 按体积: 3, + }[this.modalData.calculateMethod], + appoint: { + 全国包邮: 0, + 自定义运费: 2, + }[this.modalData.fareConfig], + shippingTemplatesRegionList: + this.modalData.fareConfig == "全国包邮" + ? null + : [ + ...this.modalData.shippingTemplatesRegionList, + ...JSON.parse( + JSON.stringify( + this.modalData.shippingTemplatesRegionListAppend.map( + (item) => { + item.cityCodes = item.cityCodes.join(","); + return item; + } + ) + ) + ), + ], + shippingTemplatesConditionList: + this.modalData.fareConfig == "全国包邮" + ? null + : JSON.parse( + JSON.stringify( + this.modalData.shippingTemplatesConditionList.map( + (item) => { + item.cityCodes = item.cityCodes.join(","); + //过滤 + if (item.conditionType == "件数") { + item.price = null; + } else if (item.conditionType == "金额") { + item.number = null; + } + return item; + } + ) ) - ) - ), - }); + ), + }) + .then((res) => { + this.toggle(); + this.$emit("refresh"); + }); } }, 300), },