$(function(){
	//页面加载完成之后执行
	pageInit();
});
function pageInit(){
	var id = $('#staff_id').val();
	var times = $('#times').val() ? $('#times').val() : 'month';
	//var colNames;
	//var colModel;
	//$.ajax({
	//    type: "post",
	//    async: false,
	//    url: "jqgrid",
	//    data: {},
	//    dataType: "json",
	//    success: function (result) {
	//var len = result.name.length;
	//var len1 = result.model.length;
	//if(len == 0){
	//    colNames = [ '编号', '姓名', '性别', '手机号', '微信','微博', 'QQ', '客户类型', '消费类型','意向店面','客户渠道','客户来源','客户意向','接单点','获取方式','客户分区','客户地域','是否进店','是否成交','是否有效' ];
	//}else{
	//    colNames = result.name;
	//}
	//if(len1 != 0){
	//    colModel = JSON.parse(result.model);
	//}else{
	var colModel = [{name: 'customer_number', index: 'customer_name, invdate',width:170,align: "left",editable: true, editoptions: {size: 25}},
		{name: 'customer_name',
			index: 'customer_number',
			align: "center",
			frozen: true,
			editable: true,
			editoptions: {size: 10},
			search: true,
			stype: 'select',
			searchoptions: {
				value:":All;0.00:0.00;12:12.00;20:20.00;40:40.00;60:60.00;120:120.00"
			}
		},
		{name: 'customer_sex', index: 'customer_sex',editable: true,align: "center", editoptions: {size: 25},search:true,stype:'select',searchoptions:{value:":All;男:男;女:女"}},
		{name: 'customer_tel', index: 'customer_tel',editable: true,align: "center", editoptions: {size: 25}},
		{name: 'customer_wechat', index: 'customer_wechat', align: "center", editoptions: {readonly: true, size: 10}},
		{name: 'customer_weibo', index: 'customer_weibo', align: "center", editoptions: {readonly: true, size: 10}},
		{name: 'customer_qq',
			index: 'customer_qq',

			align: "center",
			editable: true,
			edittype: "checkbox",
			editoptions: {value: "Yes:No"}
		},
		{name: 'customer_type',
			index: 'customer_type',
			editable: true,
			width:100,
			align: "center",
			edittype: "textarea",
			editoptions: {rows: "2", cols: "20"},
			search:true,
			stype:'select',
			size: 10,
			searchoptions:{
				value: " :[All];1:新客资;2:转介绍"
			}
		},
		{name: 'consultation_type', index: 'consultation_type',align: "center", editable: true, editoptions: {size: 10}},


		{name: 'consulation_shop', index: 'consulation_shop', align: "center", editoptions: {readonly: true, size: 10}},
		{name: 'customer_channel', index: 'customer_channel', align: "center", editoptions: {readonly: true, size: 10}},
		{name: 'customer_cource', index: 'customer_cource', align: "center", editoptions: {readonly: true, size: 10}},
		{name: 'customer_intention', index: 'customer_intention', align: "center", editoptions: {readonly: true, size: 10}},
		{name: 'customer_orderaddress', index: 'customer_orderaddress', align: "center", editoptions: {readonly: true, size: 10}},
		{name: 'access_model', index: 'access_model', align: "center", editoptions: {readonly: true, size: 10}},
		{name: 'customer_area', index: 'customer_area', align: "center", editoptions: {readonly: true, size: 10}},
		{name: 'customer_region', index: 'customer_region', align: "center", editoptions: {readonly: true, size: 10}},
		{name: 'is_intostore', index: 'is_intostore', align: "center", editoptions: {readonly: true, size: 10}},
		{name: 'is_success', index: 'is_success', align: "center", editoptions: {readonly: true, size: 10}},
		{name: 'is_valid', index: 'is_valid', align: "center", editoptions: {readonly: true, size: 10}},]
	//}

	//    }
	//})
	//var mod = [];
	//$.each(model, function(key,value) {console.log(value)
	//    mod.push(value);
	//});
	//console.log(name)
	//创建jqGrid组件
	var mygrid = jQuery("#Example").jqGrid(
			{
				url : '/crm/Customer/getCustomerList/'+'staff_id/'+id+"/times/"+times,//组件创建完成之后请求数据的url
				datatype : "json",//请求数据返回的类型。可选json,xml,txt
				colNames : [ '编号', '姓名','是否进店','是否成交','是否有效', '性别', '手机号', '微信','追踪阶段', '阶段名', '客户类型', '消费类型','意向店面','渠道名称','客户来源','客户意向','接单点','获取方式','客户分区','客户地域'],//jqGrid的列显示名字
				colModel : [
					{
						name: 'customer_number',
						index: 'customer_number',
						width:85,
						align: "left",
						editable: true,
						editoptions: {size: 25}
					},
					{name: 'customer_name',
						index: 'customer_number',
						align: "center",
						//frozen: true,
						editable: true,
						editoptions: {size: 10},
						search: true,
						width:100

					},
					{name: 'is_intostore', index: 'is_intostore', align: "center", editoptions: {readonly: true, size: 10},width:70},
					{name: 'is_success', index: 'is_success', align: "center", editoptions: {readonly: true, size: 10},width:70},
					{name: 'is_valid', index: 'is_valid', align: "center", editoptions: {readonly: true, size: 10},width:70},
					{name: 'customer_sex', index: 'customer_sex',editable: true,align: "center", editoptions: {size: 25},width:50,search:true,stype:'select',/*searchoptions:{value:":全部;男:男;女:女"}*/},
					{name: 'customer_tel', index: 'customer_tel',editable: true,align: "center",width:120, editoptions: {size: 25}},
					{name: 'customer_wechat', index: 'customer_wechat', align: "center",width:120, editoptions: {readonly: true, size: 10}},
					{name: 'seles_step', index: 'seles_step', align: "center",width:50, editoptions: {readonly: true, size: 10}},
					{name: 'step_name',
						index: 'step_name',

						align: "center",
						editable: true,
						edittype: "checkbox",
						width:100,
						editoptions: {value: "Yes:No"}
					},
					{name: 'customer_type',
						index: 'customer_type',
						editable: true,
						width:100,
						align: "center",
						edittype: "textarea",
						editoptions: {rows: "2", cols: "20"},
						search:true,
						stype:'select',
						size: 10,
						width:100,
						searchoptions:{
							value: ":全部;新客资:新客资;转介绍:转介绍"
						}
					},
					{name: 'consultation_type', index: 'consultation_type',align: "center", editable: true,width:80, editoptions: {size: 10}},


					{name: 'consulation_shop', index: 'consulation_shop', align: "center",width:80, editoptions: {readonly: true, size: 10}},
					{name: 'customer_channel', index: 'customer_channel', align: "center",width:80, editoptions: {readonly: true, size: 10}},
					{name: 'customer_cource', index: 'customer_cource', align: "center",width:80, editoptions: {readonly: true, size: 10}},
					{name: 'customer_intention', index: 'customer_intention', align: "center",width:80, editoptions: {readonly: true, size: 10}},
					{name: 'customer_orderaddress', index: 'customer_orderaddress', align: "center",width:80, editoptions: {readonly: true, size: 10}},
					{name: 'access_model', index: 'access_model', align: "center",width:80, editoptions: {readonly: true, size: 10}},
					{name: 'customer_area', index: 'customer_area', align: "center",width:80, editoptions: {readonly: true, size: 10}},
					{name: 'customer_region', index: 'customer_region', align: "center",width:80, editoptions: {readonly: true, size: 10}},
				],
				height:300,//默认高度
				width: "100%",//默认宽度
				autowidth:true,
				rowNum : 50,//一页显示多少条
				rowList : [ 50, 100, 150,300],//可供用户选择一页显示多少条
				pager : '#pager',//表格页脚的占位符(一般是div)的id
				sortname : 'id',//初始化的时候排序的字段
				sortorder : "desc",//排序方式,可选desc,asc
				mtype : "post",//向后台请求数据的ajax的类型。可选post,get
				viewrecords : true,//page页面序号信息
				sortable : true,//列排序
				multiselect : true,//tr行多选
				recordpos : 'right',//分页
				postData:{'staff_id':id},
				rownumbers: true,
				loadonce:true,
				shrinkToFit:false,
				autoScroll: false,
				//editurl : ctx+"/crm/Customer/getCustomerList"
			});
	$('.cus_click').click(function(index){
		var step = $(this).attr("id");
		$("#Example").jqGrid('setGridParam',{
			datatype:'json',
			url:"/crm/Customer/getCustomerList/"+'staff_id/'+id+"/times/"+times+"/seles_step/"+step,
			postData:{'type':0}, //发送数据
			mtype : "post",
			page:1
		}).trigger("reloadGrid"); //重新载入
	})
	$("#click11").click(function(){
		$("#Example").jqGrid('setGridParam',{
			datatype:'json',
			url:"/crm/Customer/getCustomerList/"+'staff_id/'+id+"/times/"+times,
			postData:{'type':0}, //发送数据
			mtype : "post",
			page:1
		}).trigger("reloadGrid"); //重新载入
	})
	//jQuery("#Example").jqGrid('navGrid',"#pager",{edit:false,add:false,del:false,refresh:false,search:true},{},{},{},{multipleSearch:true});
	/*创建jqGrid的操作按钮容器*/
	//jQuery("#Example").jqGrid('gridResize',{minWidth:650,maxWidth:"100%",minHeight:80, maxHeight:650});//grid改变大小
	jQuery("#Example").jqGrid('navGrid','#pager',{edit:false,add:false,del:false,search:false,refresh:true});//编辑,删除,搜索,刷新

	jQuery("#Example").jqGrid('navButtonAdd', '#pager', {//列选择
		caption: "列选择",
		title: "Reorder Columns",
		onClickButton: function () {
			jQuery("#Example").jqGrid('columnChooser');
		}
	});

	jQuery("#Example").jqGrid('filterToolbar', {
		//searchOperators : true
	});
	jQuery("#Example").jqGrid('navButtonAdd',"#pager",{caption:"筛选",title:"Toggle Search Toolbar", buttonicon :'ui-icon-pin-s',
		onClickButton:function(){
			mygrid[0].toggleToolbar()
		}
	});//筛选搜索按钮
}

// JavaScript Document
$(function(){
	//弹窗内input边框
	$(".box input").focus(function(){
		$(this).css("border","1px solid #1696a3");
	});
	$(".box input").blur(function(){
		$(this).css("border","1px solid #bfccdd");
	});


})
