//var category_id = getStorage("category_id");
//var pro_cate_id = getStorage("pro_cate_id");
var category_id = '';
var pro_cate_id = '';
//category_id = '1';
//pro_cate_id = '205';

var run_date = after(getDateTime(0));
var back_run_date = after(getDateTime(0));

var car_id = "";
var back_car_id = "";
var go_back = "0";

//var total_price = 0;
var total_no = 1;

var status_go_back = '';
var cache_data = {};
var cache_data_back = {};

var cache_select_data = {};
var cache_select_data_back = {};

//切换班次信息
var passindex = '';
var selectindex = '';

window.onload = function() {
	category_id = category_id ? category_id : getPar('category_id');
	pro_cate_id = pro_cate_id ? pro_cate_id : getPar('pro_cate_id');
	getFxUid();
	ifLogin(function(flag) {
		$('body').show();
		httpBaseInfo();
	},"station_ticket.html?fx_uid="+getFxUid()+"&category_id="+category_id+"&pro_cate_id="+pro_cate_id);
}

var temp_run = {};
var temp_start = {};
var temp_end = {};
var temp_run_back = {};
var temp_start_back = {};
var temp_end_back = {};

var go_total = '';
var back_total = '';

var sel_cate_id = '';
var back_cate_id = '';

//基础信息展示
function httpBaseInfo() {
	var urlstr = base_api + "prod/prod/get-prod-detail";
	var data = { "pro_cate_id": pro_cate_id, "category_id": category_id };
	ZZLog(urlstr);
	$.ajax({
		url: urlstr,
		data: data,
		type: "post",
		dataType: "json",
		async: false,
		success: function(res) {
			ZZLog(res);
			if(res.flag) {
				replaceBaseInfo(res.data);
			} else {
				if(codeNotLogin == res.code) {
					alert(infoNotLogin);
					var URL = '/web/fx/station_ticket.html?fx_uid='+getFxUid();
					URL = encodeURI(URL);
					location.href = res.url + URL;
				} else if(codeNotRegister == res.code) {
					location.href = 'register.html?fx_uid='+getFxUid();
				} else {
					alert(res.msg);
				}
			}
		},
		error: function(error) {
			console.log(error);
		}
	});
}

//替换初始化页面数据
function replaceBaseInfo(data) {
	var temp = "";
	for(var i = 0, j = data.prod_arr.length; i < j; i++) {
		var img = 'images/jianhao.png';
		var str = '<span class="ulev3 count aticket" type="text" readonly="true" one_price="' + data.prod_arr[i].prod_price + '" prod_name="' + data.prod_arr[i].prod_name + '" prod_id="' + data.prod_arr[i].prod_id + '">0</span>';
		if(i == 0) {
			img = 'images/jianhao_sel.png';
			str = '<span class="ulev3 count aticket" type="text" readonly="true" one_price="' + data.prod_arr[i].prod_price + '" prod_name="' + data.prod_arr[i].prod_name + '" prod_id="' + data.prod_arr[i].prod_id + '">1</span>'
		}
		temp += '<div class="ub ub-ver disney_div">' +
			'<div style="padding-bottom: 0.12rem;">' + data.prod_arr[i].prod_name + '</div>' +
			'<div class="ub">' +
			'<div class="ub-f1 ub">' +
			'<img class="cut" style="width: 0.22rem;height: 0.22rem;vertical-align: middle;" src="' + img + '"/>' +
			str +
			'<img class="add" style="width: 0.22rem;height: 0.22rem;vertical-align: middle;" src="images/jiahao_sel.png"/>' +
			'</div>' +
			'<div class="ub-f1 ub tx-r">' +
			'<div class="ub-f1 ub ub-pe ub-ae font_price" >￥</div>' +
			'<div class="ulev3 ub ub-ae font_price" style="line-height: 1;">' + data.prod_arr[i].prod_price + '<span class="font_price" style="font-size:0.12rem">/张</span></div>' +
			'</div>' +
			'</div>' +
			'</div>'
	}
	$("#tick_type").html(temp);
	//订票须知 
	if(data.booking_notice) {
		var booking_notice_arr = data.booking_notice.split('<br/>');
		var bnHTML = '';
		for(var i = 0, m = booking_notice_arr.length; i < m; i++) {
			bnHTML += '<div class="font_gray">' + booking_notice_arr[i] + '</div>';
		}
		$(".booking_notice").html(bnHTML);
	}

	//展示数据
	$("#bg_img").css("background-image", "url(" + data.show_img + ")");
	$(".top_title").text(data.pro_cate_name);
	pro_cate_name = data.pro_cate_name;

	var go_year = getMonthAndDayByDate(run_date, 'year');
	var go_month = getMonthAndDayByDate(run_date, 'month');
	var go_day = getMonthAndDayByDate(run_date, 'day');
	var back_year = getMonthAndDayByDate(back_run_date, 'year');
	var back_month = getMonthAndDayByDate(back_run_date, 'month');
	var back_day = getMonthAndDayByDate(back_run_date, 'day');
	$("#go_run_date").text(go_month + "月" + go_day + "日");
	$("#back_run_date").text(back_month + "月" + back_day + "日");
	$("#go_sel_date").text(go_month + "月" + go_day + "日");

	//添加事件
	addTargets();
	jiajian();

}

