|
- var pro_id = getPar("pro_id");
- var date = getPar("go_date");
- var p_num = getPar("peo_no");
- var json_data = {
- //缓存数据
- pro_id: pro_id, //产品id
- date: date, //出行日期
- p_num: p_num, //出行人数
- style_type: 1, //显示状态
- go_person: '', //出行人信息
- go_person_num: 0, //出行人数量
- contacts_name: '', //联系人姓名
- m_phone: '', //联系人电话
- price: 0,
- };
-
- window.onload = function() {
- if(getStorJson("trave_around_fill_order") == null) {
- //第一次加载
- json_data.pro_id = pro_id; //产品id
- json_data.p_num = p_num;
- json_data.date = date;
- json_data.style_type = 1;
- json_data.go_person = '';
- json_data.go_person_num = 0;
- json_data.contacts_name = '';
- json_data.m_phone = '';
- var param = {
- pro_id: json_data.pro_id, //产品id
- date: json_data.date,
- p_num: json_data.p_num,
- }
- setStorJson('trave_around_fill_order', json_data); //初始化缓存
- baseInfo(param);
- $("#total_person").text("共" + json_data.p_num + "人");
- $("#go_person_ul").hide();
- $("#continue_add").hide();
- $("#show_add_go_people").show();
- $("#how_many_perple_add").text("需添" + Math.ceil(json_data.p_num / 5) + "人");
- } else {
- //不是第一次加载
- var temp_data = getStorJson('trave_around_fill_order');
- var temp_pro_id = getPar("pro_id");
- var temp_date = getPar("go_date");
- var temp_p_num = getPar("peo_no");
- temp_data.pro_id = temp_pro_id;
- temp_data.date = temp_date;
- temp_data.p_num = temp_p_num;
- setStorJson("trave_around_fill_order", temp_data);
- var param = {
- pro_id: temp_data.pro_id, //产品id
- date: temp_data.date,
- p_num: temp_data.p_num,
- }
- baseInfo(param);
- if(temp_data.style_type == 1 && temp_data.go_person_num == 0) {
- //没有选择出行人
- $("#go_person_ul").hide();
- $("#continue_add").hide();
- $("#show_add_go_people").show();
- $("#how_many_perple_add").text("需添" + Math.ceil(temp_data.p_num / 5) + "人");
- $("#total_person").text("共" + temp_data.p_num + "人");
- } else {
- //选择了出行人
- show_go_people();
- }
- $("#price").text(temp_data.price);
- $("#contacts_name_input").val(temp_data.contacts_name);
- $("#m_phone_input").val(temp_data.m_phone);
- }
-
- }
-
- function base_html(data) {
- //显示基础信息
- //得到价格
- var temp_data = getStorJson("trave_around_fill_order");
- temp_data.price = data.price;
- setStorJson('trave_around_fill_order', temp_data);
- $("#tickdes").text(data.tickdes);
- $("#zname").text(data.zname);
- $("#price").text(data.price);
- $("#start_date").text(data.start_date);
- $("#end_date").text(data.end_date);
- $("#start_time").text(data.start_time);
- $("#start_area").text(data.start_area);
- $("#end_area").text(data.end_area);
- $("#end_time").text(data.end_time);
- $("#loading_html").show();
- }
-
- function baseInfo(param) {
- //获取基础信息
- ZZLog(base_api + "around/getOrder&" + JSON.stringify(param));
- $.ajax({
- type: "post",
- url: base_api + "around/getOrder",
- data: param,
- dataType: 'json',
- success: function(res_data) {
- ZZLog(res_data);
- if(res_data.flag == true) {
- base_html(res_data.data);
- } else {
- alert(res_data.msg);
- }
- },
- error: function(e) {
- ZZLog(e);
- }
- });
- }
-
- function add_new_go_person() {
- //添加新的联系人
- //扫一下当前状态,保存内存
- var temp_data = getStorJson("trave_around_fill_order");
- temp_data.contacts_name = $("#contacts_name_input").val();
- temp_data.m_phone = $("#m_phone_input").val();
- setStorJson('trave_around_fill_order', temp_data);
- window.location.href = 'add_travel_person.html'; //添加出行人
- }
-
- function show_go_person_tancen(data) {
- //分别显示不同弹层弹层
- if(data.length == 0) {
- //显示去添加出行人的弹层
- $("#tancen_main_control").addClass("weui_actionsheet_toggle");
- $("#no_go_person").show();
- $("#mask").show();
- } else {
- //显示出行人列表的弹层
- $("#tancen_main_control").addClass("weui_actionsheet_toggle");
- $("#go_person_list").show();
- $("#mask").show();
- //加载后台得到的数据
- var temp_str = '';
- for(var i = 0; i < data.length; i++) {
- // temp_str += '<li id="go_person_' + data[i].customer_id + '" onclick="choice_or_cancle_person(this)" go_person_id="' + data[i].customer_id + '" class="ub ui_p_l25 ui_p_r25 ub-ac white_bccolor">' +
- // '<img class="tancen_edit" src="images/imgEditDis@2x.png" />' +
- // '<div class="tancen_name">' + data[i].customer_name + '</div>' +
- // '<div class="ub-f1 tancen_id_num">' + data[i].customer_id_card + '</div>' +
- // '<img id="" class="tancen_select" src="images/ic_nor@2x.png" />' +
- // '</li>';
-
- temp_str += '<li id="go_person_' + data[i].customer_id + '" go_person_id="' + data[i].customer_id + '" class="ub ub-ac white_bccolor">' +
- '<img onclick="edit_person(this)" class="tancen_edit ui_p_l25 ui_p_r10" src="images/imgEditDis@2x.png" />' +
- '<div class="ub ub-f1" onclick="choice_or_cancle_person(this)">' +
- '<div style="width: 1%;" class="tancen_name ub-f1">' + data[i].customer_name + '</div>' +
- '<div style="width: 1%;" class=" tancen_id_num ub-f4">' + data[i].customer_id_card + '</div>' +
- '<img id="" class="tancen_select ub-ae ui_p_r25" src="images/ic_nor@2x.png" />' +
- '</div>' +
- '</li>';
- }
- $("#ul_tancen").html(temp_str);
- var temp_data = getStorJson("trave_around_fill_order");
- //判断已经选中的联系人为选中状态
- if(temp_data.go_person_num != 0) {
- //已经选中了几个联系人
- for(var i = 0; i < temp_data.go_person_num; i++) {
- $("#go_person_" + temp_data.go_person[i].customer_id).children().eq(1).children().eq(2).attr("src", "images/ic_sel@2x.png"); //标记选中
- $("#go_person_" + temp_data.go_person[i].customer_id).addClass("go_person_selected"); //父元素加上标记类
- }
- } else {
- //没有选择联系人
- }
- }
-
- }
-
- //修改出行人
- function edit_person(which_obj) {
- var go_person_id = $(which_obj).parent().attr("go_person_id"); //出行人id
- var name = $(which_obj).parent().children().eq(1).children().eq(0).text(); //姓名
- var idcard = $(which_obj).parent().children().eq(1).children().eq(1).text(); //id
- window.location.href = 'change_travel_person.html?go_person_id=' + go_person_id + "&name=" + name + "&idcard=" + idcard; //添加出行人
- }
-
- //选择或者取消出行人
- function choice_or_cancle_person(which_obj) {
- if($(which_obj).children().eq(2).attr("src") == "images/ic_nor@2x.png") {
- //没被选中,变成选中
- $(which_obj).children().eq(2).attr("src", "images/ic_sel@2x.png")
- $(which_obj).parent().addClass("go_person_selected"); //加上选中标记类
- } else {
- //已经选中,变成没选中
- $(which_obj).children().eq(2).attr("src", "images/ic_nor@2x.png")
- $(which_obj).parent().removeClass("go_person_selected"); //删除选中标记类
- }
-
- }
-
- function cancel_tancen() {
- //关掉所有弹层和蒙版
- $("#tancen_main_control").removeClass("weui_actionsheet_toggle");
- $("#mask").hide();
- $("#go_person_list").hide();
- $("#no_go_person").hide();
- }
-
- function add_go_person_tancen() {
- //获取出行人信息
- var param = {}
- ZZLog(base_api + "order/order/getCustomerList&" + JSON.stringify(param));
- $.ajax({
- type: "post",
- url: base_api + "order/order/getCustomerList",
- data: param,
- dataType: 'json',
- success: function(res_data) {
- ZZLog(res_data);
- if(res_data.flag == true) {
- show_go_person_tancen(res_data.data);
- } else {
- alert(res_data.msg);
- }
- },
- error: function(e) {
- ZZLog(e);
- }
- });
- }
-
- function ensure_go_person() {
- //确定按钮
- var total_people = $(".go_person_selected").length;
- var info_arr = [];
- $(".go_person_selected").each(function(index, dom) {
- var info_data = {
- customer_id: $(this).attr("go_person_id"),
- customer_name: $(this).children().eq(1).children().eq(0).text(),
- customer_id_card: $(this).children().eq(1).children().eq(1).text(),
- }
- info_arr.push(info_data);
- })
- var temp_data = getStorJson("trave_around_fill_order");
- temp_data.go_person_num = total_people;
- temp_data.go_person = info_arr;
- if(total_people > 0) {
- temp_data.style_type = 2;
- } else {
- temp_data.style_type = 1;
- }
- setStorJson('trave_around_fill_order', temp_data);
- if(total_people > 0) {
- cancel_tancen();
- show_go_people();
- } else {
- //确认后全部没有勾选
- cancel_tancen();
- $("#go_person_ul").hide();
- $("#continue_add").hide();
- $("#show_add_go_people").show();
- $("#how_many_perple_add").text("需添" + Math.ceil(json_data.p_num / 5) + "人");
- }
- }
- //显示出行人列表
- function show_go_people() {
- var temp_data = getStorJson("trave_around_fill_order"); //得到缓存
- var temp_str = '';
- for(var i = 0; i < temp_data.go_person_num; i++) {
- temp_str += '<li class="white_color_bg ">' +
- '<div class="ub ui_p_r25 ub-ac ">' +
- '<div class="ub ub-f1 ui_p_l25 ui_p_t15 ui_p_b15 people_name ">' + temp_data.go_person[i].customer_name + '</div>' +
- '<div class="ub ub-f2 ui_p_t15 ui_p_b15 id_card_css ">' + temp_data.go_person[i].customer_id_card + '</div>' +
- '<div go_person_id="' + temp_data.go_person[i].customer_id + '" onclick="remove_go_people(this)" class="ub ub-f1 ui_p_t15 ui_p_b15 text_right ub-pe jian_css ">' +
- '<img class="ub img_css " src="images/ic_remove@2x.png " />' +
- '</div>' +
- '</div>' +
- '<div class="ui_m_l25 inner_up_line_color "></div>' +
- '</li>';
- }
- $("#show_add_go_people").hide();
- $("#go_person_ul").show();
- $("#continue_add").show();
- $("#go_person_ul").html(temp_str);
- }
- //删除出行人信息
- function remove_go_people(which_obj) {
- var temp_data = getStorJson("trave_around_fill_order"); //得到缓存
- var info_arr = [];
- for(var i = 0; i < temp_data.go_person_num; i++) {
- var info_data = {
- customer_id: temp_data.go_person[i].customer_id,
- customer_name: temp_data.go_person[i].customer_name,
- customer_id_card: temp_data.go_person[i].customer_id_card,
- }
- if(temp_data.go_person[i].customer_id != $(which_obj).attr("go_person_id")) {
- info_arr.push(info_data);
- }
- }
- temp_data.go_person_num--;
- temp_data.go_person = info_arr;
- setStorJson('trave_around_fill_order', temp_data);
- if(temp_data.go_person_num > 0) {
- show_go_people();
- } else {
- $("#go_person_ul").hide();
- $("#continue_add").hide();
- $("#show_add_go_people").show();
- $("#how_many_perple_add").text("需添" + Math.ceil(json_data.p_num / 5) + "人");
- }
-
- }
-
- function payBtnDidClicked() {
- delay(makorder, 300);
-
- function makorder() {
-
- //支付
- var temp_data = getStorJson("trave_around_fill_order");
- if(temp_data.go_person_num < Math.ceil(temp_data.p_num / 5) || temp_data.go_person_num > temp_data.p_num) {
- if(temp_data.go_person_num < Math.ceil(temp_data.p_num / 5)) {
- alert("需添加" + Math.ceil(temp_data.p_num / 5) + "位出行人信息!");
- return;
- } else {
- alert("添加出行人信息过多!");
- return;
- }
- } else {
- var temp_name = $("#contacts_name_input").val();
- var temp_phone = $("#m_phone_input").val();
- if(temp_name == '' || temp_phone == '') {
- alert("请填写联系人信息!");
- return;
- } else {
- var phoneRe = /^1[3|4|5|7|8]\d{9}$/;
- if(!phoneRe.test(temp_phone)) {
- alert('请输入正确的手机号!')
- return;
- }
- temp_data.contacts_name = temp_name;
- temp_data.m_phone = temp_phone;
- var temp_str = '';
- for(var i = 0; i < temp_data.go_person_num; i++) {
- if(i == 0) {
- temp_str = temp_str + temp_data.go_person[i].customer_id;
- } else {
- temp_str = temp_str + "," + temp_data.go_person[i].customer_id;
- }
- }
- setStorJson('trave_around_fill_order', temp_data);
- var param = {
- pro_id: temp_data.pro_id, //产品id
- start_date: temp_data.date,
- p_num: temp_data.p_num,
- customer_name: temp_data.contacts_name,
- customer_moble: temp_data.m_phone,
- price: $("#price").text(),
- remark: temp_str,
- };
- $("#payBtn").removeAttr('onClick');
- $("#loadingToast").show();
-
- $.ajax({
- type: "post",
- url: base_api + "around/makeOrder",
- data: param,
- dataType: 'json',
- success: function(res_data) {
- ZZLog(res_data);
- if(res_data.flag == true) {
- //成功的回调,删除缓存
- clearStorage("trave_around_fill_order");
- $("#loadingToast").hide();
- $("#payBtn").attr('onClick', 'payBtnDidClicked();');
- window.location.href = res_data.url;
- } else {
- $("#loadingToast").hide();
- $("#payBtn").attr('onClick', 'payBtnDidClicked();');
- if(data.code != '10001') {
- alert(data.msg);
- } else {
- return;
- }
- }
- },
- error: function(e) {
- ZZLog(e);
- }
- });
- }
- }
-
- }
- }
-
- var delay = (function() {
- var timer = 0;
- return function(callback, time) {
- clearTimeout(timer);
- timer = setTimeout(callback, time);
- };
- })()
|