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.
 
 
 
 

408 lines
11 KiB

  1. var HTML = '';
  2. //记录添加的 tr id
  3. var n = 0;
  4. //记录途径顺序
  5. var m = 1;
  6. var prod_id;
  7. var stationId;
  8. window.onload = function(){
  9. $('#tr_replace').hide();
  10. initdata();
  11. }
  12. //根据用户输入检索
  13. function lineListSearch(listId){
  14. $.ajax({
  15. url:'./st-xm/Model/linemanager/stationListSearch.php', //请求地址
  16. type: "post", //请求方式
  17. // data: data, //请求参数
  18. data:{
  19. stationName:listId
  20. },
  21. async:false,
  22. dataType: "json",
  23. success: function (data) {
  24. console.log(data);
  25. if(data.code == 0){
  26. $('#line_name_search').show();
  27. var line_list = document.getElementById("line_name_search");
  28. var list = data.list;
  29. var htmlStr = "";
  30. for (var i=0;i<list.length;i++) {
  31. htmlStr +='<div class="div_input" onclick="click_select('+'\''+list[i].res_id+'\''+',\''+list[i].res_name+'\')">'+list[i].res_name+'</div>';
  32. }
  33. line_list.innerHTML = htmlStr;
  34. }
  35. },
  36. fail: function (data) {
  37. }
  38. });
  39. }
  40. //选中一个站点
  41. function click_select(id,name){
  42. $('#line_list').val(name);
  43. $('#line_name_search').hide();
  44. $('#station_select').val(id);
  45. }
  46. function initdata(){
  47. prod_id = getPar("prod_id");
  48. $.ajax({
  49. url:'./st-xm/control.php',
  50. type: "post",
  51. data: {type:"linemanager_datainfo",id: prod_id},
  52. dataType: "json",
  53. success: function (data) {
  54. console.log(data);
  55. if(data.code == 0){
  56. createHtml(data);
  57. }else if(data.code == -1){
  58. alert("请检查网络!!!")
  59. }
  60. },
  61. fail: function (data) {
  62. // 此处放失败后执行的代码
  63. }
  64. });
  65. }
  66. //拼接数据
  67. function createHtml(data){
  68. $("#line_no").text(data.cominfo.linecode);
  69. $("#line_name").text(data.cominfo.linename);
  70. if((data.cominfo.bus_type==255)||(data.cominfo.bus_type==0)){
  71. $("#bar_style_z").attr("checked","checked");
  72. }else if(data.cominfo.bus_type==256){
  73. $("#bar_style_c").attr("checked","checked");
  74. }
  75. var temp = "";
  76. var alltemp = "";
  77. var y
  78. var index = "";
  79. var ind = "";
  80. for(var i=0,j=data.list.length;i<j;i++){
  81. if(data.list[i].checkport_res_id==9127||data.list[i].checkport_res_id==227){
  82. ind = "1号口";
  83. }else if(data.list[i].checkport_res_id==9128||data.list[i].checkport_res_id==228){
  84. ind = "2号口";
  85. }else if(data.list[i].checkport_res_id==229){
  86. ind = "3号口";
  87. }else if(data.list[i].checkport_res_id==230){
  88. ind = "4号口";
  89. }else{
  90. ind = "-";
  91. }
  92. temp += '<tr id="'+(i+1)+'" style="">'
  93. + '<input type="hidden" id="hideid'+m+'" value="'+data.list[i].station_res_id+'" />'
  94. + '<td id="orderid'+m+'">'+m+'</td>'
  95. + '<td>'+data.list[i].station_res_name+'</td>'
  96. + '<td id="station_type_td'+m+'">'
  97. + '<select id="select_poi'+m+'" style="margin-right: 10px;width:150px;">'
  98. + '<option value="'+data.list[i].area_id+'">'+data.list[i].area_name+'</option>'
  99. + '</select>'
  100. + '</td>'
  101. + '<td id="timeid'+m+'">'
  102. + '<input type="text" id="time_out'+m+'" placeholder="0" value="'+data.list[i].start_minutes+'" style="font-size: 13px;width: 60px;" />分'
  103. + '</td>'
  104. + '<td id="timeid'+m+'">'
  105. + '<input type="text" id="distance'+m+'" placeholder="0" value="'+data.list[i].distance+'" style="font-size: 13px;width: 60px;" />公里'
  106. + '</td>'
  107. + '<td>'
  108. + '<select name="station_type'+m+'" id="station_type'+m+'" style="margin-right: 10px;width:100px;">'
  109. + '<option value="108">上</option>'
  110. + '<option value="109">上下</option>'
  111. + '<option value="110">下</option>'
  112. + '</select>'
  113. + '</td>'
  114. + '<td id="teller'+m+'">'
  115. + '<select id="teller_station'+m+'" style="margin-right: 10px;width:100px;">'
  116. + '<option value="'+data.list[i].checkport_res_id+'">'+ind+'</option>'
  117. + '</select>'
  118. + '</td>'
  119. + '<td name="[del]" id="[del]"><a href="#" onclick="deleteOneRow('+''+m+')">删除</a></td>'
  120. + '</tr>'
  121. m++;
  122. }
  123. $("#line_list_info").append(temp);
  124. for(var i=0;i<data.list.length;i++){
  125. if(data.list[i].inout_type==108){
  126. $("#station_type"+(i+1)).children().eq(0).attr("selected","selected");
  127. }else if(data.list[i].inout_type==109){
  128. $("#station_type"+(i+1)).children().eq(1).attr("selected","selected");
  129. }else if(data.list[i].inout_type==110){
  130. $("#station_type"+(i+1)).children().eq(2).attr("selected","selected");
  131. }
  132. var temp1 = "";
  133. for(var j=0;j<data.list[i].poi_name.length;j++){
  134. temp1 += '<option value="'+data.list[i].poi_name[j].area_name_id+'">'+data.list[i].poi_name[j].area_name_list+'</option>'
  135. }
  136. $("#select_poi"+(i+1)).append(temp1);
  137. if(i==0){
  138. $("#time_out"+(i+1)).attr("readonly","true")
  139. }
  140. }
  141. for(var i=0;i<data.list.length;i++){
  142. if(data.list[i].checkport_res_id==0){
  143. $("#teller"+(i+1)).html("-")
  144. }else{
  145. var temp2 = "";
  146. for(var j=0;j<data.list[i].checkport_res.length;j++){
  147. temp2 += '<option value="'+data.list[i].checkport_res[j].checkport_res_id+'">'+data.list[i].checkport_res[j].checkport_res_name+'</option>'
  148. }
  149. $("#teller_station"+(i+1)).append(temp2);
  150. }
  151. }
  152. }
  153. //得到url上的参数
  154. function getPar(par){
  155. var local_url = document.location.href;
  156. local_url = decodeURI(local_url);
  157. var get = local_url.indexOf(par +"=");
  158. if(get == -1){
  159. return false;
  160. }
  161. var get_par = local_url.slice(par.length + get + 1);
  162. var nextPar = get_par.indexOf("&");
  163. if(nextPar != -1){
  164. get_par = get_par.slice(0, nextPar);
  165. }
  166. return get_par;
  167. }
  168. //添加一条线路
  169. function addOneLine(){
  170. var line_list = $('#line_list').val();
  171. if (line_list == "") {
  172. alert('未选择站点信息!');
  173. return;
  174. }
  175. var stationId = $('#station_select').val();
  176. var poiAry = '';
  177. var checkPortAry = '';
  178. var poiIdAry = '';
  179. var checkPortIdAry = '';
  180. var ifHasCheckport = '';
  181. //站点id对应每一条站点信息
  182. // var stationId = '';
  183. //请求站点相关的数据
  184. $.ajax({
  185. url:'./st-xm/Model/linemanager/stationInfo.php', //请求地址
  186. type: "post",
  187. data:{stationId:stationId},
  188. async:false,
  189. dataType: "json",
  190. success: function (data) {
  191. console.log(data);
  192. if(data.code == 0){
  193. //(poi)
  194. var poiListStr = data.list.parent_area_name_list;
  195. //得到截取后返回的数组(poi)
  196. poiAry = intercept(poiListStr);
  197. //(poi)id
  198. var poiListIdStr = data.list.parent_area_id_list;
  199. //得到截取后返回的数组(poi)
  200. poiIdAry = intercept(poiListIdStr);
  201. ifHasCheckport = data.list.checkport_res_name;
  202. if (data.list.checkport_res_id != 0) {
  203. //检票口数组
  204. checkPortAry = data.list.checkport_res_name.split(',');
  205. //检票口id数组
  206. checkPortIdAry = data.list.checkport_res_id.split(',');
  207. }
  208. //站点proid
  209. stationId = data.list.res_id;
  210. }
  211. },
  212. fail: function (data) {
  213. }
  214. });
  215. //tbody
  216. var line = document.getElementById('line_list_info');
  217. //tr
  218. var tr = document.createElement("tr");
  219. tr.id = m;
  220. var newHtml = '';
  221. var tempHTML = $('#tr_replace').html();
  222. tempHTML = tempHTML.replace('[途径顺序]',m);
  223. tempHTML = tempHTML.replace('[orderid]','orderid'+m);
  224. tempHTML = tempHTML.replace('[站点]',$('#line_list').val());
  225. tempHTML = tempHTML.replace('[station_type_td]','station_type_td'+m);
  226. tempHTML = tempHTML.replace('[select_poi]','select_poi'+m);
  227. tempHTML = tempHTML.replace('[teller]','teller'+m);
  228. tempHTML = tempHTML.replace('[teller_station]','teller_station'+m);
  229. tempHTML = tempHTML.replace('[stationid]','stationid'+m);
  230. tempHTML = tempHTML.replace('[timeid]','timeid'+m);
  231. tempHTML = tempHTML.replace('[updown]','updown'+m);
  232. tempHTML = tempHTML.replace('[del]',m);
  233. tempHTML = tempHTML.replace('time_out','time_out'+m);
  234. tempHTML = tempHTML.replace('distance','distance'+m);
  235. tempHTML = tempHTML.replace('[station_type]','station_type'+m);
  236. tempHTML = tempHTML.replace('[hideid]','hideid'+m);
  237. tempHTML = tempHTML.replace('[hideid_id]',stationId);
  238. line.appendChild(tr);
  239. var str = '<a href="#" onclick="deleteOneRow('+''+m+')">删除';
  240. tempHTML = tempHTML.replace('[删除]',str);
  241. tr.innerHTML = tempHTML;
  242. //替换poi
  243. var poiHTML = '';
  244. for (var i = poiAry.length-1; i>=0;i --) {
  245. var tempHTML1 = '<option value="0">请选择</option>';
  246. tempHTML1 = tempHTML1.replace('请选择',poiAry[i]);
  247. tempHTML1 = tempHTML1.replace('0',poiIdAry[i]);
  248. poiHTML += tempHTML1;
  249. }
  250. $('#select_poi'+m).html(poiHTML);
  251. //替换检票口
  252. if (ifHasCheckport=='') {
  253. $('#teller'+m).html('-');
  254. }else{
  255. var checkportHTML = '';
  256. for (var i = 0; i<checkPortAry.length; i++ ) {
  257. var tempHTML2 = '<option value="0">请选择</option>';
  258. tempHTML2 = tempHTML2.replace('请选择',checkPortAry[i]);
  259. tempHTML2 = tempHTML2.replace('0',checkPortIdAry[i]);
  260. checkportHTML += tempHTML2;
  261. }
  262. $('#teller_station'+m).html(checkportHTML);
  263. }
  264. n++;
  265. m++;
  266. //重新排布tr的途径顺序
  267. var trCount = $('#line_list_info').children().length;
  268. for (var k = 1; k < trCount; k++) {
  269. var seltr = $('#line_list_info').children(k);
  270. var selid = seltr[k].id;
  271. $('#orderid'+selid).html(k);
  272. }
  273. }
  274. //遍历poi字符串
  275. function intercept(str){
  276. // var arr = new Array();
  277. // arr = str.split("}");
  278. // var newStr = '';
  279. // if(arr.length > 1){
  280. // for (var i = 0 ; i<arr.length ; i++) {
  281. // newStr = newStr + arr[i];
  282. // }
  283. // }
  284. // var backAry = new Array();
  285. // backAry = newStr.split("{");
  286. // return backAry;
  287. var newStr = '';
  288. newStr = str.replace(/}{/g,'@');
  289. newStr = newStr.substr(1,newStr.length-2);
  290. var backAry = new Array();
  291. backAry = newStr.split('@');
  292. return backAry;
  293. }
  294. //删除某一条数据
  295. function deleteOneRow(rowCount){
  296. var delRow = document.getElementById(rowCount);
  297. delRow.remove();
  298. //重新排布tr的途径顺序
  299. var trCount = $('#line_list_info').children().length;
  300. for (var k = 1; k < trCount; k++) {
  301. var seltr = $('#line_list_info').children(k);
  302. var selid = seltr[k].id;
  303. $('#orderid'+selid).html(k);
  304. }
  305. }
  306. //保存按钮
  307. function saveInfo(){
  308. var urlStr = '';
  309. var checkportUrl = '';
  310. //遍历所有的tr
  311. var trCount = $('#line_list_info').children().length;
  312. if (trCount==1) {
  313. alert('无相关的站点信息,无法保存!');
  314. return;
  315. }
  316. for (var k = 1; k < trCount; k++) {
  317. var seltr = $('#line_list_info').children(k);
  318. var selid = seltr[k].id;
  319. $('#orderid'+selid).html(k);
  320. //取出要传的数据
  321. var updown = $('#station_type'+selid).val();
  322. var order = $('#orderid'+selid).text();
  323. var time = $('#time_out'+selid).val();
  324. var distance = $('#distance'+selid).val();
  325. if (time=="") {
  326. time = 0;
  327. }
  328. if (distance=="") {
  329. distance = 0;
  330. }
  331. if ($('#teller'+selid).text()=="-") {
  332. checkportUrl = 0;
  333. }else{
  334. checkportUrl = $('#teller_station'+selid).val();
  335. }
  336. var station = $('#hideid'+selid).val();
  337. var poi = $('#select_poi'+selid).val();
  338. if (poi=='') {
  339. poi = 0;
  340. }
  341. urlStr = urlStr +'{'+updown+','+order+','+time+','+checkportUrl+','+station+','+poi+','+distance+'}';
  342. }
  343. // var saleStyle_company = $('#company input[name="saleStyle_company"]:checked ').val();
  344. var lineStyle = $("input[name='bar_style']:checked").val();
  345. $.ajax({
  346. url:'./st-xm/control.php', //请求地址
  347. type: "post",
  348. data:{
  349. type:'linemanager_updateline',
  350. linestyle:lineStyle,
  351. station_info:urlStr,
  352. line_id: prod_id
  353. },
  354. async:false,
  355. dataType: "json",
  356. success: function (data) {
  357. console.log(data);
  358. if(data.code == 0){
  359. alert('修改成功!');
  360. }
  361. },
  362. fail: function (data) {
  363. alert('保存失败');
  364. }
  365. });
  366. }