//添加事件
function addTargets() {

	$(".model").on("click", function() {
		$('.model_box').addClass('fadeInDown animated');
		setTimeout(function() {
			$('.model').hide();
			$('#body_mod').removeClass('mod_fil');
		}, 400);
	});
	//选择班次弹层
	$(".model_car").on("click", function() {
		$('.model_box_car').addClass('fadeInDown animated');
		if(cache_select_data.hasOwnProperty(run_date)) {}
		setTimeout(function() {
			$('.model_car').hide();
			$('#body_mod').removeClass('mod_fil');
		}, 400);
	});

	//解决冒泡
	$(".model_box").on("click", function(e) {
		e.stopPropagation();
	});
	$(".model_box_car").on("click", function(e) {
		e.stopPropagation();
	});
	//选择去程日期
	$("#go_date_select").on("click", function() {
		$('.model_box').removeClass('fadeInUp');
		$('.model_box').removeClass('animated');
		$('.model_box').removeClass('fadeInDown');
		//		$("#go_sel_date").text(go_month + "月" + go_day + "日");
		window.calendar.init({
			startDate: getDateTime(0),
			chooseDate: run_date
		}, function(year, month, day, ymdString) {
			$('.model_box').addClass('fadeInDown animated');
			setTimeout(function() {
				$('.model').hide();
				$('#body_mod').removeClass('mod_fil');
			}, 400);
			run_date = ymdString;
			cancel_back();

			function cancel_back() {
				$("#back_date").animate({
					height: "hide"
				}, 200);
				status_go_back = 'go';
				$('#if_back').attr("go_back", "0");
				$('#if_back').text("添加返程");
				$('#if_back').removeClass("cancel_back_btn");
				$('#if_back').addClass("sel_back_btn");
				$("#back_show_class").text("请选择");
				$("#back_show_class").removeAttr("go_time");
				$('.sigle_price').each(function(index, dom) {
					var current = parseInt($(this).text());
					var back = 0;
					if(back_list_ary.length > 0) {
						back = parseInt(back_list_ary[index].prod_price ? back_list_ary[index].prod_price : 0);
					}

					$(this).text(current - back);
				})
				cache_select_data_back = {};
			}
			//			go_year = year;
			//			go_month = month;
			//			go_day = day;
			if(run_date > back_run_date) {
				back_run_date = ymdString;
				//				back_year = year;
				//				back_month = month;
				//				back_day = day;
				$("#back_run_date").text(month + "月" + day + "日");
				$("#back_show_class").text("请选择");
				$("#back_show_class").removeAttr("back_time");
				$("#back_show_class").removeAttr("back_run_id");
				$("#back_show_class").removeAttr("back_cate_name");
				back_car_id = "";
			}
			$("#go_run_date").text(month + "月" + day + "日");
			$("#go_sel_date").text(month + "月" + day + "日");
			//重新选择日期后班次要重新选
			$("#go_show_class").text("请选择");
			$("#go_show_class").removeAttr("go_time");
			$("#go_show_class").removeAttr("go_run_id");
			$("#go_show_class").removeAttr("go_cate_name");
			car_id = "";
		});
		$(".model").show();
		$('.model_box').show();
		$("#body_mod").addClass("mod_fil");
		$('.model_box').addClass('fadeInUp animated');
	});

	//选择去程班次
	$("#go_classes").on("click", function() {
		$('.model_box_car').removeClass('fadeInUp');
		$('.model_box_car').removeClass('animated');
		$('.model_box_car').removeClass('fadeInDown');
		status_go_back = 'go';
		//fuhc start
		if(cache_data.hasOwnProperty(run_date)) {
			ZZLog('cache data  qu de ')
			var data = cache_data[run_date];
			//			showGoInfo(data);
			window.runbus.init({
					run_list: data.station_list,
					run_date: run_date,
					cache_select_data: cache_select_data
				},
				function(run) {
					temp_run = run;
					go_total = run.count;
				},
				function(start) {
					temp_start = start;
					go_total = start.count;
				},
				function(end) {
					temp_end = end;
					go_total = end.count;
				}
			);

			$(".model_car").show();
			$('.model_box_car').show();
			$("#body_mod").addClass("mod_fil");
			$('.model_box_car').addClass('fadeInUp animated');
		} else {
			go_back = '0';
			ajax();

			function ajax() {
				$.ajax({
					url: base_api + 'prod/prod/get-line-bus-stock',
					data: { pro_cate_id: pro_cate_id, date: run_date, if_back: go_back },
					type: "post",
					dataType: "json",
					async: false,
					success: function(res) {
						ZZLog('去程班次返回', res);
						if(res.flag) {
							cache_data[run_date] = res.data;

							window.runbus.init({
									run_list: res.data.station_list
								},
								function(run) {
									temp_run = run;
									go_total = run.count;
								},
								function(start) {
									temp_start = start;
									go_total = start.count;
								},
								function(end) {
									temp_end = end;
									go_total = end.count;
								}
							);
							$(".model_car").show();
							$('.model_box_car').show();
							$("#body_mod").addClass("mod_fil");
							$('.model_box_car').addClass('fadeInUp animated');
						} else {
							if(codeNotLogin == res.code) {
								alert(infoNotLogin);
								var URL = 'station_ticket.html?fx_uid='+getFxUid();
								URL = encodeURI(URL);
								location.href = res.url + URL;
							} else {
								alert(res.msg);
							}
						}
					},
					error: function(error) {
						console.log(error);
					}
				});
			}
		}
	});

	//选择返程日期
	$("#back_date_select").on("click", function() {
		$('.model_box').removeClass('fadeInUp');
		$('.model_box').removeClass('animated');
		$('.model_box').removeClass('fadeInDown');
		$("#go_sel_date").text($('#back_run_date').text());
		window.calendar.init({
			startDate: run_date,
			chooseDate: back_run_date
		}, function(year, month, day, ymdString) {
			$('.model_box').addClass('fadeInDown animated');
			setTimeout(function() {
				$('.model').hide();
				$('#body_mod').removeClass('mod_fil');
			}, 400);
			back_run_date = ymdString;
			if(run_date > back_run_date) {
				back_run_date = ymdString;
				$("#back_run_date").text(month + "月" + day + "日");
			}
			$("#back_run_date").text(month + "月" + day + "日");
			$("#go_sel_date").text(month + "月" + day + "日");
			$("#back_show_class").text("请选择");
			$("#back_show_class").removeAttr("back_time");
			$("#back_show_class").removeAttr("back_run_id");
			$("#back_show_class").removeAttr("back_cate_name");
			back_car_id = "";
		});
		$(".model").show();
		$('.model_box').show();
		$("#body_mod").addClass("mod_fil");
		$('.model_box').addClass('fadeInUp animated');
	});

	//选择返程班次
	$("#back_classes").on("click", function() {
		status_go_back = 'back';
		var go_run_id = '';
		if(cache_select_data.hasOwnProperty(run_date)) {
			go_run_id = cache_select_data[run_date].cache_run_id;
		}

		if(go_run_id == '') {
			alert('请选择去程班次');
			return;
		}

		$('.model_box_car').removeClass('fadeInUp');
		$('.model_box_car').removeClass('animated');
		$('.model_box_car').removeClass('fadeInDown');

		if(cache_data_back.hasOwnProperty(back_run_date)) {
			ZZLog('cache data  qu de ')
			var data = cache_data_back[back_run_date];

			//			showGoInfo(data);
			window.runbus.init({
					run_list: data.station_list,
					run_date: back_run_date,
					cache_select_data: cache_select_data_back
				},
				function(run) {
					temp_run_back = run;
					back_total = run.count;
				},
				function(start) {
					temp_start_back = start;
					back_total = start.count;
				},
				function(end) {
					temp_end_back = end;
					back_total = end.count;
				}
			);

			$(".model_car").show();
			$('.model_box_car').show();
			$("#body_mod").addClass("mod_fil");
			$('.model_box_car').addClass('fadeInUp animated');
		} else {
			ajax();

			function ajax() {
				go_back = '1';
				$.ajax({
					url: base_api + 'prod/prod/get-line-bus-stock',
					data: { pro_cate_id: sel_cate_id, date: back_run_date, if_back: go_back },
					type: "post",
					dataType: "json",
					async: false,
					success: function(res) {
						ZZLog('去程班次返回', res);
						if(res.flag) {
							cache_data_back[back_run_date] = res.data;
							window.runbus.init({
									run_list: res.data.station_list
								},
								function(run) {
									temp_run_back = run;
									back_total = run.count;
								},
								function(start) {
									temp_start_back = start;
									back_total = start.count;
								},
								function(end) {
									temp_end_back = end;
									back_total = end.count;
								}
							);
							$(".model_car").show();
							$('.model_box_car').show();
							$("#body_mod").addClass("mod_fil");
							$('.model_box_car').addClass('fadeInUp animated');
						} else {
							if(codeNotLogin == res.code) {
								alert(infoNotLogin);
								var URL = 'station_ticket.html?fx_uid='+getFxUid();
								URL = encodeURI(URL);
								location.href = res.url + URL;
							} else {
								alert(res.msg);
							}
						}
					},
					error: function(error) {
						console.log(error);
					}
				});
			}
		}
	});

	//添加或取消返程
	$(".sel_back_btn").on("click", function(e) {
		var target = e.target;
		go_back = $(target).attr("go_back");

		if(go_back == "0") {
			//		if(status_go_back == "go") {
			var go_run_id = '';
			//			if(cache_select_data.hasOwnProperty(run_date)) {
			//				go_run_id = cache_select_data[run_date].cache_run_id;
			//			}
			//			if(go_run_id == '') {
			//				alert('请选择去程班次');
			//				return;
			//			}
			$("#back_date").animate({
				height: "show"
			}, 200);
			$(target).attr("go_back", "1");
			$(target).text("取消返程");
			$(target).removeClass("sel_back_btn");
			$(target).addClass("cancel_back_btn");
		} else {
			if(pro_cate_id == '') {
				alert('请选择');
				return;
			}
			status_go_back = 'go';
			$("#back_date").animate({
				height: "hide"
			}, 200);
			$(target).attr("go_back", "0");
			$(target).text("添加返程");
			$(target).removeClass("cancel_back_btn");
			$(target).addClass("sel_back_btn");
			$("#back_show_class").text("请选择");
			$("#back_show_class").removeAttr("go_time");
			back_car_id = "";

			$('.sigle_price').each(function(index, dom) {
				var current = parseInt($(this).text());
				var back = 0;
				if(back_list_ary.length > 0) {
					back = parseInt(back_list_ary[index].prod_price ? back_list_ary[index].prod_price : 0);
				}

				$(this).text(current - back);
			})
			cache_select_data_back = {};

		}
	});
}

