|
- //记录添加的信息
- var i = 0;
- //author:
- //update by : fuhc
- var order_from_id = "-1";
- var returnStartArea = ""
- var returnEndArea = "";
- //fancheng prod_id
- var back_prod_id = '';
- var back_run_id = ''; //返程run_id
- var checkedValue = ''; //是否是返程
- //
- var start_date = '';
-
- if(window.ActiveXObject) {
- var myreq = new ActiveXObject("Microsoft.XMLHTTP");
- } else {
- var myreq = new XMLHttpRequest();
- }
- var ticketArray = new Array();
- var m_runid = 0;
- function ZZLog(str){
- var isLog=true;
- if(isLog){
- console.log(str);
- }
- }
- $(document).ready(function(){
- id = getPar("id");
- var run_id = getPar("run_id");
- m_runid = run_id;
- start_date = getPar('run_date');
- $('#start_date').html(start_date);
- $('#id-date-picker-1').val(after(start_date));
-
- document.getElementById('tableInfo').innerHTML = '';
- var tnowtime = getDateTime(4);
- //var myURL = "./st-xm/Api/get_run_sale_ticket.php?tt=" + tnowtime + "&runid=" + run_id;
- $.ajax({
- url:'./st-xm/Api/get_run_sale_ticket_outside.php', //请求地址
- type: "get", //请求方式
- data:{
- tt: tnowtime,
- runid: run_id
- },
- async:false,
- dataType: "json",
- success: function (myJson){
- console.log(myJson);
-
- var myTicket = myJson.ticket_list;
-
- var num1 = myTicket.length;
- p_cirname = myTicket[0].circuitry_name;
- document.getElementById('line').innerHTML = p_cirname;
- for(var i = 0; i < num1; i++) {
- ticketArray[i] = new Array();
- ticketArray[i][0] = myTicket[i].prod_id;
- ticketArray[i][1] = myTicket[i].prod_name;
- ticketArray[i][2] = myTicket[i].start_station_res_id;
- ticketArray[i][3] = myTicket[i].start_station_res_name;
- ticketArray[i][4] = myTicket[i].end_station_res_id;
- ticketArray[i][5] = myTicket[i].end_station_res_name;
- ticketArray[i][6] = myTicket[i].prod_price;
- ticketArray[i][7] = myTicket[i].seat_type;
- ticketArray[i][8] = myTicket[i].seat_type_name;
- }
- var myOrg = myJson.sale_org;
- num1 = myOrg.length;
- var temp = '<li value="0" class="filter-item items" data-filter="请选择">请选择</li>';
- for (var i=0;i<myOrg.length;i++) {
-
- temp += '<li value="'+myOrg[i].org_id+'" class="filter-item items" data-filter="'+myOrg[i].soure+'">'+myOrg[i].soure+'</li>'
-
- }
- $("#orderSource").html(temp);
- $(".filter-item").click(function() {
- order_from_id = $(this).val();
- });
- show_start_station();
-
- }
-
- });
- })
-
-
- function show_start_station() {
- var num1 = ticketArray.length;
- var n_old_station_res_id = 0;
- var n_now_station_res_id = 0;
- var staArray = new Array();
- var num2 = 0;
- var nflag = 0;
- for(var i = 0; i < num1; i++) {
- n_now_station_res_id = ticketArray[i][2];
- nflag = 0;
- num2 = staArray.length;
- for(var j = 0; j < num2; j++) {
- n_old_station_res_id = staArray[j][0];
- if(n_old_station_res_id - n_now_station_res_id == 0) nflag = 1;
- }
- if(nflag == 0) {
- staArray[num2] = new Array();
- staArray[num2][0] = ticketArray[i][2];
- staArray[num2][1] = ticketArray[i][3];
- }
- }
- num1 = staArray.length;
- if(num1 > 0) {
- var obj1 = document.getElementById('startArea');
- obj1.length = 0;
- for(var i = 0; i < num1; i++) {
- var myOption = new Option(staArray[i][1], staArray[i][0]);
- obj1.options[obj1.options.length] = myOption;
- }
- obj1.options.selectedIndex = 0;
- show_end_station();
- }
- }
-
- function show_end_station() {
- var obj2 = document.getElementById('startArea');
- var start_res_id = obj2.options[obj2.options.selectedIndex].value;
-
- var num1 = ticketArray.length;
- var n_old_station_res_id = 0;
- var n_now_station_res_id = 0;
- var n_now_start_res_id = 0;
- var staArray = new Array();
- var num2 = 0;
- var nflag = 0;
- for(var i = 0; i < num1; i++) {
- n_now_station_res_id = ticketArray[i][4];
- n_now_start_res_id = ticketArray[i][2];
- if(n_now_start_res_id - start_res_id == 0) {
- nflag = 0;
- num2 = staArray.length;
- for(var j = 0; j < num2; j++) {
- n_old_station_res_id = staArray[j][0];
- if(n_old_station_res_id - n_now_station_res_id == 0) nflag = 1;
- }
- if(nflag == 0) {
- staArray[num2] = new Array();
- staArray[num2][0] = ticketArray[i][4];
- staArray[num2][1] = ticketArray[i][5];
- }
- }
- }
- num1 = staArray.length;
- if(num1 > 0) {
- var obj1 = document.getElementById('endArea');
- obj1.length = 0;
- for(var i = 0; i < num1; i++) {
-
- var myOption = new Option(staArray[i][1], staArray[i][0]);
- obj1.options[obj1.options.length] = myOption;
- }
- obj1.options.selectedIndex = 0;
- }
- show_ticket_list();
- }
-
- function show_ticket_list() {
- var obj1 = document.getElementById('startArea');
- var obj2 = document.getElementById('endArea');
- var obj3 = document.getElementById('tableInfo');
- obj3.innerHTML = '';
- var start_res_id = obj1.options[obj1.options.selectedIndex].value;
- var end_res_id = obj2.options[obj2.options.selectedIndex].value;
-
- var num1 = ticketArray.length;
- var cstr1 = '';
- for(var i = 0; i < num1; i++) {
- var now_start_res_id = ticketArray[i][2];
- var now_end_res_id = ticketArray[i][4];
- if((now_start_res_id - start_res_id == 0) && (now_end_res_id - end_res_id == 0)) {
- if(ticketArray[i][1].indexOf('往返') != -1) {
- cstr1 += '<tr id ="back_back">';
- } else {
- cstr1 += '<tr id ="go_go">';
- }
-
- cstr1 += '<td style="width:80px;">' + ticketArray[i][8] + '</td>';
- cstr1 += '<td id="back" style="width:90px;">' + ticketArray[i][1] + '</td>';
- cstr1 += '<td style="width:90px;">' + ticketArray[i][6] + '</td>';
- cstr1 += '<td style="width: 105px;"><select id="ticket_count_' + i + '" style="font-size: 12px; width: 60px;">';
- for(var j = 0; j <= 20; j++) {
- cstr1 += '<option value=' + j + '>' + j + '</option>';
- }
- cstr1 += '</select></td>';
-
- }
- }
- obj3.innerHTML = cstr1;
- var t_back_select = $('#ifback').val();
- if(t_back_select == 1) {
- var t_checked = true;
- } else {
- var t_checked = false;
- }
- ifbackSelected(t_checked);
-
- }
-
- //添加乘客人信息
- function addLine() {
- var addInfo = document.getElementById('addInfo');
- //tr
- var div = document.createElement("div");
- div.id = "newInfo" + i;
- // div.style({"width":'300px'},{"height":'100px'});
- div.style.height = '100px';
- div.style.width = '350px';
- var newInfo = $('#left').html();
- newInfo += newInfo.replace('delBtn', 'delBtn' + i);
- div.innerHTML = newInfo;
-
- addInfo.appendChild(div);
- i++;
- }
-
- //删除乘客人信息
- function delOneLine(sender) {
- $('#' + sender).parent().parent().remove();
- }
- //选中返回的日期date
- var end_list2=null;
- // function selectDate(value){
- // var obj1 = document.getElementById("startAreaback");
- // obj1.innerHTML = "";
- // var obj2 = document.getElementById("endAreaback");
- // obj2.innerHTML = "";
- // if(value == null) {
- // return;
- // }
- // // 判断日期是否合理
- // var date1 = new Date(start_date.replace(/\-/g, '/'));
- // var date2 = new Date(value.replace(/\-/g, '/'));
- // if(date2 < date1) {
- // $('#id-date-picker-1').val('');
- // return;
- // }
-
- // var url = "./st-xm/Api/returnInfoSee.php?method=get_run_back_station&cur_run_id=" + m_runid + "&date_f=" + value;
- // ZZLog(url);
- // var endArea_html = '<option value="0" style="font-size: 12px;">选择班次</option>'
- // $.getJSON(url, function(res_data) {
- // ZZLog(res_data);
- // if(res_data['code'] != "0") {
- // alert(res_data['info']);
- // return;
- // }
- // if(res_data['start_station_list'].length < 0) {
- // return;
- // }
- // back_run_id = res_data.start_station_list[0].run_id;
- // var start_list = res_data.start_station_list;
- // var end_list = res_data.end_station_list;
- // end_list2=end_list;
- // if(checkedValue != "1") {
- // return;
- // }
- // if(start_list.length == 0) {
- // $('#selected').val('无相关班次');
- // } else {
- // for(var i = 0, m = start_list.length; i < m; i++) {
- // var dict = start_list[i];
- // var myOption = new Option(dict.start_station_res_name + "-" + dict.start_time, dict.start_station_res_id);
- // obj1.options[obj1.options.length] = myOption;
- // }
- // obj1.options.selectedIndex = 0;
- // }
- // // 默认给第一个
- // show_f_station(end_list,start_list[0]['run_id']);
- // });
- // }
- // function show_f_station2(){
- // var start_f_index=document.getElementById("startAreaback").selectedIndex;
- // show_f_station(end_list2,end_list2[start_f_index]['run_id']);
- // }
- // // 显示返程的目的地站
- // function show_f_station(end_list,run_id){
- // back_run_id=run_id;
- // var obj2 = document.getElementById("endAreaback");
- // obj2.innerHTML = "";
- // for(var i = 0, m = end_list.length; i < m; i++) {
- // var dict = end_list[i];
- // if(dict['run_id']!=run_id){
- // continue;
- // }
- // var myOption = new Option(dict.end_station_res_name + "-" + dict.end_time, dict.end_station_res_id);
- // obj2.options[obj2.options.length] = myOption;
- // }
- // obj2.options.selectedIndex = 0;
- // choose_f_station();
- // }
- // //选中返回的时间time
- // function select_run_time(sender) {}
- // //选择返程的上下车站点
- // function choose_f_station() {
- // var start_f_res_id = $('#startAreaback').val();
- // var end_f_res_id = $('#endAreaback').val();
- // if(start_f_res_id=="" || start_f_res_id==null || start_f_res_id==undefined
- // || end_f_res_id=="" || end_f_res_id==null || end_f_res_id==null){
- // alert('出发站或目的地为空则不能下往返程订单');
- // return;
- // }
- // if(start_f_res_id==end_f_res_id){
- // alert('出发站与目的地不能相同!!!');
- // return;
- // }
- // var url = "./st-xm/Api/returnInfoSee.php?method=get_run_back_info&f_run_id=" + back_run_id + "&f_st_res_id=" + start_f_res_id + "&f_end_res_id=" + end_f_res_id;
- // ZZLog(url);
- // $.getJSON(url, function(res_data) {
- // ZZLog(res_data);
- // if(res_data['code'] != "0") {
- // alert(res_data['info']);
- // return;
- // }
- // back_prod_id = res_data['prod_id'];
- // if(back_prod_id==null || back_prod_id==undefined || back_prod_id==""){
- // alert('没有该返程的票种,不允许下往返程订单!!!');
- // return;
- // }
- // // back_run_id = res_data['run_id'];
- // });
- // }
-
- function submit_order() {
- if($("#usersubmit").html() == "保存中...") {
- return;
- }
- $("#usersubmit").removeClass("btn-info");
- $("#usersubmit").html("保存中...");
- var num1 = ticketArray.length;
-
- var num2 = 0;
- var cstr1 = ''; //单程的
- var u_prod = '';
- var u_price = '';
-
- for(var i = 0; i < num1; i++) {
- var obj1 = document.getElementById('ticket_count_' + i);
- if(obj1) {
- var num3 = obj1.options[obj1.options.selectedIndex].value;
- if(num3 - 0 > 0) {
- // 如果是往返就不添加到此参数中
- cstr1 += '{m' + ticketArray[i][0] + 'p' + num3 + '|r' + m_runid + '}';
- num2 += parseInt(num3);
- }
- }
- }
- if(num2 == 0) {
- alert('请选择购买票张数!');
- $("#usersubmit").addClass("btn-info");
- $("#usersubmit").html("提交");
- return;
- }
-
- var c_cusname = document.getElementById('username').value;
- var c_cusmobile = document.getElementById('usernum').value;
- var c_cusidno = document.getElementById('userid').value;
- var c_ordersource = order_from_id;
- var c_channelno = document.getElementById('channelNum').value;
-
- if(c_ordersource == "-1") {
- alert('请选择订单渠道!');
- $("#usersubmit").addClass("btn-info");
- $("#usersubmit").html("提交");
- return;
- }
-
- if(c_cusname == '') {
- alert('请输入联系人姓名!');
- $("#usersubmit").addClass("btn-info");
- $("#usersubmit").html("提交");
- return;
- }
-
- if(c_cusmobile == '') {
- alert('请输入联系人手机!');
- $("#usersubmit").addClass("btn-info");
- $("#usersubmit").html("提交");
- return;
- }
- if(checkPhone(c_cusmobile)==false){
- $("#usersubmit").addClass("btn-info");
- $("#usersubmit").html("提交");
- return;
- }
- if(isCardNo(c_cusidno) == false) {
- $("#usersubmit").addClass("btn-info");
- $("#usersubmit").html("提交");
- return;
- }
- //订单备注
- // $("#accuracy").val($("#accuracy").val().replace(/\ +/g,""));//去掉空格
- //$("#content").val($("#content").val().replace(/[ ]/g,"")); //去掉空格
- //$("#content").val($("#content").val().replace(/[\r\n]/g,""));//去掉回车换行
- var order_comment=$('#order_remark').val();
- // order_comment=order_comment.replace(/\ +/g,"");
- // order_comment=order_comment.replace(/[ ]/g,"");
- order_comment=order_comment.replace(/[\r\n]/g,"");
- if(order_comment.length>500){
- $("#usersubmit").addClass("btn-info");
- $("#usersubmit").html("提交");
- alert('订单备注超出字数限制,限500字');
- return;
- }
- // {prod_id,姓名 ,性别,手机 ,证件类型,证件号 ,地址,地址对应地区ID,邮编,备注}
- // var cstr2 = '{,' + c_cusname + ',1,' + c_cusmobile + ',150,' + c_cusidno + ',,0,,'+order_comment+'}';
- // 不用逗号连接 因为后端存储过程是以,分割获取参数
- // 决定用^
- var cstr2 = '{^' + c_cusname + '^1^' + c_cusmobile + '^150^' + c_cusidno + '^^0^^'+order_comment+'}';
- var tnowtime = getDateTime(4);
-
- var myURL = '';
-
- myURL = '/st-xm/Api/add_new_order_outside.php?prod=' + cstr1 + '&customer=' + cstr2 + '&order_from_org_id=' + c_ordersource + '&outside_order_id=' + c_channelno + '&tt=' + tnowtime;
- ZZLog(myURL);
- //得到返程的prod_id
- $.getJSON(myURL, function(date) {
- ZZLog(date);
- if(date.errcode != "0") {
- alert('订单提交失败!原因:' + date.errinfo);
- $("#usersubmit").addClass("btn-info");
- $("#usersubmit").html("提交");
- return;
- } else {
- alert('订单提交成功!订单号:' + date.order_id);
- location.href = '/order_list.html';
- }
- });
- // /st-xm/Api/add_new_order_outside.php?prod={mG1104106T1996p2|rG1104106T1996}&customer={^孵化场^1^18682645203^150^511621199502032173^^0^^fdafdas}&order_from_org_id=2&outside_order_id=43&tt=20160831154316
- }
-
- //返程信息选中
- function ifbackSelected(value) {
- if(value == true) {
- var yes = $('#ifback').val('1');
- $('#back_back').show();
- $('#go_go').hide();
- checkedValue = "1";
- selectDate($('#id-date-picker-1').val());
-
- var num1 = ticketArray.length;
- for(var i = 0; i < num1; i++) {
- var obj1 = document.getElementById('ticket_count_' + i);
- if(obj1) {
- var num3 = obj1.options[obj1.options.selectedIndex].value;
- if(num3 - 0 > 0) {
- obj1.selectedIndex=0;
- }
- }
- }
- } else {
- var no = $('#ifback').val('0');
- $('#back_back').hide();
- $('#go_go').show();
- checkedValue = "0";
- //selectDate(null);
- }
-
- }
-
- function isCardNo(card) {
- if(card) {
- // 身份证号码为15位或者18位,15位时全为数字,18位前17位为数字,最后一位是校验位,可能为数字或字符X
- var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
- if(reg.test(card) === false) {
- alert("身份证输入不合法");
- return false;
- } else {
- return true;
- }
- }
- }
- //验证手机号
- function checkPhone(phone) {
- if(!(/^1[3|4|5|7|8]\d{9}$/.test(phone))) {
- alert("手机号码有误,请重填");
- return false;
- } else {
- return true;
- }
- }
-
- function after(d) {
- if(d) {
- d = new Date(d);
- d = +d + 1000*60*60*24;
- d = new Date(d);
- //return d;
- //格式化
- var year = ";" + d.getFullYear() + ";";
- var month = ";" + (d.getMonth()+0+1) + ";";
- var day = ";" + d.getDate() + ";";
- if(year.length < 4) {
- year = "0" + year;
- }
- if(month.length < 4) {
- month = "0" + month;
- }
- if(day.length < 4) {
- day = "0" + day;
- }
- var datestr = year + "-" + month + "-" + day;
- datestr = datestr.replace(/;/g, "");
- return datestr;
- } else {
- return "";
- }
- }
-
- function ConvertDateFromString(dateString) {
- if(dateString) {
- var sdate = dateString.split('-');
- var date = new Date(sdate[0], sdate[1], sdate[2]);
- return date;
- }
- }
-
- function getPar(par) {
- //获取当前URL
- var local_url = document.location.href;
- local_url = decodeURI(local_url);
- //获取要取得的get参数位置
- var get = local_url.indexOf(par + "=");
- if(get == -1) {
- return "";
- }
- //截取字符串
- var get_par = local_url.slice(par.length + get + 1);
- //判断截取后的字符串是否还有其他get参数
- var nextPar = get_par.indexOf("&");
- if(nextPar != -1) {
- get_par = get_par.slice(0, nextPar);
- }
- return get_par;
- }
-
- function getDateTime(nTypeFlag) {
- var tNowTime = new Date();
- var myYear = ';' + tNowTime.getFullYear() + ';';
- var myMonth = ';' + (tNowTime.getMonth() + 1 - 0) + ';';
- var myDay = ';' + tNowTime.getDate() + ';';
- var myHour = ';' + tNowTime.getHours() + ';';
- var myMinu = ';' + tNowTime.getMinutes() + ';';
- var mySecond = ';' + tNowTime.getSeconds() + ';';
-
- if(myMonth.length < 4) myMonth = '0' + myMonth;
- if(myDay.length < 4) myDay = '0' + myDay;
- if(myHour.length < 4) myHour = '0' + myHour;
- if(myMinu.length < 4) myMinu = '0' + myMinu;
- if(mySecond.length < 4) mySecond = '0' + mySecond;
-
- var cNewTimeStr;
- //alert(tNowTime);
- switch(nTypeFlag + 1 - 1) {
- case 0:
- cNewTimeStr = myYear + '-' + myMonth + '-' + myDay;
- break;
- case 1:
- cNewTimeStr = myYear + myMonth + myDay;
- break;
- case 2:
- cNewTimeStr = myHour + ':' + myMinu + ':' + mySecond;
- break;
- case 3:
- cNewTimeStr = myHour + myMinu + mySecond;
- break;
- case 4:
- cNewTimeStr = myYear + myMonth + myDay + myHour + myMinu + mySecond;
- break;
- case 5:
- cNewTimeStr = myYear + '年' + myMonth + '月' + myDay + '日';
- break;
- case 6:
- cNewTimeStr = myYear;
- break;
- case 7:
- cNewTimeStr = myYear + '-' + myMonth;
- break;
- default:
- cNewTimeStr = myYear + '-' + myMonth + '-' + myDay + ' ' + myHour + ':' + myMinu + ':' + mySecond;
- break;
- }
- cNewTimeStr = cNewTimeStr.replace(/;/g, "");
- return cNewTimeStr;
- }
-
- //function update_order_price(order_id,price){
- // //修改价格信息
- // $.ajax({
- // url: './st-xm/Api/change_price.php', //请求地址
- // type: "post", //请求方式
- // data: {
- // ordid: order_id,
- // prod_list: price
- // }, //请求参数
- // async: false,
- // dataType: "json",
- // success: function(date) {
- // ZZLog('修改订单价格');
- // ZZLog(date);
- // },
- // fail: function(date) {
- // // 此处放失败后执行的代码
- // }
- // });
- //}
|