You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

566 lines
17 KiB

  1. //var base_url="http://cs.zhizhuchuxing.com:8080";
  2. //var base_url="http://temp.zhizhuchuxing.com";
  3. var base_url="";
  4. var table_order_html_str='';
  5. // 打印日志
  6. var is_log=true; //是否打印日志
  7. function ZZlog(value){
  8. if(is_log==true){
  9. console.log(value);
  10. }
  11. }
  12. window.onload=function(){
  13. table_order_html_str=$('#tableOrder').html();
  14. var line=getPar('line');
  15. var start_date=getPar('start_date');
  16. var run_id=getPar('run_id');
  17. if(start_date==""){start_date=getDateTime(0);}
  18. $('#line').text(line);
  19. $('#start_date').text(start_date);
  20. var station_url=base_url+"/st-xm/Api/update_car_no.php?method=getStations&run_id="+run_id;
  21. get_station(station_url);
  22. var car_list_url=base_url+"/st-xm/Api/update_car_no.php?method=getCarList&run_id="+run_id;
  23. car_no_list(car_list_url);
  24. }
  25. function get_station(url) {
  26. ZZlog(url);
  27. $.getJSON(url, function (res_data) {
  28. ZZlog(res_data);
  29. //这里加一个对该班次时间的判断,只有在发车前一天的18:30之前才可以修改订单车次
  30. /*
  31. if (res_data['code'] == "666") {
  32. //alert(res_data['info']);
  33. $('.btn').hide();
  34. $('#rep').html('<span>只有在发车前一天的18:30之前才可以修改订单车次</span>');
  35. return;
  36. }
  37. */
  38. if (res_data['code'] != "0") {
  39. alert(res_data['info']);
  40. return;
  41. }
  42. var start_station = res_data['start_station'];
  43. var end_station = res_data['end_station'];
  44. var start_sumHTML = '<option value="-1" selected="selected" style="font-size: 12px;">请选择</option>';
  45. for (var i = 0, m = start_station.length; i < m; i++) {
  46. var dict = start_station[i];
  47. var tempHTML = '<option value="0" style="font-size: 12px;">请选择</option>';
  48. tempHTML = tempHTML.replace('0', dict['start_station_id']);
  49. tempHTML = tempHTML.replace('请选择', dict['start_station']);
  50. start_sumHTML += tempHTML;
  51. }
  52. if (start_sumHTML) {
  53. $('#startArea').html(start_sumHTML);
  54. }
  55. var end_sumHTML = '<option value="-1" selected="selected" style="font-size: 12px;">请选择</option>';
  56. for (var i = 0, m = end_station.length; i < m; i++) {
  57. var dict = end_station[i];
  58. var tempHTML = '<option value="0" style="font-size: 12px;">请选择</option>';
  59. tempHTML = tempHTML.replace('0', dict['end_station_id']);
  60. tempHTML = tempHTML.replace('请选择', dict['end_station']);
  61. end_sumHTML += tempHTML;
  62. }
  63. if (start_sumHTML) {
  64. $('#endArea').html(end_sumHTML);
  65. btn_select();
  66. }
  67. });
  68. }
  69. // 点击查询
  70. function btn_select(){
  71. var run_id=getPar('run_id');
  72. var start_station_id=$('#startArea').val();
  73. var end_station_id=$('#endArea').val();
  74. if(run_id==""){
  75. alert('缺少run_id!!!');return;
  76. }
  77. //默认传<=0的值
  78. // if(start_station_id==""){
  79. // alert('请选择出发站!!!');return;
  80. // }
  81. // if(end_station_id==""){
  82. // alert('请选择目的地站!!!');return;
  83. // }
  84. // var url="http://temp.zhizhuchuxing.com/st-xm/Api/order_list.php?tt=20160803131257&timelimit=%E4%B8%8B%E5%8D%95%E6%97%B6%E9%97%B4&starttime=&endtime=&ordersource=-1&orderstatus=0&paystatus=-1&billingstatus=&mealbounce=&refund=&moresearch=&start_area=&end_area=&line=&currpage=4&pagesize=30";
  85. var url=base_url+"/st-xm/Api/update_car_no.php?method=getOrderList&run_id="+run_id+"&start_station_id="+start_station_id+"&end_station_id="+end_station_id;
  86. get_order_list(url);
  87. }
  88. function get_order_list(url){
  89. ZZlog(url);
  90. $('#tableOrder').html('');
  91. $.getJSON(url,function(res_data){
  92. ZZlog(res_data);
  93. if(res_data['code']!="0"){alert(res_data['info']);return;}
  94. var order_list=res_data['orderList'];
  95. var sumHTML='';
  96. for (var i=0,m=order_list.length;i<m;i++) {
  97. var dict=order_list[i];
  98. var tempHTML=table_order_html_str;
  99. tempHTML=tempHTML.replace('[ace_order_id]',dict['parent_order_id']);
  100. tempHTML=tempHTML.replace('[people-count]',dict['passenger_num']);
  101. tempHTML=tempHTML.replace('[data-id]',i);
  102. tempHTML=tempHTML.replace('[order_id]',dict['parent_order_id']);
  103. tempHTML=tempHTML.replace('[订单编号]',dict['parent_order_id']);
  104. tempHTML=tempHTML.replace('[订单来源]',dict['org_name']);
  105. tempHTML=tempHTML.replace('[下单时间]',dict['create_time']);
  106. tempHTML=tempHTML.replace('[渠道订单号]',dict['outside_order_no']);
  107. // tempHTML=tempHTML.replace('[line]',dict['line']);
  108. tempHTML=tempHTML.replace('[line]',dict['parent_prod_name']);
  109. tempHTML=tempHTML.replace('[预订产品]',"("+dict['start_station']+")-("+dict['end_station']+")");
  110. tempHTML=tempHTML.replace('<div>[普通成人票]</div>',dict['prod_name'] + '×' + dict['passenger_num'] );
  111. tempHTML=tempHTML.replace('[出发时间]',dict['travel_time']);
  112. tempHTML=tempHTML.replace('[name]',dict['customer_name']);
  113. tempHTML=tempHTML.replace('[phone]',dict['customer_mobile']);
  114. tempHTML=tempHTML.replace('[车号]',dict['run_bus_order_id']);
  115. var state=dict['order_status'];
  116. tempHTML=tempHTML.replace('[状态]',get_status_by_no(state));
  117. sumHTML+=tempHTML;
  118. }
  119. if(tempHTML){
  120. $('#tableOrder').html(sumHTML);
  121. var currpage = getPar("currpage");
  122. if(currpage) {} else {
  123. currpage = 1;
  124. }
  125. $('#page').html('');
  126. var sum = res_data['totalTickets'];
  127. var tag = "page";
  128. // getPager(myURL2, sum, currpage, pagesize, tag, 'currpage');
  129. // document.getElementById("sum").innerHTML = "共"+sum+"条数据";
  130. }else{
  131. $('#tableOrder').html('');
  132. $('#page').html('');
  133. // document.getElementById("sum").innerHTML = "共0条数据";
  134. }
  135. })
  136. }
  137. //得到车座-库存
  138. function car_no_list(url){
  139. ZZlog(url);
  140. $.getJSON(url,function(res_data){
  141. ZZlog(res_data);
  142. if(res_data['code']!="0"){alert(res_data['info']);return;}
  143. var carList=res_data['carList'];
  144. var sumHTML='';
  145. for (var i=0,m=carList.length;i<m;i++) {
  146. var dict=carList[i];
  147. var tempHTML='<span class="un_select" data-car-no="[car_no]" onclick="select_car_no(this)">[文本]</span>';
  148. tempHTML=tempHTML.replace('[car_no]',dict['bus_order_id']);
  149. var str_text="车号"+dict['bus_order_id']+" "+dict['seat_count']+" 库存"+dict['stock'];
  150. tempHTML=tempHTML.replace('[文本]',str_text);
  151. sumHTML+=tempHTML;
  152. }
  153. if(sumHTML){
  154. $('#car_no_list').html(sumHTML);
  155. }else{
  156. $('#car_no_list').html('');
  157. }
  158. })
  159. }
  160. function update_f(btn_type){
  161. //先拿到order_id
  162. var arr_order_ids = new Array();
  163. $('.ace').each(function(index, item) {
  164. if (this.checked && index != 0) {
  165. arr_order_ids.push($(this).attr('data-order-id'));
  166. }
  167. });
  168. if (arr_order_ids.length <= 0) {
  169. alert('请勾选!!!');
  170. return;
  171. }
  172. var order_id_str=arr_order_ids.join(',');
  173. if(btn_type=="reset"){ //重置
  174. var run_id=getPar('run_id');
  175. var url=base_url+"/st-xm/Api/update_car_no.php?method=reset&run_id="+run_id+"&order_ids="+order_id_str;
  176. ZZlog(url);
  177. $.getJSON(url,function(res_data){
  178. ZZlog(res_data);
  179. if(res_data['code']!="0"){alert(res_data['info']);return;}
  180. alert('重置成功!!!');
  181. location.reload();
  182. })
  183. }else if(btn_type=="update"){ //修改弹出弹框
  184. if(temp_car_no_obj!=null){
  185. $(temp_car_no_obj).removeClass('select');
  186. $(temp_car_no_obj).addClass('un_select' );
  187. }
  188. center_show($('.choose_car_no'));
  189. }else{
  190. ZZlog('非重置,非修改');
  191. }
  192. }
  193. var cur_car_no=-1; //当前选中的车号
  194. function click_btn_save(){
  195. $('.choose_info').text('');
  196. if(cur_car_no==-1){
  197. $('.choose_info').text('请选择车号!!!');
  198. }else{
  199. $('.choose_info').text('');
  200. hide_all();
  201. }
  202. var run_id=getPar('run_id');
  203. //先拿到order_id
  204. var arr_order_ids = new Array();
  205. $('.ace').each(function(index, item) {
  206. if (this.checked && index != 0) {
  207. arr_order_ids.push($(this).attr('data-order-id'));
  208. }
  209. });
  210. if (arr_order_ids.length <= 0) {
  211. alert('请勾选!!!');
  212. return;
  213. }
  214. var order_ids_str=arr_order_ids.join(',');
  215. ZZlog('车号:'+cur_car_no);
  216. ZZlog('run_id:'+run_id);
  217. ZZlog('order_ids='+order_ids_str);
  218. var url=base_url+"/st-xm/Api/update_car_no.php?method=updateCar&run_id="+run_id+"&order_ids="+order_ids_str+"&bus_order_id="+cur_car_no;
  219. ZZlog(url);
  220. $.getJSON(url,function(res_data){
  221. ZZlog(res_data);
  222. if(res_data['code']!="0"){alert(res_data['info']);return;}
  223. alert('修改成功!!!');
  224. location.reload();
  225. })
  226. }
  227. var peop_count=0;
  228. function select_checked(index,self_obj) {
  229. if(index=='0'){
  230. peop_count=0;
  231. }else{
  232. var _temp_=parseInt($(self_obj).attr('data-people-count'));
  233. if(self_obj.checked){
  234. peop_count+=_temp_;
  235. }else{
  236. peop_count-=_temp_;
  237. }
  238. }
  239. //index=0最上面的全选 index=1表示的是下面所有的
  240. var cur_check = $('.ace')[0];
  241. var checkList = $('.ace');
  242. var checkCount = checkList.length - 1;
  243. var true_count = 0;
  244. for (var i = 1; i < checkList.length; i++) {
  245. if (index == '0') {
  246. checkList[i].checked = cur_check.checked;
  247. if(cur_check.checked){
  248. var __temp_=parseInt($(checkList[i]).attr('data-people-count'));
  249. peop_count+=__temp_;
  250. }
  251. } else {
  252. if (checkList[i].checked == false) {
  253. cur_check.checked = false
  254. } else {
  255. true_count = true_count + 1;
  256. }
  257. }
  258. }
  259. $('#people_count').html('已选择'+peop_count+'人');
  260. $('#car_info').html('已选择'+peop_count+'人');
  261. //判断下面是否选中完
  262. if (checkCount == true_count) {
  263. cur_check.checked = true;
  264. }
  265. temp_index=index;
  266. }
  267. //居中显示
  268. var tempDiv = null;
  269. function center_show(show_div) {
  270. tempDiv = show_div;
  271. //显示蒙板
  272. show_div.css('display', 'block');
  273. show_div.css('z-index', 30);
  274. show_div.css('background-color', 'white');
  275. show_div.css('position', 'fixed');
  276. var w = show_div.css('width');
  277. var h = show_div.css('height');
  278. w = w.substr(0, w.length - 2);
  279. h = h.substr(0, h.length - 2);
  280. // var s_left=(window.screen.availWidth-w)/2 +"px";
  281. // var s_top=(window.screen.availHeight-h)/2 +'px';
  282. var s_left = (window.innerWidth - w) / 2 + 'px';
  283. var s_top = (window.innerHeight - h) / 2 + 'px';
  284. show_div.css('left', s_left);
  285. show_div.css('top', s_top);
  286. $('.mask').css('display', 'block');
  287. }
  288. //点击蒙板
  289. function hide_all() {
  290. $('.mask').css('display', 'none');
  291. tempDiv.css('display', 'none');
  292. }
  293. //点击了关闭
  294. function click_cancel(father_name, self_name) {
  295. if (father_name) {
  296. var father = $(father_name);
  297. center_show(father);
  298. } else {
  299. $('.mask').css('display', 'none');
  300. }
  301. $(self_name).css('display', 'none');
  302. }
  303. var temp_car_no_obj=null;
  304. function select_car_no(self_obj){
  305. $('.choose_info').text('');
  306. if(temp_car_no_obj!=self_obj){
  307. $(temp_car_no_obj).removeClass('select');
  308. $(temp_car_no_obj).addClass('un_select' );
  309. temp_car_no_obj=self_obj;
  310. }
  311. $(self_obj).addClass('select');
  312. $(self_obj).removeClass('un_select' );
  313. cur_car_no=$(self_obj).attr('data-car-no');
  314. }
  315. // 根据订单状态值得到str
  316. function get_status_by_no(num) {
  317. switch(num) {
  318. case "145":
  319. return "待支付";
  320. break;
  321. case "146":
  322. return "已出票";
  323. break;
  324. case "147":
  325. return "已完成";
  326. break;
  327. case "148":
  328. return "已取消";
  329. break;
  330. default:
  331. break;
  332. }
  333. }
  334. function getPar(par) {
  335. //获取当前URL
  336. var local_url = document.location.href;
  337. local_url = decodeURI(local_url);
  338. //获取要取得的get参数位置
  339. var get = local_url.indexOf(par + "=");
  340. if(get == -1) {
  341. return "";
  342. }
  343. //截取字符串
  344. var get_par = local_url.slice(par.length + get + 1);
  345. //判断截取后的字符串是否还有其他get参数
  346. var nextPar = get_par.indexOf("&");
  347. if(nextPar != -1) {
  348. get_par = get_par.slice(0, nextPar);
  349. }
  350. return get_par;
  351. }
  352. function getDateTime(nTypeFlag) {
  353. var tNowTime = new Date();
  354. var myYear = ';' + tNowTime.getFullYear() + ';';
  355. var myMonth = ';' + (tNowTime.getMonth() + 1 - 0) + ';';
  356. var myDay = ';' + tNowTime.getDate() + ';';
  357. var myHour = ';' + tNowTime.getHours() + ';';
  358. var myMinu = ';' + tNowTime.getMinutes() + ';';
  359. var mySecond = ';' + tNowTime.getSeconds() + ';';
  360. if(myMonth.length < 4) myMonth = '0' + myMonth;
  361. if(myDay.length < 4) myDay = '0' + myDay;
  362. if(myHour.length < 4) myHour = '0' + myHour;
  363. if(myMinu.length < 4) myMinu = '0' + myMinu;
  364. if(mySecond.length < 4) mySecond = '0' + mySecond;
  365. var cNewTimeStr;
  366. //alert(tNowTime);
  367. switch(nTypeFlag + 1 - 1) {
  368. case 0:
  369. cNewTimeStr = myYear + '-' + myMonth + '-' + myDay;
  370. break;
  371. case 1:
  372. cNewTimeStr = myYear + myMonth + myDay;
  373. break;
  374. case 2:
  375. cNewTimeStr = myHour + ':' + myMinu + ':' + mySecond;
  376. break;
  377. case 3:
  378. cNewTimeStr = myHour + myMinu + mySecond;
  379. break;
  380. case 4:
  381. cNewTimeStr = myYear + myMonth + myDay + myHour + myMinu + mySecond;
  382. break;
  383. case 5:
  384. cNewTimeStr = myYear + '年' + myMonth + '月' + myDay + '日';
  385. break;
  386. case 6:
  387. cNewTimeStr = myYear;
  388. break;
  389. case 7:
  390. cNewTimeStr = myYear + '-' + myMonth;
  391. break;
  392. case 8: //得到上一个月的今天
  393. var date = getDateTime(0);
  394. var arr = date.split('-');
  395. var year = arr[0]; //获取当前日期的年份
  396. var month = arr[1]; //获取当前日期的月份
  397. var day = arr[2]; //获取当前日期的日
  398. var days = new Date(year, month, 0);
  399. days = days.getDate(); //获取当前日期中月的天数
  400. var year2 = year;
  401. var month2 = parseInt(month) - 1;
  402. if(month2 == 0) {
  403. year2 = parseInt(year2) - 1;
  404. month2 = 12;
  405. }
  406. var day2 = day;
  407. var days2 = new Date(year2, month2, 0);
  408. days2 = days2.getDate();
  409. if(day2 > days2) {
  410. day2 = days2;
  411. }
  412. if(month2 < 10) {
  413. month2 = '0' + month2;
  414. }
  415. cNewTimeStr = year2 + '-' + month2 + '-' + day2;
  416. break;
  417. case 9: //得到下一个月的今天
  418. var date = getDateTime(0);
  419. var arr = date.split('-');
  420. var year = arr[0]; //获取当前日期的年份
  421. var month = arr[1]; //获取当前日期的月份
  422. var day = arr[2]; //获取当前日期的日
  423. var days = new Date(year, month, 0);
  424. days = days.getDate(); //获取当前日期中的月的天数
  425. var year2 = year;
  426. var month2 = parseInt(month) + 1;
  427. if(month2 == 13) {
  428. year2 = parseInt(year2) + 1;
  429. month2 = 1;
  430. }
  431. var day2 = day;
  432. var days2 = new Date(year2, month2, 0);
  433. days2 = days2.getDate();
  434. if(day2 > days2) {
  435. day2 = days2;
  436. }
  437. if(month2 < 10) {
  438. month2 = '0' + month2;
  439. }
  440. var t2 = year2 + '-' + month2 + '-' + day2;
  441. return t2;
  442. break;
  443. case 10: //昨日日期
  444. var dateStr=getDateTime(0);
  445. var t_temp_sdate = dateStr.split('-');
  446. var now = new Date(t_temp_sdate[0], t_temp_sdate[1], t_temp_sdate[2]);
  447. now.setDate(now.getDate() - 0 - 1);
  448. var year = ";" + now.getFullYear() + ";";
  449. var month = ";" + now.getMonth() + ";";
  450. var day = ";" + now.getDate() + ";";
  451. if(year.length < 4) {
  452. year = "0" + year;
  453. }
  454. if(month.length < 4) {
  455. month = "0" + month;
  456. }
  457. if(day.length < 4) {
  458. day = "0" + day;
  459. }
  460. var datestr = year + "-" + month + "-" + day;
  461. datestr = datestr.replace(/;/g, "");
  462. return datestr;
  463. break;
  464. case 11: //明日日期
  465. var dateStr=getDateTime(0);
  466. var t_temp_sdate = dateStr.split('-');
  467. var now = new Date(t_temp_sdate[0], t_temp_sdate[1], t_temp_sdate[2]);
  468. now.setDate(now.getDate() - 0 + 1);
  469. var year = ";" + now.getFullYear() + ";";
  470. var month = ";" + now.getMonth() + ";";
  471. var day = ";" + now.getDate() + ";";
  472. if(year.length < 4) {
  473. year = "0" + year;
  474. }
  475. if(month.length < 4) {
  476. month = "0" + month;
  477. }
  478. if(day.length < 4) {
  479. day = "0" + day;
  480. }
  481. var datestr = year + "-" + month + "-" + day;
  482. datestr = datestr.replace(/;/g, "");
  483. return datestr;
  484. break;
  485. default:
  486. cNewTimeStr = myYear + '-' + myMonth + '-' + myDay + ' ' + myHour + ':' + myMinu + ':' + mySecond;
  487. break;
  488. }
  489. cNewTimeStr = cNewTimeStr.replace(/;/g, "");
  490. return cNewTimeStr;
  491. }
  492. //设置字符串类型的本地缓存
  493. function setStorage(objName, objValue) {
  494. var sto = window.localStorage;
  495. if(sto)
  496. sto.setItem(objName, objValue);
  497. }
  498. //读取字符串类型的本地缓存
  499. function getStorage(objName) {
  500. var ret = '';
  501. var sto = window.localStorage;
  502. if(sto)
  503. ret = sto.getItem(objName);
  504. return ret;
  505. }
  506. //清除本地缓存,如没指定名称则为清空所有缓存
  507. function clearStorage(objName) {
  508. var sto = window.localStorage;
  509. if(sto) {
  510. if(objName)
  511. sto.removeItem(objName);
  512. else
  513. sto.clear();
  514. }
  515. }
  516. //设置Json类型的本地缓存
  517. function setStorJson(objName, json) {
  518. if(json)
  519. setStorage(objName, JSON.stringify(json));
  520. }
  521. //读取Json类型的本地缓存
  522. function getStorJson(objName) {
  523. var ret = null;
  524. var str = getStorage(objName);
  525. if(str)
  526. ret = JSON.parse(str);
  527. return ret;
  528. }