var total_price = 0;
//总价
function countTotal() {
	total_price = 0;
	var prod_Arr = [];
	var ticket_info = "";
	total_no = 0;
	$(".aticket").each(function(index, domE) {
		var tick_no = parseInt($(this).text());
		var tick_price = parseInt($(this).attr("one_price"));
        total_price = (total_price * 100 + tick_no * tick_price * 100) / 100;
		total_no += tick_no;
		ticket_info = {
			"prod_id": $(this).attr("prod_id"),
			"prod_count": $(this).text(),
			"prod_name": $(this).attr("prod_name")
		}
		prod_Arr.push(ticket_info);
	});
}

var back_list_ary = [];
//点击确定按钮
function rightDidClick() {
	//	var sel_cate_id = '';
	//	var back_cate_id = '';

	var go_back = $('#if_back').attr('go_back');

	//		if(go_back == 0) {
	if(status_go_back == 'go') {
		cache_select_data[run_date] = {};

		if(temp_run.run_id) {
			cache_select_data[run_date].cache_run_id = temp_run.run_id;
			cache_select_data[run_date].cache_run_time = temp_run.run_time;
			$('#go_show_class').text(temp_run.run_time + '发车');
		} else {
			alert('请选择班次')
			return;
		}
		var run_list = cache_data[run_date]['station_list'];
		var dict = {};
		run_list.forEach(function(v, i) {
			if(v['run_id'] == cache_select_data[run_date].cache_run_id) {
				dict = v;
			}
		})
		if(temp_start.start_station_id) {
			cache_select_data[run_date].cache_start_station_id = temp_start.start_station_id;
			cache_select_data[run_date].cache_start_station_name = temp_start.start_station_name;
		} else {
			var ss_id = dict['start_station_list'][0]['start_res_id'];
			var ss_name = dict['start_station_list'][0]['start_res_name'];
			cache_select_data[run_date].cache_start_station_id = ss_id;
			cache_select_data[run_date].cache_start_station_name = ss_name;
		}
		if(temp_end.end_station_id) {
			cache_select_data[run_date].cache_end_station_id = temp_end.end_station_id;
			cache_select_data[run_date].cache_end_station_name = temp_end.end_station_name;
			sel_cate_id = temp_end.pro_cate_id;
		} else {
			for (var i=0,m=dict['start_station_list'].length;i<m;i++) {
				var d = dict['start_station_list'][i];
				if(d['start_res_id']==cache_select_data[run_date].cache_start_station_id){
					var ss_id = d['end_station_list'][0]['station_id'];
					var ss_name = d['end_station_list'][0]['station_name'];
					cache_select_data[run_date].cache_end_station_id = ss_id;
					cache_select_data[run_date].cache_end_station_name = ss_name;
					sel_cate_id = d['end_station_list'][0]['pro_cate_id'];
				}
			}
//			var ss_id = dict['start_station_list'][0]['end_station_list'][0]['station_id'];
//			var ss_name = dict['start_station_list'][0]['end_station_list'][0]['station_name'];
//			cache_select_data[run_date].cache_end_station_id = ss_id;
//			cache_select_data[run_date].cache_end_station_name = ss_name;
//			sel_cate_id = dict['start_station_list'][0]['end_station_list'][0]['pro_cate_id'];
		}

		//更换库存价格信息
		$.ajax({
			url: base_api + 'prod/prod/get-prod-arr',
			data: { pro_cate_id: sel_cate_id },
			type: "post",
			dataType: "json",
			async: false,
			success: function(res) {
				ZZLog('更换库存', res);
				cache_select_data_back = {};
				$("#back_show_class").text("请选择");
				if(res.flag) {
					replaceTicketInfo(res.data.prod_arr);
				} else {
					if(codeNotLogin == res.code) {
						alert(infoNotLogin);
						var URL = 'station_ticket.html?fx_uid='+getFxUid();
						URL = encodeURI(URL);
						location.href = res.url + URL;
					} else {
						alert(res.msg);
					}
				}
			},
			error: function(error) {
				console.log(error);
			}
		});

	} else {
		cache_select_data_back[back_run_date] = {};
		if(temp_run_back.run_id) {
			cache_select_data_back[back_run_date].cache_run_id = temp_run_back.run_id;
			cache_select_data_back[back_run_date].cache_run_time = temp_run_back.run_time;
			$('#back_show_class').text(temp_run_back.run_time + '发车');
		} else {
			alert('请选择班次')
			return;
		}
		var run_list = cache_data_back[back_run_date]['station_list'];
		var dict = {};
		run_list.forEach(function(v, i) {
			if(v['run_id'] == cache_select_data_back[back_run_date].cache_run_id) {
				dict = v;
			}
		})
		if(temp_start_back.start_station_id) {
			cache_select_data_back[back_run_date].cache_start_station_id = temp_start_back.start_station_id;
			cache_select_data_back[back_run_date].cache_start_station_name = temp_start_back.start_station_name;
		} else {
			var ss_id = dict['start_station_list'][0]['start_res_id'];
			var ss_name = dict['start_station_list'][0]['start_res_name'];
			cache_select_data_back[back_run_date].cache_start_station_id = ss_id;
			cache_select_data_back[back_run_date].cache_start_station_name = ss_name;
		}
		if(temp_end_back.end_station_id) {
			cache_select_data_back[back_run_date].cache_end_station_id = temp_end_back.end_station_id;
			cache_select_data_back[back_run_date].cache_end_station_name = temp_end_back.end_station_name;
			back_cate_id = temp_end_back.pro_cate_id;
		} else {
			for (var i=0,m=dict['start_station_list'].length;i<m;i++) {
				var d = dict['start_station_list'][i];
				if(d['start_res_id']==cache_select_data_back[back_run_date].cache_start_station_id){
					var ss_id = d['end_station_list'][0]['station_id'];
					var ss_name = d['end_station_list'][0]['station_name'];
					cache_select_data_back[back_run_date].cache_end_station_id = ss_id;
					cache_select_data_back[back_run_date].cache_end_station_name = ss_name;
					back_cate_id = d['end_station_list'][0]['pro_cate_id'];
				}
			}
//			var ss_id = dict['start_station_list'][0]['end_station_list'][0]['station_id'];
//			var ss_name = dict['start_station_list'][0]['end_station_list'][0]['station_name'];
//			cache_select_data_back[back_run_date].cache_end_station_id = ss_id;
//			cache_select_data_back[back_run_date].cache_end_station_name = ss_name;
//			back_cate_id = dict['start_station_list'][0]['end_station_list'][0]['pro_cate_id'];
		}

		//更换库存价格信息
		$.ajax({
			url: base_api + 'prod/prod/get-prod-arr',
			data: { pro_cate_id: back_cate_id },
			type: "post",
			dataType: "json",
			async: false,
			success: function(res) {
				ZZLog('更换返程库存', res);
				if(res.flag) {
					back_list_ary = res.data.prod_arr;
					replaceBackTicketInfo(res.data.prod_arr);
				} else {
					if(codeNotLogin == res.code) {
						alert(infoNotLogin);
						var URL = 'station_ticket.html?fx_uid='+getFxUid();
						URL = encodeURI(URL);
						location.href = res.url + URL;
					} else {
						alert(res.msg);
					}
				}
			},
			error: function(error) {
				console.log(error);
			}
		});
	}

	$('.model_box_car').addClass('fadeInDown animated');
	setTimeout(function() {
		$('.model_car').hide();
		$('#body_mod').removeClass('mod_fil');
	}, 400);
}

