Commit 002261de by chenwq

feat(销售管理): 添加大区人员编辑功能

- 新增 updateRegionUser API 接口用于更新大区人员信息
- 创建 editOrganize.vue 组件实现大区人员编辑页面
- 修改 organize/index.vue 跳转逻辑,传递 regionName 和 userList 参数
- 实现人员互斥选择逻辑,确保区域运营和销售人员不重复
1 parent 2b6ae2e8
...@@ -29,3 +29,9 @@ export function regionUserList(data) { ...@@ -29,3 +29,9 @@ export function regionUserList(data) {
data.method = 'dj.api.smartcarlife.sale.region.userList' data.method = 'dj.api.smartcarlife.sale.region.userList'
return request(data, "post") return request(data, "post")
} }
// 更新大区人员
export function updateRegionUser(data) {
data.method = 'dj.api.smartcarlife.sale.region.updateRegionUser'
return request(data, "post")
}
<!-- 编辑 - 组织架构信息 -->
<template>
<d2-container class="edit-page edit-tmpl">
<div style="padding: 20px">
<glsx-combi-form class="edit-form-container" ref="editFormRef" label-width="250px" default-width="314px" :isBlock="isBlock" :form-ref="editChildRef" :form-obj="editData" :form-data="editFormData" :form-rules="formRules">
</glsx-combi-form>
<div class="footer">
<el-button @click="handleConfirm" type="primary" :loading="$store.state.d2admin.loading.value">提交</el-button>
<el-button @click="handleCancel">取消</el-button>
</div>
</div>
</d2-container>
</template>
<script>
import { deepClone } from "@/common/util"
import { regionUserList, updateRegionUser } from '@api/salesManagement'
export default {
name: "EditOrganize",
data() {
return {
editChildRef: "editChildRef",
isBlock: true,
routeInfo: {},
// 控制“对账字段”,确保拿到已选数据
showTmpl: false,
tmplSelectList: [],
formRules: {
regionName: [{ required: true, message: "请输入大区名称" }]
},
editData: {
regionName: '',
operateUserId: '',
salesList: []
},
editFormData: [
{
label: "大区名称",
name: "regionName",
type: "input",
maxlength: 100,
isDisabled: true
}, {
label: '区域运营',
name: 'operateUserId',
type: 'select',
isClear: true,
optionList: [],
optionId: 'uuid',
optionLabel: 'staffName',
optionsName: 'operateUserOpt',
changeAttr: (value, targetItem) => {
console.log(value, targetItem)
this.editData.operateUserId = value
this.dealListDisable()
}
}, {
label: '销售人员',
name: 'salesList',
type: 'select',
isClear: true,
multiple: true,
optionList: [],
optionId: 'uuid',
optionLabel: 'staffName',
optionsName: 'salesPersonOpt',
changeAttr: (value, targetItem) => {
console.log(value, targetItem)
this.editData.salesList = value
this.dealListDisable()
}
}
],
selectedStaffList: [],
baseData: {
staffList: [],
operateUserOpt: [],
salesPersonOpt: []
}
}
},
mounted() {
this.routeInfo.userList = this.$route.query.userList || []
this.editData.id = this.$route.query.id
this.editData.regionName = this.$route.query.regionName
this.getregionUserList()
this.getOptionsList("editFormData", false)
},
methods: {
getregionUserList() {
regionUserList({}).then((res) => {
this.baseData.staffList = deepClone(res.staffList)
this.baseData.operateUserOpt = deepClone(res.staffList)
this.baseData.salesPersonOpt = deepClone(res.staffList)
this.selectedStaffList = res.selectedStaffList
this.dealRegionList()
})
},
dealListDisable() {
// 其他大区已选的人,在当前大区不能再选
const otherRegionSelectList = this.selectedStaffList.filter(item => item.regionId != this.editData.id).map(item => item.userId)
this.baseData.operateUserOpt.forEach((item, idx) => {
if (otherRegionSelectList.includes(item.uuid)) {
this.baseData.operateUserOpt[idx].isDisabled = true
} else {
// 本大区下,已选的销售人员,不能再选为区域运营
this.baseData.operateUserOpt[idx].isDisabled = !!this.editData.salesList.includes(item.uuid)
}
})
this.baseData.salesPersonOpt.forEach((item, idx) => {
if (otherRegionSelectList.includes(item.uuid)) {
this.baseData.salesPersonOpt[idx].isDisabled = true
} else {
// 本大区下,已选的区域运营,不能再选为销售人员
this.baseData.salesPersonOpt[idx].isDisabled = this.editData.operateUserId == item.uuid
}
})
this.getOptionsList('editFormData', false)
console.log(this.editFormData)
},
dealRegionList() {
const existUserList = this.baseData.salesPersonOpt.map(item => item.uuid)
// userType 人员类型(1.大区经理,2.销售人员)
this.routeInfo.userList.forEach(item => {
if (existUserList.includes(item.userId)) {
if (item.userType === 1) {
this.editData.operateUserId = item.userId
}
if (item.userType === 2) {
this.editData.salesList.push(item.userId)
}
}
})
this.dealListDisable()
},
getOptionsList(formName, hasAll = true, refreshSigle) {
if (refreshSigle) {
var item = this[formName].find(k => k.name == refreshSigle)
var index = this[formName].findIndex(k => k.name == refreshSigle)
this.$set(this[formName][index], 'optionList', deepClone(this.baseData[item.optionsName]))
if (hasAll && this.baseData[item.optionsName].length && this.baseData[item.optionsName][0][this[formName][index].optionLabel] !== '全部') {
const temp = {}
temp[this[formName][index].optionId] = ''
temp[this[formName][index].optionLabel] = '全部'
this[formName][index].optionList.unshift(temp)
}
} else {
this[formName].forEach((item, index) => {
if (['select', 'radio'].includes(item.type) && this.baseData[item.optionsName].length) {
this.$set(this[formName][index], 'optionList', deepClone(this.baseData[item.optionsName]))
if (hasAll && this.baseData[item.optionsName].length && this.baseData[item.optionsName][0][this[formName][index].optionLabel] !== '全部') {
const temp = {}
temp[this[formName][index].optionId] = ''
temp[this[formName][index].optionLabel] = '全部'
this[formName][index].optionList.unshift(temp)
}
}
})
}
},
findInfo(uuid) {
return this.baseData.staffList.find(item => item.uuid === uuid) || {}
},
getParams() {
const params = {
id: this.editData.id,
userList: []
}
if (this.editData.operateUserId) {
params.userList.push({
userId: this.editData.operateUserId,
// 人员类型(1.大区经理,2.销售人员)
userType: 1,
userName: this.findInfo(this.editData.operateUserId).staffName || '',
userPhone: this.findInfo(this.editData.operateUserId).staffPhone || ''
})
}
this.editData.salesList.forEach(item => {
params.userList.push({
userId: item,
// 人员类型(1.大区经理,2.销售人员)
userType: 2,
userName: this.findInfo(item).staffName || '',
userPhone: this.findInfo(item).staffPhone || ''
})
})
return params
},
handleConfirm() {
this.$refs.editFormRef.$refs[this.editChildRef].validate((valid) => {
if (valid) {
const params = this.getParams()
console.log(params)
updateRegionUser(params).then(res => {
console.log(res)
this.$message.success("操作成功")
this.handleCancel()
})
}
})
},
// 取消按钮返回列表页
handleCancel() {
this.$router.push({
name: "organize"
})
}
}
}
</script>
<style lang="scss" scoped>
.edit-page.edit-tmpl {
margin: 0 20px 20px;
background: #ffffff;
.title {
height: 50px;
line-height: 50px;
padding: 0 20px;
border-bottom: 1px solid #e5e5e5;
font-size: 16px;
font-weight: 600;
color: #333333;
}
}
.edit-tmpl {
.add-mer-btn {
margin-left: 12px;
}
}
.footer {
text-align: center;
}
</style>
...@@ -66,12 +66,12 @@ export default { ...@@ -66,12 +66,12 @@ export default {
methods: { methods: {
handleEdit(row = {}) { handleEdit(row = {}) {
const editType = row?.id ? 'edit' : 'add'
this.$router.push({ this.$router.push({
name: "editOrganize", name: "editOrganize",
query: { query: {
editType: editType, id: row?.id || '',
id: row?.id || '' regionName: row?.regionName || '',
userList: row?.userList || []
} }
}) })
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!