jhwxapp/miniprogram/newComponents/select-person/index.js

117 lines
4.1 KiB
JavaScript

// newComponents/select-person/index.js
Component({
/**
* 组件的属性列表
*/
properties: {
title:{
type:String
},
choose:{
type:Array
},
multiple:{
type:Boolean,
value:true
},
rectifierData:{
type:Array,
value:[
{state:false,name:'党鹏',url:'https://szgcwx.jhncidg.com/staticFiles/img/WEB_44D7C71ACA8E4D40B323AC929315045B.jpg'},
{state:false,name:'董超',url:'https://szgcwx.jhncidg.com/staticFiles/img/WEB_44D7C71ACA8E4D40B323AC929315045B.jpg'},
{state:false,name:'黄海军',url:'https://szgcwx.jhncidg.com/staticFiles/img/WEB_44D7C71ACA8E4D40B323AC929315045B.jpg'},
{state:false,name:'黄嘉伟',url:'https://szgcwx.jhncidg.com/staticFiles/img/WEB_44D7C71ACA8E4D40B323AC929315045B.jpg'},
{state:false,name:'李鑫',url:'https://szgcwx.jhncidg.com/staticFiles/img/WEB_44D7C71ACA8E4D40B323AC929315045B.jpg'},
{state:false,name:'聂少刚',url:'https://szgcwx.jhncidg.com/staticFiles/img/WEB_44D7C71ACA8E4D40B323AC929315045B.jpg'},
{state:false,name:'王晨',url:'https://szgcwx.jhncidg.com/staticFiles/img/WEB_44D7C71ACA8E4D40B323AC929315045B.jpg'},
{state:false,name:'王程',url:'https://szgcwx.jhncidg.com/staticFiles/img/WEB_44D7C71ACA8E4D40B323AC929315045B.jpg'},
{state:false,name:'王国雄',url:'https://szgcwx.jhncidg.com/staticFiles/img/WEB_44D7C71ACA8E4D40B323AC929315045B.jpg'},
{state:false,name:'杨启明',url:'https://szgcwx.jhncidg.com/staticFiles/img/WEB_44D7C71ACA8E4D40B323AC929315045B.jpg'},
{state:false,name:'赵平印',url:'https://szgcwx.jhncidg.com/staticFiles/img/WEB_44D7C71ACA8E4D40B323AC929315045B.jpg'},
{state:false,name:'张明亮',url:'https://szgcwx.jhncidg.com/staticFiles/img/WEB_44D7C71ACA8E4D40B323AC929315045B.jpg'},
{state:false,name:'张露露',url:'https://szgcwx.jhncidg.com/staticFiles/img/WEB_44D7C71ACA8E4D40B323AC929315045B.jpg'}
]
}
},
observers: {
choose: function (val) {
this.setData({
gridData : val
})
},
},
lifetimes: {
created: function(){
//在组件实例刚刚被创建时执行,注意此时不能调用 setData
},
attached: function () {
//在组件实例进入页面节点树时执行
},
ready: function () {
// 在组件在视图层布局完成后执行
},
detached: function () {
// 在组件实例被从页面节点树移除时执行
},
},
/**
* 组件的初始数据
*/
data: {
show:false,
gridData:[]
},
/**
* 组件的方法列表
*/
methods: {
onAddResponsible(){
this.setData({
show:true
})
},
onClose(){
this.setData({
show:false
})
},
onSelected(e){
if(!this.data.multiple){
let tempData = JSON.parse(JSON.stringify(this.data.rectifierData))
tempData.forEach(item=>item.state = false)
this.setData({
rectifierData:tempData
})
}
var index = e.currentTarget.dataset.index
var data = this.data.rectifierData
if(data[index].state == false){
data[index].state = true
}else{
data[index].state = false
}
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
})
}
}
})