//替换去程的票种html
function replaceTicketInfo(list_ary) {
	var html = '';
	var str = '0';
	var img = 'images/jianhao.png';
	list_ary.forEach(function(dict, index) {
		if(index == 0) {
			img = 'images/jianhao_sel.png'
			str = '1';
		} else {
			img = 'images/jianhao.png';
			str = '0';
		}
		html += '<div class="ub ub-ver disney_div">' +
			'	<div class="ui_p_b12" prod_count="' + dict.prod_count + '"  >' + dict.prod_name + '</div>' +
			'	<div class="ub">' +
			'		<div class="ub-f1 ub">' +
			'			<img class="cut" style="width: 0.22rem;height: 0.22rem;vertical-align: middle;" src="' + img + '"/>' +
			'			<span class="ulev3 count aticket"  type="text" readonly="true" value="' + str + '">' + str + '</span>' +
			'			<img class="add" style="width: 0.22rem;height: 0.22rem;vertical-align: middle;" src="images/jiahao_sel.png"/>' +
			'		</div>' +
			'		<div class="ub-f1 ub tx-r">' +
			'			<div class="ub-f1 ub ub-pe ub-ae font_price" >¥</div>' +
			'			<div class="ulev3 ub ub-ae font_price sigle_price" prod_id="' + dict.prod_id + '" style="line-height: 1;">' + dict.prod_price + '<span class="font_price" style="font-size:0.12rem">/张</span></div>' +
			'		</div>' +
			'	</div>' +
			'</div>';
	})
	$('#tick_type').html(html);
	jiajian();
}

