|
- var addhour = "100";
- var line_distance = 0;
- var base_cost = [];
- function getweek() {
- var week = "week=";
- var weeknum = '';
- for (var i = 1; i < $(".weeklist input").length; i++) {
- if ($(".weeklist input").eq(i).is(":checked")) {
- weeknum += $(".weeklist input").eq(i).val()
- }
- }
- if (weeknum == '') {
- return false;
- }
- return week += weeknum;
- }
-
- function getalltime() {
- var allstation = "allstation=";
- for (var i = 0; i < $(".replace-lineinfo tr").length; i++) {
- var allattr = [];
- var atime = parseInt($(".replace-lineinfo tr").eq(i).children("td:eq(0)").children(".hour").val()) * 60 + parseInt($(".replace-lineinfo tr").eq(i).children("td:eq(0)").children(".minute").val());
- var astationid = $(".replace-lineinfo tr").eq(i).children("td:eq(1)").attr("alineid");
- var aupdowntype = $(".replace-lineinfo tr").eq(i).children("td:eq(2)").children("select").val();
- var amouth = $(".replace-lineinfo tr").eq(i).children("td:eq(3)").children("select").val();
- if (amouth == null) {
- amouth = 0;
- }
- allattr.push(astationid);
- allattr.push(atime);
- allattr.push(aupdowntype);
- allattr.push(amouth);
- var astation = '{' + allattr.join() + '}'
- allstation += astation;
- }
- ;
- return allstation;
- }
-
- function auto_update_cost(obj) {
- var acartype = $(obj).parent().children(".car-item").val();
- var car_cost = $(obj).parent().children(".cost-type").val();
- var car_supplier = $(obj).parent().children(".supplier-list").val();
- if( typeof(base_cost[car_supplier][acartype]) != "undefined" && car_cost == "477" ) {
- var cost_price_auto = Math.round(base_cost[car_supplier][acartype] * line_distance);
- $(obj).parent().children(".cost_price").val(cost_price_auto);
- }
- }
-
- function getallcar() {
- var allcar = "allcar=";
- for (var i = 0; i < $(".car-select").length; i++) {
- var allattr = [];
- var acartype = $(".car-select").eq(i).children(".car-item").val();
- var acarnum = $(".car-select").eq(i).children(".car_number").val();
- var acarseat = $(".car-select").eq(i).children(".ifseat").val();
- //..品牌
- var car_brand = $('.car-select').eq(i).children(".car-brand").val();
- var car_supplier = $('.car-select').eq(i).children(".supplier-list").val();
- var car_cost = $('.car-select').eq(i).children(".cost-type").val();
- var car_cost_price = $('.car-select').eq(i).children(".cost_price").val();
- if (!car_brand) {
- car_brand = '';
- }
- if(!/^\d+(\.\d{1,2})?$/.test(car_cost_price)){
- alert("请输入价格");
- return false;
- }
-
-
-
- allattr.push(acartype);
- allattr.push(acarnum);
- allattr.push(acarseat);
- allattr.push(car_brand)
- allattr.push(car_supplier);
- allattr.push(car_cost);
- allattr.push(car_cost_price);
- var acar = '{' + allattr.join() + '}'
- allcar += acar;
- }
- return allcar;
- }
-
- function gettickettype() {
- var allticket = "allticket=";
- // var starareaid = $(".stararea").eq(0).attr("starareaid");
- // var endareaid = $(".endarea").eq(0).attr("endareaid");
-
- //console.log(starareaid)
- var judge = false;
- for (var i = 0; i < $(".ticket_sel").length; i++) {
- if ($(".ticket_sel").eq(i).is(":checked")) {
- judge = true;
- var index = $(".ticket_sel").eq(i).parent().parent().index();
-
- var allattr = [];
- var starareaid = $(".adult").eq(index).children(".stararea").attr("starareaid");
- var endareaid = $(".adult").eq(index).children(".endarea").attr("endareaid");
-
- var seatid = $(".adult").eq(index).children(".seatid").attr("seatid");
- var crowd = $(".adult").eq(index).children(".crowdid").attr("crowdid");
- if (!crowd || crowd == 0) {
- crowd = 334;
- }
- var aticketnum = $(".adult").eq(index).children(".ticketnum").children("input").val();
-
- allattr.push(starareaid);
- allattr.push(endareaid);
- allattr.push(seatid);
- allattr.push(crowd);
- //allattr.push(aticketnum);
- allattr.push(0);
-
- var aticket = '{' + allattr.join() + '}'
- allticket += aticket;
- }
- }
- if (judge == false) {
- return false;
- }
-
- return allticket
- }
- $(document).ready(function () {
-
- $(".startime").on("change", function () {
- if ($(".startime").val() != '' || $(".endtime").val() != '') {
- $(".data-erro").html("");
- }
- })
- $(".endtime").on("change", function () {
- if ($(".startime").val() != '' || $(".endtime").val() != '') {
- $(".data-erro").html("");
- }
- })
- $(".add-cartype").on("click", function () {
- $(".car-erro").html("")
- })
- // $(".ticket_sel").on("click",function(){
- // $(".ticket-erro").html("")
- // })
- $(".allweek").on("change", function () {
- if ($(this)[0].checked) {
- $(".aday").each(function () {
- this.checked = true;
- })
- } else {
- $(".aday").each(function () {
- this.checked = false;
- })
- }
- })
- $(".aday").on("change", function () {
- $(".allweek")[0].checked = false;
- $(".week-erro").html("")
- })
-
- $(".line-item").hide();
- var ticket1 = $(".adult").outerHTML();
- $(".adult").remove();
- var ticket2 = $(".noble").outerHTML();
- var addcar = $(".car-select").outerHTML();
- $(".car-select").remove();
-
- $(".storage").on("click", function () {
- var week = getweek();
-
- if ($(".add-line").val() == '') {
- $(".addline-erro").html("必填项");
- return;
- }
- ;
-
- if ($(".startime").val() == '' || $(".endtime").val() == '') {
- $(".data-erro").html("必填项")
-
- return;
- }
- ;
- if (week == false) {
- $(".week-erro").html("必填项");
- return;
- }
- ;
- if ($(".car-type").html() == '') {
- $(".car-erro").html("必填项");
- return;
- }
- if (gettickettype() == false) {
- $(".ticket-erro").html("必填项");
-
- return;
- }
- ;
-
- var lineid = getval(".add-line", "lineid");
- var startime = getval(".startime", "val");
- var endtime = getval(".endtime", "val");
-
- var alltime = getalltime();
- var allcar = getallcar();
- if(allcar == false){
- return false;
- }
- var allticket = gettickettype();
- var sellday = getval(".sellday", "val");
- var all = getdata(lineid, startime, endtime, week, alltime, allcar, allticket, sellday);
-
- // if(/week=\s+/.test(week)){
- // console.log("weektrue");
- // }else{
- // alert("bitian") ;
- // return;
- // }
-
- //console.log(week);
- //console.log(startime);
- //console.log(endtime);
- //console.log($(".add-line").html());
- //console.log(allcar);
- //console.log(allticket);
-
- if ($('.storage').html() == "保存") {
- $('.storage').html('保存中...');
- console.log('保存的次数');
- $.getJSON("st-xm/Api/run_bus_new_save.php?" + all, function (data) {
- $('.storage').html('保存');
- if (data.code == "0") {
- swal({
- title: '保存成功',
- text: '车次添加成功',
- type: 'success',
- timer: 10000,
- confirmButtonText: 'OK'
- }).then(
- function () {
- location.href = "carList.html";
- },
- // handling the promise rejection
- function (dismiss) {
- location.href = "carList.html";
- }
- )
- } else {
- swal({
- title: '保存失败',
- text: data.info,
- type: 'error',
- confirmButtonText: 'OK'
- });
- $('.storage').css('display', '');
- console.log(all)
- }
- // if(data.errcode == 0) {
- // alert('保存成功!!!');
- // location.href = "carList.html";
- // } else {
- // alert(data.errinfo);
- // $('.storage').css('display', '');
- // console.log(all)
- // }
- })
- }
-
- //location.href="st-xm/Api/run_bus_new_save.php?"+all;
-
- //$.getJSON("st-xm/Api/run_bus_new_save.php?"+all,function(){
- // console.log("st-xm/Api/run_bus_new_save.php?"+all)
- //})
-
- })
- $('.add-line').on('keyup', function (ev) {
- var val = this.value;
-
- $.getJSON("st-xm/Api/addCarTime.php?method=searchline&word=" + val, function (data) {
-
- $(".line-item").show();
-
- var html = [];
- $.each(data, function (i, v) {
- html.push('<li lineid=' + v.lineid + '>' + v.name + '</li>')
- });
-
- $(".line-item").html(html.join(""));
- $(".line-item>li").on("click", function () {
- $(".addline-erro").html("")
- $(".add-cartype").unbind();
- var val = $(this).attr("lineid");
- $('.add-line').val($(this).html()).attr("lineid", $(this).attr("lineid"));
- $(".line-item").html("");
- $.getJSON("st-xm/Api/addCarTime.php?method=throughstation&lineid=" + val, function (data) {
- console.log(data);
- base_cost = data.base_cost;
- $(".car-type").html("")
- $(".line-item").hide();
- var linehtml = [];
- var tickethtml = [];
- $(".add-cartype").on("click", function () {
- $(".car-erro").html("")
-
- var cartype = [];
- $.each(data.addcartype, function (i, v) {
- var acar = additemall("option", v.cartype, {
- "value": v.id
- });
- cartype.push(acar);
- })
-
- var supplier_str = '';
- for (var ii = 0; ii < data.supplier_list.length; ii++) {
- supplier_str += '<option value="' + data.supplier_list[ii].supplier_id+'">' + data.supplier_list[ii].bus_team+'</option>'
- }
- var cost_str = '';
- for ( ii = 0; ii < data.cost_type.length; ii++) {
- cost_str += '<option value="' + data.cost_type[ii].type_id+'">' + data.cost_type[ii].type_name+'</option>'
- }
- // alert(cost_str);
- //var cartype_str = cartype.join()+supplier_str+cost_str;
- var acartype = addcar.replace("cartype", cartype.join());
- var acartype = acartype.replace("supplier_list", supplier_str);
- var acartype = acartype.replace("cost_type", cost_str);
- $(".car-type").append(acartype);
- $(".car-select .del").unbind();
- $(".car-select .del").on("click", function () {
- $(this).parent().remove();
- });
-
- });
-
- line_distance = 0;
- $.each(data.station, function (i, v) {
- line_distance += parseInt(v.DISTANCE);
- var td1 = addTd(addTime(v.DATE_TIME));
- var td2 = additemall("td", v.SITES, {
- alineid: v.RES_ID
- });
-
- // if(i==0){var td3= addTd('<select style="width: 50px" disabled><option value="108">上</option></select>')}
- // else{var td3=addTd(addUpdownType(v.UP_DOWN_TYPE))};
- var td3 = addTd(addUpdownType(v.UP_DOWN_TYPE));
- var td4 = addTd(addMouth(v.TICKET_GATE, v.CHECKPORT));
- linehtml.push(addItem("tr", "aline", td1.concat(td2, td3, td4)))
- });
- $("#disp_line_distance").html(line_distance+"公里");
-
- $.each(data.ticket, function (i, v) {
- if (v.SEAT == "普通座") {
- var seatid = 72;
- } else if (v.SEAT == "贵宾座") {
- var seatid = 73;
- } else if (v.SEAT == "儿童特票座") {
- var seatid = 74;
- }
- ;
- if (v.CROWD == "成人") {
- var crowdid = 159;
- } else if (v.CROWD == "儿童") {
- var crowdid = 160;
- } else if (v.CROWD == "老人") {
- var crowdid = 161;
- } else if (v.CROWD == "军残") {
- var crowdid = 162;
- } else {
- var crowdid = 0;
- }
- ;
- // if(i==0){
- var atciket = ticket1.replace(/SID|EID|START_AREA|END_AREA|SEAT|CROWD|PRICE|MAX_COUNT|PROD_ID|aseatid|acrowdid/g, function (match) {
- switch (match) {
- case "SID":
- return v.SID;
- case "EID":
- return v.EID;
- case "aseatid":
- return seatid;
- case "acrowdid":
- return crowdid;
- case "START_AREA":
- return v.START_AREA;
- case "END_AREA":
- return v.END_AREA;
- case "SEAT":
- return v.SEAT;
- case "CROWD":
- return v.CROWD;
- case "MAX_COUNT":
- return v.MAX_COUNT;
- case "PROD_ID":
- return v.PROD_ID;
- case "PRICE":
- return v.PRICE;
- }
- })
- tickethtml.push(atciket)
-
- // }else{
- // var atciket = ticket1.replace(/SID|EID|START_AREA|END_AREA|SEAT|CROWD|PRICE|MAX_COUNT|PROD_ID|aseatid|acrowdid/g,function(match){
- // switch(match){
- // case "SID":
- // return v.SID;
- // case "EID":
- // return v.EID;
- // case "aseatid":
- // return seatid;
- // case "acrowdid":
- // return crowdid;
- // case "START_AREA":
- // return "";
- // case "END_AREA":
- // return "";
- // case "SEAT":
- // return v.SEAT;
- // case "CROWD":
- // return v.CROWD;
- // case "MAX_COUNT":
- // return v.MAX_COUNT;
- // case "PROD_ID":
- // return v.PROD_ID;
- // case "PRICE":
- // return v.PRICE;
- // }
- // })
- // tickethtml.push(atciket)
- // }
-
- });
-
- $(".replace-lineinfo").html(linehtml).attr("lineid", data.station[1].PROD_ID);
- $(".able-ticket").html(tickethtml.join());
-
- $(".ticket_sel").on("click", function () {
- $(".ticket-erro").html("");
- })
-
- var hourinfo = [];
- $.each($('.hour'), function (i, v) {
- var val = $('.hour').eq(i).val()
- if (val < 10) {
- val = "0" + val;
- }
- var arr = [i, val]
- hourinfo.push(arr)
- })
- var minuteinfo = [];
- $.each($('.minute'), function (i, v) {
- var val = $('.minute').eq(i).val()
- if (val < 10) {
- val = "0" + val;
- }
- var arr = [i, val]
- minuteinfo.push(arr)
- })
-
- $(".hour").on("change", function () {
- var index = $(this).parent().parent().index();
- var max = $(".hour").length;
- var dangvalue = $(this).val();
- console.log("index:" + index + ";max:" + max + ";dangvalue:" + dangvalue);
- console.log("hourinfo:" + hourinfo + ";dangvalue" + dangvalue);
- for (var i = 0; i < hourinfo.length; i++) {
- if (index == hourinfo[i][0]) {
- var nextindex = hourinfo[i][0] + 1;
-
- var myaddvalue = dangvalue - hourinfo[i][1];
- for (var t = nextindex; t < max; t++) {
- var myvalue = hourinfo[t][1];
- var addvalue = myaddvalue + parseInt(myvalue);
- console.log("myvalue:" + myvalue + ";addvalue:" + addvalue);
- if (addvalue > 23) {
- addvalue -= 24
- console.log("addvalue:" + addvalue);
- } else if (addvalue < 0) {
- addvalue += 24
- }
- // $(".hour").eq(t).find("option").removeAttr("selected");
- $(".hour").eq(t).val(addvalue);
-
- hourinfo[t][1] = addvalue;
-
- }
- // if(myaddvalue<0){
- // hourinfo[i][1]=myaddvalue;
- // }else{
- // for(var t = nextindex;t<max;t++){
- //
- // var myvalue = hourinfo[t][1];
- // var addvalue = myaddvalue+parseInt(myvalue);
- //
- // if(addvalue>23){addvalue-=24}{
- // $(".hour").eq(t).find("option").removeAttr("selected");$(".hour").eq(t).find("option").eq(addvalue).attr("selected","true")
- //
- // hourinfo[t][1]=addvalue;
- // }
- // }
- // }
- }
-
- }
- hourinfo[index][1] = dangvalue;
-
- })
-
- $(".minute").on("change", function () {
- var index = $(this).parent().parent().index();
- var max = $(".minute").length;
- var dangvalue = parseInt($(this).val());
-
- for (var i = 0; i < minuteinfo.length; i++) {
- if (index == minuteinfo[i][0]) {
- var nextindex = parseInt(minuteinfo[i][0]) + 1;
- var addnum = dangvalue - parseInt(minuteinfo[i][1]);
- for (var t = nextindex; t < max; t++) {
- var myhourvalue = hourinfo[t][1];
- var myminutevalue = minuteinfo[t][1];
-
- var addvalue = addnum + parseInt(myminutevalue);
-
- if (addvalue >= 60) {
- addvalue -= 60;
- addhour = parseInt(hourinfo[t][1]) + 1;
- } else if (addvalue <= 0) {
- addvalue += 60;
- addhour = parseInt(hourinfo[t][1]) - 1;
- } else {
- addhour = "100";
- }
- if (addhour == "100") {
- //$(".minute").eq(t).find("option").removeAttr("selected");
- $(".minute").eq(t).val(addvalue);
- minuteinfo[t][1] = addvalue;
- } else {
- // $(".minute").eq(t).find("option").removeAttr("selected");
- $(".minute").eq(t).val(addvalue);
- minuteinfo[t][1] = addvalue;
-
- // $(".hour").eq(t).find("option").removeAttr("selected");
- $(".hour").eq(t).val(addhour);
- hourinfo[t][1] = addhour;
- }
- }
- // if(addnum<0){
- // minuteinfo[i][1]=addnum
- // }
- // else{
- // for(var t = nextindex;t<max;t++){
- // var myhourvalue = hourinfo[t][1];
- // var myminutevalue = minuteinfo[t][1];
- //
- // var addvalue = addnum+parseInt(myminutevalue);
- //
- // if(addvalue>=60){addvalue-=60; var addhour = parseInt(hourinfo[t][1])+1;}
- // if(typeof addhour=="undefined"){
- // $(".minute").eq(t).find("option").removeAttr("selected");$(".minute").eq(t).find("option").eq(addvalue).attr("selected","true")
- // minuteinfo[t][1]=addvalue;
- // }else{
- // $(".minute").eq(t).find("option").removeAttr("selected");$(".minute").eq(t).find("option").eq(addvalue).attr("selected","true")
- // minuteinfo[t][1]=addvalue;
- //
- // $(".hour").eq(t).find("option").removeAttr("selected");$(".hour").eq(t).find("option").eq(addhour).attr("selected","true");
- // hourinfo[t][1]=addhour;
- // }
- // }
- // }
-
- }
- }
- minuteinfo[index][1] = dangvalue;
- })
- })
-
- })
- })
-
- });
-
- $('.date-picker').datepicker({
- autoclose: true
- }).next().on('click', function () {
- $(this).prev().focus();
- });
-
- $('.allweek').on('change', function () {
-
- if ($(this).is(":checked")) {
- for (var i = 0; i < $(".week").length; i++) {
- $(".week").eq(i).click()
- }
- } else {
- for (var i = 0; i < $(".week").length; i++) {
- $(".week").eq(i).removeAttr("checked");
- }
- }
- })
-
- // $(".storage").on("click",function(){
- // var lineid = 'lineid='+$(".add-line").attr('dataid');
- // var time = 'time='+$("#id-date-picker-1").val()+'-'+$("#id-date-picker-2").val();
- // var pass = [];
- // (function(){
- // var line =[];
- // for(var i = 0;i<$(".aline").length;i++){
- // var aline = [];
-
- // aline.push("time="+$(".aline").eq(i).find(".hour").val()+":"+$(".aline").eq(i).find(".minute").val());
- // aline.push("site="+$(".aline").find("td").eq(1).html());
- // aline.push("updown="+$(".aline").find(".updown").val());
- // aline.push("mouth="+$(".aline").find(".mouth").val());
- // line.push(aline.join(""));
-
- // }
-
- // })()
-
- // url = 'lineid='+$(".add-line").attr('dataid')+'time='+$("#id-date-picker-1").val()+'-'+$("#id-date-picker-2").val()
- // console.log(url)
-
- // })
-
- })
-
- function addItem(label, classname, cent) {
-
- var html = ['<' + label + ' class=' + classname + '>'];
- html.push(cent);
- html.push('</' + label + '>');
-
- return html.join("")
-
- }
-
- function addLi(html) {
- var li = ['<li>'];
- li.push(html);
- li.push('</li>');
- li = li.join("");
- return li
- }
-
- function addTime(time) {
- var time = time.split(":");
- var newHour = parseInt(time[0]),
- newMinute = parseInt(time[1]);
- var html = ['<select class="hour">'];
- for (var i = 0; i < 24; i++) {
- if (i == newHour) {
- //..a
- if (i < 10) {
- html.push('<option selected value=' + i + '>0' + i + '</option>')
- } else {
- html.push('<option selected value=' + i + '>' + i + '</option>')
- }
- } else {
- if (i < 10) {
- html.push('<option value=' + i + '>0' + i + '</option>')
- } else {
- html.push('<option value=' + i + '>' + i + '</option>')
- }
-
- }
- }
- html.push('</select style="width: 50px">:<select class="minute">')
- for (var t = 0; t < 60; t++) {
- if (t == newMinute) {
- if (t < 10) {
- html.push('<option selected value=' + t + '>0' + t + '</option>')
- } else {
- html.push('<option selected value=' + t + '>' + t + '</option>')
- }
-
- } else {
- if (t < 10) {
- html.push('<option value=' + t + '>0' + t + '</option>')
- } else {
- html.push('<option value=' + t + '>' + t + '</option>')
- }
-
- }
- }
- html.push('</select>');
- html = html.join("")
- return html
- }
-
- function addUpdownType(type) {
- var typeid = null;
- var alltypeid = [108, 109, 110, 114]
- if (type == 108) {
- typeid = "仅上客"
- } else if (type == 109) {
- typeid = "同时上下客"
- } else if (type == 110) {
- typeid = "仅下客"
- } else if (type == 114) {
- typeid = "不停靠"
- }
- var html = ['<select style="width: 100px" class="updown">'],
- alltype = ['仅上客', '同时上下客', '仅下客', '不停靠']
- for (var i = 0; i < 4; i++) {
- if (typeid == alltype[i]) {
- html.push('<option selected value=' + alltypeid[i] + '>' + alltype[i] + '</option>')
- } else {
- html.push('<option value = ' + alltypeid[i] + '>' + alltype[i] + '</option>')
- }
- }
- html.push('</select>');
- html = html.join("")
- return html
- }
-
- function addMouth(maxNum, num) {
- var html = ['<select style="width: 55px" class="mouth">'];
- for (var i in maxNum) {
- if (i == num) {
- html.push('<option selected value = ' + i + '>' + maxNum[i] + '</option>')
- // html.push('<option selected value = '+i+'>-</option>')
- } else {
- html.push('<option value=' + i + '>' + maxNum[i] + '</option>')
-
- }
- }
- ;
- html.push("</select>");
- if (maxNum <= 0) {
- html = ['-'];
- }
- html = html.join("")
- return html;
- }
-
- function addTd(html) {
- var td = ['<td>'];
- td.push(html);
- td.push('</td>');
- td = td.join("")
- return td;
- }
-
- function addTr(html) {
- var tr = ['<tr>'];
- tr.push(html)
- tr.push('</tr>');
-
- tr = tr.join("")
-
- return tr;
-
- }
-
- jQuery.fn.outerHTML = function (s) {
- return (s) ? this.before(s).remove() : $("<Hill_man>").append(this.eq(0).clone()).html();
- }
-
- function additemall(lable, cen, attr) {
- var html = ['<' + lable + ' ' + (function (attr) {
- if (typeof(attr) == "undefined") {
- return ""
- } else {
- var arr = [];
- for (i in attr) {
- arr.push(i + '="' + attr[i] + '"')
- }
- ;
- return arr.join(" ")
- }
- })(attr) + '>'];
- html.push(cen);
- html.push('</' + lable + '>');
- return html.join("")
- }
-
- function getdata() {
- var val = [];
- Array.prototype.push.apply(val, arguments);
- return val.join("&");
- }
-
- function getval(dom, value) {
- var val = null;
- if (value == "val" || value == "value") {
- val = $(dom).eq(0).val()
- } else if (value == "html") {
- val = $(dom).eq(0).html()
- } else {
- val = $(dom).eq(0).attr(value);
- var name = value;
- return name + "=" + val;
- }
- var name = $(dom).eq(0).attr("name");
- return name + "=" + val
- }
-
- function out_login() {
- window.location = 'login.html';
- }
|