Commit 245573aa by Jaxon

Merge branch 'feature/marketing-sop-push-strategy' into 'SAAS+V5.8.3'

Feature/marketing sop push strategy

See merge request !794
2 parents a83fae81 c9c2602f
......@@ -99,6 +99,7 @@ const flushPromises = () => new Promise(resolve => setTimeout(resolve, 0));
describe("marketingPushStrategy 集成测试", () => {
const localVue = createLocalVue();
localVue.use(Vuex);
localVue.directive("loading", () => {});
let wrapper;
let store;
......@@ -199,7 +200,84 @@ describe("marketingPushStrategy 集成测试", () => {
return vm;
}
function mockMetaOptions() {
function createModifyWrapper(query = { editType: "add" }) {
store = createStore();
routerPushMock = jest.fn();
messageSuccessMock = jest.fn();
wrapper = shallowMount(ModifyPage, {
localVue,
store,
mocks: {
$route: {
query,
},
$router: {
push: routerPushMock,
},
$message: {
success: messageSuccessMock,
},
},
stubs: {
"glsx-combi-form": {
name: "glsx-combi-form",
render(h) {
return h("div", [
...(this.$slots.default || []),
...(this.$slots.storeIds || []),
...(this.$slots.stageSlot || []),
...(this.$slots.step2ConditionGroups || []),
]);
},
},
"el-form": {
name: "el-form",
render(h) {
return h("form", this.$slots.default);
},
},
"el-form-item": {
name: "el-form-item",
render(h) {
return h("div", this.$slots.default);
},
},
"el-radio-group": {
name: "el-radio-group",
render(h) {
return h("div", this.$slots.default);
},
},
"el-radio": {
name: "el-radio",
functional: true,
props: {
label: {
type: [String, Number],
default: "",
},
},
render(h, ctx) {
return h("label", {
attrs: {
"data-action-confirm-label": String(ctx.props.label),
},
}, ctx.children);
},
},
"el-button": true,
"el-select": true,
"el-option": true,
"el-input-number": true,
BranchGroup: true,
ConditionPanel: true,
SelectStoreDialog: true,
},
});
return wrapper;
}
function mockMetaOptions(overrides = {}) {
mockGetMetaOptionsApi.mockResolvedValue({
conditionVariables: [{ code: "age", name: "车龄" }],
step2ConditionVariables: [{ code: "level", name: "等级" }],
......@@ -213,6 +291,11 @@ describe("marketingPushStrategy 集成测试", () => {
],
triggers: [{ code: "DATE_TIME", name: "日期时间" }],
messageVariables: [{ code: "customerName", name: "客户姓名" }],
actionConfirmOptions: [
{ value: 0, label: "自动执行" },
{ value: 1, label: "需驻店人员确认" },
],
...overrides,
});
}
......@@ -359,6 +442,30 @@ describe("marketingPushStrategy 集成测试", () => {
);
});
it("应根据元数据动态渲染动作执行确认选项", async () => {
mockMetaOptions({
actionConfirmOptions: [
{ value: 2, label: "总部确认" },
{ value: 3, label: "门店确认" },
],
});
createModifyWrapper({ editType: "add" });
await flushPromises();
await flushPromises();
wrapper.vm.form.marketingStage = "AFTER_DELIVERY";
wrapper.vm.form.triggerType = "DATE_TIME";
await wrapper.vm.$nextTick();
const actionConfirmRadios = wrapper.findAll("[data-action-confirm-label]");
expect(actionConfirmRadios).toHaveLength(2);
expect(actionConfirmRadios.at(0).attributes("data-action-confirm-label")).toBe("2");
expect(actionConfirmRadios.at(1).attributes("data-action-confirm-label")).toBe("3");
expect(wrapper.text()).toContain("总部确认");
expect(wrapper.text()).toContain("门店确认");
});
it("编辑场景应回填详情并转换网页素材数据", async () => {
mockMetaOptions();
mockGetMarketingPushStrategyDetailApi.mockResolvedValue({
......
......@@ -46,7 +46,9 @@ describe("marketingPushStrategy 执行记录集成测试", () => {
});
return wrapper;
}
beforeEach(() => {
consoleLogSpy = jest.spyOn(console, "log").mockImplementation(() => {});
});
afterEach(() => {
if (wrapper) {
wrapper.destroy();
......@@ -57,10 +59,6 @@ describe("marketingPushStrategy 执行记录集成测试", () => {
jest.clearAllMocks();
});
beforeEach(() => {
consoleLogSpy = jest.spyOn(console, "log").mockImplementation(() => {});
});
function getDetailDialogVm() {
return wrapper.vm.$children.find(child => child.$options && child.$options.name === "DetailDialog");
}
......
......@@ -112,11 +112,10 @@
label="动作执行确认:"
required>
<el-radio-group v-model="form.actionConfirmType">
<el-radio :label="0">
自动执行
</el-radio>
<el-radio :label="1">
需驻点人员确认
<el-radio v-for="opt in options.actionConfirmOptions"
:key="opt.value"
:label="opt.value">
{{ opt.label }}
</el-radio>
</el-radio-group>
</el-form-item>
......@@ -158,7 +157,7 @@ import { createStrategy, getMarketingPushStrategyDetailApi, getMetaOptionsApi, u
import BranchGroup from "@/views/marketingManagement/marketingPushStrategy/components/branchGroup/index.vue";
import ConditionPanel from "@/views/marketingManagement/marketingPushStrategy/components/conditionPanel/index.vue";
import SelectStoreDialog from "@/views/marketingManagement/marketingPushStrategy/components/selectStoreDialog/index.vue";
import { formatTriggerTimeValue, getDefaultBranch, hourOptions, MessageTypeEnum, minuteOptions, relativeDateTypeOpt } from "@/views/marketingManagement/marketingPushStrategy/constant";
import { actionConfirmOptions, formatTriggerTimeValue, getDefaultBranch, hourOptions, MessageTypeEnum, minuteOptions, relativeDateTypeOpt } from "@/views/marketingManagement/marketingPushStrategy/constant";
import { getFormSchema, getSpecFormSchema, rules } from "@/views/marketingManagement/marketingPushStrategy/views/modify/modify.data.js";
export default {
......@@ -208,6 +207,7 @@ export default {
relativeDateTypeOpt,
hourOptions,
minuteOptions,
actionConfirmOptions,
},
dialog: {
step2ConditionGroup: {
......@@ -289,8 +289,9 @@ export default {
setTriggerMetaDateOptions(list = []) {
const index = this.specFormSchema.findIndex(item => item.name === "dateVariableType");
if (index === -1)
if (index === -1) {
return;
}
const dateVariableItem = {
...this.specFormSchema[index],
optionList: list,
......@@ -361,11 +362,10 @@ export default {
}
const params = this.dealParams();
const api = this.$route.query.editType === "edit" ? updateStrategy : createStrategy;
api(params).then((res) => {
this.setReportTrackData(0, "sop_strategy_web_submit_change", {});
this.$message.success("操作成功");
this.handleCancel();
});
await api(params);
this.setReportTrackData(0, "sop_strategy_web_submit_change", {});
this.$message.success("操作成功");
this.handleCancel();
} catch (error) {
return;
}
......
import { bizTypeOpt, storeTypeOpt } from "@/views/marketingManagement/marketingPushStrategy/constant";
import { actionConfirmOptions } from "@/views/marketingManagement/marketingPushStrategy/constant/index";
export function getModifySchema() {
return [
{
addHtml: "_label3",
},
{
label: "动作执行确认",
name: "actionConfirmType",
type: "radio",
optionList: actionConfirmOptions,
optionId: "value",
optionLabel: "label",
},
{
labelWidth: "0px",
addHtml: "_branchList",
},
];
}
export const rules = {
strategyName: [
......
const { bizTypeOpt, storeTypeOpt } = require("../../constant/index.js");
const {
actionConfirmOptions,
bizTypeOpt,
storeTypeOpt,
} = require("../../constant/index.js");
const {
getModifySchema,
getFormSchema,
getSpecFormSchema,
rules,
} = require("./modify.data.js");
describe("marketingPushStrategy views/modify/modify.data.js", () => {
it("getModifySchema 应返回动作确认配置", () => {
const schema = getModifySchema();
const actionConfirmItem = schema.find(item => item.name === "actionConfirmType");
expect(actionConfirmItem.optionList).toBe(actionConfirmOptions);
expect(actionConfirmItem.type).toBe("radio");
});
it("storeIds 校验应在不限门店或已选择门店时通过", () => {
const validator = rules.storeIds[0].validator;
const passCallback = jest.fn();
......@@ -55,11 +42,13 @@ describe("marketingPushStrategy views/modify/modify.data.js", () => {
const storeScopeItem = schema.find(item => item.name === "storeScopeType");
const storeIdsItem = schema.find(item => item.name === "storeIds");
const marketingStageItem = schema.find(item => item.name === "marketingStage");
const actionConfirmItem = schema.find(item => item.name === "actionConfirmType");
expect(bizTypeItem.optionList).toBe(bizTypeOpt);
expect(storeScopeItem.optionList).toBe(storeTypeOpt);
expect(storeIdsItem.isHide({ formModel: { storeScopeType: 0 } })).toBe(true);
expect(storeIdsItem.isHide({ formModel: { storeScopeType: 1 } })).toBe(false);
expect(actionConfirmItem).toBeUndefined();
marketingStageItem.changeAttr("AFTER_DELIVERY", marketingStageItem);
expect(setTriggerMetaDateOptions).toHaveBeenCalledWith([
......
<template>
<div class="wrapper">
<div style="margin-left:30px;padding">
<glsx-combi-form label-width="150px"
:form-data="formSchema"
:form-obj="form"
:form-rules="formRules"
:inline="false">
<template #_branchList>
<el-form label-width="150px" size="small">
<BranchItem v-for="(branch, index) in form.branches"
:key="branch._key"
:branch="branch"
:options="{
messageVariables: options.messageVariables,
triggers: options.triggers,
}"
:title="`分支${index + 1}`"
@appendAction="handleAppendAction(index)"
@input="handleBranchChange($event, index)"
@removeAction="handleRemoveAction($event, index)"
@removeBranch="handleRemoveBranch(index)" />
<el-button block @click="handleAppendBranch">
<i class="el-icon-plus "></i>
添加分支
</el-button>
</el-form>
</template>
</glsx-combi-form>
</div>
<!-- <div class="step3-wrapper">
<div class="title-wrapper">
③ 就执行以下动作
</div>
</div>
<glsx-combi-form default-width="400px"
label-width="150px"
:form-data="formSchema"
:form-obj="form"
:form-rules="formRules">
<template #_label4>
<div>默认执行第一条满足条件规则的分支</div>
</template>
</glsx-combi-form> -->
<!-- <div style="width:800px">
<ConditionGroup style="width:880px;margin:0 0 0 30px;padding-top:30px;"
:options="{
conditionVariables: getStep2ConditionOptions,
}" />
</div> -->
</div>
</template>
<script>
import { nanoid } from "nanoid";
import { getMetaOptions } from "@/views/marketingManagement/marketingPushStrategy/api/index.js";
import BranchItem from "@/views/marketingManagement/marketingPushStrategy/components/branchItem/index.vue";
import ConditionGroup from "@/views/marketingManagement/marketingPushStrategy/components/conditionGroup/index.vue";
import VariableTextarea from "@/views/marketingManagement/marketingPushStrategy/components/variableTextarea/index.vue";
import { getDefaultAction, getDefaultBranch, MessageTypeEnum } from "@/views/marketingManagement/marketingPushStrategy/constant";
import { replaceCodeWithName } from "@/views/marketingManagement/marketingPushStrategy/utils/index.js";
import { getModifySchema } from "./modify.data";
export default {
name: "",
components: {
BranchItem,
ConditionGroup,
VariableTextarea,
},
props: {
},
data() {
return {
test: "123",
form: {
actionConfirmType: 0,
branches: [getDefaultBranch()],
},
formSchema: [],
formRules: {},
options: {
conditionVariables: [],
step2ConditionVariables: [],
stages: [],
triggers: [],
messageVariables: [],
},
};
},
computed: {
getStep2ConditionOptions() {
return this.options.step2ConditionVariables;
},
},
async mounted() {
this.formSchema = await getModifySchema();
await this.getData();
},
methods: {
handleSubmit() {
console.log(this.form);
},
handleRemoveAction(actionIndex, branchIndex) {
this.form.branches[branchIndex].actions.splice(actionIndex, 1);
},
handleAppendBranch() {
this.form.branches.push(getDefaultBranch());
},
handleRemoveBranch(branchIndex) {
this.form.branches.splice(branchIndex, 1);
},
handleAppendAction(branchIndex) {
this.form.branches[branchIndex].actions.push(getDefaultAction());
},
handleBranchChange({ actionIndex, actionItem }, branchIndex) {
this.$set(this.form.branches[branchIndex].actions, actionIndex, actionItem);
},
async getData() {
const data = await getMetaOptions();
Object.assign(this.options, data);
},
},
};
</script>
<style scoped lang="scss">
.wrapper {
background-color: white;
height: 100%;
margin: 0 20px 20px;
::v-deep .branch-item-wrapper {
margin-top: 12px;
&:first-child {
margin-top: 0;
}
}
}
</style>
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!