Commit 86a0945c by 李伟康

refactor(earlyWarningManager): 优化策略相关组件代码逻辑

1. 调整批量创建策略API请求配置,新增returnAll参数
2. 移除MultipleRecording组件的biz props,通过inject获取业务类型
3. 简化AddStrategy组件传参,移除冗余的biz属性传递
4. 修复多处代码的空判断格式,补充完整代码块括号
5. 优化AddStrategy和AddTask的接口请求处理逻辑,新增对返回码和错误信息的处理
6. 删除废弃的AddTeaching组件
7. 补充AddTask组件的注入参数和初始化逻辑
1 parent c6f533d3
...@@ -412,7 +412,9 @@ export function getStrategyEffectList(data = {}) { ...@@ -412,7 +412,9 @@ export function getStrategyEffectList(data = {}) {
*/ */
export function batchCreateStrategy(data = {}) { export function batchCreateStrategy(data = {}) {
data.method = "dj.api.strategy.info.batch.create"; data.method = "dj.api.strategy.info.batch.create";
return request(data, RequestMethods.POST); return request(data, RequestMethods.POST, [], {
returnAll: true,
});
} }
/** /**
* *
......
...@@ -90,8 +90,7 @@ ...@@ -90,8 +90,7 @@
</div> </div>
<!-- 批量下发策略组件 --> <!-- 批量下发策略组件 -->
<AddStrategy :biz="currentTab.value" <AddStrategy :dialogVisible.sync="addStrategyVisible"
:dialogVisible.sync="addStrategyVisible"
:merchant-list="selectedMerchantList"> :merchant-list="selectedMerchantList">
</AddStrategy> </AddStrategy>
</div> </div>
...@@ -145,9 +144,14 @@ export default { ...@@ -145,9 +144,14 @@ export default {
}, },
provide() { provide() {
return { return {
GET_PARAMS_INFO: () => {}, GET_PARAMS_INFO: () => {
return {
bizs: this.currentTab.value,
};
},
GET_MERCHANT_NAME: () => "", GET_MERCHANT_NAME: () => "",
deepClone, deepClone,
GET_BIZ: () => this.currentTab.value,
}; };
}, },
data() { data() {
...@@ -257,8 +261,9 @@ export default { ...@@ -257,8 +261,9 @@ export default {
// 判断是否全部选中 // 判断是否全部选中
isAllSelected() { isAllSelected() {
if (this.cardList.length === 0) if (this.cardList.length === 0) {
return false; return false;
}
return this.cardList.every(item => item.checked); return this.cardList.every(item => item.checked);
}, },
...@@ -737,8 +742,9 @@ export default { ...@@ -737,8 +742,9 @@ export default {
}, },
// 格式化日期为 YYYY-MM-DD // 格式化日期为 YYYY-MM-DD
formatDate(date) { formatDate(date) {
if (!date) if (!date) {
return null; return null;
}
const d = new Date(date); const d = new Date(date);
const year = d.getFullYear(); const year = d.getFullYear();
const month = String(d.getMonth() + 1).padStart(2, "0"); const month = String(d.getMonth() + 1).padStart(2, "0");
......
...@@ -120,16 +120,6 @@ import multipleMixin from "./multipleMixin"; ...@@ -120,16 +120,6 @@ import multipleMixin from "./multipleMixin";
export default { export default {
name: "MultipleRecording", name: "MultipleRecording",
mixins: [multipleMixin], mixins: [multipleMixin],
props: {
/**
* biz: 业务类型
* 1.延保 2.轻改 3.权益 4.二手车
*/
biz: {
type: Number,
default: 1,
},
},
data() { data() {
return { return {
dialogConfig: { dialogConfig: {
......
...@@ -164,7 +164,6 @@ ...@@ -164,7 +164,6 @@
@dialogClose="staffTag1Visible = false"> @dialogClose="staffTag1Visible = false">
</MultipleStaff> </MultipleStaff>
<MultipleRecording ref="recordingTagRef" <MultipleRecording ref="recordingTagRef"
:biz="biz"
:choose-data="formData.recordingList" :choose-data="formData.recordingList"
:visible="recordingTagVisible" :visible="recordingTagVisible"
@choose="formatMultipleList($event, 'recordingList')" @choose="formatMultipleList($event, 'recordingList')"
...@@ -231,14 +230,14 @@ export default { ...@@ -231,14 +230,14 @@ export default {
type: Array, type: Array,
default: () => [], default: () => [],
}, },
/** // /**
* biz: 业务类型 // * biz: 业务类型
* 1.延保 2.轻改 3.权益 4.二手车 // * 1.延保 2.轻改 3.权益 4.二手车
*/ // */
biz: { // biz: {
type: Number, // type: Number,
default: 1, // default: 1,
}, // },
}, },
data() { data() {
return { return {
...@@ -327,7 +326,7 @@ export default { ...@@ -327,7 +326,7 @@ export default {
}, },
// 门店看板从 inject 的 paramsInfo.bizs 取;策略中心批量下发走 biz prop // 门店看板从 inject 的 paramsInfo.bizs 取;策略中心批量下发走 biz prop
currentBiz() { currentBiz() {
return this.paramsInfo?.bizs ?? this.biz; return this.paramsInfo?.bizs;
}, },
formRules() { formRules() {
const { strategyType } = this; const { strategyType } = this;
...@@ -438,6 +437,7 @@ export default { ...@@ -438,6 +437,7 @@ export default {
}, },
methods: { methods: {
init() { init() {
this.loading = false;
this.formData = this.$options.data.call(this).formData; this.formData = this.$options.data.call(this).formData;
this.$refs?.addRef?.resetFields(); this.$refs?.addRef?.resetFields();
this.viewKey = Date.now(); this.viewKey = Date.now();
...@@ -552,14 +552,18 @@ export default { ...@@ -552,14 +552,18 @@ export default {
}; };
}); });
} }
const data = await batchCreateStrategy(params); const { code, data, message } = await batchCreateStrategy(params);
this.loading = false; this.loading = false;
if (data) { if (code == 0) {
this.$emit("refresh"); if (data) {
this.$message.success("操作成功"); this.$emit("refresh");
this.close(); this.$message.success("操作成功");
this.close();
} else {
this.$message.error("操作失败");
}
} else { } else {
this.$message.error("操作失败"); this.$message.error(message);
} }
} else { } else {
this.loading = false; this.loading = false;
......
...@@ -56,8 +56,9 @@ export default { ...@@ -56,8 +56,9 @@ export default {
if (val) { if (val) {
this.searchForm = this.$options.data.call(this).searchForm; this.searchForm = this.$options.data.call(this).searchForm;
let multipleTable = this.multipleTable(); let multipleTable = this.multipleTable();
if (multipleTable) if (multipleTable) {
multipleTable.page.currentPage = 1; multipleTable.page.currentPage = 1;
}
this.chooseList = this.deepClone(this.chooseData); this.chooseList = this.deepClone(this.chooseData);
this.viewKey = Date.now(); this.viewKey = Date.now();
} }
...@@ -123,8 +124,9 @@ export default { ...@@ -123,8 +124,9 @@ export default {
let { chooseList, targetId } = this; let { chooseList, targetId } = this;
chooseList.map((item) => { chooseList.map((item) => {
let index = data.findIndex(i => i[targetId] === item[targetId]); let index = data.findIndex(i => i[targetId] === item[targetId]);
if (index > -1) if (index > -1) {
this.multipleTable().tableRef.toggleRowSelection(data[index], true); this.multipleTable().tableRef.toggleRowSelection(data[index], true);
}
}); });
}); });
}, },
...@@ -148,8 +150,9 @@ export default { ...@@ -148,8 +150,9 @@ export default {
let index = list.findIndex(i => i[targetId] === row[targetId]); let index = list.findIndex(i => i[targetId] === row[targetId]);
if (index == -1) { if (index == -1) {
let delIndex = this.chooseList.findIndex(i => i[targetId] === row[targetId]); let delIndex = this.chooseList.findIndex(i => i[targetId] === row[targetId]);
if (delIndex > -1) if (delIndex > -1) {
this.chooseList.splice(delIndex, 1); this.chooseList.splice(delIndex, 1);
}
} }
}, },
selectAll(list) { selectAll(list) {
......
...@@ -242,6 +242,7 @@ export default { ...@@ -242,6 +242,7 @@ export default {
GET_MERCHANT_LIST: () => [], GET_MERCHANT_LIST: () => [],
GET_BIZ: () => this.biz, GET_BIZ: () => this.biz,
DEL_PARAMS_MERCHANT_LIST: () => false, DEL_PARAMS_MERCHANT_LIST: () => false,
GET_POSITION_TYPE_LIST_SALE: () => this.positionTypeListSale,
}; };
}, },
props: { props: {
...@@ -297,6 +298,8 @@ export default { ...@@ -297,6 +298,8 @@ export default {
staffTagVisible: false, staffTagVisible: false,
positionTypeList: [0], // 0:驻店人员 positionTypeList: [0], // 0:驻店人员
executorList: [], // 区域运营列表 executorList: [], // 区域运营列表
positionTypeListSale: null,
}; };
}, },
computed: { computed: {
...@@ -361,6 +364,7 @@ export default { ...@@ -361,6 +364,7 @@ export default {
}, },
methods: { methods: {
init() { init() {
this.loading = false;
this.formData = { this.formData = {
taskType: "", taskType: "",
taskTitle: "", taskTitle: "",
...@@ -468,14 +472,18 @@ export default { ...@@ -468,14 +472,18 @@ export default {
if (allStaffs.length) { if (allStaffs.length) {
params.staffList = allStaffs; params.staffList = allStaffs;
} }
const data = await batchCreateStrategy(params); const { code, data, message } = await batchCreateStrategy(params);
this.loading = false; this.loading = false;
if (data) { if (code == 0) {
this.$emit("refresh"); if (data) {
this.$message.success("操作成功"); this.$emit("refresh");
this.close(); this.$message.success("操作成功");
this.close();
} else {
this.$message.error("操作失败");
}
} else { } else {
this.$message.error("操作失败"); this.$message.error(message);
} }
} else { } else {
this.loading = false; this.loading = false;
......
<template>
<el-drawer ref="drawer"
class="strategy-drawer"
size="50vw"
:visible.sync="dialogShow"
:wrapper-closable="false"
@close="close">
<template #title>
<div class="strategy-drawer-title">
添加带教申请
</div>
</template>
<div class="strategy-drawer-content">
<el-scrollbar class="content">
<el-form ref="form"
class="form"
label-width="110px"
size="small"
:model="formData"
:rules="rules">
<el-form-item label="需带教人员:" prop="staffList">
<el-button size="small" @click="openStaffDialog">
选择人员
</el-button>
<div v-if="formData.staffList && formData.staffList.length > 0" class="tags-container">
<el-tag v-for="(item, index) in formData.staffList"
:key="item.staffUuid"
class="staff-tag"
closable
@close="removeStaff(index)">
{{ item.staffName }}
</el-tag>
</div>
</el-form-item>
<el-form-item label="申请说明:" prop="description">
<el-input v-model="formData.description"
maxlength="200"
placeholder="请输入申请说明"
type="textarea"
:rows="6">
</el-input>
</el-form-item>
</el-form>
</el-scrollbar>
<div class="footer">
<el-button v-preventReClick
size="small"
@click="close">
取消
</el-button>
<el-button size="small"
type="primary"
:loading="loading"
@click="confirm">
确定
</el-button>
</div>
</div>
<MultipleStaff ref="staffTagRef"
:choose-data="formData.staffList"
:visible="staffTagVisible"
@choose="handleStaffChoose"
@dialogClose="staffTagVisible = false">
</MultipleStaff>
</el-drawer>
</template>
<script>
import { batchCreateStrategy } from "@/api/earlyWarningManager";
import MultipleStaff from "../AddStrategy/MultipleStaff.vue";
export default {
name: "AddTeaching",
components: {
MultipleStaff,
},
inject: ["GET_PARAMS_INFO", "GET_MERCHANT_NAME"],
provide() {
return {
GET_POSITION_TYPE_LIST: () => this.positionTypeList,
GET_MERCHANT_LIST: () => [],
GET_BIZ: () => this.biz,
DEL_PARAMS_MERCHANT_LIST: () => false,
};
},
props: {
visibleSync: {
type: Boolean,
default: false,
},
biz: {
type: Number,
default: 1,
},
},
data() {
return {
loading: false,
formData: {
staffList: [],
description: "",
},
rules: {
staffList: [
{ type: "array", required: true, message: "请选择需带教人员", trigger: "change" },
],
description: [
{ required: true, message: "请输入申请说明", trigger: "blur" },
],
},
staffTagVisible: false,
positionTypeList: [0], // 0:驻店人员
};
},
computed: {
dialogShow: {
get() {
return this.visibleSync;
},
set(val) {
this.$emit("update:visibleSync", val);
},
},
paramsInfo() {
return this.GET_PARAMS_INFO && this.GET_PARAMS_INFO();
},
merchantName() {
return this.GET_MERCHANT_NAME && this.GET_MERCHANT_NAME();
},
},
watch: {
visibleSync(val) {
if (val) {
this.init();
}
},
},
methods: {
init() {
this.formData = {
staffList: [],
description: "",
};
this.$nextTick(() => {
if (this.$refs.form) {
this.$refs.form.clearValidate();
}
});
},
close() {
this.dialogShow = false;
},
openStaffDialog() {
this.staffTagVisible = true;
},
removeStaff(index) {
this.formData.staffList.splice(index, 1);
},
handleStaffChoose(list) {
this.formData.staffList = list;
this.$refs.form.validateField("staffList");
},
confirm() {
try {
this.loading = true;
const { paramsInfo, merchantName, formData, biz } = this;
const { staffList, description } = formData;
this.$refs.form.validate(async (valid) => {
if (valid) {
const params = {
strategyInfo: {
strategyType: 8,
biz,
description,
},
merchantList: [
{
merchantId: paramsInfo.merchantIds[0],
merchantName,
},
],
};
if (staffList && staffList.length) {
if (staffList.length > 100) {
this.loading = false;
this.$message.error("最多只能选择100个人员");
return;
}
params.staffList = staffList.map((e) => {
return {
userUuid: e.staffUuid,
userName: e.staffName,
userPhone: e.phoneNumber,
userPosition: e.positionType,
};
});
}
const data = await batchCreateStrategy(params);
this.loading = false;
if (data) {
this.$emit("refresh");
this.$message.success("操作成功");
this.close();
} else {
this.$message.error("操作失败");
}
} else {
this.loading = false;
}
});
} catch (error) {
console.log(error, "===");
this.loading = false;
if (error)
this.$message.error(error);
console.log(error);
}
},
},
};
</script>
<style scoped lang="scss">
::v-deep.strategy-drawer {
.el-drawer__header {
padding: 0;
margin: 0;
border-bottom: 1px solid #e5e5e5;
}
.el-drawer__close-btn {
padding: 0 20px;
.el-dialog__close {
font-weight: 700;
font-size: 24px;
}
}
&-title {
height: 26px;
line-height: 26px;
color: #333333;
font-size: 18px;
padding: 17px 20px;
font-weight: bold;
}
&-content {
height: calc(100vh - 61px);
.content {
height: calc(100% - 61px);
.form {
padding: 20px;
.tags-container {
margin-top: 10px;
padding: 10px;
border: 1px solid #e4e7ed;
border-radius: 4px;
min-height: 40px;
max-height: 120px;
overflow-y: auto;
display: flex;
flex-wrap: wrap;
gap: 8px;
}
.staff-tag {
margin-right: 0;
}
}
}
.footer {
padding: 14px 0;
border-top: 1px solid #e5e5e5;
display: flex;
justify-content: flex-end;
padding-right: 20px;
}
}
}
</style>
\ No newline at end of file \ No newline at end of file
...@@ -56,8 +56,7 @@ ...@@ -56,8 +56,7 @@
:item="currentItem" :item="currentItem"
@openReceptionDialog="$emit('openReceptionDialog', $event)"> @openReceptionDialog="$emit('openReceptionDialog', $event)">
</StrategyDetail> </StrategyDetail>
<AddStrategy :biz="paramsInfo.bizs" <AddStrategy :dialogVisible.sync="addStrategyVisible"
:dialogVisible.sync="addStrategyVisible"
@refresh="init"> @refresh="init">
</AddStrategy> </AddStrategy>
<TeachingDetail :item="currentItem" <TeachingDetail :item="currentItem"
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!