/**
 * create by robot 
 * date Mon Dec 16 17:48:28 CST 2019 
 */ 

var pageIndex=1;
$(document).ready(function(){
	//调用查询
	pageIndex=StringUtil.getQueryString('pageIndex');
	if(pageIndex==undefined||pageIndex==null){
		pageIndex=1;
	}
	//绑定hover操作
	$(document).on('mouseenter','.listOperaters',function(){
		$(this).children(".ops_itemDiv").show();
		var width=15;
		$(this).children('div').find('li').each(function(){
			//获取li宽度
			width+=$(this).width();
		});
		$(this).children('div').width(width);
	})
	$(document).on('mouseleave','.listOperaters',function(){
		$(this).children(".ops_itemDiv").hide();
	});

	//日历控件
	layui.use(['layer', 'laydate'], function() {
		var layer = layui.layer;
		laydate = layui.laydate;
		laydate.render({
			elem: '#date1',
			format:'yyyy-MM-dd 00:00:00'//指定元素
		});
		laydate.render({
			elem: '#date2',
			format:'yyyy-MM-dd 23:59:59'//指定元素
		});
	});


	//行选中事件
	$("#allCheck").find("span").click(function() {
		$(this).toggleClass('checked');
		if($(this).hasClass('checked')){
			//所有列选中
		  $(".checker").find("span").each(function () {
		         $(this).addClass("checked");
		    })
		}else{
			//所有列取消选中
			$(".checker").find("span").each(function () {
				 $(this).removeClass("checked");
		    })
		}
	});

	//单个选中
	$(document).on('click','.checkeBox span',function() {
		$(this).toggleClass('checked');
		//设置头部事件
		var length=$('.checkeBox span').length;
		var count=0;
		$(".checkeBox").find("span").each(function () {
	        if($(this).hasClass("checked")){
	        	count++;
	        }
	   })
		//全选
	   if(count==length){
		   $("#allCheck").find("span").addClass('checked');
	   }else{
		   $("#allCheck").find("span").removeClass('checked');
	   }
	})
	//左右div高度相等
	var left_content_height = $(".right-content").height();
	$(".left-content").height(left_content_height+35);
	var sub_left_height=$(".res-menu").height(left_content_height-60);
});

//初始化新增
function initAddDeviceMerchantBuy(){
	window.location=ctx+'/deviceMerchantBuy/queryDeviceMerchantBuyDetails?pageIndex='+pageIndex;
}

//初始化修改
function showDeviceMerchantBuyDetails(d){
	layer.open({
		type:1,
		title: '其他信息',
		area: ['500px', '600px'],
		content: $("#showDeviceDetail").text(),
		success:function (){
			$('#form3>input[name="id"]').val(d.id);
			$("#quantity").val(d.quantity);
			$("#orderAmount").val(d.orderAmount);
			$("#statusDesc").val(d.status === "1" ? '已支付' : '未支付');
			$("#orderStatus").val(d.status);
			$('#form3>div>div>textarea[name="addressComposite"]').val(d.linkName + d.linkPhone + d.provinces + d.address)
			$('#form3>div>div>input[name="linkName"]').val(d.linkName);
			$('#form3>div>div>input[name="linkPhone"]').val(d.linkPhone);
			$('#form3>div>div>input[name="provinces"]').val(d.provinces);
			$('#form3>div>div>textarea[name="address"]').val(d.address);
		}
	})
	//window.location=ctx+'/deviceMerchantBuy/queryDeviceMerchantBuyDetails?id='+id+'&pageIndex='+pageIndex;
}

//初始化删除
function initDeleteDeviceMerchantBuy(id){
	
		layer.open({
		type: 1,
		closeBtn: 1,		title: '提示',
		offset: 'm', //具体配置参考：offset参数项
		area: ['300px', '180px'],
		content: '<div style="padding:10px;" class="textc mt20">确认删除吗？</div>',
		btn: ['确认','取消'],
		btnAlign: 'r'	, //按钮居中
		shade: 0.3 ,//不显示遮罩
		yes: function() {
			layer.closeAll();
			deleteDeviceMerchantBuy(id,true);
		}
	});
}

//删除
function deleteDeviceMerchantBuy(id,showMsg){
	$.ajax({
		url:ctx+'/deviceMerchantBuy/deleteDeviceMerchantBuy',
		data:[{
			name:'id',
			value:id
		}],
		type:'POST',
		dataType:'json',
		success:function(){
			queryDeviceMerchantBuy(pageIndex);
			if(showMsg){
				layer.msg('删除成功!');	
			}
		}
	});
}
//头部编辑
function initEditDeviceMerchantBuy(){
	var count=0;
	var id=0;
	$(".checkeBox").find("span").each(function () {
         if($(this).hasClass("checked")){
        	 count++;
        	 id=$(this).data('id');
         }
    })
    if(count>1){
    	layer.msg('只能选中一行记录进行操作!');
    	return ;
    }
	 if(count==0){
    	layer.msg('请选中一行记录!');
    	return ;
	  }
	 if(id>0){
	  showDeviceMerchantBuyDetails(id);
	 }
}
//头部删除
function initBatchDeleteDeviceMerchantBuy(){
	var count=0;
	$(".checkeBox").find("span").each(function () {
         if($(this).hasClass("checked")){
        	 count++;
         }
    })
	
	 if(count==0){
    	layer.msg('请选中一行记录!');
    	return ;
	  }
	

	layer.open({
		type: 1,
		closeBtn: 1,
		title: '提示',
		offset: 'm', //具体配置参考：offset参数项
		area: ['300px', '180px'],
		content: '<div style="padding:10px;" class="textc mt20">确认删除吗？</div>',
		btn: ['确认','取消'],
		btnAlign: 'r', //按钮居中
		shade: 0.3, //不显示遮罩
		yes: function() {
			layer.closeAll();
			deleteBatchDeviceMerchantBuy();
		}
	});
	
}
//批量删除
function deleteBatchDeviceMerchantBuy(){
	
	$(".checkeBox").find("span").each(function () {
        if($(this).hasClass("checked")){
        	var id=$(this).data('id');
        	deleteDeviceMerchantBuy(id,false);
        	layer.msg('删除成功!');	
        }
   })
}

function  updateExpressNo(id){
	var htmlStr = '<div style="margin: 10px;"><label >请输入单号：</label><input id="expressNo"></div>';
	layer.open({
		type:1,
		title:'发货单号',
		area: '350px;',
		shade:0.3,
		maxmin:true,
		content:htmlStr,
		btn:['确定','取消'],
		yes:function(){
			var expressNo = $("#expressNo").val();
			ExpressNo(id,expressNo);
		},
	})
}

function ExpressNo(id,expressNo){
	$.ajax({
		url:ctx+'/deviceMerchantBuy/expressNo',
		 type:"post", 
	        dataType:"json",  
	        data:{  
	        	"expressNo":expressNo,
	        	"id":id,
	        },  
	        success:function(result){ 
	        	queryDeviceMerchantBuy(pageIndex);
	        	layer.closeAll();
	        	layer.msg(result.msg);	
	        }
	})
}
function dateFtt(fmt,date)
{ //author: meizz
	var o = {
		"M+" : date.getMonth()+1,                 //月份
		"d+" : date.getDate(),                    //日
		"h+" : date.getHours(),                   //小时
		"m+" : date.getMinutes(),                 //分
		"s+" : date.getSeconds(),                 //秒
		"q+" : Math.floor((date.getMonth()+3)/3), //季度
		"S"  : date.getMilliseconds()             //毫秒
	};
	if(/(y+)/.test(fmt))
		fmt=fmt.replace(RegExp.$1, (date.getFullYear()+"").substr(4 - RegExp.$1.length));
	for(var k in o)
		if(new RegExp("("+ k +")").test(fmt))
			fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
	return fmt;
}
