Commit 485aedc6 by Jaxon

feat(performanceScheme): 重构提成方案保存与提交审批流程

- 将保存逻辑提取到 store 中,新增 submitToSave 和 fetchSave 方法
- 优化表单验证规则,移除冗余的验证函数
- 重构审批弹窗组件,支持从 store 获取数据并处理不同状态
- 统一门店品牌数据格式转换,添加相关工具函数导出
- 简化配置页面逻辑,移除不必要的字段验证触发
1 parent 9415329e
...@@ -8,9 +8,7 @@ ...@@ -8,9 +8,7 @@
<div v-loading="loading" class="sun-dialog"> <div v-loading="loading" class="sun-dialog">
<div class="approve-info"> <div class="approve-info">
提交后经由嘀加企微,推送到审批人 提交后经由嘀加企微,推送到审批人
<template v-if=" <template v-if=" detailInfo.examineData && detailInfo.examineData.length ">
detailInfo.examineData && detailInfo.examineData.length
">
<span v-for="(item, index) in detailInfo.examineData" <span v-for="(item, index) in detailInfo.examineData"
:key="`${index}exam`"> :key="`${index}exam`">
{{ item.approverName }}{{ item.approverMobile }} {{ item.approverName }}{{ item.approverMobile }}
...@@ -25,15 +23,13 @@ ...@@ -25,15 +23,13 @@
<span v-else>-</span>,审批人通过方案后,方案正式生效 <span v-else>-</span>,审批人通过方案后,方案正式生效
</div> </div>
<template v-if="detailInfo"> <template v-if="detailInfo">
<DetailComp :config-data="configData" <DetailComp ref="DetailCompRef"
:config-data="configData"
:detail-info="detailInfo" :detail-info="detailInfo"
:is-close="isEdit" :is-close="isEdit"
:rules="rules"> :rules="rules">
<template #merchantBrandRefList> <template #merchantBrandRefList>
<div v-if=" <div v-if="detailInfo.merchantBrandList && detailInfo.merchantBrandList.length"
detailInfo.merchantBrandList
&& detailInfo.merchantBrandList.length
"
class="merchantBrand-box"> class="merchantBrand-box">
<div v-for="item in detailInfo.merchantBrandList" <div v-for="item in detailInfo.merchantBrandList"
:key="item.merchantId" :key="item.merchantId"
...@@ -98,7 +94,7 @@ ...@@ -98,7 +94,7 @@
<script> <script>
import { isFunction } from "lodash-es"; import { isFunction } from "lodash-es";
import { getPerformanceConfigDetailAPI } from "@/api/resident"; import { mapActions } from "vuex";
import { import {
getApproveConfig, getApproveConfig,
getConfigApprovetDetail, getConfigApprovetDetail,
...@@ -120,9 +116,13 @@ export default { ...@@ -120,9 +116,13 @@ export default {
type: Boolean, type: Boolean,
default: false, default: false,
}, },
params: {
type: Object,
default: () => {},
},
id: { id: {
type: Number || String, type: Number || String,
default: "", default: 0,
}, },
isEdit: { isEdit: {
type: Boolean, type: Boolean,
...@@ -138,6 +138,10 @@ export default { ...@@ -138,6 +138,10 @@ export default {
approveConfigData: [], approveConfigData: [],
getStatusItem, getStatusItem,
rules: { rules: {
editApproveRemark: [
{ required: true, message: "请输入变更、新增方案说明", trigger: "blur" },
],
}, },
dialogConfig: { dialogConfig: {
title: "审批查看", title: "审批查看",
...@@ -152,6 +156,7 @@ export default { ...@@ -152,6 +156,7 @@ export default {
isShow: true, isShow: true,
configData: [ configData: [
{ {
childRef: "DetailCompRef",
infoData: [ infoData: [
{ {
title: "提成方案名称", title: "提成方案名称",
...@@ -162,6 +167,7 @@ export default { ...@@ -162,6 +167,7 @@ export default {
title: "应用门店及品牌", title: "应用门店及品牌",
key: "merchantBrandRefList", key: "merchantBrandRefList",
col: 24, col: 24,
colClass: "merchant-brand-ref-list-col",
slot: "merchantBrandRefList", slot: "merchantBrandRefList",
}, },
{ {
...@@ -241,6 +247,10 @@ export default { ...@@ -241,6 +247,10 @@ export default {
}, },
methods: { methods: {
...mapActions ("PerformanceFormStore", [
"submitToSave",
]),
validateBeforeSave() { validateBeforeSave() {
if (!this.detailInfo.editApproveRemark) { if (!this.detailInfo.editApproveRemark) {
this.$message.error("请输入变更、新增方案说明"); this.$message.error("请输入变更、新增方案说明");
...@@ -252,6 +262,14 @@ export default { ...@@ -252,6 +262,14 @@ export default {
async handleClick() { async handleClick() {
if (!this.validateBeforeSave()) if (!this.validateBeforeSave())
return; return;
// 根据status来
if (this.isEdit) {
// 先根据状态处理保存逻辑
const { id } = await this.submitToSave();
this.detailInfo.id = id;
}
let params = { let params = {
performanceConfigId: this.detailInfo.id, performanceConfigId: this.detailInfo.id,
approveRemark: this.detailInfo.editApproveRemark, approveRemark: this.detailInfo.editApproveRemark,
...@@ -268,7 +286,6 @@ export default { ...@@ -268,7 +286,6 @@ export default {
if (res) { if (res) {
this.$message.success("操作成功"); this.$message.success("操作成功");
this.isConfirm = true; this.isConfirm = true;
this.$emit("afterSubmit");
} }
} finally { } finally {
this.visible = false; this.visible = false;
...@@ -277,28 +294,24 @@ export default { ...@@ -277,28 +294,24 @@ export default {
editDetail() { editDetail() {
getApproveConfig({}).then((res) => { getApproveConfig({}).then((res) => {
console.log(res);
// 查阅人 // 查阅人
res.referData = res.length res.referData = res.length ? res.filter(item => item.approverType == 1) : [];
? res.filter(item => item.approverType == 1)
: [];
// 审阅人 // 审阅人
res.examineData = res.length res.examineData = res.length ? res.filter(item => item.approverType == 2) : [];
? res.filter(item => item.approverType == 2)
: [];
this.detailInfo.referData = res.referData; this.detailInfo.referData = res.referData;
this.detailInfo.examineData = res.examineData; this.detailInfo.examineData = res.examineData;
});
getPerformanceConfigDetailAPI({ id: this.id }).then((res) => { const result = {
res.attachmentImgs = this.formatterImg(res.attachment_imgs); merchantBrandList: this.handleMerchantBrandRefList(this.params.merchantBrandRefList),
res.merchantBrandList = this.handleMerchantBrandRefList( // editApproveRemark: res.approveRemark,
res.merchantBrandRefList, schemeName: this.params.schemeName,
); effectiveMonth: this.params.effectiveMonth,
if (this.isEdit) { };
res.editApproveRemark = res.approveRemark;
res.editAttachmentImgs = []; console.log("this.merchantBrandRefList", this.merchantBrandRefList);
this.dialogConfig.title = "提交审批"; this.dialogConfig.title = "提交审批";
this.config.isShowFooter = true; this.config.isShowFooter = true;
}
this.loading = false; this.loading = false;
this.configData[0].infoData[ this.configData[0].infoData[
this.findAttrIdx("infoData", "approveRemark") this.findAttrIdx("infoData", "approveRemark")
...@@ -313,9 +326,12 @@ export default { ...@@ -313,9 +326,12 @@ export default {
this.findAttrIdx("infoData", "editAttachmentImgs") this.findAttrIdx("infoData", "editAttachmentImgs")
].isHidden = !this.isEdit; ].isHidden = !this.isEdit;
// this.detailInfo = res // this.detailInfo = res
Object.assign(this.detailInfo, res);
Object.assign(this.detailInfo, result);
console.log(this.detailInfo, "this.detailInfo"); console.log(this.detailInfo, "this.detailInfo");
this.loading = false;
}); });
}, },
getDetail() { getDetail() {
...@@ -335,27 +351,18 @@ export default { ...@@ -335,27 +351,18 @@ export default {
: []; : [];
res.merchantBrandList = this.handleMerchantBrandRefList( res.merchantBrandList = this.handleMerchantBrandRefList(
res.merchantBrandRefList, this.merchantBrandRefList,
); );
if (this.isEdit) { res.editApproveRemark = res.approveRemark;
res.editApproveRemark = res.approveRemark; res.editAttachmentImgs = [];
res.editAttachmentImgs = []; this.dialogConfig.title = "提交审批";
this.dialogConfig.title = "提交审批"; this.config.isShowFooter = true;
this.config.isShowFooter = true;
}
this.loading = false; this.loading = false;
this.configData[0].infoData[ this.configData[0].infoData[this.findAttrIdx("infoData", "approveRemark")].isHidden = !!this.isEdit;
this.findAttrIdx("infoData", "approveRemark") this.configData[0].infoData[this.findAttrIdx("infoData", "attachmentImgs")].isHidden = !!this.isEdit;
].isHidden = !!this.isEdit; this.configData[0].infoData[this.findAttrIdx("infoData", "editApproveRemark")].isHidden = !this.isEdit;
this.configData[0].infoData[ this.configData[0].infoData[this.findAttrIdx("infoData", "editAttachmentImgs")].isHidden = !this.isEdit;
this.findAttrIdx("infoData", "attachmentImgs")
].isHidden = !!this.isEdit;
this.configData[0].infoData[
this.findAttrIdx("infoData", "editApproveRemark")
].isHidden = !this.isEdit;
this.configData[0].infoData[
this.findAttrIdx("infoData", "editAttachmentImgs")
].isHidden = !this.isEdit;
this.detailInfo = res; this.detailInfo = res;
// console.log(this.detailInfo, "this.detailInfo") // console.log(this.detailInfo, "this.detailInfo")
...@@ -403,7 +410,7 @@ export default { ...@@ -403,7 +410,7 @@ export default {
return result; return result;
}, },
findAttrIdx(formName, name) { findAttrIdx(formName, name) {
let index = this.configData[0][formName].findIndex( const index = this.configData[0][formName].findIndex(
k => k.key == name, k => k.key == name,
); );
return index || 0; return index || 0;
...@@ -414,8 +421,7 @@ export default { ...@@ -414,8 +421,7 @@ export default {
formatterImg(val) { formatterImg(val) {
if (!val) if (!val)
return []; return [];
let arr = val.split(","); return val.split(",");
return arr;
}, },
// 把字面量的 \r\n / \n 转为真实换行符 // 把字面量的 \r\n / \n 转为真实换行符
formatOpinionText(opinion) { formatOpinionText(opinion) {
...@@ -441,6 +447,9 @@ export default { ...@@ -441,6 +447,9 @@ export default {
font-size: 20px; font-size: 20px;
font-weight: bold; font-weight: bold;
} }
::v-deep .merchant-brand-ref-list-col {
margin-bottom: 0 !important;
}
.operation-wrapper { .operation-wrapper {
background: #fafafa; background: #fafafa;
padding: 0 20px; padding: 0 20px;
...@@ -484,8 +493,13 @@ export default { ...@@ -484,8 +493,13 @@ export default {
} }
} }
.merchantBrand-box { .merchantBrand-box {
max-height: 300px;
overflow: auto;
.box { .box {
margin-bottom: 8px; margin-bottom: 8px;
&:last-child {
margin-bottom: 0;
}
.merchantName { .merchantName {
color: #1d1d1d; color: #1d1d1d;
font-size: 14px; font-size: 14px;
......
import { isArray, set } from "lodash-es"; import { isArray, set } from "lodash-es";
import { getPerformanceConfigDetailAPI, getTargetProductConfigListAPI, postSalaryPerformanceScheme } from "@/api/resident";
import { normalizeTree } from "@/common/treeData"; import { normalizeTree } from "@/common/treeData";
import { baseConfig } from "@/main"; import { baseConfig } from "@/main";
import { commissionTypeEnum, paramConfigListTemplate, assessmentFactorOptions as staticAssessmentFactorOptions } from "../components/performanceRuleSelection/options.js"; import { commissionTypeEnum, paramConfigListTemplate, assessmentFactorOptions as staticAssessmentFactorOptions } from "../components/performanceRuleSelection/options.js";
import { buildMerchantBrandPayload, convertDataToBackend } from "../utils/index.js";
export default { export default {
namespaced: true, namespaced: true,
...@@ -275,6 +277,49 @@ export default { ...@@ -275,6 +277,49 @@ export default {
}, },
actions: { actions: {
// 主要用这个就可以了,
async submitToSave({ state, commit, dispatch }) {
let id = -1;
console.log("state.formData.status", state.formData.status);
if (!state.formData.status) {
// 新增 || 草稿状态, 直接存 提交后返回id
id = await dispatch("fetchSave", {});
}
if ([1, 2, 3].includes(state.formData.status)) {
// 1.审批中,2.生效,3.未生效 save不带id,提交后返回新的id
// 1. 审批中不应该走到这里
id = await dispatch("fetchSave", { extendsParams: { id: undefined } });
}
return {
id,
// 不管处于什么状态进行保存, 状态都会变为草稿
// 审批中 -> 新增一条, 状态变为 草稿
// 未生效 -> 新增一条, 状态为 草稿
// 生效 -> 新增一条 , 状态为 草稿
// 草稿 -> 保存数据, 状态为 草稿
// 新增 -> 保存数据 , 状态为 草稿
status: 0,
};
},
// 直接发送 保存请求
async fetchSave({ state, commit }, { extendsParams = {} }) {
console.log("extendsParamssss", extendsParams);
const params = convertDataToBackend({
...state.formData,
merchantBrandRefList: state.merchantBrandRefList,
});
if (state.formData.id) {
params.id = state.formData.id;
}
if (state.formData.schemeType) {
params.schemeType = state.formData.schemeType;
}
const res = await postSalaryPerformanceScheme({
...params,
...extendsParams,
});
return res;
},
onBusinessTypeChange({ state, commit }, options) { onBusinessTypeChange({ state, commit }, options) {
if (isArray(state.formData.paramConfigList)) { if (isArray(state.formData.paramConfigList)) {
for (const [tableIndex, table] of state.formData.paramConfigList.entries()) { for (const [tableIndex, table] of state.formData.paramConfigList.entries()) {
......
...@@ -291,7 +291,8 @@ function coverParamsType2(ParamsType2, fn) { ...@@ -291,7 +291,8 @@ function coverParamsType2(ParamsType2, fn) {
}); });
} }
function buildMerchantBrandPayload( // 本地数据 门店品牌数据 转成后端所需格式
export function buildMerchantBrandPayload(
merchantBrandRefList, merchantBrandRefList,
businessType, businessType,
) { ) {
......
...@@ -3,96 +3,6 @@ ...@@ -3,96 +3,6 @@
*/ */
/** /**
* 校验方案名称
*/
export function validateSchemeName(rule, value, callback) {
if (!value || value.trim() === "") {
callback(new Error("请输入当前方案名称"));
} else if (value.length > 30) {
callback(new Error("方案名称不能超过30个字符"));
} else {
callback();
}
}
/**
* 校验考核因子
*/
export function validateAssessmentFactorValue(rule, value, callback) {
if (!value || value.length === 0) {
callback(new Error("请至少选择一个考核因子"));
} else {
callback();
}
}
/**
* 校验提成基数
*/
export function validateCommissionBases(rule, value, callback) {
if (!value || value.length === 0) {
callback(new Error("请至少选择一个提成基数"));
} else {
callback();
}
}
/**
* 校验提成方式
*/
export function validateCommissionTypes(rule, value, callback) {
if (!value || value.length === 0) {
callback(new Error("请至少选择一个提成方式"));
} else {
callback();
}
}
/**
* 校验商品分类
*/
export function validateGoodsConfigTypes(rule, value, callback) {
if (!value || value.length === 0) {
callback(new Error("请至少选择一个商品分类"));
} else {
callback();
}
}
/**
* 校验适配业务
*/
export function validateBusinessType(rule, value, callback) {
if (value === undefined || value === null || value === "") {
callback(new Error("请选择适配业务"));
} else {
callback();
}
}
/**
* 校验生效月份
*/
export function validateEffectiveMonth(rule, value, callback) {
if (!value || value.trim() === "") {
callback(new Error("请选择生效月份"));
} else {
callback();
}
}
/**
* 校验门店列表
*/
export function validateMerchantBrandRefList(rule, value, callback) {
if (!value || value.length === 0) {
callback(new Error("请至少选择一个门店"));
} else {
callback();
}
}
/**
* 校验参数配置列表 * 校验参数配置列表
* @param {object} formData - 表单数据 * @param {object} formData - 表单数据
*/ */
...@@ -296,25 +206,26 @@ export function validateParamConfigList(formData) { ...@@ -296,25 +206,26 @@ export function validateParamConfigList(formData) {
export function getFormRules(formData, merchantBrandRefList) { export function getFormRules(formData, merchantBrandRefList) {
return { return {
schemeName: [ schemeName: [
{ required: true, validator: validateSchemeName, trigger: "blur" }, { required: true, trigger: "blur", message: "方案名称不能为空" },
{ min: 3, max: 30, message: "方案名称长度在3-30个字符之间", trigger: "blur" },
], ],
assessmentFactorValue: [ assessmentFactorValue: [
{ required: true, validator: validateAssessmentFactorValue, trigger: "blur" }, { required: true, trigger: "change", message: "请选择考核因子" },
], ],
commissionBases: [ commissionBases: [
{ required: true, validator: validateCommissionBases, trigger: "blur" }, { required: true, trigger: "change", message: "请选择提成基数" },
], ],
commissionTypes: [ commissionTypes: [
{ required: true, validator: validateCommissionTypes, trigger: "blur" }, { required: true, trigger: "change", message: "请选择提成方式" },
], ],
goodsConfigTypes: [ goodsConfigTypes: [
{ required: true, validator: validateGoodsConfigTypes, trigger: "blur" }, { required: true, trigger: "change", message: "请选择商品分类" },
], ],
businessType: [ businessType: [
{ required: true, validator: validateBusinessType, trigger: "blur" }, { required: true, trigger: "change", message: "请选择适配业务" },
], ],
effectiveMonth: [ effectiveMonth: [
{ required: true, validator: validateEffectiveMonth, trigger: "blur" }, { required: true, trigger: "change", message: "请选择生效月份" },
], ],
}; };
} }
...@@ -28,10 +28,8 @@ ...@@ -28,10 +28,8 @@
<el-form-item label="当前方案名称:" prop="schemeName"> <el-form-item label="当前方案名称:" prop="schemeName">
<el-input v-model="schemeName" <el-input v-model="schemeName"
clearable clearable
maxlength="20"
placeholder="请输入当前方案名称" placeholder="请输入当前方案名称"
style="width:290px" style="width:290px" />
@blur="handleFieldBlur('schemeName')" />
</el-form-item> </el-form-item>
<ParamConfigList v-for="(parameter, index) in formData.paramConfigList" <ParamConfigList v-for="(parameter, index) in formData.paramConfigList"
...@@ -69,17 +67,17 @@ ...@@ -69,17 +67,17 @@
</el-button> </el-button>
</div> </div>
</el-form> </el-form>
<DetailDialog v-if="detailVisible" <DetailDialog v-if="dialog.approvalView.show"
:id="id" :detail-visible="dialog.approvalView.show"
:detail-visible="detailVisible" is-edit
:is-edit="true" :params="dialog.approvalView.params"
@dialogClose="handleCheckClose"> @dialogClose="handleCheckClose">
</DetailDialog> </DetailDialog>
</d2-container> </d2-container>
</template> </template>
<script> <script>
import { mapMutations, mapState } from "vuex"; import { mapActions, mapMutations, mapState } from "vuex";
import { getAllCategory } from "@/api/product.js"; import { getAllCategory } from "@/api/product.js";
import { getPerformanceConfigDetailAPI, getTargetProductConfigListAPI, postSalaryPerformanceScheme } from "@/api/resident"; import { getPerformanceConfigDetailAPI, getTargetProductConfigListAPI, postSalaryPerformanceScheme } from "@/api/resident";
import { import {
...@@ -91,7 +89,7 @@ import PerformanceRuleSelection from "../components/performanceRuleSelection/ind ...@@ -91,7 +89,7 @@ import PerformanceRuleSelection from "../components/performanceRuleSelection/ind
import StoreApply from "../components/storeApply/index.vue"; import StoreApply from "../components/storeApply/index.vue";
import { bindFormFields } from "../store/helper.js"; import { bindFormFields } from "../store/helper.js";
import { convertBackendToData } from "../utils/convertBackendToData.js"; import { convertBackendToData } from "../utils/convertBackendToData.js";
import { convertDataToBackend } from "../utils/index.js"; import { buildMerchantBrandPayload, convertDataToBackend } from "../utils/index.js";
import { getFormRules, validateParamConfigList } from "../utils/rules.js"; import { getFormRules, validateParamConfigList } from "../utils/rules.js";
// 提成方案配置 // 提成方案配置
export default { export default {
...@@ -116,9 +114,14 @@ export default { ...@@ -116,9 +114,14 @@ export default {
loading: { loading: {
page: false, page: false,
}, },
rules: {}, rules: getFormRules(),
detailVisible: false, dialog: {
shouldValidateAll: false, // 是否应该验证所有字段 approvalView: {
show: false,
params: {},
},
},
}; };
}, },
computed: { computed: {
...@@ -166,27 +169,48 @@ export default { ...@@ -166,27 +169,48 @@ export default {
"setParamConfigList", "setParamConfigList",
"resetFormData", "resetFormData",
]), ]),
...mapActions("PerformanceFormStore", ["submitToSave"]),
// 提交审核 // 提交审核
async handleSubmitCheck() { async handleSubmitCheck() {
this.detailVisible = !this.detailVisible; // 审批中
}, if (this.formData.status === 1) {
this.$message.warning("已存在审批中的提成方案,请审批通过后再操作");
return;
}
// 其他情况, 先校验
const valid = await this.validForm();
if (!valid) {
return;
}
// 其他状态直接弹窗,在弹窗确定后在提交保存
this.dialog.approvalView.params = convertDataToBackend({
...this.formData,
merchantBrandRefList: this.merchantBrandRefList,
});
this.dialog.approvalView.show = !this.dialog.approvalView.show;
},
// 提交保存
async handleSubmitSave() {
const valid = await this.validForm();
if (!valid) {
return;
}
const { id, status } = await this.submitToSave();
this.formData.id = id;
this.id = id;
this.formData.status = status;
this.$message.success("保存成功");
},
handleCheckClose(e) { handleCheckClose(e) {
this.detailVisible = !this.detailVisible; this.dialog.approvalView.show = !this.dialog.approvalView.show;
if (e.isConfirm) { if (e.isConfirm) {
this.handleCancelSubmit(); this.handleCancelSubmit();
} }
}, },
// 处理单个字段失焦事件,只验证当前字段 // 校验
handleFieldBlur(prop) {
if (!this.shouldValidateAll && this.$refs.form) {
this.$refs.form.validateField(prop, () => {});
}
},
async validForm() { async validForm() {
// 设置需要验证所有字段
this.shouldValidateAll = true;
const valid = await this.$refs.form.validate(); const valid = await this.$refs.form.validate();
if (!valid) { if (!valid) {
return; return;
...@@ -204,45 +228,31 @@ export default { ...@@ -204,45 +228,31 @@ export default {
} }
return true; return true;
}, },
// 提交保存
async handleSubmitSave(isConfirm = false) { async handleSave(extendsParams = {}) {
const valid = await this.validForm(); const params = convertDataToBackend({
let result = false; ...this.formData,
if (valid) { merchantBrandRefList: this.merchantBrandRefList,
try { });
const params = convertDataToBackend({ if (this.formData.id) {
...this.formData, params.id = this.formData.id;
merchantBrandRefList: this.merchantBrandRefList,
});
if (this.formData.id) {
params.id = this.formData.id;
if (this.formData.schemeType) {
params.schemeType = this.formData.schemeType;
}
}
const res = await postSalaryPerformanceScheme(params);
this.id = res;
result = true;
if (res) {
this.$message.success("保存成功");
}
if (isConfirm) {
this.handleCancelSubmit();
}
} catch (error) {
this.$message.warning("请完善表单信息");
} finally {
this.shouldValidateAll = false;
}
} }
return result; if (this.formData.schemeType) {
params.schemeType = this.formData.schemeType;
}
const res = await postSalaryPerformanceScheme({
...params,
...extendsParams,
});
return res;
}, },
// 取消按钮 // 取消按钮
handleCancelSubmit() { handleCancelSubmit() {
if (window.history.length > 1) { if (window.history.length > 1) {
this.$router.back(); this.$router.back();
} else { } else {
this.$router.replace("/salaryPerformance"); // 兜底页 this.$router.replace("/salaryPerformance");
} }
}, },
async initLoad() { async initLoad() {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!