function replaceBackTicketInfo(back_list_ary) {
	$('.sigle_price').each(function(index, dom) {
		var cc = $(this).text() ? $(this).text() : 0
		var current = parseInt(cc);
		var bb = back_list_ary[index].prod_price ? back_list_ary[index].prod_price : 0;
		var back = parseInt(bb);
		$(this).text(current + back);
	})
}

function jiajian() {
	//加
	$(".add").on("touchstart", function(e) {
		var target = e.target;
		console.log(e.target);
		if(pro_cate_id == "3") {
			$(".aticket").each(function(index, domE) {
				total_no += parseInt($(domE).text());
			});
			if(total_no == 5) {
				alert("迪士尼最多只能买五张票");
			} else {
				var current = $(target).parent().find(".aticket").text();
				var now_count = parseInt(current) + 1;
				$(target).parent().find(".aticket").text(now_count);
				$(target).parent().find(".cut").attr("src", "images/jianhao_sel.png");
			}
		} else {
			var current = $(target).parent().find(".aticket").text();
			var now_count = parseInt(current) + 1;
			$(target).parent().find(".aticket").text(now_count);
			$(target).parent().find(".cut").attr("src", "images/jianhao_sel.png");
		}
	});
	//减
	$(".cut").on("touchstart", function(e) {
		var target = e.target;
		var current = $(target).parent().find(".aticket").text();
		var now_count = parseInt(current) - 1;
		if(now_count > 0) {
			$(target).parent().find(".aticket").text(now_count);
		} else {
			$(target).parent().find(".aticket").text('0');
			$(target).attr("src", "images/jianhao.png");
		}
	})
}
//预订
function reserve() {
	//	countTotal();
	var if_back = $('#if_back').attr('go_back');
	var total_money = 0;
	var total_num = 0;
	var is_line = "1"; //是主线路

	var fill_order_20170307 = {};
	fill_order_20170307['if_back'] = if_back;
	fill_order_20170307['is_line'] = is_line;
	//去程
	if(!cache_select_data.hasOwnProperty(run_date)) { alert('请选择去程班次'); return; };
	var go_run_id = cache_select_data[run_date].cache_run_id ? cache_select_data[run_date].cache_run_id : "";
	var go_start_date = run_date;
	var go_start_time = cache_select_data[run_date].cache_run_time ? cache_select_data[run_date].cache_run_time : "";
	var t_start_station_name = cache_select_data[run_date].cache_start_station_name ? cache_select_data[run_date].cache_start_station_name : "";
	var t_end_station_name = cache_select_data[run_date].cache_end_station_name ? cache_select_data[run_date].cache_end_station_name : "";
	var go_pro_cate_name = t_start_station_name + '-' + t_end_station_name;
	var pro_cate_id = sel_cate_id;

	if(go_run_id == '') { alert('请选择去程班次'); return; }
	if(go_start_time == '') { alert('请选择去程班次'); return; }
	if(go_pro_cate_name == '-') { alert('请选择去程班次'); return; }

	var prod_arr = [];
	$('.disney_div').each(function(index, dom) {

		var t_prod_name = $(this).children().eq(0).text();
		var t_prod_id = $(this).find('.sigle_price').attr('prod_id');
		var t_prod_count = $(this).find('.count').text();
		var t_obj = {
			prod_name: t_prod_name,
			prod_id: t_prod_id,
			prod_count: t_prod_count
		}
		prod_arr.push(t_obj);

		var tick_price = parseInt($(this).find('.sigle_price').text());
		var num = parseInt($(this).find('.aticket').text());
		total_money += parseInt(num * tick_price);
		total_num += num-0;
	})

	var go_info = {
		go_run_id: go_run_id,
		go_pro_cate_name: go_pro_cate_name,
		go_start_date: go_start_date,
		go_start_time: go_start_time
	}
	fill_order_20170307['go_info'] = go_info;
	fill_order_20170307['pro_cate_id'] = pro_cate_id;
	fill_order_20170307['prod_arr'] = prod_arr;
	fill_order_20170307['total_money'] = total_money;

	if(go_run_id == '') {
		alert('请选择去程班次');
		return;
	} else if(total_num > go_total) {
		alert('库存不足');
		return;
	} else if(total_num == 0) {
		alert('请选择购买数量');
		return;
	}
	if(if_back == '1') {
		//返程
		var back_pro_cate_id = back_cate_id;
		if(!cache_select_data_back.hasOwnProperty(back_run_date)) { alert('请选择返程班次'); return; };
		var back_run_id = cache_select_data_back[back_run_date].cache_run_id ? cache_select_data_back[back_run_date].cache_run_id : "";
		var back_start_date = back_run_date;
		var back_start_time = cache_select_data_back[back_run_date].cache_run_time ? cache_select_data_back[back_run_date].cache_run_time : "";
		var t_start_station_name = cache_select_data_back[back_run_date].cache_start_station_name ? cache_select_data_back[back_run_date].cache_start_station_name : "";
		var t_end_station_name = cache_select_data_back[back_run_date].cache_end_station_name ? cache_select_data_back[back_run_date].cache_end_station_name : "";
		var back_pro_cate_name = t_start_station_name + '-' + t_end_station_name;

		if(back_run_id == '') { alert('请选择返程班次'); return; }
		if(back_start_time == '') { alert('请选择返程班次'); return; }
		if(back_pro_cate_name == '-') { alert('请选择返程班次'); return; }

		var back_prod_arr = [];
		fill_order_20170307['back_pro_cate_id'] = back_pro_cate_id;
		fill_order_20170307['back_run_id'] = back_run_id;
		fill_order_20170307['back_start_date'] = back_start_date;
		fill_order_20170307['back_start_time'] = back_start_time;
		fill_order_20170307['back_pro_cate_name'] = back_pro_cate_name;

		$('.disney_div').each(function(index, dom) {
			var v = back_list_ary[index];
			var t_prod_name = v['prod_name'];
			var t_prod_id = v['prod_id'];
			var t_prod_count = $(this).find('.count').text();
			var t_obj = {
				prod_name: t_prod_name,
				prod_id: t_prod_id,
				prod_count: t_prod_count
			}
			back_prod_arr.push(t_obj);

			var tick_price = parseInt($(this).find('.sigle_price').text());
			var num = parseInt($(this).find('.aticket').text());
			total_money += parseInt(num * tick_price);
			total_num += num;
		})

		var back_info = {
			back_run_id: back_run_id,
			back_pro_cate_name: back_pro_cate_name,
			back_start_date: back_start_date,
			back_start_time: back_start_time
		}
		fill_order_20170307['back_info'] = back_info;
		fill_order_20170307['back_prod_arr'] = back_prod_arr;

		var temp_count = go_total > back_total ? back_total : go_total;

		if(back_run_id == '') {
			alert('请选择返程班次');
			return;
		} else if(total_num > temp_count) {
			alert('库存不足');
			return;
		} else if(total_num == 0) {
			alert('请选择购买数量');
			return;
		}
	}
	setStorJson("fill_order_20170307", fill_order_20170307);
	window.location.href = "fill_order.html??"+version+"&fx_uid="+getFxUid();
}