feat:部门选择
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import { defineStore } from 'pinia'
|
||||
|
||||
const defaultState = () => ({
|
||||
show: false,
|
||||
@@ -7,60 +7,69 @@ const defaultState = () => ({
|
||||
selectedCompanyId: null,
|
||||
selectedDeptId: null,
|
||||
onConfirm: null,
|
||||
onCancel: null,
|
||||
});
|
||||
onCancel: null
|
||||
})
|
||||
|
||||
const companyDeptStore = defineStore({
|
||||
id: 'company-dept',
|
||||
state: defaultState,
|
||||
actions: {
|
||||
open({ companyList = [], onConfirm = null, onCancel = null, defaultCompanyId = null, defaultDeptId = null, title = null }) {
|
||||
this.companyList = companyList;
|
||||
this.onConfirm = onConfirm;
|
||||
this.onCancel = onCancel;
|
||||
this.title = title || '请选择当前业务办理归属的公司部门信息';
|
||||
this.show = true;
|
||||
this.selectedCompanyId = defaultCompanyId;
|
||||
this.selectedDeptId = defaultDeptId;
|
||||
open({
|
||||
companyList = [],
|
||||
onConfirm = null,
|
||||
onCancel = null,
|
||||
defaultCompanyId = null,
|
||||
defaultDeptId = null,
|
||||
title = null
|
||||
}) {
|
||||
this.companyList = companyList
|
||||
this.onConfirm = onConfirm
|
||||
this.onCancel = onCancel
|
||||
this.title = title || '请选择当前业务办理归属的公司部门信息'
|
||||
this.show = true
|
||||
this.selectedCompanyId = defaultCompanyId
|
||||
this.selectedDeptId = defaultDeptId
|
||||
if (!this.selectedCompanyId && this.companyList.length > 0) {
|
||||
this.selectedCompanyId = this.companyList[0].companyId;
|
||||
this.selectedCompanyId = this.companyList[0].companyId
|
||||
}
|
||||
if (!this.selectedDeptId) {
|
||||
const depts = this.getDeptsByCompanyId(this.selectedCompanyId);
|
||||
this.selectedDeptId = depts.length > 0 ? depts[0].deptId : null;
|
||||
const depts = this.getDeptsByCompanyId(this.selectedCompanyId)
|
||||
this.selectedDeptId = depts.length > 0 ? depts[0].deptId : null
|
||||
}
|
||||
},
|
||||
close() {
|
||||
Object.assign(this, defaultState());
|
||||
this.show = false
|
||||
},
|
||||
getDeptsByCompanyId(companyId) {
|
||||
const company = this.companyList.find((item) => item.companyId === companyId);
|
||||
return company?.depts || [];
|
||||
const company = this.companyList.find(item => item.companyId === companyId)
|
||||
return company?.depts || []
|
||||
},
|
||||
setSelectedCompany(companyId) {
|
||||
this.selectedCompanyId = companyId;
|
||||
const depts = this.getDeptsByCompanyId(companyId);
|
||||
const currentDeptIds = depts.map((dept) => dept.deptId);
|
||||
console.log(companyId)
|
||||
|
||||
this.selectedCompanyId = companyId
|
||||
const depts = this.getDeptsByCompanyId(companyId)
|
||||
const currentDeptIds = depts.map(dept => dept.deptId)
|
||||
if (!currentDeptIds.includes(this.selectedDeptId)) {
|
||||
this.selectedDeptId = depts.length > 0 ? depts[0].deptId : null;
|
||||
this.selectedDeptId = depts.length > 0 ? depts[0].deptId : null
|
||||
}
|
||||
},
|
||||
setSelectedDept(deptId) {
|
||||
this.selectedDeptId = deptId;
|
||||
this.selectedDeptId = deptId
|
||||
},
|
||||
confirm() {
|
||||
if (this.onConfirm) {
|
||||
this.onConfirm({ companyId: this.selectedCompanyId, deptId: this.selectedDeptId });
|
||||
this.onConfirm({ companyId: this.selectedCompanyId, deptId: this.selectedDeptId })
|
||||
}
|
||||
this.close();
|
||||
this.close()
|
||||
},
|
||||
cancel() {
|
||||
if (this.onCancel) {
|
||||
this.onCancel();
|
||||
this.onCancel()
|
||||
}
|
||||
this.close();
|
||||
},
|
||||
},
|
||||
});
|
||||
this.close()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
export default companyDeptStore;
|
||||
export default companyDeptStore
|
||||
|
||||
Reference in New Issue
Block a user