|
- var HTML = '';
- //记录添加的 tr id
- var n = 0;
- //记录途径顺序
- var m = 1;
- var prod_id;
-
- var stationId;
- window.onload = function(){
- $('#tr_replace').hide();
- initdata();
- }
-
- //根据用户输入检索
- function lineListSearch(listId){
- $.ajax({
- url:'./st-xm/Model/linemanager/stationListSearch.php', //请求地址
- type: "post", //请求方式
- // data: data, //请求参数
- data:{
- stationName:listId
- },
- async:false,
- dataType: "json",
- success: function (data) {
- console.log(data);
- if(data.code == 0){
- $('#line_name_search').show();
- var line_list = document.getElementById("line_name_search");
- var list = data.list;
- var htmlStr = "";
- for (var i=0;i<list.length;i++) {
- htmlStr +='<div class="div_input" onclick="click_select('+'\''+list[i].res_id+'\''+',\''+list[i].res_name+'\')">'+list[i].res_name+'</div>';
- }
- line_list.innerHTML = htmlStr;
- }
- },
- fail: function (data) {
-
- }
- });
- }
-
- //选中一个站点
- function click_select(id,name){
- $('#line_list').val(name);
- $('#line_name_search').hide();
- $('#station_select').val(id);
- }
-
- function initdata(){
-
-
- prod_id = getPar("prod_id");
- $.ajax({
- url:'./st-xm/control.php',
- type: "post",
- data: {type:"linemanager_datainfo",id: prod_id},
- dataType: "json",
- success: function (data) {
- console.log(data);
- if(data.code == 0){
- createHtml(data);
-
- }else if(data.code == -1){
-
- alert("请检查网络!!!")
-
- }
- },
- fail: function (data) {
- // 此处放失败后执行的代码
- }
- });
- }
-
- //拼接数据
- function createHtml(data){
- $("#line_no").text(data.cominfo.linecode);
- $("#line_name").text(data.cominfo.linename);
- if((data.cominfo.bus_type==255)||(data.cominfo.bus_type==0)){
- $("#bar_style_z").attr("checked","checked");
-
- }else if(data.cominfo.bus_type==256){
- $("#bar_style_c").attr("checked","checked");
- }
- var temp = "";
- var alltemp = "";
- var y
- var index = "";
- var ind = "";
-
- for(var i=0,j=data.list.length;i<j;i++){
-
-
- if(data.list[i].checkport_res_id==9127||data.list[i].checkport_res_id==227){
- ind = "1号口";
- }else if(data.list[i].checkport_res_id==9128||data.list[i].checkport_res_id==228){
- ind = "2号口";
- }else if(data.list[i].checkport_res_id==229){
- ind = "3号口";
- }else if(data.list[i].checkport_res_id==230){
- ind = "4号口";
- }else{
- ind = "-";
- }
-
- temp += '<tr id="'+(i+1)+'" style="">'
- + '<input type="hidden" id="hideid'+m+'" value="'+data.list[i].station_res_id+'" />'
- + '<td id="orderid'+m+'">'+m+'</td>'
- + '<td>'+data.list[i].station_res_name+'</td>'
- + '<td id="station_type_td'+m+'">'
- + '<select id="select_poi'+m+'" style="margin-right: 10px;width:150px;">'
- + '<option value="'+data.list[i].area_id+'">'+data.list[i].area_name+'</option>'
- + '</select>'
- + '</td>'
- + '<td id="timeid'+m+'">'
- + '<input type="text" id="time_out'+m+'" placeholder="0" value="'+data.list[i].start_minutes+'" style="font-size: 13px;width: 60px;" />分'
- + '</td>'
- + '<td id="timeid'+m+'">'
- + '<input type="text" id="distance'+m+'" placeholder="0" value="'+data.list[i].distance+'" style="font-size: 13px;width: 60px;" />公里'
- + '</td>'
- + '<td>'
- + '<select name="station_type'+m+'" id="station_type'+m+'" style="margin-right: 10px;width:100px;">'
- + '<option value="108">上</option>'
- + '<option value="109">上下</option>'
- + '<option value="110">下</option>'
- + '</select>'
- + '</td>'
- + '<td id="teller'+m+'">'
- + '<select id="teller_station'+m+'" style="margin-right: 10px;width:100px;">'
- + '<option value="'+data.list[i].checkport_res_id+'">'+ind+'</option>'
- + '</select>'
- + '</td>'
- + '<td name="[del]" id="[del]"><a href="#" onclick="deleteOneRow('+''+m+')">删除</a></td>'
- + '</tr>'
- m++;
-
-
-
-
- }
-
- $("#line_list_info").append(temp);
- for(var i=0;i<data.list.length;i++){
- if(data.list[i].inout_type==108){
- $("#station_type"+(i+1)).children().eq(0).attr("selected","selected");
- }else if(data.list[i].inout_type==109){
- $("#station_type"+(i+1)).children().eq(1).attr("selected","selected");
- }else if(data.list[i].inout_type==110){
- $("#station_type"+(i+1)).children().eq(2).attr("selected","selected");
- }
- var temp1 = "";
- for(var j=0;j<data.list[i].poi_name.length;j++){
- temp1 += '<option value="'+data.list[i].poi_name[j].area_name_id+'">'+data.list[i].poi_name[j].area_name_list+'</option>'
-
- }
- $("#select_poi"+(i+1)).append(temp1);
- if(i==0){
- $("#time_out"+(i+1)).attr("readonly","true")
- }
- }
- for(var i=0;i<data.list.length;i++){
- if(data.list[i].checkport_res_id==0){
- $("#teller"+(i+1)).html("-")
- }else{
- var temp2 = "";
- for(var j=0;j<data.list[i].checkport_res.length;j++){
- temp2 += '<option value="'+data.list[i].checkport_res[j].checkport_res_id+'">'+data.list[i].checkport_res[j].checkport_res_name+'</option>'
-
- }
- $("#teller_station"+(i+1)).append(temp2);
- }
-
- }
-
-
-
- }
-
- //得到url上的参数
- function getPar(par){
- var local_url = document.location.href;
- local_url = decodeURI(local_url);
- var get = local_url.indexOf(par +"=");
- if(get == -1){
- return false;
- }
- var get_par = local_url.slice(par.length + get + 1);
- var nextPar = get_par.indexOf("&");
- if(nextPar != -1){
- get_par = get_par.slice(0, nextPar);
- }
- return get_par;
- }
-
- //添加一条线路
- function addOneLine(){
- var line_list = $('#line_list').val();
- if (line_list == "") {
- alert('未选择站点信息!');
- return;
- }
- var stationId = $('#station_select').val();
- var poiAry = '';
- var checkPortAry = '';
- var poiIdAry = '';
- var checkPortIdAry = '';
- var ifHasCheckport = '';
- //站点id对应每一条站点信息
- // var stationId = '';
- //请求站点相关的数据
- $.ajax({
- url:'./st-xm/Model/linemanager/stationInfo.php', //请求地址
- type: "post",
- data:{stationId:stationId},
- async:false,
- dataType: "json",
- success: function (data) {
- console.log(data);
- if(data.code == 0){
- //(poi)
- var poiListStr = data.list.parent_area_name_list;
- //得到截取后返回的数组(poi)
- poiAry = intercept(poiListStr);
- //(poi)id
- var poiListIdStr = data.list.parent_area_id_list;
- //得到截取后返回的数组(poi)
- poiIdAry = intercept(poiListIdStr);
- ifHasCheckport = data.list.checkport_res_name;
- if (data.list.checkport_res_id != 0) {
- //检票口数组
- checkPortAry = data.list.checkport_res_name.split(',');
- //检票口id数组
- checkPortIdAry = data.list.checkport_res_id.split(',');
- }
- //站点proid
- stationId = data.list.res_id;
- }
- },
- fail: function (data) {
-
- }
- });
-
- //tbody
- var line = document.getElementById('line_list_info');
- //tr
- var tr = document.createElement("tr");
- tr.id = m;
- var newHtml = '';
- var tempHTML = $('#tr_replace').html();
- tempHTML = tempHTML.replace('[途径顺序]',m);
- tempHTML = tempHTML.replace('[orderid]','orderid'+m);
- tempHTML = tempHTML.replace('[站点]',$('#line_list').val());
- tempHTML = tempHTML.replace('[station_type_td]','station_type_td'+m);
- tempHTML = tempHTML.replace('[select_poi]','select_poi'+m);
- tempHTML = tempHTML.replace('[teller]','teller'+m);
- tempHTML = tempHTML.replace('[teller_station]','teller_station'+m);
- tempHTML = tempHTML.replace('[stationid]','stationid'+m);
- tempHTML = tempHTML.replace('[timeid]','timeid'+m);
- tempHTML = tempHTML.replace('[updown]','updown'+m);
- tempHTML = tempHTML.replace('[del]',m);
- tempHTML = tempHTML.replace('time_out','time_out'+m);
- tempHTML = tempHTML.replace('distance','distance'+m);
- tempHTML = tempHTML.replace('[station_type]','station_type'+m);
- tempHTML = tempHTML.replace('[hideid]','hideid'+m);
- tempHTML = tempHTML.replace('[hideid_id]',stationId);
- line.appendChild(tr);
- var str = '<a href="#" onclick="deleteOneRow('+''+m+')">删除';
- tempHTML = tempHTML.replace('[删除]',str);
- tr.innerHTML = tempHTML;
- //替换poi
- var poiHTML = '';
-
- for (var i = poiAry.length-1; i>=0;i --) {
- var tempHTML1 = '<option value="0">请选择</option>';
- tempHTML1 = tempHTML1.replace('请选择',poiAry[i]);
- tempHTML1 = tempHTML1.replace('0',poiIdAry[i]);
- poiHTML += tempHTML1;
- }
- $('#select_poi'+m).html(poiHTML);
- //替换检票口
- if (ifHasCheckport=='') {
- $('#teller'+m).html('-');
- }else{
- var checkportHTML = '';
-
- for (var i = 0; i<checkPortAry.length; i++ ) {
- var tempHTML2 = '<option value="0">请选择</option>';
- tempHTML2 = tempHTML2.replace('请选择',checkPortAry[i]);
- tempHTML2 = tempHTML2.replace('0',checkPortIdAry[i]);
- checkportHTML += tempHTML2;
- }
- $('#teller_station'+m).html(checkportHTML);
- }
- n++;
- m++;
- //重新排布tr的途径顺序
- var trCount = $('#line_list_info').children().length;
- for (var k = 1; k < trCount; k++) {
- var seltr = $('#line_list_info').children(k);
- var selid = seltr[k].id;
- $('#orderid'+selid).html(k);
-
- }
- }
-
- //遍历poi字符串
- function intercept(str){
- // var arr = new Array();
- // arr = str.split("}");
- // var newStr = '';
- // if(arr.length > 1){
- // for (var i = 0 ; i<arr.length ; i++) {
- // newStr = newStr + arr[i];
- // }
- // }
- // var backAry = new Array();
- // backAry = newStr.split("{");
- // return backAry;
- var newStr = '';
- newStr = str.replace(/}{/g,'@');
- newStr = newStr.substr(1,newStr.length-2);
- var backAry = new Array();
- backAry = newStr.split('@');
- return backAry;
-
- }
- //删除某一条数据
- function deleteOneRow(rowCount){
- var delRow = document.getElementById(rowCount);
- delRow.remove();
- //重新排布tr的途径顺序
- var trCount = $('#line_list_info').children().length;
- for (var k = 1; k < trCount; k++) {
- var seltr = $('#line_list_info').children(k);
- var selid = seltr[k].id;
- $('#orderid'+selid).html(k);
- }
-
- }
- //保存按钮
- function saveInfo(){
- var urlStr = '';
-
- var checkportUrl = '';
- //遍历所有的tr
- var trCount = $('#line_list_info').children().length;
- if (trCount==1) {
- alert('无相关的站点信息,无法保存!');
- return;
- }
- for (var k = 1; k < trCount; k++) {
- var seltr = $('#line_list_info').children(k);
- var selid = seltr[k].id;
- $('#orderid'+selid).html(k);
- //取出要传的数据
- var updown = $('#station_type'+selid).val();
- var order = $('#orderid'+selid).text();
- var time = $('#time_out'+selid).val();
- var distance = $('#distance'+selid).val();
- if (time=="") {
- time = 0;
- }
- if (distance=="") {
- distance = 0;
- }
- if ($('#teller'+selid).text()=="-") {
- checkportUrl = 0;
- }else{
-
- checkportUrl = $('#teller_station'+selid).val();
- }
- var station = $('#hideid'+selid).val();
- var poi = $('#select_poi'+selid).val();
- if (poi=='') {
- poi = 0;
- }
- urlStr = urlStr +'{'+updown+','+order+','+time+','+checkportUrl+','+station+','+poi+','+distance+'}';
- }
-
- // var saleStyle_company = $('#company input[name="saleStyle_company"]:checked ').val();
- var lineStyle = $("input[name='bar_style']:checked").val();
-
- $.ajax({
- url:'./st-xm/control.php', //请求地址
- type: "post",
- data:{
- type:'linemanager_updateline',
- linestyle:lineStyle,
- station_info:urlStr,
- line_id: prod_id
- },
- async:false,
- dataType: "json",
- success: function (data) {
- console.log(data);
- if(data.code == 0){
- alert('修改成功!');
- }
- },
- fail: function (data) {
- alert('保存失败');
- }
- });
-
- }
|