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.
 
 
 
 

555 line
16 KiB

  1. //author:fuhc
  2. //date:20161018
  3. //单一线路基本信息
  4. var trHTML = '';
  5. var trRowHTML='';
  6. var line_id = ''; //line_id if{没有就不能点击售卖票种}
  7. var line_type = '';
  8. var res_id = '';
  9. var res_name = '';
  10. var cstr_time = '<span class="arrive_time minutes" data-time="0" style="width: 55px;display: inline-block;text-align: center;">0</span>';
  11. window.onload = function() {
  12. // $('.select_line').comboSelect();
  13. line_id=getPar('line_id');
  14. if(line_id){
  15. $('.up_hide').hide();
  16. $('#top_type').hide();
  17. $('.up_info').text('基本信息');
  18. }
  19. //setBaseInfo();
  20. setHttpBaseInfo();
  21. $('.tr_row').show();
  22. trHTML = $('.tr_row').html();
  23. trRowHTM = $('#tbody').html();
  24. $('#tbody').html('');
  25. }
  26. //配置
  27. function setBaseInfo() {
  28. var obj1 = document.getElementById('hour');
  29. for(var i = 0; i <= 24; i++) {
  30. var hour = (Array(2).join(0) + i).slice(-2);
  31. var myOption = new Option(hour, hour);
  32. obj1.options[obj1.options.length] = myOption;
  33. }
  34. obj1.selectedIndex = 0;
  35. var obj2 = document.getElementById('ne_minutes');
  36. for(var i = 0; i <= 59; i++) {
  37. var minutes = (Array(2).join(0) + i).slice(-2);
  38. var myOption = new Option(minutes, minutes);
  39. obj2.options[obj2.options.length] = myOption;
  40. }
  41. obj2.selectedIndex = 0;
  42. }
  43. //设置页面配置信息
  44. function setHttpBaseInfo() {
  45. var param = {
  46. tp: "singleLine_getBaseManager"
  47. }
  48. ZZLog(base_api + 'lineManager/index.php' + JSON.stringify(param));
  49. $.ajax({
  50. type: "post",
  51. url: base_api + 'lineManager/index.php',
  52. data: param,
  53. dataType: "json",
  54. success: function(res_data) {
  55. ZZLog(res_data);
  56. if(res_data['code'] != "0") {
  57. ZZAlertInfo(res_data['info']);
  58. } else {
  59. //类目
  60. var bus_type = res_data['bus_type'];
  61. var obj = document.getElementById('bus_type');
  62. for(var i = 0, m = bus_type.length; i < m; i++) {
  63. var tempDict = bus_type[i];
  64. var myOption = new Option(tempDict['name'], tempDict['id']);
  65. obj.options[obj.options.length] = myOption;
  66. }
  67. //售卖截止
  68. // var time_type = res_data['time_type'];
  69. // var obj = document.getElementById('time_type');
  70. // for(var i = 0, m = time_type.length; i < m; i++) {
  71. // var tempDict = time_type[i];
  72. // var myOption = new Option(tempDict['type_name'], tempDict['id']);
  73. // obj.options[obj.options.length] = myOption;
  74. // }
  75. // //运营公司
  76. // var supply_list = res_data['supply_list'];
  77. // var obj = document.getElementById('supply');
  78. // for(var i = 0, m = supply_list.length; i < m; i++) {
  79. // var tempDict = supply_list[i];
  80. // var myOption = new Option(tempDict['supplier_name'], tempDict['supplier_id']);
  81. // obj.options[obj.options.length] = myOption;
  82. // }
  83. //判断是否是修改
  84. //设置默认选中项
  85. if(""!=line_id.trim()){
  86. setSelectBaseInfo();
  87. }
  88. }
  89. },
  90. error: function(error) {
  91. ZZLog(error);
  92. }
  93. });
  94. }
  95. //设置选中的值
  96. function setSelectBaseInfo(){
  97. var param={
  98. tp:"singleLine_getLineDetail",
  99. line_id:line_id
  100. }
  101. ZZLog(base_api+"lineManager/index.php"+JSON.stringify(param));
  102. $.ajax({
  103. type:"post",
  104. url:base_api+"lineManager/index.php",
  105. data:param,
  106. dataType:"json",
  107. success:function(res_data){
  108. ZZLog(res_data);
  109. if(res_data['code']!="0"){
  110. ZZAlertInfo(res_data['info']);
  111. }else{
  112. var line_info=res_data['line_info'];
  113. $('#line_name').val(line_info['line_name']);
  114. $('#line_code').val(line_info['line_code']);
  115. $('#bus_type').val(line_info['line_type']);
  116. $('#time_type').val(line_info['sale_expired_type']);
  117. var time=line_info['sale_expired_time'];
  118. var hour=time.split(':')[0];
  119. var minutes=time.split(':')[1];
  120. $('#hour').val(hour);
  121. $('#ne_minutes').val(minutes);
  122. $('#supply').val(line_info['org_id']);
  123. setSelectStationHTML(res_data['station_info']);
  124. }
  125. },error:function(e){
  126. ZZLog(e);
  127. }
  128. });
  129. }
  130. //设置选中的站点信息
  131. function setSelectStationHTML(station_info){
  132. var HTML='';
  133. for (var j=0,m=station_info.length;j<m;j++) {
  134. var res_info=station_info[j];
  135. var tempHTML = trRowHTM;
  136. tempHTML = tempHTML.replace(cstr_time, '<input class="minutes" value="'+res_info['start_minutes']+'" type="text" style="width: 55px;"/>');
  137. //处理站点
  138. tempHTML = tempHTML.replace('[res-name]', res_info['res_name']);
  139. tempHTML = tempHTML.replace('[res-id]', res_info['res_id']);
  140. //处理POI
  141. var parent_area = res_info['parent_area'];
  142. var cstr1 = '<select class="select_line poi" style="width: 200px;display: inline-block;border: 0;">';
  143. for(var i = 0; i < parent_area.length; i++) {
  144. var dict = parent_area[i];
  145. var temp = '';
  146. if(dict['checked']=="1"){
  147. temp='<option selected="selected" value="' + dict['id'] + '">' + dict['name'] + '</option>';
  148. }else{
  149. temp='<option value="' + dict['id'] + '">' + dict['name'] + '</option>';
  150. }
  151. cstr1 += temp;
  152. if(i == parent_area.length) {
  153. cstr1 += '</select>';
  154. }
  155. }
  156. tempHTML = tempHTML.replace('[POI]', cstr1);
  157. var cstr5 = '<input class="distance" value="'+res_info.distance+'" type="text" style="width: 55px;"/>公里';
  158. tempHTML = tempHTML.replace('[距离]', cstr5);
  159. //处理上下
  160. var inout_type = res_info['inout_type'];
  161. var cstr2 = '<select class="inout_type" style="width: 55px;">';
  162. for(var i = 0; i < inout_type.length; i++) {
  163. var dict = inout_type[i];
  164. var temp = ' ';
  165. if(dict['checked']=="1"){
  166. temp='<option selected="selected" value="' + dict['id'] + '">' + dict['name'] + '</option>';
  167. }else{
  168. temp='<option value="' + dict['id'] + '">' + dict['name'] + '</option>';
  169. }
  170. cstr2 += temp;
  171. if(i == inout_type.length) {
  172. cstr2 += '</select>';
  173. }
  174. }
  175. tempHTML = tempHTML.replace('[上下]', cstr2);
  176. //处理检票口
  177. var check_port = res_info['check_port'];
  178. var cstr3 = '<select class="check_port" style="width: 55px;">';
  179. var cstr4 = '';
  180. for(var i = 0; i < check_port.length; i++) {
  181. var dict = check_port[i];
  182. var temp='';
  183. if(dict['id']!='0'){
  184. temp = '<option value="' + dict['id'] + '">' + dict['name'] + '</option>';
  185. }else{
  186. temp = '';
  187. }
  188. cstr3 += temp;
  189. cstr4 += temp;
  190. if(i == check_port.length) {
  191. cstr3 += '</select>';
  192. }
  193. }
  194. if(check_port.length <= 0 || cstr4 == '') {
  195. cstr3 = "-";
  196. }
  197. tempHTML = tempHTML.replace('[检票口]', cstr3);
  198. HTML+=tempHTML;
  199. // addtr.innerHTML = tempHTML;
  200. // $('.select_line').comboSelect();
  201. // //删除ROW
  202. // $('.delrow').on('click', function() {
  203. // $(this).closest('tr').remove();
  204. // sortTr();
  205. // })
  206. // sortTr();
  207. }
  208. $('#tbody').html(HTML);
  209. $('.select_line').comboSelect();
  210. //上下类型改变联动检票口
  211. var cstrCheck = '';
  212. $('.inout_type').on('change',function(){
  213. var typeid=$(this).val();
  214. var $check = $(this).closest('tr').children().eq(6);
  215. cstrCheck = $check.html();
  216. if(typeid!='110'){
  217. $check.html(cstrCheck);
  218. }else{
  219. $check.html('-');
  220. }
  221. })
  222. $('.delrow').on('click',function(){
  223. $(this).closest('tr').remove();
  224. sortTr();
  225. })
  226. sortTr();
  227. }
  228. $(document).ready(function() {
  229. // 添加站点
  230. $('#btn_add').on('click', function() {
  231. var _res_id = res_id;
  232. var param = {
  233. tp: "singleLine_getStationInfo",
  234. res_id: res_id
  235. }
  236. ZZLog(base_api + "lineManager/index.php" + JSON.stringify(param));
  237. $.ajax({
  238. type: "post",
  239. url: base_api + "lineManager/index.php",
  240. data: param,
  241. dataType: "json",
  242. success: function(res_data) {
  243. ZZLog(res_data);
  244. if(res_data['code'] != "0") {
  245. ZZAlertInfo(res_data['info']);
  246. } else {
  247. setTrRowHtml(res_data['res_info']);
  248. }
  249. },
  250. error: function() {
  251. ZZLog('error');
  252. }
  253. });
  254. function setTrRowHtml(res_info) {
  255. var addtr = document.createElement('tr');
  256. var tbody = document.getElementById('tbody');
  257. addtr.className = 'tr_row';
  258. tbody.appendChild(addtr);
  259. var tempHTML = trHTML;
  260. tempHTML = tempHTML.replace(cstr_time, '<input class="minutes" type="text" style="width: 55px;"/>');
  261. //处理站点
  262. tempHTML = tempHTML.replace('[res-name]', res_name);
  263. tempHTML = tempHTML.replace('[res-id]', res_id);
  264. //处理POI
  265. var parent_area = res_info['parent_area'];
  266. var cstr1 = '<select class="select_line poi" style="width: 200px;display: inline-block;border: 0;">';
  267. for(var i = 0; i < parent_area.length; i++) {
  268. var dict = parent_area[i];
  269. var temp = '<option value="' + dict['id'] + '">' + dict['name'] + '</option>';
  270. cstr1 += temp;
  271. if(i == parent_area.length) {
  272. cstr1 += '</select>';
  273. }
  274. }
  275. tempHTML = tempHTML.replace('[POI]', cstr1);
  276. var cstr5 = '<input class="distance" value="" type="text" style="width: 55px;"/>公里';
  277. tempHTML = tempHTML.replace('[距离]', cstr5);
  278. //处理上下
  279. var inout_type = res_info['inout_type'];
  280. var cstr2 = '<select class="inout_type" style="width: 55px;">';
  281. for(var i = 0; i < inout_type.length; i++) {
  282. var dict = inout_type[i];
  283. var temp = '<option value="' + dict['id'] + '">' + dict['name'] + '</option>';
  284. cstr2 += temp;
  285. if(i == inout_type.length) {
  286. cstr2 += '</select>';
  287. }
  288. }
  289. tempHTML = tempHTML.replace('[上下]', cstr2);
  290. //处理检票口
  291. var check_port = res_info['check_port'];
  292. var cstr3 = '<select class="check_port" style="width: 55px;">';
  293. var cstr4 = '';
  294. for(var i = 0; i < check_port.length; i++) {
  295. var dict = check_port[i];
  296. var temp='';
  297. if(dict['id']!='0'){
  298. temp = '<option value="' + dict['id'] + '">' + dict['name'] + '</option>';
  299. }else{
  300. temp = '';
  301. }
  302. cstr3 += temp;
  303. cstr4 += temp;
  304. if(i == check_port.length) {
  305. cstr3 += '</select>';
  306. }
  307. }
  308. if(check_port.length <= 0 || cstr4 == '') {
  309. cstr3 = "-";
  310. }
  311. tempHTML = tempHTML.replace('[检票口]', cstr3);
  312. addtr.innerHTML = tempHTML;
  313. $('.select_line').comboSelect();
  314. //上下类型改变联动检票口
  315. var cstrCheck = '';
  316. $('.inout_type').on('change',function(){
  317. var typeid=$(this).val();
  318. var $check = $(this).closest('tr').children().eq(6);
  319. cstrCheck = $check.html();
  320. if(typeid!='110'){
  321. $check.html(cstrCheck);
  322. }else{
  323. $check.html('-');
  324. }
  325. })
  326. //删除ROW
  327. $('.delrow').on('click', function() {
  328. $(this).closest('tr').remove();
  329. sortTr();
  330. })
  331. sortTr();
  332. }
  333. })
  334. //检索行驶路线
  335. $('#run_road').on('input', function() {
  336. var keyword = $(this).val();
  337. var param = {
  338. tp: "singleLine_getLineStation",
  339. res_name: keyword
  340. }
  341. ZZLog(base_api + "lineManager/index.php" + JSON.stringify(param));
  342. $.ajax({
  343. type: "post",
  344. url: base_api + "lineManager/index.php",
  345. data: param,
  346. dataType: "json",
  347. success: function(res_data) {
  348. ZZLog(res_data);
  349. if(res_data['code'] != "0") {
  350. ZZAlertInfo(res_data['info']);
  351. } else {
  352. var res_list = res_data['res_list'];
  353. var HTML = '';
  354. for(var i = 0, m = res_list.length; i < m; i++) {
  355. var dict = res_list[i];
  356. var cstr = '<div onclick="chooseRunRoad(' + dict['res_id'] + ',\'' + dict['res_name'] + '\')" class="content_xiala" onmouseover="getDark(this)" onmouseout="getLight(this)" style="cursor: pointer;">' + dict['res_name'] + '</div>';
  357. HTML += cstr;
  358. }
  359. if(HTML) {
  360. $('.select_content').html(HTML);
  361. $('.select_content').show();
  362. }
  363. }
  364. },
  365. error: function() {
  366. ZZLog('error');
  367. }
  368. });
  369. })
  370. //保存
  371. $('#base_info_save').on('click', function() {
  372. baseInfoSave();
  373. })
  374. })
  375. function getDark(obj){
  376. $(obj).addClass('get_dark');
  377. }
  378. function getLight(obj){
  379. $(obj).removeClass('get_dark');
  380. }
  381. //保存
  382. function baseInfoSave() {
  383. $('.errinfo').html('');
  384. // 参数非空验证
  385. var _line_name = $('#line_name').val(); //线路名称
  386. if("" == _line_name.trim()) {
  387. $('#line_name').focus();
  388. $('#line_name').parent().children().eq(1).html('请输入名称');
  389. return;
  390. }
  391. var _line_code = $('#line_code').val(); //线路代码
  392. if("" == _line_code) {
  393. $('#line_code').focus();
  394. $('#line_code').parent().children().eq(1).html('请输入编号');
  395. return;
  396. }
  397. var _line_type = $('#bus_type').val(); //线路类型1
  398. var _line_sub_type = "0"; ////线路类型2 目前固定
  399. // var _time_type = $('#time_type').val(); //时间类型
  400. // var _hour = $('#hour').val();
  401. // var _ne_minutes = $('#ne_minutes').val();
  402. // var _time_info = _hour + ":" + _ne_minutes; //时间
  403. // var _supply_id = $('#supply').val(); //供应商id
  404. var _time_type = 322; //时间类型
  405. var _time_info = '00:00'; //时间
  406. var _supply_id = 0; //供应商id //
  407. var _station_list = '';
  408. var bool_inout_type=false;
  409. $('.tr_row').each(function(index, domEle) {
  410. var _inout_type = $(this).children().find('.inout_type').val();
  411. if(index==$('.tr_row').length-1 && _inout_type!='110'){
  412. bool_inout_type = true;
  413. }
  414. var _index = index + 1;
  415. var _arrive_time = '';
  416. if(index == 0) {
  417. _arrive_time = $(this).children().find('.minutes').text();
  418. } else {
  419. _arrive_time = $(this).children().find('.minutes').val();
  420. if("" == _arrive_time) {
  421. $(this).children().find('.minutes').focus();
  422. return false;
  423. }
  424. }
  425. var _distance = $(this).children().find('.distance').val();
  426. if("" == _distance) {
  427. $(this).children().find('.distance').focus();
  428. return false;
  429. }
  430. var _check_port = $(this).children().find('.check_port').val();
  431. _check_port=_check_port==undefined?"0":_check_port;
  432. var _res_id = $(this).children().eq(1).attr('data-res-id');
  433. var _area_id = $(this).children().find('.poi').val();
  434. //
  435. // var _json=$(this).children().eq(2).attr('data-json');
  436. // ZZLog(_json);
  437. // _json=_json.replace(/'/g,'\"');
  438. // ZZLog(_json);
  439. // var param=JSON.parse(_json);
  440. // ZZLog(_json);
  441. // ZZLog(param);
  442. if(_check_port == null)
  443. _check_port = 0;
  444. _station_list += "{" + _inout_type + "," + _index + "," + _arrive_time + ","+_distance+"," + _check_port + "," + _res_id + "," + _area_id + "}";
  445. })
  446. if(bool_inout_type){
  447. ZZAlertInfo('最后一个站点不能选择下车类型');
  448. return;
  449. }
  450. if("" == _station_list.trim()) {
  451. $('#run_road').focus();
  452. return;
  453. }
  454. var param = {}
  455. if(!line_id){
  456. param={
  457. tp: "singleLine_addLine",
  458. line_name: _line_name,
  459. line_code: _line_code,
  460. line_type: _line_type,
  461. line_sub_type: _line_sub_type,
  462. time_type: _time_type,
  463. time_info: _time_info,
  464. supply_id: _supply_id,
  465. station_list: _station_list
  466. }
  467. }else{
  468. param={
  469. tp: "singleLine_lineUpdate",
  470. line_id:line_id,
  471. line_name: _line_name,
  472. line_code: _line_code,
  473. line_type: _line_type,
  474. line_sub_type: _line_sub_type,
  475. time_type: _time_type,
  476. time_info: _time_info,
  477. supply_id: _supply_id,
  478. station_list: _station_list
  479. }
  480. }
  481. ZZLog(base_api + "lineManager/index.php" + JSON.stringify(param));
  482. $.ajax({
  483. type: "post",
  484. url: base_api + "lineManager/index.php",
  485. data: param,
  486. dataType: "json",
  487. success: function(res_data) {
  488. ZZLog(res_data);
  489. if(res_data['code'] != "0") {
  490. ZZAlertInfo(res_data['info']);
  491. } else {
  492. if(line_id){
  493. var lourl = "line_list.html";
  494. window.location.href = lourl;
  495. return;
  496. }
  497. line_id = res_data['line_id'];
  498. line_type = res_data['line_type'];
  499. var lochref="singline_sell_ticket_type.html?line_id=" + line_id + "&line_type=" + line_type;
  500. // window.open(lochref);
  501. $.cookie("path_url",cookie_path+"web/lineManager/"+lochref,{domain:domain_path});
  502. window.open(system_path);
  503. }
  504. },
  505. error: function() {
  506. ZZLog('error');
  507. }
  508. });
  509. }
  510. //点击检索的
  511. function chooseRunRoad(re_id, re_name) {
  512. res_id = re_id;
  513. res_name = re_name;
  514. $('#run_road').val(res_name);
  515. $('.select_content').hide();
  516. }
  517. //重新排序
  518. function sortTr() {
  519. $('.tr_row').each(function(index, domEle) {
  520. if(index == 0) {
  521. var cstr = cstr_time + '<span style="margin-left: 10px;">分</span>';
  522. $(this).children().eq(3).html(cstr);
  523. }
  524. $(this).children().eq(0).text(index + 1);
  525. $(this).children().eq(0).attr('index', index + 1);
  526. })
  527. }
  528. //头部切换
  529. function click_type(op) {
  530. var lochref = '';
  531. if(op == "com_baseinfo") {
  532. lochref = "combination_line.html";
  533. } else if(op == "sing_ticket") {
  534. ZZLog(line_id);
  535. if(line_id == "") {
  536. ZZAlertInfo('请先填写保存线路基本信息');
  537. return;
  538. }
  539. // line_type = line_type;
  540. line_type = $('#bus_type').val();
  541. lochref = "singline_sell_ticket_type.html?line_id=" + line_id + "&line_type=" + line_type;
  542. }
  543. window.location.href = lochref;
  544. }