Commit fb7bd0ce by 张立顺

fix bug

1 parent f834c531
import GLMapSdk from "@/common/glsk-mapapi-sdk";
let singleton = null;
function attachReady(sdk) {
if (typeof sdk.ready === "function") return;
sdk.ready = function mapApiReady(timeoutMs = 30000) {
const inst = this;
const deadline = Date.now() + timeoutMs;
return new Promise((resolve, reject) => {
function tick() {
if (inst.GLMap) {
resolve(inst);
return;
}
if (Date.now() >= deadline) {
reject(new Error("Map SDK load timeout"));
return;
}
setTimeout(tick, 50);
}
tick();
});
};
}
function getOrCreateSdk() {
if (!singleton) {
singleton = new GLMapSdk();
attachReady(singleton);
}
return singleton;
}
/**
* 注册 Vue.prototype.$mapapi:首次访问再实例化 GLMapSdk,并补全 glsk-mapapi-sdk 未提供的 ready()(轮询 GLMap)。
*/
export function installVueMapApi(Vue) {
Object.defineProperty(Vue.prototype, "$mapapi", {
get() {
return getOrCreateSdk();
},
configurable: true,
});
}
......@@ -119,6 +119,20 @@ export function buildMerchantVerifyEchoDisplay(mi) {
const mainBrandsFromTree = formatMainBrandsFromBrandTreeList(m.brandTreeList);
/** 详情「商户名称」后附半角括号内商户号:优先 merchantNo,缺省用 merchantId */
let noPart = "";
if (m.merchantNo != null && String(m.merchantNo).trim() !== "") {
noPart = String(m.merchantNo).trim();
} else if (m.merchantId != null && String(m.merchantId).trim() !== "") {
noPart = String(m.merchantId).trim();
}
const namePart = displayScalarMerchantVerify(m.merchantName);
let merchantNameEcho = namePart;
if (noPart) {
merchantNameEcho =
namePart !== "-" ? `${namePart}(${noPart})` : `(${noPart})`;
}
return {
merchantType: displayScalarMerchantVerify(
merchantTypeFromAccountTypes || m.merchantTypeName || m.merchantType
......@@ -131,7 +145,7 @@ export function buildMerchantVerifyEchoDisplay(mi) {
),
superChannel: displayScalarMerchantVerify(m.channelName),
openMode: openParts.length ? openParts.join(" / ") : "-",
merchantName: displayScalarMerchantVerify(m.merchantName),
merchantName: merchantNameEcho,
_emptyRightMerchantName: "",
merchantNo: displayScalarMerchantVerify(m.merchantNo),
merchantInnerId: displayScalarMerchantVerify(m.id),
......
......@@ -8,7 +8,7 @@ import Vue from "vue";
import VueLazyload from "vue-lazyload";
import { config } from "@/common/baseConfig";
import GLMapSdk from "@/common/glsk-mapapi-sdk";
import { installVueMapApi } from "@/common/installVueMapApi";
import notice from "@/common/notice";
import util from "@/libs/util.js";
// 针对template模板中使用可选链操作符
......@@ -26,7 +26,7 @@ import router from "./router";
import "default-passive-events";
import "element-ui/lib/theme-chalk/index.css";
Vue.prototype.$mapapi = new GLMapSdk();
installVueMapApi(Vue);
Vue.use(VueLazyload, {
// 懒加载默认加载图片
loading:
......
......@@ -101,12 +101,14 @@
<!-- <span class="title-tips">切换品类前会自动保存当前编辑内容。</span> -->
<span class="division-rules-toolbar__controls">
<span class="select-wrapper">
<el-select :value="editableTabsValue" class="tab-select" :popper-append-to-body="false"
placeholder="请选择特殊品类" @change="handleDivisionTabChange">
<el-select :value="editableTabsValue"
:class="['tab-select', { 'tab-select--error': divisionTabSelectError }]"
:popper-append-to-body="false" placeholder="请选择特殊品类" @change="handleDivisionTabChange">
<el-option v-for="(item, idx) in editableTabs" :key="item.name" :label="item.title" :value="item.name">
<div class="tab-select-options-wrapper">
<span class="tab-select-options-wrapper__left">
<span v-show="item.calculateModeError || item.divisionTestTabWarningFromApi"
<span
v-show="item.calculateModeError || item.divisionTestTabWarningFromApi || item.rulePayloadValidationError"
class="el-icon-warning icons car-error-txt" />
<span class="label">{{ item.title }}</span>
</span>
......@@ -201,6 +203,7 @@ import {
} from "./utils/classificationRuleCache"
import {
distributionRulesLookComplete,
ledgerMerchantIdLooseEqual,
prepareRuleForValidation,
validateGoodsTypeGroupRulePayload
} from "./utils/validateGoodsTypeGroupRulePayload"
......@@ -304,7 +307,11 @@ export default {
financialRulesEnv: {
routerInfo: {},
scene: undefined
}
},
/** getFinancialObj 等初始化完成后再响应分账方变更,避免首屏回填误清空测试状态 */
_ledgerInvalidateReady: false,
/** getGoodsTypeGroupRules 失败时品类切换下拉标红 */
divisionTabSelectError: false
}
},
provide() {
......@@ -485,6 +492,15 @@ export default {
this.initBaseData()
},
immediate: true
},
"financialObj.realityShopMerchantId"(newVal, oldVal) {
this._maybeInvalidateDivisionTabsForLedgerFieldChange(newVal, oldVal)
},
"financialObj.realityPlatformMerchantId"(newVal, oldVal) {
this._maybeInvalidateDivisionTabsForLedgerFieldChange(newVal, oldVal)
},
"financialObj.djzhySubMerchantId"(newVal, oldVal) {
this._maybeInvalidateDivisionTabsForLedgerFieldChange(newVal, oldVal)
}
},
mounted() {
......@@ -509,6 +525,9 @@ export default {
// merchantId && this.getMerchantLevel(merchantId, "merchantLevelList", scene)
Promise.all(eventArr).then(() => {
this.checkSelectEmpty()
this.$nextTick(() => {
this._ledgerInvalidateReady = true
})
})
},
methods: {
......@@ -1480,6 +1499,7 @@ export default {
* @returns {Promise<{ ok: boolean, incrementalRules: Array, fullMergedRules: Array|null, firstErrorTabIndex?: number }>}
*/
async getGoodsTypeGroupRules(_list, options = {}) {
this.clearDivisionTabSelectValidationUi()
const onlyActiveTab = options.onlyActiveTab === true
const startTabName = this.editableTabsValue
......@@ -1502,10 +1522,15 @@ export default {
|| allRuleTabIndices.length === 0
) {
this.rebuildCrossTabGoodsSelectionsFromRules()
this.setDivisionTabSelectValidationUiFailed(
this.activeDivisionTabIndex >= 0 ? this.activeDivisionTabIndex : null
)
return {
ok: false,
incrementalRules: [],
fullMergedRules: null
fullMergedRules: null,
firstErrorTabIndex:
this.activeDivisionTabIndex >= 0 ? this.activeDivisionTabIndex : undefined
}
}
} else {
......@@ -1580,9 +1605,15 @@ export default {
const tab = this.editableTabs[tabindex]
const rulePayload = this.resolveRulePayloadForTabValidation(tabindex)
if (!validateGoodsTypeGroupRulePayload(rulePayload)) {
if (
!validateGoodsTypeGroupRulePayload(
rulePayload,
this.getLedgerContextForRuleValidation()
)
) {
await this.focusTabAndRunHandleConfirm(tab.name)
this.rebuildCrossTabGoodsSelectionsFromRules()
this.setDivisionTabSelectValidationUiFailed(tabindex)
return {
ok: false,
incrementalRules: [],
......@@ -1632,6 +1663,7 @@ export default {
}
this.rebuildCrossTabGoodsSelectionsFromRules()
this.clearDivisionTabSelectValidationUi()
return {
ok: true,
incrementalRules,
......@@ -1644,6 +1676,37 @@ export default {
closeLoading()
}
},
/** 品类切换下拉及选项上的纯数据校验失败提示 */
clearDivisionTabSelectValidationUi() {
this.divisionTabSelectError = false
const tabs = this.editableTabs || []
for (let i = 0; i < tabs.length; i++) {
const t = tabs[i]
if (!t || String(t.name) === "add") continue
if (t.rulePayloadValidationError) {
this.$set(t, "rulePayloadValidationError", false)
}
}
},
setDivisionTabSelectValidationUiFailed(firstErrorTabIndex) {
const tabs = this.editableTabs || []
for (let i = 0; i < tabs.length; i++) {
const t = tabs[i]
if (!t || String(t.name) === "add") continue
if (t.rulePayloadValidationError) {
this.$set(t, "rulePayloadValidationError", false)
}
}
this.divisionTabSelectError = true
if (
firstErrorTabIndex != null
&& firstErrorTabIndex >= 0
&& tabs[firstErrorTabIndex]
&& String(tabs[firstErrorTabIndex].name) !== "add"
) {
this.$set(tabs[firstErrorTabIndex], "rulePayloadValidationError", true)
}
},
getSelectingList(defaultSelect) {
getAllGoodsList({
// upgradeGoodsNameOrCCode: this.goodsNameKeyword,
......@@ -1772,6 +1835,34 @@ export default {
}
})
},
/** 提交前纯数据校验:分账表须与当前基础分账方一致(见 validateGoodsTypeGroupRulePayload 第二参) */
getLedgerContextForRuleValidation() {
const fo = this.financialObj || {}
return {
realityPlatformMerchantId: fo.realityPlatformMerchantId,
realityShopMerchantId: fo.realityShopMerchantId,
djzhySubMerchantId: fo.djzhySubMerchantId
}
},
/**
* 平台方 / 流量方 / 嘀加子商户变更后:各品类 Tab 视为未再确认,避免缓存快路径与 UI 清空脱节。
*/
invalidateAllDivisionTabsAfterLedgerPartyChange() {
const tabs = this.editableTabs || []
for (let i = 0; i < tabs.length; i++) {
const tab = tabs[i]
if (!tab || String(tab.name) === "add") continue
this.ensureTabRevisionFields(tab)
this.$set(tab, "testFlag", "N")
this.$set(tab, "divisionTestTabWarningFromApi", false)
this.$set(tab, "ruleCacheRevision", (tab.ruleCacheRevision || 0) + 1)
}
},
_maybeInvalidateDivisionTabsForLedgerFieldChange(newVal, oldVal) {
if (!this._ledgerInvalidateReady) return
if (ledgerMerchantIdLooseEqual(newVal, oldVal)) return
this.invalidateAllDivisionTabsAfterLedgerPartyChange()
},
getMerchantLevel(id, name, scene) {
// console.log(this.merchantInfo)
// getPlatformMerchantList().then(res => {
......@@ -1886,6 +1977,7 @@ export default {
this.rebuildCrossTabGoodsSelectionsFromRules()
this.editableTabsValue = newName
this.currentIndex = newName
this.clearDivisionTabSelectValidationUi()
},
/**
* 下拉切换品类:受控 el-select,先持久化旧 tab 再更新 editableTabsValue。
......@@ -2248,6 +2340,15 @@ export default {
width: 280px;
max-width: 100%;
&.tab-select--error .el-input__inner {
border-color: #f56c6c;
}
&.tab-select--error .el-input.is-focus .el-input__inner,
&.tab-select--error .el-input__inner:focus {
border-color: #f56c6c;
}
.el-select-dropdown__item {
display: flex;
justify-content: space-between;
......
......@@ -79,13 +79,134 @@ function validateCostConvertRates(rule) {
return true
}
/** 与 rulePayloadCanonicalCompare.looseLeafEqual 对齐:number / string 同值视为相等 */
export function ledgerMerchantIdLooseEqual(a, b) {
if (a === b) return true
if (a == null || b == null) return false
const s1 = String(a).trim()
const s2 = String(b).trim()
if (s1 === "" && s2 === "") return true
const n1 = Number(s1)
const n2 = Number(s2)
if (!Number.isNaN(n1) && !Number.isNaN(n2) && s1 === String(n1) && s2 === String(n2)) {
return n1 === n2
}
return s1 === s2
}
function pushId(set, id) {
if (id === "" || id === undefined || id === null) return
set.add(String(id).trim())
}
/**
* 从 expenseCategoryRules 解析服务商商户号(与 classificationCpt handleSelectChange 一致)
* @param {Array} rules
* @returns {string[]}
*/
export function extractServiceMerchantIdsFromExpenseCategoryRules(rules) {
if (!Array.isArray(rules)) return []
const out = []
const seen = new Set()
const add = (id) => {
if (id === "" || id === undefined || id === null) return
const s = String(id).trim()
if (!s || seen.has(s)) return
seen.add(s)
out.push(s)
}
for (let i = 0; i < rules.length; i++) {
const cur = rules[i]
if (!cur || typeof cur !== "object") continue
const id1 = cur.targetMerchant?.merchantId ?? cur.targetMerchantId
add(id1)
if (cur.formType === 2 && Array.isArray(cur.children)) {
for (let j = 0; j < cur.children.length; j++) {
const ele = cur.children[j]
if (!ele || typeof ele !== "object") continue
const id2 = ele.targetMerchant?.merchantId ?? ele.targetMerchantId
add(id2)
}
}
}
return out
}
/**
* 当前基础分账方 + 本条规则内服务商,用于校验分账表 merchantId 是否在可选范围内。
* @typedef {object} FinancialLedgerContext
* @property {string|number} [realityPlatformMerchantId]
* @property {string|number} [realityShopMerchantId]
* @property {string|number} [djzhySubMerchantId]
*/
/**
* @param {object} rule 已 fillDj 的规则
* @param {FinancialLedgerContext} ledger
* @returns {Set<string>}
*/
function buildAllowedMerchantIdSet(rule, ledger) {
const set = new Set()
if (ledger && typeof ledger === "object") {
pushId(set, ledger.realityPlatformMerchantId)
pushId(set, ledger.realityShopMerchantId)
pushId(set, ledger.djzhySubMerchantId)
}
const svc = extractServiceMerchantIdsFromExpenseCategoryRules(rule.expenseCategoryRules)
for (let k = 0; k < svc.length; k++) {
pushId(set, svc[k])
}
return set
}
function merchantIdInAllowedSet(allowedSet, merchantId) {
if (merchantId === "" || merchantId === undefined || merchantId === null) return false
const s = String(merchantId).trim()
for (const x of allowedSet) {
if (ledgerMerchantIdLooseEqual(s, x)) return true
}
return false
}
/**
* 分账表每行 merchantId 须在「平台/流量/子商户 + 本条 expense 内服务商」集合内;
* 导流方行 targetMerchantType===3 时 merchantId 须等于当前 realityShopMerchantId。
*/
export function distributionRulesConsistentWithLedgerParty(rule, ledger) {
if (!ledger || typeof ledger !== "object") return true
const md = rule.merchantDistributionRules
const od = rule.owningMerchantDistributionRules
if (!Array.isArray(md) || !Array.isArray(od)) return false
const allowed = buildAllowedMerchantIdSet(rule, ledger)
const shopId = ledger.realityShopMerchantId
const rowOk = (rows) => {
for (let i = 0; i < rows.length; i++) {
const r = rows[i]
if (!r || typeof r !== "object") return false
const mid = r.merchantId
if (mid === "" || mid === undefined || mid === null) return false
if (!merchantIdInAllowedSet(allowed, mid)) return false
const t = Number(r.targetMerchantType)
if (t === 3) {
if (shopId === "" || shopId === undefined || shopId === null) return false
if (!ledgerMerchantIdLooseEqual(mid, shopId)) return false
}
}
return true
}
return rowOk(md) && rowOk(od)
}
/**
* 对单条 goodsTypeGroupRules 项做纯数据校验(不挂载 el-form)。
* 先 fillDjGoodsTypeGroupRelations 再验,与提交流程一致。
*
* @param {object} rawRule
* @param {FinancialLedgerContext} [ledgerContext] 传入时校验分账行与当前基础分账方 / 本条规则内服务商一致(提交路径);不传则跳过该项以保持与 persist 内 prev/next 形态校验兼容。
* @returns {boolean}
*/
export function validateGoodsTypeGroupRulePayload(rawRule) {
export function validateGoodsTypeGroupRulePayload(rawRule, ledgerContext) {
if (!rawRule || typeof rawRule !== "object") return false
const rule = fillDjGoodsTypeGroupRelations(deepClone(rawRule))
if (!rule || typeof rule !== "object") return false
......@@ -109,6 +230,10 @@ export function validateGoodsTypeGroupRulePayload(rawRule) {
if (!distributionRulesLookComplete(rule)) return false
if (ledgerContext != null && typeof ledgerContext === "object") {
if (!distributionRulesConsistentWithLedgerParty(rule, ledgerContext)) return false
}
const gt = Number(rule.groupType)
const gs = Number(rule.goodsSource)
// 嘀加来源且特殊品类:须指定品类/商品/套餐清单;goodsSource 为 2、3 时模板不展示该校验项
......
......@@ -217,6 +217,20 @@ export default {
}
return out;
},
/** 弹框回写:StepTwo 字段为权威值,同步到 estimated*(供经营区块等读取) */
syncEstimatedFieldsFromStepTwo(row) {
const out = { ...row };
if (out.estimatedConversionRate != null) {
out.estimatedConversion = out.estimatedConversionRate;
}
if (out.upgradePrice != null) {
out.estimatedUpgradePrice = out.upgradePrice;
}
if (out.revenue != null) {
out.estimatedRevenue = out.revenue;
}
return out;
},
mapProductDetailsForSubmit(list) {
if (!Array.isArray(list) || !list.length) return [];
return list.map((pd) => this.applyLegacySalesCategoryKeys(pd));
......@@ -241,12 +255,13 @@ export default {
);
},
editSalesCategoryData(data) {
const next = this.syncEstimatedFieldsFromStepTwo({ ...data });
this.productDetails = this.productDetails.map(item => {
if (
item.productType === data.productType &&
item.productCategory === data.productCategory
) {
return data;
return next;
}
return item;
});
......@@ -261,7 +276,7 @@ export default {
throw new Error("该销售品类已存在");
}
});
this.productDetails.push(data);
this.productDetails.push(this.syncEstimatedFieldsFromStepTwo({ ...data }));
} catch (error) {
this.$message.error(error.message);
}
......
......@@ -107,6 +107,16 @@ function detailScalarSubmitValue(v) {
}
function mapProductDetailBusinessRow(pd) {
// StepTwo 弹框只绑定 estimatedConversionRate / upgradePrice / revenue,优先于详情里可能未更新的 estimated*
const estimatedConversionVal = numOrNull(
pd.estimatedConversionRate != null ? pd.estimatedConversionRate : pd.estimatedConversion,
);
const estimatedUpgradePriceVal = numOrNull(
pd.upgradePrice != null ? pd.upgradePrice : pd.estimatedUpgradePrice,
);
const estimatedRevenueVal = numOrNull(
pd.revenue != null ? pd.revenue : pd.estimatedRevenue,
);
const row = {
productType: pd.productType,
productCategory: pd.productCategory,
......@@ -114,15 +124,13 @@ function mapProductDetailBusinessRow(pd) {
penetrationRate: numOrNull(pd.penetrationRate),
conversionRate: numOrNull(pd.conversionRate),
revenuePerCar: numOrNull(pd.revenuePerCar),
estimatedConversion: numOrNull(
pd.estimatedConversion != null ? pd.estimatedConversion : pd.estimatedConversionRate,
),
estimatedUpgradePrice: numOrNull(
pd.estimatedUpgradePrice != null ? pd.estimatedUpgradePrice : pd.upgradePrice,
),
estimatedRevenue: numOrNull(
pd.estimatedRevenue != null ? pd.estimatedRevenue : pd.revenue,
),
estimatedConversion: estimatedConversionVal,
estimatedUpgradePrice: estimatedUpgradePriceVal,
estimatedRevenue: estimatedRevenueVal,
// 与上列 estimated* 同源,兼容 StepTwo / 历史字段名
estimatedConversionRate: estimatedConversionVal,
upgradePrice: estimatedUpgradePriceVal,
revenue: estimatedRevenueVal,
recyclingFilm: numOrNull(pd.recyclingFilm),
trafficFee: numOrNull(pd.trafficFee),
marketFee1: numOrNull(pd.marketFee1),
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!