(function($) {
	//0并行分支,1手动分支,2条件分支 

	Vue.component('user-select', {
		template: '\
    			<section>\
					<input type="hidden" id="selTmodelId" value="" />\
					<template v-for="(dept,index) in depts">\
						<a href="#" @click="getParentGroup(dept.id,index)">\
							<label v-if="index > 0">></label>\
							{{dept.name}}\
						</a>\
					</template>\
					<ul class="mui-table-view">\
						<li class="mui-table-view-cell" v-for="groupUser in groupUsers" v-if="groupUser.type == \'dept\'">\
							<a class="mui-navigate-right" href="#" @click="getChildGroup(groupUser.id,groupUser.text);">{{groupUser.text}}</a>\
						</li>\
					</ul>\
					<div class="mui-table-view-cell mui-radio" style="padding:5px;" v-for="groupUser in groupUsers" v-if="groupUser.type == \'user\'">\
						<label style="width: 60%;padding:5px;">{{groupUser.text}}</label>\
						<input name="radio1" type="radio" :value="groupUser.id" @click="incrementHandler(groupUser)">\
					</div>\
				</section>\
    		',
		props: ['groupUsers', 'depts'],
		 methods: {
		    incrementHandler: function (user) {
     			vmdepts.curUser = user;
		      	this.$emit('increment')
		    }
	  	},
		//组件渲染之前
		created: function() {},
		//组件渲染之后
		mounted: function() {}
	});

})(jQuery);

var vmdepts = new Vue({
	el: '#personData',
	data: {
		groupUsers: [],
		depts: [{
			id: API.UNIT_ID,
			name: '联系人'
		}],
		curUser: {}
	}
});

function getParentGroup(groupId, index) {
	console.log(vmdepts.depts)
	vmdepts.depts.splice(index+1,vmdepts.depts.length);
	getGroupUser(groupId);
}

function getChildGroup(groupId, groupName) {
	var dept = {}
	dept.id = groupId;
	dept.name = groupName;
	vmdepts.depts.push(dept);
	getGroupUser(groupId);
}

//获取人员选择列表信息
function getGroupUser(groupId) {
	mui('#person-scroll').scroll().scrollTo(0, 0);
	console.log(groupId);
	var state = app.getState(); //获取登陆信息
	var staffId = state.user.useId;
	mui.ajax(url, {
		dataType: 'json', //服务器返回json格式数据
		type: 'post', //HTTP请求类型
		data: {
			'serviceId': 'eu_20180308loadUserByGroup',
			'params': '{staffId:"' + staffId + '",groupId:"' + groupId + '"}'
		},
		timeout: 10000, //超时时间设置为10秒；
		headers: {
			'Accept': 'application/json'
		},
		success: function(data) {
			//服务器返回响应
			console.log("人员信息:" + JSON.stringify(data));
			if(data.returnCode == "1") {
				vmdepts.groupUsers = data.returnParams;
			} else {
				mui.toast("获取人员信息错误");
			}
		},
		error: function(xhr, type, errorThrown) {
			//异常处理；
			console.log(xhr + "========" + type + "===========" + errorThrown);
		}
	});
};