//author:fuhc //date:20161018 //单一线路基本信息 var trHTML = ''; var trRowHTML=''; var line_id = ''; //line_id if{没有就不能点击售卖票种} var line_type = ''; var res_id = ''; var res_name = ''; var cstr_time = '0'; window.onload = function() { // $('.select_line').comboSelect(); line_id=getPar('line_id'); if(line_id){ $('.up_hide').hide(); $('#top_type').hide(); $('.up_info').text('基本信息'); } //setBaseInfo(); setHttpBaseInfo(); $('.tr_row').show(); trHTML = $('.tr_row').html(); trRowHTM = $('#tbody').html(); $('#tbody').html(''); } //配置 function setBaseInfo() { var obj1 = document.getElementById('hour'); for(var i = 0; i <= 24; i++) { var hour = (Array(2).join(0) + i).slice(-2); var myOption = new Option(hour, hour); obj1.options[obj1.options.length] = myOption; } obj1.selectedIndex = 0; var obj2 = document.getElementById('ne_minutes'); for(var i = 0; i <= 59; i++) { var minutes = (Array(2).join(0) + i).slice(-2); var myOption = new Option(minutes, minutes); obj2.options[obj2.options.length] = myOption; } obj2.selectedIndex = 0; } //设置页面配置信息 function setHttpBaseInfo() { var param = { tp: "singleLine_getBaseManager" } ZZLog(base_api + 'lineManager/index.php' + JSON.stringify(param)); $.ajax({ type: "post", url: base_api + 'lineManager/index.php', data: param, dataType: "json", success: function(res_data) { ZZLog(res_data); if(res_data['code'] != "0") { ZZAlertInfo(res_data['info']); } else { //类目 var bus_type = res_data['bus_type']; var obj = document.getElementById('bus_type'); for(var i = 0, m = bus_type.length; i < m; i++) { var tempDict = bus_type[i]; var myOption = new Option(tempDict['name'], tempDict['id']); obj.options[obj.options.length] = myOption; } //售卖截止 // var time_type = res_data['time_type']; // var obj = document.getElementById('time_type'); // for(var i = 0, m = time_type.length; i < m; i++) { // var tempDict = time_type[i]; // var myOption = new Option(tempDict['type_name'], tempDict['id']); // obj.options[obj.options.length] = myOption; // } // //运营公司 // var supply_list = res_data['supply_list']; // var obj = document.getElementById('supply'); // for(var i = 0, m = supply_list.length; i < m; i++) { // var tempDict = supply_list[i]; // var myOption = new Option(tempDict['supplier_name'], tempDict['supplier_id']); // obj.options[obj.options.length] = myOption; // } //判断是否是修改 //设置默认选中项 if(""!=line_id.trim()){ setSelectBaseInfo(); } } }, error: function(error) { ZZLog(error); } }); } //设置选中的值 function setSelectBaseInfo(){ var param={ tp:"singleLine_getLineDetail", line_id:line_id } ZZLog(base_api+"lineManager/index.php"+JSON.stringify(param)); $.ajax({ type:"post", url:base_api+"lineManager/index.php", data:param, dataType:"json", success:function(res_data){ ZZLog(res_data); if(res_data['code']!="0"){ ZZAlertInfo(res_data['info']); }else{ var line_info=res_data['line_info']; $('#line_name').val(line_info['line_name']); $('#line_code').val(line_info['line_code']); $('#bus_type').val(line_info['line_type']); $('#time_type').val(line_info['sale_expired_type']); var time=line_info['sale_expired_time']; var hour=time.split(':')[0]; var minutes=time.split(':')[1]; $('#hour').val(hour); $('#ne_minutes').val(minutes); $('#supply').val(line_info['org_id']); setSelectStationHTML(res_data['station_info']); } },error:function(e){ ZZLog(e); } }); } //设置选中的站点信息 function setSelectStationHTML(station_info){ var HTML=''; for (var j=0,m=station_info.length;j'); //处理站点 tempHTML = tempHTML.replace('[res-name]', res_info['res_name']); tempHTML = tempHTML.replace('[res-id]', res_info['res_id']); //处理POI var parent_area = res_info['parent_area']; var cstr1 = ''; } } tempHTML = tempHTML.replace('[POI]', cstr1); var cstr5 = '公里'; tempHTML = tempHTML.replace('[距离]', cstr5); //处理上下 var inout_type = res_info['inout_type']; var cstr2 = ''; } } tempHTML = tempHTML.replace('[上下]', cstr2); //处理检票口 var check_port = res_info['check_port']; var cstr3 = ''; } } if(check_port.length <= 0 || cstr4 == '') { cstr3 = "-"; } tempHTML = tempHTML.replace('[检票口]', cstr3); HTML+=tempHTML; // addtr.innerHTML = tempHTML; // $('.select_line').comboSelect(); // //删除ROW // $('.delrow').on('click', function() { // $(this).closest('tr').remove(); // sortTr(); // }) // sortTr(); } $('#tbody').html(HTML); $('.select_line').comboSelect(); //上下类型改变联动检票口 var cstrCheck = ''; $('.inout_type').on('change',function(){ var typeid=$(this).val(); var $check = $(this).closest('tr').children().eq(6); cstrCheck = $check.html(); if(typeid!='110'){ $check.html(cstrCheck); }else{ $check.html('-'); } }) $('.delrow').on('click',function(){ $(this).closest('tr').remove(); sortTr(); }) sortTr(); } $(document).ready(function() { // 添加站点 $('#btn_add').on('click', function() { var _res_id = res_id; var param = { tp: "singleLine_getStationInfo", res_id: res_id } ZZLog(base_api + "lineManager/index.php" + JSON.stringify(param)); $.ajax({ type: "post", url: base_api + "lineManager/index.php", data: param, dataType: "json", success: function(res_data) { ZZLog(res_data); if(res_data['code'] != "0") { ZZAlertInfo(res_data['info']); } else { setTrRowHtml(res_data['res_info']); } }, error: function() { ZZLog('error'); } }); function setTrRowHtml(res_info) { var addtr = document.createElement('tr'); var tbody = document.getElementById('tbody'); addtr.className = 'tr_row'; tbody.appendChild(addtr); var tempHTML = trHTML; tempHTML = tempHTML.replace(cstr_time, ''); //处理站点 tempHTML = tempHTML.replace('[res-name]', res_name); tempHTML = tempHTML.replace('[res-id]', res_id); //处理POI var parent_area = res_info['parent_area']; var cstr1 = ''; } } tempHTML = tempHTML.replace('[POI]', cstr1); var cstr5 = '公里'; tempHTML = tempHTML.replace('[距离]', cstr5); //处理上下 var inout_type = res_info['inout_type']; var cstr2 = ''; } } tempHTML = tempHTML.replace('[上下]', cstr2); //处理检票口 var check_port = res_info['check_port']; var cstr3 = ''; } } if(check_port.length <= 0 || cstr4 == '') { cstr3 = "-"; } tempHTML = tempHTML.replace('[检票口]', cstr3); addtr.innerHTML = tempHTML; $('.select_line').comboSelect(); //上下类型改变联动检票口 var cstrCheck = ''; $('.inout_type').on('change',function(){ var typeid=$(this).val(); var $check = $(this).closest('tr').children().eq(6); cstrCheck = $check.html(); if(typeid!='110'){ $check.html(cstrCheck); }else{ $check.html('-'); } }) //删除ROW $('.delrow').on('click', function() { $(this).closest('tr').remove(); sortTr(); }) sortTr(); } }) //检索行驶路线 $('#run_road').on('input', function() { var keyword = $(this).val(); var param = { tp: "singleLine_getLineStation", res_name: keyword } ZZLog(base_api + "lineManager/index.php" + JSON.stringify(param)); $.ajax({ type: "post", url: base_api + "lineManager/index.php", data: param, dataType: "json", success: function(res_data) { ZZLog(res_data); if(res_data['code'] != "0") { ZZAlertInfo(res_data['info']); } else { var res_list = res_data['res_list']; var HTML = ''; for(var i = 0, m = res_list.length; i < m; i++) { var dict = res_list[i]; var cstr = '
' + dict['res_name'] + '
'; HTML += cstr; } if(HTML) { $('.select_content').html(HTML); $('.select_content').show(); } } }, error: function() { ZZLog('error'); } }); }) //保存 $('#base_info_save').on('click', function() { baseInfoSave(); }) }) function getDark(obj){ $(obj).addClass('get_dark'); } function getLight(obj){ $(obj).removeClass('get_dark'); } //保存 function baseInfoSave() { $('.errinfo').html(''); // 参数非空验证 var _line_name = $('#line_name').val(); //线路名称 if("" == _line_name.trim()) { $('#line_name').focus(); $('#line_name').parent().children().eq(1).html('请输入名称'); return; } var _line_code = $('#line_code').val(); //线路代码 if("" == _line_code) { $('#line_code').focus(); $('#line_code').parent().children().eq(1).html('请输入编号'); return; } var _line_type = $('#bus_type').val(); //线路类型1 var _line_sub_type = "0"; ////线路类型2 目前固定 // var _time_type = $('#time_type').val(); //时间类型 // var _hour = $('#hour').val(); // var _ne_minutes = $('#ne_minutes').val(); // var _time_info = _hour + ":" + _ne_minutes; //时间 // var _supply_id = $('#supply').val(); //供应商id var _time_type = 322; //时间类型 var _time_info = '00:00'; //时间 var _supply_id = 0; //供应商id // var _station_list = ''; var bool_inout_type=false; $('.tr_row').each(function(index, domEle) { var _inout_type = $(this).children().find('.inout_type').val(); if(index==$('.tr_row').length-1 && _inout_type!='110'){ bool_inout_type = true; } var _index = index + 1; var _arrive_time = ''; if(index == 0) { _arrive_time = $(this).children().find('.minutes').text(); } else { _arrive_time = $(this).children().find('.minutes').val(); if("" == _arrive_time) { $(this).children().find('.minutes').focus(); return false; } } var _distance = $(this).children().find('.distance').val(); if("" == _distance) { $(this).children().find('.distance').focus(); return false; } var _check_port = $(this).children().find('.check_port').val(); _check_port=_check_port==undefined?"0":_check_port; var _res_id = $(this).children().eq(1).attr('data-res-id'); var _area_id = $(this).children().find('.poi').val(); // // var _json=$(this).children().eq(2).attr('data-json'); // ZZLog(_json); // _json=_json.replace(/'/g,'\"'); // ZZLog(_json); // var param=JSON.parse(_json); // ZZLog(_json); // ZZLog(param); if(_check_port == null) _check_port = 0; _station_list += "{" + _inout_type + "," + _index + "," + _arrive_time + ","+_distance+"," + _check_port + "," + _res_id + "," + _area_id + "}"; }) if(bool_inout_type){ ZZAlertInfo('最后一个站点不能选择下车类型'); return; } if("" == _station_list.trim()) { $('#run_road').focus(); return; } var param = {} if(!line_id){ param={ tp: "singleLine_addLine", line_name: _line_name, line_code: _line_code, line_type: _line_type, line_sub_type: _line_sub_type, time_type: _time_type, time_info: _time_info, supply_id: _supply_id, station_list: _station_list } }else{ param={ tp: "singleLine_lineUpdate", line_id:line_id, line_name: _line_name, line_code: _line_code, line_type: _line_type, line_sub_type: _line_sub_type, time_type: _time_type, time_info: _time_info, supply_id: _supply_id, station_list: _station_list } } ZZLog(base_api + "lineManager/index.php" + JSON.stringify(param)); $.ajax({ type: "post", url: base_api + "lineManager/index.php", data: param, dataType: "json", success: function(res_data) { ZZLog(res_data); if(res_data['code'] != "0") { ZZAlertInfo(res_data['info']); } else { if(line_id){ var lourl = "line_list.html"; window.location.href = lourl; return; } line_id = res_data['line_id']; line_type = res_data['line_type']; var lochref="singline_sell_ticket_type.html?line_id=" + line_id + "&line_type=" + line_type; // window.open(lochref); $.cookie("path_url",cookie_path+"web/lineManager/"+lochref,{domain:domain_path}); window.open(system_path); } }, error: function() { ZZLog('error'); } }); } //点击检索的 function chooseRunRoad(re_id, re_name) { res_id = re_id; res_name = re_name; $('#run_road').val(res_name); $('.select_content').hide(); } //重新排序 function sortTr() { $('.tr_row').each(function(index, domEle) { if(index == 0) { var cstr = cstr_time + ''; $(this).children().eq(3).html(cstr); } $(this).children().eq(0).text(index + 1); $(this).children().eq(0).attr('index', index + 1); }) } //头部切换 function click_type(op) { var lochref = ''; if(op == "com_baseinfo") { lochref = "combination_line.html"; } else if(op == "sing_ticket") { ZZLog(line_id); if(line_id == "") { ZZAlertInfo('请先填写保存线路基本信息'); return; } // line_type = line_type; line_type = $('#bus_type').val(); lochref = "singline_sell_ticket_type.html?line_id=" + line_id + "&line_type=" + line_type; } window.location.href = lochref; }