Commit b8d38110 by 张立顺

Merge branch 'feature/V5.8.4/zls' into 'SAAS+V5.8.4'

fix 商品上架需求修改

See merge request !924
2 parents 6d96ae19 c3c70328
[mcp_servers.codegraph]
command = "codegraph"
args = [
"serve",
"--mcp",
]
const { shallowMount } = require("@vue/test-utils");
jest.mock("@/main", () => ({
baseConfig: {
shelfManageFinanceConfig: [],
},
}));
jest.mock("@/views/goods/shelfProduct/api", () => ({
postReconciliationConfigOtherGoodsApi: jest.fn(),
}));
jest.mock("@/views/goods/shelfProduct/hooks/fetchRemoteSelect", () => ({
fetchGoodsListHook: jest.fn(),
fetchPackagesGoodsListHook: jest.fn(),
fetchUpgradeGoodsListHook: jest.fn(),
}));
const Modify = require("./modify.vue").default;
function createWrapper() {
return shallowMount(Modify, {
propsData: {
businessCode: "test-business",
operationMode: 1,
specialDetail: {
expenseCategoryRuleList: [],
goodsTypeGroupRelationList: [],
groupType: 1,
id: "test-id",
},
},
});
}
describe("商品上架类目对账模型", () => {
let wrapper;
beforeEach(() => {
wrapper = createWrapper();
});
afterEach(() => {
wrapper.destroy();
jest.clearAllMocks();
});
it.each([ 1, 2, 3 ])("应用对象类型 %i 使用统一的对账模式选项", (applicationObjectType) => {
const options = wrapper.vm.getExpenseCategoryCalculateTypeOptions(applicationObjectType);
expect(options).toEqual([
{ expenseCategoryCalculateType: 2, label: "按收入比例" },
{ expenseCategoryCalculateType: 1, label: "按毛利比例" },
{ expenseCategoryCalculateType: 3, label: "按固定金额" },
{ expenseCategoryCalculateType: 10, label: "按固定金额*购买数量" },
]);
});
it.each([ 1, 2, 3, 10 ])("有效对账模式 %i 可以通过校验", (value) => {
const callback = jest.fn();
wrapper.vm.validateExpenseCategoryCalculateType({}, value, callback);
expect(callback).toHaveBeenCalledWith();
});
it.each([ 4, 5, 6, 8, 9 ])("历史对账模式 %i 会提示选择有效模式", (value) => {
const callback = jest.fn();
wrapper.vm.validateExpenseCategoryCalculateType({}, value, callback);
expect(callback).toHaveBeenCalledWith(expect.objectContaining({ message: "请选择有效的对账模式" }));
});
it.each([ undefined, null, "" ])("缺失对账模式 %p 保留必选提示", (value) => {
const callback = jest.fn();
wrapper.vm.validateExpenseCategoryCalculateType({}, value, callback);
expect(callback).toHaveBeenCalledWith(expect.objectContaining({ message: "请选择分润模式" }));
});
it.each([
[ 1, false, "请输入比例" ],
[ 2, false, "请输入比例" ],
[ 3, true, "请输入金额" ],
[ 10, true, "请输入金额" ],
])("对账模式 %i 保持金额与比例输入行为", (value, isAmount, placeholder) => {
expect(wrapper.vm.isAmountExpenseCategoryCalculateType(value)).toBe(isAmount);
expect(wrapper.vm.getExpenseCategoryValuePlaceholder(value)).toBe(placeholder);
});
});
......@@ -85,7 +85,7 @@
<el-form-item label=""
label-width="154px"
:prop="getTrafficSideRuleProp(item, 'expenseCategoryCalculateType')"
:rules="[{ required: true, message: '请选择分润模式', trigger: 'change' }]">
:rules="[{ validator: validateExpenseCategoryCalculateType, trigger: 'change' }]">
<el-select v-model="item.expenseCategoryCalculateType"
placeholder="请选择对账模式"
style="width:414px">
......@@ -104,14 +104,14 @@
<VenusNumberInput v-model="item.expenseCategoryValue"
style="flex:1;"
:controls="false"
:max="[3, 10].includes(item.expenseCategoryCalculateType) ? 9999999999 : 100"
:max="isAmountExpenseCategoryCalculateType(item.expenseCategoryCalculateType) ? 9999999999 : 100"
:min="0"
:placeholder="item.expenseCategoryCalculateType | filerPlaceName"
:placeholder="getExpenseCategoryValuePlaceholder(item.expenseCategoryCalculateType)"
:precision="2"
:title="item.expenseCategoryCalculateType | filerPlaceName" />
:title="getExpenseCategoryValuePlaceholder(item.expenseCategoryCalculateType)" />
<div class="prefix" style="margin-left:4px">
{{ [3, 10].includes(item.expenseCategoryCalculateType) ? '元' : '%' }}
{{ isAmountExpenseCategoryCalculateType(item.expenseCategoryCalculateType) ? '元' : '%' }}
</div>
</div>
</el-form-item>
......@@ -124,7 +124,6 @@
<script>
import { uniqBy } from "lodash-es";
import { defaultSelectOptions, goodsSourceList, otherSelectOptions, severSelectOptions } from "@/common/constant/merchant";
import RemoteSelect from "@/components/remoteSearchSelect/index.vue";
import VenusNumberInput from "@/components/venusNumberInput/index.vue";
import { baseConfig } from "@/main";
......@@ -132,7 +131,14 @@ import {
postReconciliationConfigOtherGoodsApi,
} from "@/views/goods/shelfProduct/api";
import { categoryTypeOptions } from "@/views/goods/shelfProduct/constant";
import { fetchGoodsListHook, fetchPackagesGoodsListHook, fetchUpgradeGoodsListHook } from "@/views/goods/shelfProduct/hooks/fetchRemoteSelect";
import { fetchPackagesGoodsListHook, fetchUpgradeGoodsListHook } from "@/views/goods/shelfProduct/hooks/fetchRemoteSelect";
const expenseCategoryCalculateTypeOptions = Object.freeze([
{ expenseCategoryCalculateType: 2, label: "按收入比例" },
{ expenseCategoryCalculateType: 1, label: "按毛利比例" },
{ expenseCategoryCalculateType: 3, label: "按固定金额" },
{ expenseCategoryCalculateType: 10, label: "按固定金额*购买数量" },
]);
export default {
name: "",
......@@ -140,15 +146,6 @@ export default {
RemoteSelect,
VenusNumberInput,
},
filters: {
filerPlaceName(value) {
// value? :''
if (!value) {
return "";
}
return value === 3 || value === 10 ? "请输入金额" : "请输入比例";
},
},
model: {
prop: "specialDetail",
event: "update:specialDetail",
......@@ -184,13 +181,6 @@ export default {
selectedPackageGoods: [],
selectedUpgradeGoods: [],
server: Object.freeze(severSelectOptions), // 服务商费用列表
platform: Object.freeze(severSelectOptions), // 平台方费用列表
goodsSource: Object.freeze(goodsSourceList), // 商品来源
flow: Object.freeze([
...defaultSelectOptions,
...otherSelectOptions,
]), // 流量方费用列表
},
};
},
......@@ -226,16 +216,27 @@ export default {
},
methods: {
getExpenseCategoryCalculateTypeOptions(applicationObjectType) {
if (applicationObjectType === 1) {
return this.options.flow;
if ([ 1, 2, 3 ].includes(applicationObjectType)) {
return expenseCategoryCalculateTypeOptions;
}
if (applicationObjectType === 2) {
return this.options.server;
return [];
},
validateExpenseCategoryCalculateType(rule, value, callback) {
if (value === undefined || value === null || value === "") {
callback(new Error("请选择分润模式"));
return;
}
if (applicationObjectType === 3) {
return this.options.platform;
if (![ 1, 2, 3, 10 ].includes(value)) {
callback(new Error("请选择有效的对账模式"));
return;
}
return [];
callback();
},
isAmountExpenseCategoryCalculateType(value) {
return [ 3, 10 ].includes(value);
},
getExpenseCategoryValuePlaceholder(value) {
return this.isAmountExpenseCategoryCalculateType(value) ? "请输入金额" : "请输入比例";
},
getTrafficSideRuleProp(rule, field) {
const expenseCategoryRules = this.specialDetail?.expenseCategoryRuleList || [];
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!