// 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:'http://fileimg.makalu.cc/WEB_44D7C71ACA8E4D40B323AC929315045B.jpg'},
                {state:false,name:'董超',url:'http://fileimg.makalu.cc/WEB_B3F05B5BC25C452F90EAA2347833D228.jpg'},
                {state:false,name:'黄海军',url:'http://fileimg.makalu.cc/WEB_08FE97020FBD49C3A775B97B5FAA05DF.jpg'},
                {state:false,name:'黄嘉伟',url:'http://fileimg.makalu.cc/WEB_65398BB3CB5A4098B5D222AFB6C286EF.jpg'},
                {state:false,name:'李鑫',url:'http://fileimg.makalu.cc/WEB_F62AAB25BA4946BB8CC406BA2AAF4CA7.jpg'},
                {state:false,name:'聂少刚',url:'http://fileimg.makalu.cc/WEB_9D3E6D980B2A4B57AC4A32C16CB384A0.jpg'},
                {state:false,name:'王晨',url:'http://fileimg.makalu.cc/WEB_E8BD336312324B69924D7264AC726D65.jpg'},
                {state:false,name:'王程',url:'http://fileimg.makalu.cc/WEB_F5E8BF2385E747AA8D9FD328A413E021.jpg'},
                {state:false,name:'王国雄',url:'http://fileimg.makalu.cc/WEB_37C63EB77EC240598C72979582273990.jpg'},
                {state:false,name:'杨启明',url:'http://fileimg.makalu.cc/WEB_A09316E46D1C4A1AB558258918740247.jpg'},
                {state:false,name:'赵平印',url:'http://fileimg.makalu.cc/WEB_CA897DDFF6294940ADB187099F77F6FE.jpg'},
                {state:false,name:'张明亮',url:'http://fileimg.makalu.cc/WEB_B2C7971895B74BA6B33A6D17F132E86E.jpg'},
                {state:false,name:'张露露',url:'http://fileimg.makalu.cc/WEB_0185D8D49A00474D8058A9651E96506A.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
            })
        }

    }
})
