优化考勤系统的班组编辑功能
parent
ee10019aa1
commit
00d696e516
|
@ -5,26 +5,28 @@ Component({
|
||||||
*/
|
*/
|
||||||
properties: {
|
properties: {
|
||||||
title: {
|
title: {
|
||||||
type:String
|
type: String,
|
||||||
},
|
},
|
||||||
index: {
|
index: {
|
||||||
type:String
|
type: String,
|
||||||
},
|
},
|
||||||
choose: {
|
choose: {
|
||||||
type:String
|
type: String,
|
||||||
},
|
},
|
||||||
multiple: {
|
multiple: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
value:true
|
value: true,
|
||||||
},
|
},
|
||||||
rectifierData: {
|
rectifierData: {
|
||||||
type: Array,
|
type: Array,
|
||||||
value:[]
|
value: [],
|
||||||
}
|
observer: function (newVal, oldVal) {
|
||||||
|
// 当rectifierData变化时,重新初始化选中状态
|
||||||
|
this.initSelectedData(newVal);
|
||||||
},
|
},
|
||||||
observers: {
|
|
||||||
|
|
||||||
},
|
},
|
||||||
|
},
|
||||||
|
observers: {},
|
||||||
lifetimes: {
|
lifetimes: {
|
||||||
created: function () {
|
created: function () {
|
||||||
//在组件实例刚刚被创建时执行,注意此时不能调用 setData
|
//在组件实例刚刚被创建时执行,注意此时不能调用 setData
|
||||||
|
@ -34,6 +36,8 @@ Component({
|
||||||
},
|
},
|
||||||
ready: function () {
|
ready: function () {
|
||||||
// 在组件在视图层布局完成后执行
|
// 在组件在视图层布局完成后执行
|
||||||
|
// 初始化选中数据
|
||||||
|
this.initSelectedData(this.data.rectifierData);
|
||||||
},
|
},
|
||||||
detached: function () {
|
detached: function () {
|
||||||
// 在组件实例被从页面节点树移除时执行
|
// 在组件实例被从页面节点树移除时执行
|
||||||
|
@ -46,85 +50,136 @@ Component({
|
||||||
data: {
|
data: {
|
||||||
show: false,
|
show: false,
|
||||||
gridData: [],
|
gridData: [],
|
||||||
selectedIndex:[]
|
selectedIndex: [],
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 组件的方法列表
|
* 组件的方法列表
|
||||||
*/
|
*/
|
||||||
methods: {
|
methods: {
|
||||||
|
// 初始化选中数据
|
||||||
|
initSelectedData(rectifierData) {
|
||||||
|
if (!rectifierData || rectifierData.length === 0) return;
|
||||||
|
|
||||||
|
let selectedIndex = [];
|
||||||
|
let chooses = "";
|
||||||
|
|
||||||
|
// 遍历数据,查找已选中的用户
|
||||||
|
rectifierData.forEach((group, groupIndex) => {
|
||||||
|
if (group.userList && group.userList.length > 0) {
|
||||||
|
group.userList.forEach((user, userIndex) => {
|
||||||
|
if (user.state === true) {
|
||||||
|
// 记录选中项的索引
|
||||||
|
selectedIndex.push(groupIndex + "_" + userIndex);
|
||||||
|
|
||||||
|
// 构建显示文本
|
||||||
|
let post = user.userPostName
|
||||||
|
? " [" + user.userPostName + "]"
|
||||||
|
: "";
|
||||||
|
chooses += "," + user.userName + post;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 更新数据
|
||||||
|
this.setData({
|
||||||
|
selectedIndex: selectedIndex,
|
||||||
|
choose: chooses ? chooses.substring(1) : "",
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
onAddResponsible() {
|
onAddResponsible() {
|
||||||
this.setData({
|
this.setData({
|
||||||
show:true
|
show: true,
|
||||||
})
|
});
|
||||||
},
|
},
|
||||||
onClose() {
|
onClose() {
|
||||||
this.setData({
|
this.setData({
|
||||||
show:false
|
show: false,
|
||||||
})
|
});
|
||||||
},
|
},
|
||||||
onSelected(e) {
|
onSelected(e) {
|
||||||
var data = this.data.rectifierData;
|
// 使用深拷贝避免直接修改原始数据
|
||||||
|
const data = JSON.parse(JSON.stringify(this.data.rectifierData));
|
||||||
let ei = e.currentTarget.dataset.index;
|
let ei = e.currentTarget.dataset.index;
|
||||||
let index = ei.split('_');
|
let index = ei.split("_");
|
||||||
let userdata = data[index[0]].userList[index[1]];
|
let userdata = data[index[0]].userList[index[1]];
|
||||||
let of = this.data.selectedIndex.indexOf(ei);
|
let selectedIndex = [...this.data.selectedIndex];
|
||||||
|
let of = selectedIndex.indexOf(ei);
|
||||||
|
|
||||||
if (of > -1) {
|
if (of > -1) {
|
||||||
this.data.selectedIndex.splice(of, 1);
|
// 取消选中
|
||||||
|
selectedIndex.splice(of, 1);
|
||||||
userdata.state = false;
|
userdata.state = false;
|
||||||
} else {
|
} else {
|
||||||
this.data.selectedIndex.push(ei);
|
// 选中
|
||||||
userdata.state = true;
|
if (!this.data.multiple) {
|
||||||
}
|
// 单选模式,清空之前选中的项
|
||||||
if(!this.data.multiple && this.data.selectedIndex.length>0){
|
selectedIndex.forEach((item) => {
|
||||||
if(this.data.selectedIndex.length>1){
|
let _indexs = item.split("_");
|
||||||
this.data.selectedIndex.forEach((item) =>{
|
|
||||||
let _indexs = item.split('_');
|
|
||||||
data[_indexs[0]].userList[_indexs[1]].state = false;
|
data[_indexs[0]].userList[_indexs[1]].state = false;
|
||||||
});
|
});
|
||||||
|
selectedIndex = [ei];
|
||||||
|
} else {
|
||||||
|
// 多选模式
|
||||||
|
selectedIndex.push(ei);
|
||||||
|
}
|
||||||
userdata.state = true;
|
userdata.state = true;
|
||||||
this.data.selectedIndex=[];
|
|
||||||
this.data.selectedIndex.push(ei);
|
|
||||||
}
|
}
|
||||||
let _post="";
|
|
||||||
if(userdata.userPostName){
|
// 如果是单选模式且有选中项,直接触发事件并关闭弹窗
|
||||||
_post = " ["+userdata.userPostName+"]";
|
if (!this.data.multiple && selectedIndex.length > 0) {
|
||||||
}
|
let _post = userdata.userPostName
|
||||||
let _gridData=[{'userId':userdata.userId,'userName':userdata.userName+_post,'userPhone':userdata.userPhone}];
|
? " [" + userdata.userPostName + "]"
|
||||||
this.triggerEvent('selected',_gridData)
|
: "";
|
||||||
|
let _gridData = [
|
||||||
|
{
|
||||||
|
userId: userdata.userId,
|
||||||
|
userName: userdata.userName + _post,
|
||||||
|
userPhone: userdata.userPhone,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
this.triggerEvent("selected", _gridData);
|
||||||
this.setData({
|
this.setData({
|
||||||
choose: _gridData[0].userName,
|
choose: _gridData[0].userName,
|
||||||
rectifierData: data,
|
rectifierData: data,
|
||||||
show:false
|
selectedIndex: selectedIndex,
|
||||||
})
|
show: false,
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
this.setData({
|
this.setData({
|
||||||
rectifierData : data
|
rectifierData: data,
|
||||||
})
|
selectedIndex: selectedIndex,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onConfirm() {
|
onConfirm() {
|
||||||
var data = this.data.rectifierData;
|
const data = this.data.rectifierData;
|
||||||
let _gridData = [];
|
let _gridData = [];
|
||||||
let chooses = "";
|
let chooses = "";
|
||||||
if (this.data.selectedIndex.length > 0) {
|
if (this.data.selectedIndex.length > 0) {
|
||||||
this.data.selectedIndex.forEach((item) => {
|
this.data.selectedIndex.forEach((item) => {
|
||||||
let _indexs = item.split('_');
|
let _indexs = item.split("_");
|
||||||
let _post = "";
|
let _post = "";
|
||||||
if (data[_indexs[0]].userList[_indexs[1]].userPostName) {
|
if (data[_indexs[0]].userList[_indexs[1]].userPostName) {
|
||||||
_post = " ["+data[_indexs[0]].userList[_indexs[1]].userPostName+"]";
|
_post =
|
||||||
|
" [" + data[_indexs[0]].userList[_indexs[1]].userPostName + "]";
|
||||||
}
|
}
|
||||||
let name = data[_indexs[0]].userList[_indexs[1]].userName + _post;
|
let name = data[_indexs[0]].userList[_indexs[1]].userName + _post;
|
||||||
_gridData.push({'userId':data[_indexs[0]].userList[_indexs[1]].userId,'userName':name,'userPhone':data[_indexs[0]].userList[_indexs[1]].userPhone});
|
_gridData.push({
|
||||||
|
userId: data[_indexs[0]].userList[_indexs[1]].userId,
|
||||||
|
userName: name,
|
||||||
|
userPhone: data[_indexs[0]].userList[_indexs[1]].userPhone,
|
||||||
|
});
|
||||||
chooses += "," + name;
|
chooses += "," + name;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
this.triggerEvent('selected',_gridData)
|
this.triggerEvent("selected", _gridData);
|
||||||
this.setData({
|
this.setData({
|
||||||
choose: chooses.substring(1),
|
choose: chooses.substring(1),
|
||||||
show:false
|
show: false,
|
||||||
})
|
});
|
||||||
}
|
},
|
||||||
|
},
|
||||||
}
|
});
|
||||||
})
|
|
||||||
|
|
|
@ -95,7 +95,7 @@ Page({
|
||||||
form.address = cfgData.address;
|
form.address = cfgData.address;
|
||||||
form.range = cfgData.range;
|
form.range = cfgData.range;
|
||||||
let groupList = (cfgData.groupList || []).map((it) => {
|
let groupList = (cfgData.groupList || []).map((it) => {
|
||||||
it.status = true;
|
it.state = true;
|
||||||
it.userId = it.id;
|
it.userId = it.id;
|
||||||
it.userName = it.groupName;
|
it.userName = it.groupName;
|
||||||
it.subDeptName = it.deptName;
|
it.subDeptName = it.deptName;
|
||||||
|
@ -129,6 +129,10 @@ Page({
|
||||||
}).then((res) => {
|
}).then((res) => {
|
||||||
if (res.code == 200) {
|
if (res.code == 200) {
|
||||||
let tmps = res.rows || [];
|
let tmps = res.rows || [];
|
||||||
|
let findIds = [];
|
||||||
|
if (this.data.cfgData) {
|
||||||
|
findIds = this.data.form.subGroup.map((it) => it.id);
|
||||||
|
}
|
||||||
this.setData({
|
this.setData({
|
||||||
groupList: tmps,
|
groupList: tmps,
|
||||||
});
|
});
|
||||||
|
@ -153,7 +157,7 @@ Page({
|
||||||
subDeptType: val.subDeptType,
|
subDeptType: val.subDeptType,
|
||||||
subDeptTypeName: deptType?.dictLabel || "",
|
subDeptTypeName: deptType?.dictLabel || "",
|
||||||
userList: obj[key].map((it) => {
|
userList: obj[key].map((it) => {
|
||||||
it.status = false;
|
it.state = findIds.includes(it.id);
|
||||||
it.userId = it.id;
|
it.userId = it.id;
|
||||||
it.userName = it.groupName;
|
it.userName = it.groupName;
|
||||||
return it;
|
return it;
|
||||||
|
|
Loading…
Reference in New Issue