123 lines
3.4 KiB
JavaScript
123 lines
3.4 KiB
JavaScript
// newComponents/select-group-person/index.js
|
|
Component({
|
|
/**
|
|
* 组件的属性列表
|
|
*/
|
|
properties: {
|
|
title:{
|
|
type:String
|
|
},
|
|
choose:{
|
|
type:Array
|
|
},
|
|
multiple:{
|
|
type:Boolean,
|
|
value:true
|
|
},
|
|
rectifierData:{
|
|
type:Array,
|
|
value:[]
|
|
}
|
|
},
|
|
observers: {
|
|
choose: function (val) {
|
|
this.setData({
|
|
gridData : val
|
|
})
|
|
},
|
|
},
|
|
lifetimes: {
|
|
created: function(){
|
|
//在组件实例刚刚被创建时执行,注意此时不能调用 setData
|
|
},
|
|
attached: function () {
|
|
//在组件实例进入页面节点树时执行
|
|
},
|
|
ready: function () {
|
|
// 在组件在视图层布局完成后执行
|
|
},
|
|
detached: function () {
|
|
// 在组件实例被从页面节点树移除时执行
|
|
},
|
|
},
|
|
|
|
/**
|
|
* 组件的初始数据
|
|
*/
|
|
data: {
|
|
show:false,
|
|
gridData:[],
|
|
selectedIndex:[],
|
|
titleValue:""
|
|
},
|
|
|
|
/**
|
|
* 组件的方法列表
|
|
*/
|
|
methods: {
|
|
onAddResponsible(){
|
|
this.setData({
|
|
show:true
|
|
})
|
|
},
|
|
onClose(){
|
|
this.setData({
|
|
show:false
|
|
})
|
|
},
|
|
onSelected(e){
|
|
var data = this.data.rectifierData;
|
|
let ei = e.currentTarget.dataset.index;
|
|
let index = ei.split('_');
|
|
let userdata = data[index[0]].userinfoList[index[1]];
|
|
let of = this.data.selectedIndex.indexOf(ei);
|
|
if(of>-1){
|
|
this.data.selectedIndex.splice(of, 1);
|
|
userdata.state = false;
|
|
}else{
|
|
this.data.selectedIndex.push(ei);
|
|
userdata.state = true;
|
|
}
|
|
if(!this.data.multiple && this.data.selectedIndex.length>0){
|
|
if(this.data.selectedIndex.length>1){
|
|
this.data.selectedIndex.forEach((item) =>{
|
|
let _indexs = item.split('_');
|
|
data[_indexs[0]].userinfoList[_indexs[1]].state = false;
|
|
});
|
|
userdata.state = true;
|
|
this.data.selectedIndex=[];
|
|
this.data.selectedIndex.push(ei);
|
|
}
|
|
let _gridData=[{userName:userdata.nickName+" ["+userdata.jobTypeName+"]",phoneNumber:userdata.phonenumber}];
|
|
this.triggerEvent('selected',_gridData)
|
|
this.setData({
|
|
titleValue:_gridData[0].userName,
|
|
rectifierData:data,
|
|
show:false
|
|
})
|
|
}else{
|
|
if(of>-1){
|
|
this.data.selectedIndex.splice(of, 1);
|
|
userdata.state = false;
|
|
}else{
|
|
this.data.selectedIndex.push(index);
|
|
userdata.state = true;
|
|
}
|
|
this.setData({
|
|
rectifierData : data
|
|
})
|
|
}
|
|
},
|
|
onConfirm(){
|
|
var data = this.data.rectifierData
|
|
let gridData = data.filter(x => x.state == true);
|
|
this.triggerEvent('selected',gridData)
|
|
this.setData({
|
|
gridData:gridData,
|
|
show:false
|
|
})
|
|
}
|
|
|
|
}
|
|
})
|