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.
 
 
 
 

665 lines
22 KiB

  1. var line_id = getPar('run_id');
  2. var run_date = getPar('run_date');
  3. var urlstr = base_api + 'orderManager/index.php';
  4. var listHTML = ''
  5. var newstr = base_api + 'index.php';
  6. var order_id = '';
  7. var old_data = [];
  8. var last_supplier_id='';
  9. var supplier_id= '';
  10. var line_name = '';
  11. window.onload = function () {
  12. $('#Wdate2').val(run_date);
  13. listHTML = $('#list').html();
  14. //修改订单时,先通过order_id获取run_date和line_id
  15. order_id = getPar('order_id');
  16. if (order_id != '') {
  17. //把日期设置为不可修改
  18. //$('#Wdate2').attr('disabled',true);
  19. $.ajax({
  20. url: newstr,
  21. data: {
  22. tp: 'order_groupOrder_getOrderInfo',
  23. order_id: order_id
  24. },
  25. type: "post",
  26. dataType: "json",
  27. async: false,
  28. success: function (data) {
  29. if (data.code == "0") {
  30. run_date = data.list[0]['PROD_START_STATION_DATE'];
  31. line_id = data.list[0]['LINE_ID'];
  32. line_name = data.list[0]['line_name'];
  33. old_data = data.list[0];
  34. supplier_id = data.list[0]['SUPPLIER_ID'];
  35. $('#hotel').val(data.list[0]['tavern_stay']);
  36. $('#substitute_add').val(data.list[0]['add_line_price']);
  37. var sel_text = data.list[0]['terrace'];
  38. $(".if_online").find('option[text='+sel_text+']').attr("selected",true);
  39. } else {
  40. ZZAlertInfo(data.info);
  41. }
  42. },
  43. error: function (e) {
  44. ZZLog(e);
  45. }
  46. });
  47. }
  48. reloadData();
  49. //载入时如果是修改订单,则重置订单值
  50. if (order_id != ''){
  51. initEditData();
  52. }
  53. //这里给上车站点的空间生成input加一个onblur事件
  54. $('.start_sta input').blur(function(){reset_sta()});
  55. total_collection();
  56. }
  57. //combo-select(bug)插件如果输入项没有对应值,则将显示值设置为厦门未知酒店
  58. function reset_sta(){
  59. if( $("#start_area").val()=='11964'){
  60. var name= $("#start_area").find("option[value='11964']").text();
  61. $('.start_sta input:eq(0)').val(name);
  62. }
  63. }
  64. //选择日期
  65. function selectDate() {
  66. run_date = $('#Wdate2').val();
  67. //新接口请求地址
  68. var newstr = base_api + 'index.php';
  69. var data = {
  70. tp: 'order_groupOrder_groupProductList',
  71. run_date: run_date,
  72. line_name:line_name,
  73. line_id:line_id
  74. };
  75. ZZLog(data);
  76. $.ajax({
  77. url: newstr,
  78. data: data,
  79. type: "post",
  80. dataType: "json",
  81. async: false,
  82. success: function (data) {
  83. if (data.code == "0") {
  84. console.log(data);
  85. if (data.product_list.length == 0) {
  86. // ZZAlertInfo('选择的日期没有相关的线路信息!');
  87. // $('#Wdate2').val(run_date);
  88. /*var newdate = getPar('run_date');
  89. $('#Wdate2').val(newdate);
  90. reloadData();*/
  91. ZZAlertInfo('选择的日期没有相关的线路信息!');
  92. //如果是修改订单,还原日期为修改前日期
  93. if (order_id != '') {
  94. $('#Wdate2').val(old_data['PROD_START_STATION_DATE']);
  95. run_date=old_data['PROD_START_STATION_DATE'];
  96. //如果是添加订单 ,还原日期为url上的run_date
  97. }else{
  98. var newdate = getPar('run_date');
  99. $('#Wdate2').val(newdate);
  100. run_date=newdate;
  101. }
  102. } else {
  103. //如果当前日期有组合线路
  104. $('#Wdate2').val(run_date);
  105. //这里判断一下原线路是否在新的可选线路中,如果有则选中该线路,否则新线路取第一项
  106. for(var item in data.product_list){
  107. if(data.product_list[item].line_id==line_id){
  108. var new_line_id=line_id;
  109. break;
  110. }
  111. }
  112. if(typeof new_line_id === 'undefined'){
  113. var new_line_id = data.product_list[0].line_id;
  114. }
  115. //按照新需求 修改逻辑 -白哥说的
  116. line_id=new_line_id;
  117. reloadData();
  118. }
  119. } else {
  120. ZZAlertInfo(data.info);
  121. }
  122. },
  123. error: function (e) {
  124. ZZLog(e);
  125. }
  126. });
  127. }
  128. //页面加载数据
  129. function reloadData() {
  130. var data = {
  131. tp: 'groupOrder_getProductBase',
  132. run_date: run_date,
  133. line_id: line_id
  134. };
  135. ZZLog(data);
  136. $.ajax({
  137. url: urlstr,
  138. data: data,
  139. type: "post",
  140. dataType: "json",
  141. async: false,
  142. success: function (data) {
  143. if (data.code == "0") {
  144. console.log(data);
  145. replaceData(data);
  146. } else {
  147. ZZAlertInfo(data.info);
  148. run_date = $('#Wdate2').val();
  149. }
  150. /*if (order_id != ''){
  151. initEditData();
  152. }*/
  153. total_collection();
  154. },
  155. error: function (e) {
  156. ZZLog(e);
  157. }
  158. });
  159. }
  160. //修改线路数据展示
  161. function replace1Data(data) {
  162. //修改线路列表
  163. var value=$('#channel_list').val();
  164. for(var item in data.channel_list){
  165. if(data.channel_list[item].supplier_id==$('#channel_list').val()){
  166. var new_supplier_id=data.channel_list[item].supplier_id;
  167. break;
  168. }
  169. }
  170. if(typeof new_supplier_id === 'undefined'){
  171. ZZConfirm('此线路无当前渠道信息,是否确认修改?', function (ok) {
  172. //修改线路列表
  173. changeLine();
  174. $('#line_code').html(data.line_name);
  175. var startHTML = '';
  176. var start_station = data.start_station;
  177. for (var i = 0; i < start_station.length; i++) {
  178. var tempHTML1 = '<option seq_id="[seq_id]" start_time="[start_time]" value="0">请选择</option>';
  179. tempHTML1 = tempHTML1.replace('请选择', start_station[i].res_name);
  180. tempHTML1 = tempHTML1.replace('0', start_station[i].res_id);
  181. tempHTML1 = tempHTML1.replace('[seq_id]', start_station[i].seq_id);
  182. tempHTML1 = tempHTML1.replace('[start_time]', start_station[i].start_time);
  183. startHTML += tempHTML1;
  184. }
  185. $('#start_area').html(startHTML);
  186. //如果始发站点 有 名为‘厦门未知酒店’的站点,则默认选中
  187. $('#start_area').comboSelect();
  188. $("#start_area").find("option[value='11964']").attr("selected", true);
  189. var new_supplier_id = data.channel_list[0].supplier_id;
  190. supplier_id=new_supplier_id;
  191. var channelHTML = '';
  192. var channel_list = data.channel_list;
  193. for (var j = 0; j < channel_list.length; j++) {
  194. var tempHTML = '<option saleman="[saleman]" value="0">请选择</option>';
  195. tempHTML = tempHTML.replace('请选择', channel_list[j].supplier_name);
  196. tempHTML = tempHTML.replace('0', channel_list[j].supplier_id);
  197. tempHTML = tempHTML.replace('[saleman]', channel_list[j].sales_man);
  198. $('#salesman').html(channel_list[0].sales_man);
  199. channelHTML += tempHTML;
  200. }
  201. $('#channel_list').html(channelHTML);
  202. $('.select_line').comboSelect();
  203. value = $('#channel_list').val();
  204. last_supplier_id = value;
  205. }, function (cancel) {
  206. value = last_supplier_id;
  207. }, function (close) {
  208. })
  209. }
  210. changeChannelSelected(value);
  211. }
  212. //首次加载数据
  213. function replaceData(data) {
  214. //修改线路列表
  215. changeLine();
  216. $('#line_code').html(data.line_name);
  217. var startHTML = '';
  218. var start_station = data.start_station;
  219. for (var i = 0; i < start_station.length; i++) {
  220. var tempHTML1 = '<option seq_id="[seq_id]" start_time="[start_time]" value="0">请选择</option>';
  221. tempHTML1 = tempHTML1.replace('请选择', start_station[i].res_name);
  222. tempHTML1 = tempHTML1.replace('0', start_station[i].res_id);
  223. tempHTML1 = tempHTML1.replace('[seq_id]', start_station[i].seq_id);
  224. tempHTML1 = tempHTML1.replace('[start_time]', start_station[i].start_time);
  225. startHTML += tempHTML1;
  226. }
  227. $('#start_area').html(startHTML);
  228. //如果始发站点 有 名为‘厦门未知酒店’的站点,则默认选中
  229. $('#start_area').comboSelect();
  230. $("#start_area").find("option[value='11964']").attr("selected", true);
  231. var channelHTML = '';
  232. var channel_list = data.channel_list;
  233. for (var j = 0; j < channel_list.length; j++) {
  234. var tempHTML = '<option saleman="[saleman]" value="0">请选择</option>';
  235. tempHTML = tempHTML.replace('请选择', channel_list[j].supplier_name);
  236. tempHTML = tempHTML.replace('0', channel_list[j].supplier_id);
  237. tempHTML = tempHTML.replace('[saleman]', channel_list[j].sales_man);
  238. $('#salesman').html(channel_list[0].sales_man);
  239. channelHTML += tempHTML;
  240. }
  241. $('#channel_list').html(channelHTML);
  242. $('.select_line').comboSelect();
  243. if(supplier_id) {
  244. var value = supplier_id;
  245. } else {
  246. var value = $('#channel_list').val();
  247. }
  248. $("#channel_list").val(value).comboSelect();
  249. changeChannelSelected(value);
  250. }
  251. //修改线路
  252. function changeLine() {
  253. //新接口请求地址
  254. var newstr = base_api + 'index.php';
  255. var data = {
  256. tp: 'order_groupOrder_groupProductList',
  257. run_date: run_date,
  258. line_id:line_id,
  259. line_name:line_name
  260. };
  261. ZZLog(data);
  262. $.ajax({
  263. url: newstr,
  264. data: data,
  265. type: "post",
  266. dataType: "json",
  267. async: false,
  268. success: function (data) {
  269. if (data.code == "0") {
  270. console.log(data);
  271. //替换线路的相关信息
  272. replaceLineInfo(data);
  273. } else {
  274. ZZAlertInfo(data.info);
  275. }
  276. },
  277. error: function (e) {
  278. ZZLog(e);
  279. }
  280. });
  281. }
  282. //替换线路的相关信息
  283. function replaceLineInfo(data) {
  284. var productHTML = '';
  285. var product_list = data.product_list;
  286. for (var i = 0; i < product_list.length; i++) {
  287. var tempHTML1 = '<option value="0">请选择</option>';
  288. tempHTML1 = tempHTML1.replace('请选择', product_list[i].line_name);
  289. tempHTML1 = tempHTML1.replace('0', product_list[i].line_id);
  290. productHTML += tempHTML1;
  291. }
  292. $('#line_info').html(productHTML);
  293. $('.select_line').comboSelect();
  294. // $("#line_info option[value='"+line_id+"']").attr("select","selected");
  295. $("#line_info").find("option[value='" + line_id + "']").attr("selected", true);
  296. }
  297. //切换渠道
  298. function changeChannelSelected(value) {
  299. var saleman = $("#channel_list").find("option:selected").attr('saleman');
  300. console.log(saleman);
  301. $('#salesman').val(saleman);
  302. var data = {
  303. tp: 'groupOrder_getTicketType',
  304. line_id: line_id,
  305. channel_id: value
  306. };
  307. ZZLog(data);
  308. $.ajax({
  309. url: urlstr,
  310. data: data,
  311. type: "post",
  312. dataType: "json",
  313. async: false,
  314. success: function (data) {
  315. if (data.code == "0") {
  316. console.log(data);
  317. showTicketInfo(data);
  318. } else {
  319. ZZAlertInfo(data.info);
  320. }
  321. },
  322. error: function (e) {
  323. ZZLog(e);
  324. }
  325. });
  326. }
  327. //展示票种信息
  328. function showTicketInfo(data) {
  329. var list = data.list;
  330. var newHTML = '';
  331. var sin_price_arr=new Array();
  332. var count_arr=new Array();
  333. for (var i = 0; i < list.length; i++) {
  334. var tempHTML = listHTML;
  335. sin_price_arr[i]=$('.sin_price').eq(i).val();
  336. count_arr[i]=$('.count').eq(i).val();
  337. tempHTML = tempHTML.replace('[座位等级]', list[i].seat_type_name);
  338. tempHTML = tempHTML.replace('[人群]', list[i].human_type_name);
  339. tempHTML = tempHTML.replace('[价格]', list[i].price);
  340. tempHTML = tempHTML.replace('[ticket_id]', list[i].ticket_id);
  341. // 数量
  342. var stock = 1000;
  343. var maxCount = stock > 55 ? 55 : stock;
  344. maxCount = maxCount > 0 ? maxCount : 0;
  345. var newHTML1 = '';
  346. for (var j = 0; j <= maxCount; j++) {
  347. var str = '<option value="[0]">[-]</option> ';
  348. str = str.replace('[0]', j);
  349. str = str.replace('[-]', j);
  350. newHTML1 += str;
  351. }
  352. tempHTML = tempHTML.replace('<option value="[0]">[-]</option>', newHTML1);
  353. tempHTML = tempHTML.replace('[总额]', '0');
  354. newHTML += tempHTML;
  355. }
  356. $('#list').html(newHTML);
  357. $('#list').show();
  358. for(var i =0;i<sin_price_arr.length;i++){
  359. $('.sin_price').eq(i).val(sin_price_arr[i]);
  360. $('.count').eq(i).val(count_arr[i]);
  361. if($('.sin_price').eq(i).val()==''){
  362. $('.sin_price').eq(i).val(0);
  363. }
  364. if( $('.count').eq(i).val()==''){
  365. $('.count').eq(i).val(0);
  366. }
  367. }
  368. for(var i =0;i<sin_price_arr.length;i++){
  369. changeTotalPrice($('.count').eq(i));
  370. }
  371. }
  372. //切换票种数量,更改价格
  373. function changeTotalPrice(obj) {
  374. var single_price = $(obj).parent().parent().find('.price').val();
  375. var count= $(obj).parent().parent().find('.count').val();
  376. var total_price = parseInt(single_price)*count;
  377. $(obj).parent().parent().find('.total_price').html(total_price);
  378. total_collection()
  379. }
  380. //保存按钮
  381. function basicInfoSave() {
  382. //出发日期
  383. var start_date = $('#Wdate2').val();
  384. var start_area = $('#start_area').val();
  385. if (!start_date || !start_area) {
  386. ZZAlertInfo('出发日期填写不完整!');
  387. return;
  388. }
  389. //订单渠道
  390. var order_channel = $('#channel_list').val();
  391. var channel_id = $('#channel_id').val();
  392. if (!order_channel) {
  393. ZZAlertInfo('订单渠道填写不完整!');
  394. return;
  395. }
  396. //数量
  397. var count_str = '';
  398. var rec_str = '';
  399. var count_num = 0;
  400. $('.list_info').each(function (index, dom) {
  401. var ticket_id = $(this).attr('id');
  402. var price = $(this).children().find('.price').val();
  403. var sin_price = $(this).children().find('.sin_price').val();
  404. if(!sin_price){sin_price=0}
  405. var count = $(this).children().find('.count').val();
  406. count_num += parseInt(count);
  407. if (count > 0) {
  408. var str = '{' + ticket_id + ',' + price + ',' + count + '}';
  409. count_str += str;
  410. var str2 = ticket_id + ',' + sin_price;
  411. rec_str +=str2+'|';
  412. } else {
  413. return;
  414. }
  415. })
  416. if (count_str == '') {
  417. ZZAlertInfo('请完善订单信息,并选择数量!');
  418. return;
  419. }
  420. //联系人
  421. var link_man = $('#name').val().trim();
  422. var link_tel = $('#tel').val().trim();
  423. var remarks = $('#remarks').val();
  424. //如果联系人或者备注中有半角逗号,替换为全角
  425. link_man=link_man.replace(/,/g, ",");
  426. remarks=remarks.replace(/,/g, ",");
  427. if (!link_man && !link_tel) {
  428. ZZAlertInfo('联系人信息输入不完整!');
  429. return;
  430. }
  431. // if (link_tel != '' && !validate(link_tel, 'phone')) {
  432. // return;
  433. // }
  434. var link_info = '{' + link_man + ',' + link_tel + ',' + remarks + '}';
  435. //业务员
  436. var salesman = $('#salesman').val();
  437. //代收
  438. /*var substitute = $('#substitute').val();
  439. // substitute = substitute== " " ? '0' : substitute;
  440. if (substitute == '') {
  441. var substitute_all = $('#substitute_all').val();
  442. if (substitute_all == '') {
  443. substitute = '0';
  444. }else{
  445. substitute = substitute_all;
  446. }
  447. }else {
  448. substitute = substitute * count_num;
  449. }*/
  450. var if_sin = 0;//如果为0表示代收单价没有填写,如果非0,则表示代收总价
  451. var terrace = $('#if_online').text();
  452. var tavern_stay = $('#hotel').val();
  453. var add_line_price = $('#substitute_add').val();
  454. $('.sin_price').each(function () {
  455. var tmp = $(this).val();
  456. if (tmp) {
  457. var snum = $(this).parent().parent().find('.count').val();
  458. if_sin += parseInt(tmp) * parseInt(snum);
  459. }
  460. })
  461. //总价计算规则改变--2017-01-20 娄梦宁
  462. var receive_value = $('#total_collection').val();
  463. //得到总价(如果没写任何单价[或者代收单价累计计算值为0]),则取代收总价栏的数值,否则取代收单价计算得到代收总价)
  464. // if (!if_sin) {
  465. // receive_value = substitute_all ? parseInt(substitute_all) : 0;
  466. // } else {
  467. // receive_value = if_sin;
  468. // }
  469. //alert(receive_value);
  470. //站点信息 order_groupOrder_groupProductList
  471. var seq_id = $("#start_area").find("option:selected").attr('seq_id');
  472. var start_time = $("#start_area").find("option:selected").attr('start_time');
  473. var tp = order_id != '' ? 'order_groupOrder_updateGroupOrder' : 'order_groupOrder_addOrder';
  474. var data = {
  475. tp: tp,
  476. line_id: line_id,
  477. org_id: order_channel,
  478. order_id: order_id,
  479. order_no: channel_id,
  480. salesman: salesman,
  481. start_date: start_date,
  482. start_station: start_area,
  483. prod_list: count_str,
  484. rec_list: rec_str, //代收单价列表
  485. customer_info: link_info,
  486. receive_value: receive_value,
  487. seq_id: seq_id,
  488. start_time: start_time,
  489. terrace : terrace,
  490. tavern_stay : tavern_stay,
  491. add_line_price : add_line_price
  492. };
  493. ZZLog(data);
  494. $.ajax({
  495. url: newstr,
  496. data: data,
  497. type: "post",
  498. dataType: "json",
  499. async: false,
  500. success: function (data) {
  501. if (data.code == "0") {
  502. ZZLog(data);
  503. ZZAlertInfo(data.info);
  504. setTimeout(function () {
  505. if (order_id == '')
  506. window.location.href = "select_product.html";
  507. else {
  508. window.location.href = "order_list.html";
  509. }
  510. }, 3000)
  511. } else {
  512. ZZAlertInfo(data.info);
  513. }
  514. },
  515. error: function (e) {
  516. ZZLog(e);
  517. }
  518. });
  519. }
  520. //切换线路
  521. function changeLineInfo(obj) {
  522. var ttt = $(obj).val();
  523. line_id = ttt;
  524. var data = {
  525. tp: 'groupOrder_getProductBase',
  526. run_date: run_date,
  527. line_id: line_id
  528. };
  529. ZZLog(data);
  530. $.ajax({
  531. url: urlstr,
  532. data: data,
  533. type: "post",
  534. dataType: "json",
  535. async: false,
  536. success: function (data) {
  537. if (data.code == "0") {
  538. console.log(data);
  539. replace1Data(data);
  540. } else {
  541. ZZAlertInfo(data.info);
  542. }
  543. },
  544. error: function (e) {
  545. ZZLog(e);
  546. }
  547. });
  548. }
  549. //如果是修改订单,对表单赋值
  550. function initEditData() {
  551. $("#Wdate2").val(old_data['PROD_START_STATION_DATE']);
  552. $("#start_area").val(old_data['PROD_START_STATION_RES_ID']).comboSelect();
  553. $("#channel_list").val(old_data['SUPPLIER_ID']).comboSelect();
  554. //没有触发 changeChannelSelected函数
  555. changeChannelSelected(old_data['SUPPLIER_ID']);
  556. var count_num = 0;
  557. $.each(old_data['ticket_info'], function (k, item) {
  558. $("#" + item['ticket_id'] + " .count").val(item['num']);
  559. $("#" + item['ticket_id'] + " .sin_price").val(item['sin_price']);
  560. var total_amount = item['num'] * $("#" + item['ticket_id'] + " .count").parent().prev('td').find('.price').val();
  561. $("#" + item['ticket_id'] + " .count").parent().next('.total_price').html(total_amount);
  562. count_num += parseInt(item['num']);
  563. });
  564. $("#channel_id").val(old_data['OUTSIDE_ORDER_NO']);
  565. $("#substitute_all").val(old_data['RECEIVE_VALUE']);
  566. /*if(count_num > 0)
  567. $("#substitute").val(parseInt(old_data['RECEIVE_VALUE']) / count_num);*/
  568. $("#name").val(old_data['customer_name']);
  569. $("#tel").val(old_data['customer_mobile']);
  570. $("#salesman").val(old_data['sales_man']);
  571. $("#remarks").val(old_data['customer_memo']);
  572. }
  573. //手机号验证取消,后台判断,当手机号,日期,线路一致时返回提示错误信息---娄梦宁2017-01-20
  574. //当手机输入框手机号码输完即时判断
  575. // $("#tel").bind('input propertychange', function () {
  576. //
  577. // var tel = $('#tel').val().trim();
  578. // if (tel.length == 11) {
  579. // $.ajax({
  580. // url: base_api + 'index.php', //请求地址
  581. // data: {
  582. // tp: "order_groupOrder_getPurchaseHistory",
  583. // tel: tel
  584. // },
  585. // type: "post",
  586. // dataType: "json",
  587. // success: function (data) {
  588. // console.log(data);
  589. // if (data.code == "0") {
  590. // $('#attention').text('提示:该电话号码今日已有下单记录!');
  591. // $('#attention').show();
  592. // return;
  593. // } else {
  594. // // $('#attention').text('提示:该电话号码今日已有下单记录!');
  595. // $('#attention').hide();
  596. // }
  597. //
  598. // }
  599. // });
  600. //
  601. // } else {
  602. // $('#attention').hide();
  603. // }
  604. // })
  605. //代收总价计算
  606. function total_collection(){
  607. var total_collection_price=0;
  608. var count=$('.sin_price').length;
  609. for(i=0;i<count;i++ ){
  610. if(isNaN(Number($('.sin_price').eq(i).val()))){
  611. total_collection_price+=0;
  612. }else{
  613. count_ticket=$('.count').eq(i).val();
  614. total_collection_price+=Number($('.sin_price').eq(i).val())*count_ticket;
  615. }
  616. }
  617. if(isNaN(Number($('#substitute_add').val()))){
  618. total_collection_price+=0;
  619. }else{
  620. total_collection_price+=Number($('#substitute_add').val());
  621. }
  622. $('#total_collection').val(total_collection_price);
  623. }