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.
 
 
 
 

286 lines
7.5 KiB

  1. var HTML = '';
  2. //记录添加的 tr id
  3. var n = 0;
  4. //记录途径顺序
  5. var m = 1;
  6. window.onload = function(){
  7. // HTML = $('#tr_replace').html();
  8. $('#tr_replace').hide();
  9. }
  10. //根据用户输入检索
  11. function lineListSearch(listId){
  12. $.ajax({
  13. url:'./st-xm/Model/linemanager/stationListSearch.php', //请求地址
  14. type: "post", //请求方式
  15. // data: data, //请求参数
  16. data:{
  17. stationName:listId
  18. },
  19. async:false,
  20. dataType: "json",
  21. success: function (data) {
  22. console.log(data);
  23. if(data.code == 0){
  24. $('#line_name_search').show();
  25. var line_list = document.getElementById("line_name_search");
  26. var list = data.list;
  27. var htmlStr = "";
  28. for (var i=0;i<list.length;i++) {
  29. htmlStr +='<div class="div_input" onclick="click_select('+'\''+list[i].res_id+'\''+',\''+list[i].res_name+'\')">'+list[i].res_name+'</div>';
  30. }
  31. line_list.innerHTML = htmlStr;
  32. }
  33. },
  34. fail: function (data) {
  35. }
  36. });
  37. }
  38. //选中一个站点
  39. function click_select(id,name){
  40. $('#line_list').val(name);
  41. $('#line_name_search').hide();
  42. $('#station_select').val(id);
  43. }
  44. //添加一条线路
  45. function addOneLine(){
  46. var line_list = $('#line_list').val();
  47. if (line_list == "") {
  48. swal(
  49. '添加线路失败',
  50. '未选择站点信息',
  51. 'error'
  52. );
  53. return;
  54. }
  55. var stationId = $('#station_select').val();
  56. var poiAry = '';
  57. var checkPortAry = '';
  58. var poiIdAry = '';
  59. var checkPortIdAry = '';
  60. var ifHasCheckport = '';
  61. //站点id对应每一条站点信息
  62. // var stationId = '';
  63. //请求站点相关的数据
  64. $.ajax({
  65. url:'./st-xm/Model/linemanager/stationInfo.php', //请求地址
  66. type: "post",
  67. data:{stationId:stationId},
  68. async:false,
  69. dataType: "json",
  70. success: function (data) {
  71. console.log(data);
  72. if(data.code == 0){
  73. //(poi)
  74. var poiListStr = data.list.parent_area_name_list;
  75. //得到截取后返回的数组(poi)
  76. poiAry = intercept(poiListStr);
  77. //(poi)id
  78. var poiListIdStr = data.list.parent_area_id_list;
  79. //得到截取后返回的数组(poi)
  80. poiIdAry = intercept(poiListIdStr);
  81. ifHasCheckport = data.list.checkport_res_name;
  82. if (data.list.checkport_res_id != 0) {
  83. //检票口数组
  84. checkPortAry = data.list.checkport_res_name.split(',');
  85. //检票口id数组
  86. checkPortIdAry = data.list.checkport_res_id.split(',');
  87. }
  88. //站点proid
  89. stationId = data.list.res_id;
  90. }
  91. },
  92. fail: function (data) {
  93. }
  94. });
  95. //tbody
  96. var line = document.getElementById('line_list_info');
  97. //tr
  98. var tr = document.createElement("tr");
  99. tr.id = m;
  100. var newHtml = '';
  101. var tempHTML = $('#tr_replace').html();
  102. tempHTML = tempHTML.replace('[途径顺序]',m);
  103. tempHTML = tempHTML.replace('[orderid]','orderid'+m);
  104. tempHTML = tempHTML.replace('[站点]',$('#line_list').val());
  105. tempHTML = tempHTML.replace('[station_type_td]','station_type_td'+m);
  106. tempHTML = tempHTML.replace('[select_poi]','select_poi'+m);
  107. tempHTML = tempHTML.replace('[teller]','teller'+m);
  108. tempHTML = tempHTML.replace('[teller_station]','teller_station'+m);
  109. tempHTML = tempHTML.replace('[stationid]','stationid'+m);
  110. tempHTML = tempHTML.replace('[timeid]','timeid'+m);
  111. tempHTML = tempHTML.replace('[updown]','updown'+m);
  112. tempHTML = tempHTML.replace('[del]',m);
  113. tempHTML = tempHTML.replace('time_out','time_out'+m);
  114. tempHTML = tempHTML.replace('[station_type]','station_type'+m);
  115. tempHTML = tempHTML.replace('[hideid]','hideid'+m);
  116. tempHTML = tempHTML.replace('[hideid_id]',stationId);
  117. line.appendChild(tr);
  118. var str = '<a href="#" onclick="deleteOneRow('+''+m+')">删除';
  119. tempHTML = tempHTML.replace('[删除]',str);
  120. tr.innerHTML = tempHTML;
  121. //替换poi
  122. var poiHTML = '';
  123. for (var i = poiAry.length-1; i>=0;i --) {
  124. var tempHTML1 = '<option value="0">请选择</option>';
  125. tempHTML1 = tempHTML1.replace('请选择',poiAry[i]);
  126. tempHTML1 = tempHTML1.replace('0',poiIdAry[i]);
  127. poiHTML += tempHTML1;
  128. }
  129. $('#select_poi'+m).html(poiHTML);
  130. //替换检票口
  131. if (ifHasCheckport=='') {
  132. $('#teller'+m).html('-');
  133. }else{
  134. var checkportHTML = '';
  135. for (var i = 0; i<checkPortAry.length; i++ ) {
  136. var tempHTML2 = '<option value="0">请选择</option>';
  137. tempHTML2 = tempHTML2.replace('请选择',checkPortAry[i]);
  138. tempHTML2 = tempHTML2.replace('0',checkPortIdAry[i]);
  139. checkportHTML += tempHTML2;
  140. }
  141. $('#teller_station'+m).html(checkportHTML);
  142. }
  143. n++;
  144. m++;
  145. //重新排布tr的途径顺序
  146. var trCount = $('#line_list_info').children().length;
  147. for (var k = 1; k < trCount; k++) {
  148. var seltr = $('#line_list_info').children(k);
  149. var selid = seltr[k].id;
  150. $('#orderid'+selid).html(k);
  151. if(k==1){
  152. $("#time_out"+selid).attr("readonly","true")
  153. }
  154. }
  155. }
  156. //遍历poi字符串
  157. function intercept(str){
  158. // var arr = new Array();
  159. // arr = str.split("}");
  160. // var newStr = '';
  161. // if(arr.length > 1){
  162. // for (var i = 0 ; i<arr.length ; i++) {
  163. // newStr = newStr + arr[i];
  164. // }
  165. // }
  166. // var backAry = new Array();
  167. // backAry = newStr.split("{");
  168. // return backAry;
  169. var newStr = '';
  170. newStr = str.replace(/}{/g,'@');
  171. newStr = newStr.substr(1,newStr.length-2);
  172. var backAry = new Array();
  173. backAry = newStr.split('@');
  174. return backAry;
  175. }
  176. //删除某一条数据
  177. function deleteOneRow(rowCount){
  178. var delRow = document.getElementById(rowCount);
  179. delRow.remove();
  180. //重新排布tr的途径顺序
  181. var trCount = $('#line_list_info').children().length;
  182. for (var k = 1; k < trCount; k++) {
  183. var seltr = $('#line_list_info').children(k);
  184. var selid = seltr[k].id;
  185. $('#orderid'+selid).html(k);
  186. // if(k==1){
  187. // $("#time_out"+selid).attr("readonly","true")
  188. // }
  189. }
  190. }
  191. //保存按钮
  192. function saveInfo(){
  193. var urlStr = '';
  194. var checkportUrl = '';
  195. //遍历所有的tr
  196. var trCount = $('#line_list_info').children().length;
  197. if (trCount==1) {
  198. swal(
  199. '添加线路失败',
  200. '无相关的站点信息,无法保存',
  201. 'error'
  202. );
  203. return;
  204. }
  205. for (var k = 1; k < trCount; k++) {
  206. var seltr = $('#line_list_info').children(k);
  207. var selid = seltr[k].id;
  208. $('#orderid'+selid).html(k);
  209. //取出要传的数据
  210. var updown = $('#station_type'+selid).val();
  211. var order = $('#orderid'+selid).text();
  212. var time = $('#time_out'+selid).val();
  213. if (time=="") {
  214. time = 0;
  215. }
  216. if ($('#teller'+selid).text()=="-") {
  217. checkportUrl = 0;
  218. }else{
  219. checkportUrl = $('#teller_station'+selid).val();
  220. }
  221. var station = $('#hideid'+selid).val();
  222. var poi = $('#select_poi'+selid).val();
  223. if ((poi=='')||(poi==null)) {
  224. poi = 0;
  225. }
  226. urlStr = urlStr +'{'+updown+','+order+','+time+','+checkportUrl+','+station+','+poi+'}';
  227. }
  228. // var saleStyle_company = $('#company input[name="saleStyle_company"]:checked ').val();
  229. var lineStyle = $("input[name='bar_style']:checked").val();
  230. $.ajax({
  231. url:'./st-xm/control.php', //请求地址
  232. type: "post",
  233. data:{
  234. type:'linemanager_add',
  235. linestyle:lineStyle,
  236. station_list:urlStr
  237. },
  238. async:false,
  239. dataType: "json",
  240. success: function (data) {
  241. console.log(data);
  242. if(data.code == 0){
  243. swal({
  244. title: '添加线路成功',
  245. type: 'success',
  246. timer: 20000,
  247. confirmButtonText: 'OK'
  248. }).then(
  249. function () { window.location.href="search_line.html"; },
  250. // handling the promise rejection
  251. function (dismiss) {
  252. window.location.href="search_line.html";
  253. }
  254. )
  255. }
  256. },
  257. fail: function (data) {
  258. swal({
  259. title: '添加线路失败',
  260. type: 'error'
  261. }
  262. );
  263. }
  264. });
  265. }