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