Commit 1ffa267a by zhangxw

客户编辑bug修复

1 parent cbf49596
<template> <template>
<div class="map-box" :style="{ height: `${mapHeight}px` }"> <div class="map-box" :style="{ height: `${mapHeight}px` }">
<div id="mapContainer" style="width: 100%; height: 100%;z-index: 999999"></div> <div :id="mapContainerId" style="width: 100%; height: 100%;z-index: 999999"></div>
<el-input v-model="address" <!-- 使用原生 input 替代 el-input,避免触发 Element UI 的表单校验 -->
class="map-address-input" <div class="map-address-input-wrapper">
placeholder="请选择或输入地址" <input v-model="address"
size="small" class="map-address-native-input"
clearable /> placeholder="请选择或输入地址"
@blur.stop
@click.stop
@focus.stop />
</div>
<div id="myPageTop" style="position: absolute; top: 10px; width: 50%; left: 25%"> <div id="myPageTop" style="position: absolute; top: 10px; width: 50%; left: 25%">
<el-input id="input" <el-input id="input"
v-model="input" v-model="input"
...@@ -39,6 +43,8 @@ export default { ...@@ -39,6 +43,8 @@ export default {
lnglat: [], lnglat: [],
geocoderAddress: {}, geocoderAddress: {},
mapapi: null, mapapi: null,
// 动态容器 ID(避免多个弹窗容器 ID 冲突)
mapContainerId: `mapContainer_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`,
}; };
}, },
...@@ -94,7 +100,7 @@ export default { ...@@ -94,7 +100,7 @@ export default {
// 多次尝试获取地图容器(最多等待2秒) // 多次尝试获取地图容器(最多等待2秒)
let mapContainer = null; let mapContainer = null;
for (let i = 0; i < 20; i++) { for (let i = 0; i < 20; i++) {
mapContainer = document.getElementById("mapContainer"); mapContainer = document.getElementById(this.mapContainerId);
if (mapContainer) { if (mapContainer) {
break; break;
} }
...@@ -110,7 +116,7 @@ export default { ...@@ -110,7 +116,7 @@ export default {
let mapInstance = null; let mapInstance = null;
for (let i = 0; i < 3; i++) { for (let i = 0; i < 3; i++) {
try { try {
mapInstance = await mapapi.invoke("Map", "mapContainer"); mapInstance = await mapapi.invoke("Map", this.mapContainerId);
if (mapInstance) { if (mapInstance) {
map = mapInstance; map = mapInstance;
break; break;
...@@ -251,11 +257,31 @@ export default { ...@@ -251,11 +257,31 @@ export default {
right: 10px; right: 10px;
width: 280px; width: 280px;
} }
.map-address-input { .map-address-native-input {
position: absolute;
bottom: -40px;
left: 0;
right: 0;
width: 100%; width: 100%;
height: 32px;
padding: 0 15px;
font-size: 14px;
line-height: 32px;
color: #606266;
background-color: #fff;
background-image: none;
border: 1px solid #dcdfe6;
border-radius: 4px;
box-sizing: border-box;
outline: none;
transition: border-color 0.2s cubic-bezier(0.645, 0.045, 0.355, 1);
margin-top: 10px;
&::placeholder {
color: #c0c4cc;
}
&:hover {
border-color: #c0c4cc;
}
&:focus {
border-color: #409eff;
}
} }
</style> </style>
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
<el-input v-model.trim="searchForm.matchPackageCode" <el-input v-model.trim="searchForm.matchPackageCode"
placeholder="请输入套餐ID" placeholder="请输入套餐ID"
:clearable="true" :clearable="true"
:maxlength="20" :maxlength="30"
:style="{ width: '100%' }" :style="{ width: '100%' }"
@input="matchPackageCodeInput" /> @input="matchPackageCodeInput" />
</template> </template>
...@@ -174,7 +174,7 @@ import { getSearchFormSchema, getTableColumnsSchema } from "./index.data.js"; ...@@ -174,7 +174,7 @@ import { getSearchFormSchema, getTableColumnsSchema } from "./index.data.js";
export default { export default {
// 需与路由 name 一致,d2admin keep-alive include 按路由名匹配 // 需与路由 name 一致,d2admin keep-alive include 按路由名匹配
name: "packageManage", name: "PackageManage",
components: { components: {
// ApplicableAreaSelect, // ApplicableAreaSelect,
BatchModifyPackageInventoryDialog, BatchModifyPackageInventoryDialog,
......
...@@ -158,29 +158,14 @@ function mapMerchantDetailToEditData(detail) { ...@@ -158,29 +158,14 @@ function mapMerchantDetailToEditData(detail) {
}; };
} }
/** 从商户详情映射品牌树勾选数据(处理 merchantBrandMain 字符串以逗号分隔的情况) */ /** 从商户详情映射品牌树勾选数据 */
function mapMerchantBrandListFromDetail(detail) { function mapMerchantBrandListFromDetail(detail) {
if (!detail || !detail?.merchantBrandMain) { if (!detail?.brandTreeList) {
return []; return [];
} }
return detail.brandTreeList.flatMap((val) => {
const brandMainStr = detail.merchantBrandMain; return val.subList?.map(v => v.id) ?? [];
});
// 去除末尾分号,split成数组,转换为数字
const brandIds = brandMainStr
.replace(/[;;]\s*$/, "") // 去除末尾的分号或中文分号
.split(/[,,]/) // 支持英文逗号和中文逗号
.map((id) => {
const trimmed = id.trim();
if (!trimmed) {
return null;
} // 过滤空字符串
const num = Number.parseInt(trimmed, 10);
return Number.isNaN(num) ? null : num; // 转换为数字,过滤无效值
})
.filter(id => id !== null); // 过滤空值和无效值
return brandIds;
} }
export default { export default {
...@@ -260,6 +245,10 @@ export default { ...@@ -260,6 +245,10 @@ export default {
// loading 已在 watch/mounted 中设置,此处无需重复设置 // loading 已在 watch/mounted 中设置,此处无需重复设置
try { try {
this.resetMerchantVerifyForm(); this.resetMerchantVerifyForm();
// 编辑场景:设置当前编辑商户的 merchantNo(用于排除上级商户列表)
if (this.customerRow && this.customerRow.merchantId) {
this.setCurrentEditMerchantNo(this.customerRow.merchantId);
}
// 编辑场景:立即设置字段为只读文本显示(避免loading期间显示输入框) // 编辑场景:立即设置字段为只读文本显示(避免loading期间显示输入框)
this.initEditFieldDisplayTypes(); this.initEditFieldDisplayTypes();
// 编辑场景:修改上级商户字段使用 merchantNo 作为 optionId // 编辑场景:修改上级商户字段使用 merchantNo 作为 optionId
...@@ -546,18 +535,17 @@ export default { ...@@ -546,18 +535,17 @@ export default {
} }
this.syncEditDataRegionFromProvinceCityRef(); this.syncEditDataRegionFromProvinceCityRef();
const params = this.buildSubmitPayload(merchantBrandList); const params = this.buildSubmitPayload(merchantBrandList);
console.log(params); this.loading = true;
// this.loading = true; try {
// try { await Promise.resolve(this.submitApi(params));
// await Promise.resolve(this.submitApi(params)); await showMerchantCreateSuccess(this);
// await showMerchantCreateSuccess(this); this.$emit("success");
// this.$emit("success"); this.closeDialog();
// this.closeDialog(); } catch (e) {
// } catch (e) { /* 接口失败由全局封装提示 */
// /* 接口失败由全局封装提示 */ } finally {
// } finally { this.loading = false;
// this.loading = false; }
// }
}); });
}, },
}, },
......
...@@ -20,6 +20,7 @@ import merchantVerifyFormMixin, { ...@@ -20,6 +20,7 @@ import merchantVerifyFormMixin, {
export default { export default {
mixins: [merchantVerifyFormMixin], mixins: [merchantVerifyFormMixin],
data() { data() {
const vm = this;
return { return {
// 标记是否正在加载编辑数据(初始化阶段) // 标记是否正在加载编辑数据(初始化阶段)
isLoadingEditDetail: false, isLoadingEditDetail: false,
...@@ -27,6 +28,62 @@ export default { ...@@ -27,6 +28,62 @@ export default {
_READONLY_PLACEHOLDER_: "__readonly_placeholder__", _READONLY_PLACEHOLDER_: "__readonly_placeholder__",
// 编辑场景:初始商户名称(用于排除重复校验) // 编辑场景:初始商户名称(用于排除重复校验)
initialMerchantName: "", initialMerchantName: "",
// 编辑场景:当前编辑商户的 merchantNo(用于排除上级商户列表中的当前商户)
currentEditMerchantNo: "",
// 编辑场景:地址选择只显示省市两级,不显示区县
subdistrict: 2,
// 编辑场景:重写地址校验规则(只校验省市,不校验区县)
formRules: {
...merchantVerifyFormMixin.data().formRules,
detailAddress: [
{
validator(rule, value, callback) {
const d = vm.editData;
const hasText = !!(
d.detailAddress
&& String(d.detailAddress).trim()
);
const hasProvince = !!(
d.provinceName && String(d.provinceName).trim()
);
const hasCity = !!(
d.cityName && String(d.cityName).trim()
);
const coordOk = x =>
x !== ""
&& x != null
&& String(x).trim() !== ""
&& !Number.isNaN(Number(x));
const latOk = coordOk(d.lat) || coordOk(d.latitude);
const lngOk
= coordOk(d.lng) || coordOk(d.longitude);
// 已通过地图选址(有详细文案与经纬度)时,不要求与省市下拉逐项一致
if (latOk && lngOk && hasText) {
callback();
return;
}
// 编辑场景:只校验省市和详细地址(不校验区县)
if (!hasProvince || !hasCity || !hasText) {
callback(
new Error("请选择省、市并填写详细地址"),
);
return;
}
if (!latOk || !lngOk) {
callback(
new Error("请通过地图选择地址以获取经纬度"),
);
return;
}
callback();
},
trigger: "blur",
},
],
},
}; };
}, },
methods: { methods: {
...@@ -179,7 +236,6 @@ export default { ...@@ -179,7 +236,6 @@ export default {
this.baseData.parentMerchantList = []; this.baseData.parentMerchantList = [];
this.merchantNameKeyword = ""; this.merchantNameKeyword = "";
this.getOptionsList("editFormData", false, "parentId"); this.getOptionsList("editFormData", false, "parentId");
// 自动请求上级商户列表(非工厂级时) // 自动请求上级商户列表(非工厂级时)
if (v != "1") { if (v != "1") {
this.get4sAndServiceMerchantList("store"); this.get4sAndServiceMerchantList("store");
...@@ -228,6 +284,44 @@ export default { ...@@ -228,6 +284,44 @@ export default {
}, },
/** /**
* 编辑场景:设置当前编辑商户的 merchantNo
* @param {string|number} merchantNo - 商户号
*/
setCurrentEditMerchantNo(merchantNo) {
this.currentEditMerchantNo = String(merchantNo || "");
},
/**
* 编辑场景:从上级商户列表中过滤掉当前编辑的商户
* 直接从列表中删除,不显示该选项
*/
filterCurrentMerchantFromParentList() {
if (!this.currentEditMerchantNo) {
return;
}
const list = this.baseData.parentMerchantList || [];
this.baseData.parentMerchantList = list.filter(
item => item.merchantNo != this.currentEditMerchantNo,
);
},
/**
* 编辑场景:重写上级商户列表获取方法
* 获取列表后过滤当前商户
*/
async get4sAndServiceMerchantList(searchIndex) {
// 调用父类方法获取列表
await merchantVerifyFormMixin.methods.get4sAndServiceMerchantList.call(this, searchIndex);
// 编辑场景:处理当前编辑商户
if (this.currentEditMerchantNo) {
this.filterCurrentMerchantFromParentList();
// 更新下拉选项
this.getOptionsList("editFormData", false, "parentId");
}
},
/**
* 编辑场景:排除初始商户名称 * 编辑场景:排除初始商户名称
* 如果当前商户名称与初始商户名称相同,则跳过校验 * 如果当前商户名称与初始商户名称相同,则跳过校验
*/ */
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!