Commit 9afa942a authored by xinzhedeai's avatar xinzhedeai

add:员工 部门列表 岗位下拉

parent cbed1d6f
...@@ -13,8 +13,8 @@ export function getDept(data) { ...@@ -13,8 +13,8 @@ export function getDept(data) {
export function getPosition(data) { export function getPosition(data) {
return request({ return request({
url: '/pos/list', url: '/pos/list',
method: 'post', method: 'get',
data: data params: data
}) })
} }
......
...@@ -143,19 +143,15 @@ ...@@ -143,19 +143,15 @@
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col :span="12"> <el-col :span="12">
<el-form-item label="所在部门" prop="cardId"> <el-form-item label="所在部门" prop="deptId">
<el-select <el-cascader
v-model="form.cardId" v-model="form.deptPath"
:options="deptOptions"
:props="cascaderProps"
placeholder="请选择所在部门" placeholder="请选择所在部门"
clearable clearable
> @change="handleDeptChange"
<el-option ></el-cascader>
v-for="item in deptOptions"
:key="item.value"
:label="item.label"
:value="item.value"
></el-option>
</el-select>
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col :span="12"> <el-col :span="12">
...@@ -166,10 +162,10 @@ ...@@ -166,10 +162,10 @@
clearable clearable
> >
<el-option <el-option
v-for="item in cardIdOptions" v-for="item in positionOptions"
:key="item.cardId" :key="item.value"
:label="item.cardId" :label="item.label"
:value="item.cardId" :value="item.value"
></el-option> ></el-option>
</el-select> </el-select>
</el-form-item> </el-form-item>
...@@ -306,6 +302,12 @@ export default { ...@@ -306,6 +302,12 @@ export default {
name: "Info", name: "Info",
data() { data() {
return { return {
// 级联选择器配置
cascaderProps: {
value: "index",
label: "name",
children: "children",
},
deptOptions: [ deptOptions: [
{ {
label: "部门1", label: "部门1",
...@@ -386,7 +388,6 @@ export default { ...@@ -386,7 +388,6 @@ export default {
this.getPersonTypeOptions(); this.getPersonTypeOptions();
// 获取部门列表 // 获取部门列表
this.getDeptList(); this.getDeptList();
// 获取岗位列表 // 获取岗位列表
this.getPositionList(); this.getPositionList();
// 获取定位卡号列表 // 获取定位卡号列表
...@@ -394,31 +395,120 @@ export default { ...@@ -394,31 +395,120 @@ export default {
}, },
methods: { methods: {
/** 递归处理部门树,转换为级联选择器需要的格式 */
processDepartmentTreeForCascader(departments) {
// 直接返回处理后的部门树,不需要扁平化
return departments.map((dept) => {
const processedDept = {
index: dept.index,
name: dept.name,
children: [],
};
// 如果有子部门,递归处理
if (dept.children && dept.children.length > 0) {
processedDept.children = this.processDepartmentTreeForCascader(
dept.children
);
} else {
// 如果没有子部门,设置为null
processedDept.children = null;
}
return processedDept;
});
},
/** 获取部门列表 */
getDeptList() {
getDept({})
.then((response) => {
console.log(response.data, "部门数据");
// 检查数据格式是否正确
if (
response.data &&
Array.isArray(response.data) &&
response.data.length > 0
) {
// 获取根节点的子部门并处理为级联格式
const rootChildren = response.data[0].children || [];
this.deptOptions =
this.processDepartmentTreeForCascader(rootChildren);
} else {
this.deptOptions = [];
console.error("部门数据格式不正确");
}
})
.catch((error) => {
console.error("获取部门列表失败:", error);
this.deptOptions = [];
});
},
/** 处理部门选择变化 */
handleDeptChange(value) {
if (value && value.length > 0) {
// 保存最后一级的部门ID作为deptId
this.form.deptId = value[value.length - 1];
// 查找选择的部门对象,获取部门名称
if (this.deptOptions && this.deptOptions.length > 0) {
let selectedDept = this.findDeptById(
this.deptOptions,
this.form.deptId
);
if (selectedDept) {
this.form.deptName = selectedDept.name;
}
}
} else {
this.form.deptId = null;
this.form.deptName = null;
}
},
/** 根据ID查找部门对象 */
findDeptById(departments, targetId) {
for (const dept of departments) {
if (dept.index === targetId) {
return dept;
}
if (dept.children && dept.children.length > 0) {
const found = this.findDeptById(dept.children, targetId);
if (found) {
return found;
}
}
}
return null;
},
/** 获取岗位列表 */ /** 获取岗位列表 */
getPositionList() { getPositionList() {
getPosition({ getPosition({
pageNum: 1, pageNum: 1,
pageSize: 1000, pageSize: 1000,
}).then((response) => { }).then((response) => {
console.log(response.data); console.log(response.data, "22222");
this.positionOptions = response.data.map((item) => ({ this.positionOptions = response.data.map((item) => ({
label: item.posName, label: item.posName,
value: item.posId, value: item.id,
})); }));
}); });
}, },
/** 获取部门列表 */ /** 获取部门列表 */
getDeptList() { // getDeptList() {
getDept({ // getDept({
pageNum: 1, // pageNum: 1,
pageSize: 1000, // pageSize: 1000,
}).then((response) => { // }).then((response) => {
this.deptOptions = response.data.map((item) => ({ // console.log(response.data, "33333");
label: item.deptName, // this.deptOptions = response.data.data[0].children.map((item) => ({
value: item.deptId, // label: item.deptName,
})); // value: item.deptId,
}); // }));
}, // });
// },
/** 解绑卡按钮操作 */ /** 解绑卡按钮操作 */
handleUnbindCard(row) { handleUnbindCard(row) {
this.$modal this.$modal
...@@ -637,7 +727,7 @@ export default { ...@@ -637,7 +727,7 @@ export default {
submitForm() { submitForm() {
this.$refs["form"].validate((valid) => { this.$refs["form"].validate((valid) => {
if (valid) { if (valid) {
this.form.personType = "staff"; this.form.personType = "1";
// 创建一个表单数据的副本,避免直接修改原表单 // 创建一个表单数据的副本,避免直接修改原表单
const formData = { ...this.form }; const formData = { ...this.form };
...@@ -652,7 +742,7 @@ export default { ...@@ -652,7 +742,7 @@ export default {
(item) => item.value === formData.deptId (item) => item.value === formData.deptId
); );
if (deptItem) { if (deptItem) {
formData.deptName = deptItem.label; // 添加部门名称参数 formData.deptName = deptItem.label.replace(/^├─/, ""); // 移除前缀后作为部门名称
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment