/**
 * [OEmarry] (C)2010-2099 OEMARRY.COM Inc.
 * Email: service@phpcoo.com, phpcoo@qq.com
 * This is NOT a freeware, use is subject to license terms
 * $ Last update 2016-08-05 by OEdev $
*/
//订单处理
$(function(){

	//取消操作
	$(document).on("click", "[f='close_var']", function(){
		$_box = $(this).attr("data-id");
		$("#varpop_shade").hide();
		$("#"+$_box).fadeOut(200);
	});
	
	//弹出取消操作
	$(document).on("click", "[f='confirm_cancel_order']", function(){
		$_id = $(this).attr("data-id");
		$("#orderid").val($_id);
		$("#varpop_shade").show();
		tabPopMarginAuto("cancel_box");
		$("#cancel_box").fadeIn(200); //显示
	});
	
	//取消订单
	$(document).on("click", "[f='but_cancel_order']", function(){
		$_orderid = $("#orderid").val();
		$.ajax({
			type: "POST",
			url: WAP_APPFILE+"&c=order&a=cancel&id="+$_orderid,
			cache: false,
			data: {r:get_rndnum(8)},
			dataType: "json",
			success: function($data) {
				$json = eval($data);
				$response = $json.response;
				$result = $json.result;
				if ($response == "1") {
					ToastShow("取消成功");
					setTimeout(function(){
						window.location.reload();
					}, 400);
				}
				else {
					ToastShow("取消失败");
				}
				$("#orderid").val("");
				$("#varpop_shade").hide();
				$("#cancel_box").fadeOut(200);
			},
			error: function() {
				
			}
		});
	});


	//弹出收货操作
	$(document).on("click", "[f='confirm_receive_order']", function(){
		$_id = $(this).attr("data-id");
		$("#orderid").val($_id);
		$("#varpop_shade").show();
		tabPopMarginAuto("receive_box");
		$("#receive_box").fadeIn(200); //显示
	});
	
	//收货订单
	$(document).on("click", "[f='but_receive_order']", function(){
		$_orderid = $("#orderid").val();
		$.ajax({
			type: "POST",
			url: WAP_APPFILE+"&c=order&a=confirmreceipt&id="+$_orderid,
			cache: false,
			data: {r:get_rndnum(8)},
			dataType: "json",
			success: function($data) {
				$json = eval($data);
				$response = $json.response;
				$result = $json.result;
				if ($response == "1") {
					ToastShow("操作成功");
					setTimeout(function(){
						window.location.reload();
					}, 400);
				}
				else {
					ToastShow("操作失败");
				}
				$("#orderid").val("");
				$("#varpop_shade").hide();
				$("#receive_box").fadeOut(200);
			},
			error: function() {
				
			}
		});
	});


	//弹出余额支付框
	$(document).on("click", "[f='confirm_payment']", function(){
		$_orderid = $(this).attr("data-id");
		$_ordersn = $(this).attr("data-sn");
		$_money = $(this).attr("data-money");
		$("#orderid").val($_orderid);
		$("#tips_ordersn").html($_ordersn);
		$("#tips_money").html("¥"+$_money);
		$("#var_order_box").slideDown("fast");

	});

	//取消余额支付
	$(document).on("click", ".order_cancel_box", function(){
		$("#var_order_box").slideUp("fast");
	});
	
	//提交余额支付
	$(document).on("click", "[f='but_payment']", function(){
		$tips_obj = $("#tips_payment");
		$tips_obj.html("");
		$_orderid = $("#orderid").val();
		$payword = $("#payword").val();
		if ($_orderid.length == 0) {
			$tips_obj.html("<font color='red'>请选择要付款的订单</font>");
			return false;
		}
		if ($payword.length == 0) {
			$tips_obj.html("<font color='red'>请输入支付密码</font>");
			return false;
		}

		$.ajax({
			type: "POST",
			url: WAP_APPFILE+"&c=order",
			cache: false,
			data: {a:"buyorder", id:$_orderid, payword:$payword, r:get_rndnum(8)},
			dataType: "json",
			success: function($data) {
				$json = eval($data);
				$response = $json.response;
				$result = $json.result;
				if ($response == "1") {
					ToastShow("付款成功");
					setTimeout(function(){
						window.location.reload();
					}, 400);
				}
				else {
					ToastShow("付款失败");
				}
				$("#orderid").val("");
				$("#var_order_box").slideUp("fast");
			},
			error: function() {
				
			}
		});
	});

	//提交在线支付
	$(document).on("click", "[f='but_payonline']", function(){
		$_orderid = $(this).attr("data-id");
		$.ajax({
			type: "POST",
			url: WAP_APPFILE+"&c=order",
			cache: false,
			data: {a:"pay", id:$_orderid, r:get_rndnum(8)},
			dataType: "json",
			success: function($data) {
				$json = eval($data);
				$response = $json.response;
				$result = $json.result;
				if ($response == "1") {
					if ($result.length > 0) {
						goUrl(WAP_APPFILE+"&c=pay&paynum="+$result);
					}
					else {
						ToastShow("参数错误");
					}
				}
				else {
					if ($result.length > 0) {
						ToastShow($result);
					}
					else {
						ToastShow("参数错误");
					}
				}
			},
			error: function() {
				
			}
		});

	});


});