|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757 |
- var login_data = getStorJson("login_data");
- var data = getStorJson("payOrderInfo");
-
- //记录出发地站点数组
- var start_station_list = '';
- //记录目的地站点数组
- var end_station_list = '';
- //记录返程出发地站点数组
- var back_start_station_list = '';
- //记录返程目的地站点数组
- var back_end_station_list = '';
- //记录是否选择返程状态
- var ifback = 0;
- //上弹框
- var wei_infoHTML = '';
- //返程的startid
- var back_start_id = ''
- //返程的end_id
- var back_end_id = ''
- //返程结果的html()
- var HTML = '';
- //返程的html()
- var backHTML = '';
- //总页面html
- var allHTML = '';
- //票种数量的html
- var count_html = '';
- //去程和往返的交集库存
- var stockCount = 0;
- //定义一个 只记录去程库存 一般取消返程选中时 重置去程库存
- var stockCountTemp = 0;
- //记录可选择的票种数量
- var ticketCount = 0;
- //去程单价
- var go_price = "";
-
- var newHTML = '';
-
- var curpage = 1;
-
- var thisdataStrShow = '';
-
- //去程
- var run_id = '';
- var line_id = '';
- var line_type = '';
- var ticket_id = '';
- var start_area_id = '';
- var end_area_id = '';
-
- //返程
- var back_run_id = '';
- var back_line_id = '';
- var back_ticket_id = '';
-
-
- var compare_data = '';
-
-
- window.onload = function () {
-
- wei_infoHTML = $('#wei_info').html();
- HTML = $('#list_info').html();
- backHTML = $('#select_back_div').html();
- allHTML = $('#back_info').html();
- count_html = $('#seat_count_info').html();
-
- var run_id = data.run_id;
- var start_area_id = data.start_area_id;
- var end_area_id = data.end_area_id;
- //返程
- back_start_id = data.end_area_id;
- back_end_id = data.start_area_id;
- //展示去程信息
- showGoInfo(run_id, start_area_id, end_area_id);
-
-
- }
- //展示去程信息
- function showGoInfo(run_id, start_area_id, end_area_id) {
- $.ajax({
- url: './zz-fx/control.php',
- type: "post",
- data: {
- run_id: run_id,
- start_area_id: start_area_id,
- end_area_id: end_area_id,
- back: 1,
- type: "retrieval_site",
- operate: 'initial'
- },
- dataType: "json",
- success: function (data) {
- if (data.code == 0) {
- console.log(data);
- //去程信息的数据交互
- goInfoReloadData(data.list);
- }
- },
- fail: function (data) {
- // 此处放失败后执行的代码
- }
- });
- }
-
- //去程信息的数据交互
- function goInfoReloadData(data) {
- var go_info_HTML = $('#go_info').html();
- var temp = go_info_HTML;
- // temp = temp.replace('7月28日',data.date);
-
- var month = getMonthAndDayByDate(data.run_date, 'month');
- if (month != '10' && month != '11' && month != '12') {
- month = month.substring(1, month.length);
- }
- var day = getMonthAndDayByDate(data.run_date, 'day');
- temp = temp.replace('7月28日', month + '月' + day + '日');
-
- compare_data = data.run_date;
- temp = temp.replace('[出发地]', data.start_area_name);
- temp = temp.replace('[目的地]', data.end_area_name);
-
- start_area_id = data.start_area_id;
- end_area_id = data.end_area_id;
-
- $('#go_info').html(temp);
-
- start_station_list = data.start_res_arr;
- end_station_list = data.end_res_arr;
-
- $('#up_station_time').html(data.select_start_res.res_time + ' ' + data.select_start_res.res_name);
- $('#up_station_time').attr('valId', data.select_start_res.res_id);
-
- $('#down_station_time').html(data.select_end_res.res_time + ' ' + data.select_end_res.res_name);
- $('#down_station_time').attr('valId', data.select_end_res.res_id);
-
- run_id = data.run_id;
- line_id = data.line_id;
- var start_id = $('#up_station_time').attr('valid');
- var end_id = $('#down_station_time').attr('valid');
- ticket = data.ticket;
- line_type = data.line_type;
- //在展示数据后 继续调用票种价格等相关信息
- showCountInfoByGo(data.ticket_info);
-
- }
-
-
- //替换去程票种数量信息
- function showCountInfoByGo(data) {
- var html1 = '';
- var temp1 = count_html;
- go_price = data.price;
- temp1 = temp1.replace('[普通座]', data.seat_type_name);
- temp1 = temp1.replace('50元', data.price);
- //数量
- var maxCount = data.stock > 20 ? 20 : data.stock;
- maxCount = maxCount > 0 ? maxCount : 0;
-
- stockCount = maxCount;
- stockCountTemp = maxCount;
-
- html1 += temp1;
- $('#seat_count_info').html(html1);
-
- ticket_id = data.ticket_id;
- countPrice();
- }
-
- //增加购买数量
- function addition() {
- if (ticketCount < stockCount) {
- ticketCount++;
- $('#adult').val(ticketCount);
- } else {
- alert('无法购买更多!');
- }
- countPrice();
- }
-
- //减法购买数量
- function subtraction() {
- if (ticketCount > 0) {
- ticketCount--;
- $('#adult').val(ticketCount);
- } else {
- alert('请选择正确的票种数量!');
- }
- countPrice();
- }
-
-
- //上弹框的内容封装
- function upDiv(data, select_id, goBack) {
- var html = '';
- for (var i = 0; i < data.length; i++) {
- var tempHTML = wei_infoHTML;
- tempHTML = tempHTML.replace('示例菜单', data[i].res_time + ' ' + data[i].res_name);
- tempHTML = tempHTML.replace('[id]', data[i].res_id);
- html += tempHTML;
- }
- $('#wei_info').html(html);
- $('.weui_actionsheet_cell').click(function () {
- if (this.innerHTML == '取消') {
- $('#mask').click();
- return;
- } else {
- $('#' + select_id).html(this.innerHTML);
- $('#' + select_id).attr('valid', this.id);
- $('#mask').click();
- }
- //alert(goBack);
- if (goBack == 'go') { // 去程
- var start_id = $('#up_station_time').attr('valid');
- var end_id = $('#down_station_time').attr('valid');
- if (select_id == "up_station_time") {//去程 上
- $.ajax({
- url: './zz-fx/control.php',
- type: "post",
- data: {
- run_id: run_id,
- start_res_id: start_id,
- end_area_id: end_area_id,
- back: 1,
- type: "retrieval_site",
- operate: 'start',
- line_type: line_type
- },
- dataType: "json",
- success: function (data) {
- if (data.code == 0) {
- console.log(data);
- //下车站点替换
- end_station_list = data.list.end_res_arr;
- $('#down_station_time').html(data.list.select_end_res.res_time + ' ' + data.list.select_end_res.res_name);
- $('#down_station_time').attr('valId', data.list.select_end_res.res_id);
- //替换去程票种数量信息
- showCountInfoByGo(data.list.ticket_info);
- }
- },
- fail: function (data) {
- // 此处放失败后执行的代码
- }
- });
- } else { //去程 下
- $.ajax({
- url: './zz-fx/control.php',
- type: "post",
- data: {
- run_id: run_id,
- start_res_id: start_id,
- end_res_id: end_id,
- back: 1,
- type: "retrieval_site",
- operate: 'end',
- line_type: line_type
- },
- dataType: "json",
- success: function (data) {
- if (data.code == 0) {
- console.log(data);
- //替换去程票种数量信息
- showCountInfoByGo(data.list.ticket_info);
- }
- },
- fail: function (data) {
- // 此处放失败后执行的代码
- }
- });
- }
- } else { // 返程
- var go_start_res_id = $('#up_station_time').attr('valid');
- var go_end_res_id = $('#down_station_time').attr('valid');
-
- var back_start_station_id = $('#back_up_station_time').attr('valid');
- var back_end_station_id = $('#back_down_station_time').attr('valid');
- if(select_id == 'back_up_station_time'){ //返程 上
- $.ajax({
- url: './zz-fx/control.php',
- type: "post",
- data: {
- go_run_id:run_id,
- go_start_res_id:go_start_res_id,
- go_end_res_id:go_end_res_id,
- run_id: back_run_id,
- start_res_id: back_start_station_id,
- end_area_id: start_area_id,
- line_type:line_type,
- back: 2,
- type: "retrieval_site",
- operate: 'start'
- },
- dataType: "json",
- success: function (data) {
- if (data.code == 0) {
- console.log(data);
- data = data.list;
- //替换去程票种数量信息
- back_end_station_list = data.end_res_arr;
-
- $('#back_down_station_time').html(data.select_end_res.res_time + ' ' + data.select_end_res.res_name);
- $('#back_down_station_time').attr('valId', data.select_end_res.res_id);
- showCountInfoByBack(data.ticket_info);
- }
- },
- fail: function (data) {
- // 此处放失败后执行的代码
- }
- });
- }else{ // 返程 下
- $.ajax({
- url: './zz-fx/control.php',
- type: "post",
- data: {
- go_run_id:run_id,
- go_start_res_id:go_start_res_id,
- go_end_res_id:go_end_res_id,
- run_id: back_run_id,
- start_res_id: back_start_station_id,
- end_res_id: back_end_station_id,
- line_type:line_type,
- back: 2,
- type: "retrieval_site",
- operate: 'start'
- },
- dataType: "json",
- success: function (data) {
- if (data.code == 0) {
- console.log(data);
- data = data.list;
- //替换去程票种数量信息
- showCountInfoByBack(data.ticket_info);
- }
- },
- fail: function (data) {
- // 此处放失败后执行的代码
- }
- });
- }
- }
-
- })
- }
-
- //选择站点的下侧弹层
- $("#start_area").click(function () {
- upDiv(start_station_list, 'up_station_time', 'go');
- $("#mask").css("display", "block");
- $("#weui_actionsheet").addClass("weui_actionsheet_toggle");
- })
- $("#end_area").click(function () {
- upDiv(end_station_list, 'down_station_time', 'go');
- $("#mask").css("display", "block");
- $("#weui_actionsheet").addClass("weui_actionsheet_toggle");
- })
-
- $('#mask').click(function () {
- $("#mask").css("display", "none");
- $("#weui_actionsheet").removeClass("weui_actionsheet_toggle");
- })
-
-
- //选择返程
- $(document).ready(function () {
- var tomonth = new Date();
-
- $("#ifback").on("click", function () {
- if (ifback == 1) {
- ifback = 0;
- $('#back_info').addClass('ui_hide');
- $('#ifandback').addClass('ui_hide');
- stockCount = stockCountTemp;
- $('#adult').val(0);
- ticketCount = 0;
-
-
- var start_id = $('#up_station_time').attr('valid');
- var end_id = $('#down_station_time').attr('valid');
- $.ajax({
- url: './zz-fx/control.php',
- type: "post",
- data: {
- run_id: run_id,
- line_id: line_id,
- start_id: start_id,
- end_id: end_id,
- tickets: ticket,
- back: 1,
- type: "retrieval_tickets"
- },
- dataType: "json",
- success: function (data) {
- if (data.code == 0) {
- console.log(data);
- //替换去程票种数量信息
- showCountInfoByGo(data.list);
- }
- },
- fail: function (data) {
- // 此处放失败后执行的代码
- }
- });
-
- } else {
- addmouth($(".month"), tomonth.getFullYear(), tomonth.getMonth());
- $(".month").show();
- $("#order_detail_info").hide();
- $("#back_info").removeClass('ui_hide');
- $('#ifandback').removeClass('ui_hide');
- $('#cancle').html('取消');
- ticketCount = 0;
- selectDate();
- }
- });
- })
- //点击取消按钮
- function cancleShow() {
- ifback = 0;
- $('#back_info').addClass('ui_hide');
- $('#ifandback').addClass('ui_hide');
- $('#cancle').html('>');
- stockCount = stockCountTemp;
- $('#adult').val(0);
- ticketCount = 0;
-
- var start_id = $('#up_station_time').attr('valid');
- var end_id = $('#down_station_time').attr('valid');
- $.ajax({
- url: './zz-fx/control.php',
- type: "post",
- data: {
- run_id: run_id,
- line_id: line_id,
- start_id: start_id,
- end_id: end_id,
- tickets: ticket,
- back: 1,
- type: "retrieval_tickets"
- },
- dataType: "json",
- success: function (data) {
- if (data.code == 0) {
- console.log(data);
- //替换去程票种数量信息
- showCountInfoByGo(data.list);
- }
- },
- fail: function (data) {
- // 此处放失败后执行的代码
- }
- });
- }
- //重新选择
- function selectAgain() {
- var tomonth = new Date();
- addmouth($(".month"), tomonth.getFullYear(), tomonth.getMonth());
- $(".month").show();
- $("#order_detail_info").hide();
- $("#back_info").removeClass('ui_hide');
- $('#ifandback').removeClass('ui_hide');
- $('#cancle').html('取消');
- ticketCount = 0;
- selectDate();
- }
-
-
- //选中日期
- function selectDate() {
- $(".canday").on("click", function () {
- ifback = 1;
- if ($(this).html() == "今天") {
- var seldate = new Date().getDate();
- } else {
- var seldate = $(this).html();
- }
- var yearmonth = $(".currentdate").html().split("年");
-
- if (yearmonth[1] != 10 && yearmonth[1] != 11 && yearmonth[1] != 12) {
- var show_yearmonth = '0' + yearmonth[1];
- } else {
- var show_yearmonth = yearmonth[1];
- }
- if (seldate < 10) {
- var show_seldate = '0' + seldate;
- } else {
- var show_seldate = seldate;
- }
- //前台展示
- thisdataStrShow = yearmonth[1] + '月' + seldate + '日';
- //后台传参
- var thisdataStrSend = yearmonth[0] + "-" + show_yearmonth + "-" + show_seldate;
- if (compare_data > thisdataStrSend) {
- console.log(compare_data + '+' + thisdataStrSend)
- alert('返程日期不能小于出发日期!');
- return;
- } else {
- //根据返程日期 调用数据
- reloadBackData(thisdataStrSend);
- }
- //获取星期
- var thisdata = yearmonth[0] + "/" + yearmonth[1] + "/" + seldate;
- var select_week = getWeekDay(thisdata);
-
- $('#adult').val(0);
-
- //根据返程日期 调用数据
- // reloadBackData(thisdataStrSend);
- })
- }
- //加载返程数据
- function reloadBackData(backtime) {
- $.ajax({
- url: './zz-fx/control.php', //请求地址
- type: "post", //请求方式
- // data: data, //请求参数
- data: {
- start_area: back_start_id,
- end_area: back_end_id,
- go_time: backtime,
- bus_type: data.bus_type,
- type: "retrieval_through",
- run_type: 1,
- currpage: 1,
- pagesize: data.pagesize
- },
- async: false,
- dataType: "json",
- success: function (data) {
- console.log(data);
- if (data.code == 0) {
- var sum = data.totalnum;
- if (sum == 0) {
- alert('没有返程相关班次,请重新选择!')
- return;
- } else {
- $(".month").hide();
- $('#ifandback').removeClass('ui_hide');
- $('#back_search_results').removeClass('ui_hide');
- $('#order_detail_info').addClass('ui_hide');
- //替换返程数据信息
- replaceBackInfo(data);
- }
- }
- },
- fail: function (date) {
- }
- });
- }
-
- //替换返程数据信息
- function replaceBackInfo(data) {
- var list = data.list;
- $('#select_date_a').html(thisdataStrShow);
- newHTML = '';
- for (var i = 0; i < list.length; i++) {
- var tempHTML = HTML;
- tempHTML = tempHTML.replace('[出发地]', list[i].start_area_name);
- tempHTML = tempHTML.replace('[目的地]', list[i].end_area_name);
- tempHTML = tempHTML.replace('[时间]', list[i].start_time);
- tempHTML = tempHTML.replace('[价格]', list[i].price);
- console.log(list[i].line_id);
- tempHTML = tempHTML.replace('[order_id]', list[i].run_id);
- tempHTML = tempHTML.replace('[order_idli]', list[i].run_id);
- tempHTML = tempHTML.replace('[start_id]', list[i].start_area_id);
- tempHTML = tempHTML.replace('[end_id]', list[i].end_area_id);
- tempHTML = tempHTML.replace('[start_name]', '\'' + list[i].start_area_name + '\'');
- tempHTML = tempHTML.replace('[end_name]', '\'' + list[i].end_area_name + '\'');
- newHTML += tempHTML;
- }
- $('#list_info').html(newHTML);
- }
-
- //每个详情的点击事件
- function goPayInfo(id, start_id, end_id, start_name, end_name) {
-
- var go_start_res_id = $('#up_station_time').attr('valid');
- var go_end_res_id = $('#down_station_time').attr('valid');
-
- $('#order_detail_info').removeClass('ui_hide');
- $('#order_detail_info').show();
- $('#back_search_results').addClass('ui_hide');
- var newhtml = '';
- var temp = allHTML;
- temp = temp.replace('7月28日', thisdataStrShow);
- temp = temp.replace('[出发地]', start_name);
- temp = temp.replace('[目的地]', end_name);
- $('#back_info').html(temp);
-
- $.ajax({
- url: './zz-fx/control.php',
- type: "post",
- data: {
- go_run_id: run_id,
- go_start_res_id: go_start_res_id,
- go_end_res_id: go_end_res_id,
- run_id: id,
- start_area_id: start_id,
- end_area_id: end_id,
- back: 2,
- type: "retrieval_site",
- operate: 'initial'
- },
- dataType: "json",
- success: function (data) {
- if (data.code == 0) {
- console.log(data);
- //返程信息的数据交互
- backInfoReloadData(data.list);
- }
- },
- fail: function (data) {
- // 此处放失败后执行的代码
- }
- });
-
- }
-
- //返程站点信息的数据交互
- function backInfoReloadData(data) {
- back_start_station_list = data.start_res_arr;
- back_end_station_list = data.end_res_arr;
-
- $('#back_up_station_time').html(data.select_start_res.res_time + ' ' + data.select_start_res.res_name);
- $('#back_up_station_time').attr('valId', data.select_start_res.res_id);
-
- $('#back_down_station_time').html(data.select_end_res.res_time + ' ' + data.select_end_res.res_name);
- $('#back_down_station_time').attr('valId', data.select_end_res.res_id);
-
-
- //选择站点的下侧弹层
- $("#back_up_station").click(function () {
- upDiv(back_start_station_list, 'back_up_station_time', 'back');
- $("#mask").css("display", "block");
- $("#weui_actionsheet").addClass("weui_actionsheet_toggle");
- })
-
- $("#back_down_station").click(function () {
- upDiv(back_end_station_list, 'back_down_station_time', 'back');
- $("#mask").css("display", "block");
- $("#weui_actionsheet").addClass("weui_actionsheet_toggle");
- })
-
- back_run_id = data.run_id;
- back_line_id = data.line_id;
-
- //替换去程票种数量信息
- showCountInfoByBack(data.ticket_info);
-
-
- }
-
- //返程票种数量相关信息
- function showCountInfoByBack(data) {
-
-
- var html1 = '';
- var temp1 = count_html;
- temp1 = temp1.replace('[普通座]', data.seat_type_name);
- temp1 = temp1.replace('50元', data.price);
- //数量
- var maxCount = data.stock > 20 ? 20 : data.stock;
- maxCount = maxCount > 0 ? maxCount : 0;
-
- stockCount = maxCount < stockCount ? maxCount : stockCount;
-
- html1 += temp1;
- $('#seat_count_info').html(html1);
- $('#ifandback').removeClass('ui_hide');
-
- //把票种数据存入ifandback中
- var json_str = JSON.stringify(data);
- $('#ifandback').attr('data_str',json_str);
- back_ticket_id = data.ticket_id;
- countPrice();
- }
-
-
- //计算价格
- function countPrice() {
- var price = $('#ticket_price').html();
- var count = $('#adult').val();
- var totalPrice = count * price;
- $('#total_price').html('¥' + totalPrice);
- }
-
- //支付按钮
- function payBtnDidCLicked() {
- var linkman = $('#linkman').val();
- var telnum = $('#telnum').val();
- var phoneRe = /^1[3|4|5|7|8]\d{9}$/;
- if (linkman == "" || telnum == "") {
- alert('联系人信息输入不完整 !');
- return;
- }
- if (!phoneRe.test(telnum)) {
- alert('请输入正确的手机号!')
- return;
- }
- ;
- var tic_count = $('#adult').val();
- var peoInfo = '{' + linkman + ',' + telnum + ',}';
- if (tic_count == 0) {
- alert('购买数量为空!');
- return;
- }
-
- if (ifback == 0) {
- var tic_price = $('#ticket_price').html();
- var ticket_info = '{1,' + run_id + ',' + ticket_id + ',' + tic_price + ',' + tic_count + '}';
- $("#loadingToast").show();
- } else {
- var json_str = $('#ifandback').attr('data_str');
- var ticket_data = JSON.parse(json_str);
- var go_ticket_info = '{1,' + ticket_data.go_run_id + ',' + ticket_data.go_ticket_id + ',' + ticket_data.go_discount_price + ',' + tic_count + '}';
- var back_ticket_info = '{2,' + ticket_data.back_run_id + ',' + ticket_data.back_ticket_id + ',' + ticket_data.back_discount_price + ',' + tic_count + '}';
- var ticket_info = go_ticket_info + back_ticket_info;
- $("#loadingToast").show();
- }
- // var data = {
- // ticket_info: ticket_info,
- // customer_info: peoInfo,
- // run_id:run_id,
- // type: "distribut_OrderUp1"
- // };
- // console.log(data);
- // return 123;
- $.ajax({
- url: './zz-fx/control.php',
- type: "post",
- data: {
- ticket_info: ticket_info,
- customer_info: peoInfo,
- run_id:run_id,
- type: "distribut_OrderUp1"
- },
- dataType: "json",
- success: function (data) {
- $("#loadingToast").hide();
- $(".weui_toast").hide();
- if (data.code == 0) {
- console.log(data);
- if (login_data.pay_status == "0") {
- setStorJson("submite_success", data);
- window.location.href = "pay_order.html";
- } else if (login_data.pay_status == "1") {
- setStorJson("submite_success", data);
- window.location.href = "submite_success.html";
- }
- } else {
- alert(data.info);
- }
- },
- fail: function (data) {
- // 此处放失败后执行的代码
- }
- });
- }
|