123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347 |
- //构建编辑行程单
- function buildStrokeTable(sessionItinerary){
- let table=$("table[stroke]");
- let html='';let nodeCount=0;let dataId=0;
- let explanationHtml='';
- sessionItinerary.forEach(function(value,index){
- dataId=Object.keys(value)[0];
- nodeCount=index+1;
- html+=`<tbody strokeNode id="node_${dataId}" ><tr><th colspan="2" class="taC">行程${nodeCount}#详细
- <a href="#" dataID="${dataId}" stroke='delNode' class="fR text-danger">删除</a>
- </th></tr>`;
- html+=buildItinerary(value[dataId],dataId,index);
- html+=`<tr><th colspan="2" class="taC"><a href="#route-add"class="button" dataID="${dataId}" dataIndex="${index}" addStroke data-toggle="modal">设置行程费用单</a></th></tr></tbody>`;
-
- explanationHtml+=`行程${nodeCount}#\n`;
- for(let i=0;i<value[dataId].length;i++){
- if(i==0){
- explanationHtml+=`${value[dataId][i].departuredate}${value[dataId][i].arrivalsdate} ${value[dataId][i].departurecity}${value[dataId][i].arrivalscity} \n`;
- }else{
- let previousIndex=i-1;
- explanationHtml+=`${value[dataId][previousIndex].arrivalsdate.substring(1)}${value[dataId][i].arrivalsdate} ${value[dataId][previousIndex].arrivalscity.substring(1)}${value[dataId][i].arrivalscity} \n`;
- }
- }
- })
- table.html(html);
- $('#explanation').val(explanationHtml);
-
- }
- //设置行程详情--列表页
- function buildItinerary(list,strokeId,strokeIndex){
-
- var html='';
- for(let i=0;i<list.length;i++){
- if(i==0){
- html+='<tr><th colspan="2" class="ta"><i class="contactsMark icon-">P</i> '+list[i].departuredate+list[i].arrivalsdate+' '+list[i].departurecity+list[i].arrivalscity+'';
- }else{
- let previousIndex=i-1;
- html+='<tr><th colspan="2" class="ta"><i class="contactsMark icon-">P</i> '+list[previousIndex].arrivalsdate.substring(1)+list[i].arrivalsdate+' '+list[previousIndex].arrivalscity.substring(1)+list[i].arrivalscity+'';
- }
- html+='<div class="fR"><a href="#route-add" ediStroke data-toggle="modal" dataId="'+i+'" strokeIndex="'+strokeIndex+'" strokeId="'+strokeId+'" >编辑</a> <a href="#" dataId="'+i+'" strokeIndex="'+strokeIndex+'" strokeId="'+strokeId+'" removeitinerary class="colRed">移除</a></div></th></tr>';
- let feeTraveItem=list[i].feeTraveItem;
- let price=0;let detail='';
-
- for(let k=0;k<feeTraveItem.length;k++){
- price+=parseFloat(feeTraveItem[k].price);
-
- if(!(typeof feeTraveItem[k].detail==='undefined')){
- detail=feeTraveItem[k].detail.replace(new RegExp("\n", "gm"), '<br/>');
- }
- html+='<tr><th>'+feeTraveItem[k].name+'<p class="colGray">'+detail+'</p></th><td width="200" class="taR">¥'+feeTraveItem[k].price+'</td></tr>';
- }
- html+='<tr><th class="taR">合计</th><td class="colGreen taR">¥'+price+'</td></tr>';
- }
- return html;
- }
- //构建总行程单
- function buildItineraryProcess(data){
- let html='';
- let strokeJson=data;
- if(typeof data==='string'){
- strokeJson=JSON.parse(data);
- }
-
-
- let dataJson;
- strokeJson.forEach(function(value,index){
- dataId=Object.keys(value)[0];
- dataJson=value[dataId];
- let last=dataJson.length-1;
- let n=0;var ln=index+1;
- html+=`<li>行程${ln}#</li>`;
- for(let i=0;i<dataJson.length;i++){
- let price=0;
- for(let p=0;p<dataJson[i].feeTraveItem.length;p++){
- price+=parseFloat(dataJson[i].feeTraveItem[p].price);
- }
- price=price.toFixed(2);
-
- let city='';
- if(i==0){
- city=dataJson[i].departurecity;
- }else{
- n=i-1;
- city=dataJson[n].arrivalscity.substring(1);
- }
-
- html+=`<li>
- <div class="itineraryList">
- <div class="addressName"><i class="contactsMark icon-">P</i> <b>${city}</b></div>
- <div class="pointLine">
- <div class="priceList">
- <span class="priceTitle">金额</span>
- <span class="price colGreen">¥${price}</span>
- </div>
- <div class="timeList">
- <span class="timeTitle">时间</span>
- <span class="time">${dataJson[i].departuredate}${dataJson[i].arrivalsdate}</span>
- </div>
- </div>
- </div>
- </li>`;
-
- if(i===last){
- let arrivalscity=dataJson[i].arrivalscity.substring(1);
-
- html+=`<li>
- <div class="itineraryList">
- <div class="addressName"><i class="contactsMark icon-">P</i> <b>${arrivalscity}</b></div>
-
- </div>
- </li>`;
-
- //html+=`<div class="addressName fL"><i class="contactsMark icon-">P</i><b>${arrivalscity}</b></div>`;
- }
- }
-
- html+=`<li><br/></li>`;
-
- })
-
- $("ul[itineraryinfo]").html(html);
- }
- //重新计算费用单金额
- function fnTotTravelPrice(){
- var itineraryStr=sessionStorage.getItem(sessionStorageList);
-
- //重新赋值行程详情
- $("#itinerary").val(itineraryStr);
-
- //var sessionItinerary= JSON.parse(itineraryStr);
- var strokeJson= JSON.parse(itineraryStr);
-
- var priceList=[];
- strokeJson.forEach(function(value,index){
- dataId=Object.keys(value)[0];
- var sessionItinerary=value[dataId];
- for(let i=0;i<sessionItinerary.length;i++){
- let feeTraveItem=sessionItinerary[i].feeTraveItem;
- for(let k=0;k<feeTraveItem.length;k++){
- if(typeof priceList[feeTraveItem[k].id]==='undefined'){
- priceList[feeTraveItem[k].id]=0;
- }
- priceList[feeTraveItem[k].id]+=parseFloat(feeTraveItem[k].price);
- }
- }
- })
-
- $("input[id^='travel_']").val(0);
- $("td span").html(0);
-
- let travelResult=0;
- for(let i=0;i<priceList.length;i++){
- if(typeof priceList[i]==='number'){
- $("span[travelprice_"+i+"]").html(priceList[i].toFixed(2));
- $("#travel_"+i+"").val(priceList[i].toFixed(2));
- travelResult+=priceList[i];
- }
- }
-
- $("#travelResult").html(travelResult.toFixed(2));
- $("#RS").html(travelResult.toFixed(2));
- }
- //构建费用说明
- function buildFeeTravelItem(feeTraveItem){
-
- var html='';let detail='';
- for(let i=0;i<feeTraveItem.length;i++){
- html+='<tr class="remove" ><th>'+feeTraveItem[i].name+'</th>';
-
- if(!(typeof feeTraveItem[i].detail==='undefined')){
- detail=feeTraveItem[i].detail.replace(new RegExp("<br/>", "gm"), '\n');
- }
-
- html+='<td class="taR"><p>¥<input type="number" itemId_'+feeTraveItem[i].id+' data="'+feeTraveItem[i].name+'" dataId="'+feeTraveItem[i].id+'" value="'+feeTraveItem[i].price+'" placeholder="输入费用" pattern="[0-9]" step="1" min="0"class="span2"></p>'+
- '<p><textarea type="text" itemDetail_'+feeTraveItem[i].id+' placeholder="填写费用说明" rows="2" style=" width: 350px; margin: 10px 0px 0px 12px; height: 65px;">'+detail+'</textarea></p></td>';
- //html+='<td><textarea type="text" itemDetail_'+feeTraveItem[i].id+' placeholder="填写费用说明">'+feeTraveItem[i].detail+'</textarea> </td>';
- html+='<td><a href="#" removeFeeTravelItem >移除</a></td></tr>';
- }
- $("tbody[feeTravelItem]").html(html);
- }
- //获得对应的行程单
- function getItineraryData(dataString,dataID){
- strokeList=JSON.parse(dataString);
- let sessionItinerary={};let keyId=0;
- strokeList.forEach(function(value,index){
- keyId=Object.keys(value)[0];
- if(keyId===dataID){
- sessionItinerary=value;
- }
- })
- return sessionItinerary[dataID];
- }
- function setUnDisabled(){
- //禁用出发地
- $('select[departureprovince]').removeAttr("disabled");
- $('select[departurecity]').removeAttr("disabled");
- $('input[departuredate]').removeAttr("disabled");
- }
- function setDisabled(sessionItinerary){
- if(sessionItinerary!==''){
- let si=JSON.parse(sessionItinerary);
- $('input[departuredate]').val(si.arrivalsdate.substring(1));
- }
-
- //禁用出发地
- $('select[departureprovince]').attr("disabled","disabled");
- $('select[departurecity]').attr("disabled","disabled");
-
- $('input[departuredate]').attr("disabled","disabled");
- }
- //获得设置行程单的相关内容
- function fnGetItineraryData(){
- var departurecity=$("select[departurecity] option:selected").text();
- var arrivalscity=$("select[arrivalscity] option:selected").text();
- var departureprovince=$("select[departureprovince] option:selected").text();
- var arrivalsprovince=$("select[arrivalsprovince] option:selected").text();
-
- var departuredate=$("input[departuredate]").val();
- var arrivalsdate=$("input[arrivalsdate]").val();
-
- var feeTravePriceList=$("tbody[feeTravelItem]").find('input[type=number]');
- //var feeTraveDetailList=$("tbody[feeTravelItem]").find('input[type=text]');
- var feeTraveDetailList=$("tbody[feeTravelItem]").find('textarea');
- if(arrivalscity!==''){
- arrivalscity='-'+arrivalscity;
- }
- if(arrivalsdate!==''){
- arrivalsdate='~'+arrivalsdate;
- }
-
- var feeTraveItem=[];
- for(let i=0;i<feeTravePriceList.length;i++){
- feeTraveItem.push({'id':$(feeTravePriceList[i]).attr('dataId'),'name':$(feeTravePriceList[i]).attr('data'),'price':$(feeTravePriceList[i]).val(),'detail':$(feeTraveDetailList[i]).val()});
- }
-
- var itinerary={'departuredate':departuredate,'departureprovince':departureprovince,'departurecity':departurecity,'arrivalsdate':arrivalsdate,'arrivalsprovince':arrivalsprovince,'arrivalscity':arrivalscity,'feeTraveItem':feeTraveItem};
- return itinerary;
- }
- //--设置省份下拉
- function districtTop(selected){
-
- var storage=window.localStorage;
-
- if(typeof storage["districtTop"]==='undefined'||storage["districtTop"]===''){
- $.ajax({
- url : '/api/district',
- type : "post",
- cache : false,
- dataType : "json",
- global : true,
- success : function(data) {
-
- storage.setItem("districtTop",JSON.stringify(data.districtList));
- //districtTop(data.districtList);
- districtTopHtml(data.districtList,selected);
- },
- error : function(err) {}
- });
- }else{
-
- districtTopHtml(JSON.parse(storage["districtTop"]),selected);
- }
- }
- function districtTopHtml(districtTop,selected){
- //var districtTop=JSON.parse(storage["districtTop"]);
- //console.log(districtTop.length);
-
- var html='';
- for(let i=0;i<districtTop.length;i++){
- if(typeof selected!=='undefined'&&selected.departureprovince==districtTop[i].name){
- html+='<option selected value='+districtTop[i].id+'>'+districtTop[i].name+'</option>';
- }else{
- html+='<option value='+districtTop[i].id+'>'+districtTop[i].name+'</option>';
- }
-
- }
- $("select[departureProvince]").html(html);
-
- html='';
- for(let i=0;i<districtTop.length;i++){
- if(typeof selected!=='undefined'&&selected.arrivalsprovince==districtTop[i].name){
- html+='<option selected value='+districtTop[i].id+'>'+districtTop[i].name+'</option>';
- }else{
- html+='<option value='+districtTop[i].id+'>'+districtTop[i].name+'</option>';
- }
-
- }
- $("select[arrivalsProvince]").html(html);
- }
- //设置城市下来菜单-存储数据
- function districtCityBuild(selectDom,obj,selected){
- var storage=window.localStorage;
- var id=$('select['+obj+']').val();
- if(typeof storage["district_"+id]==='undefined'||storage["district_"+id]===''){
- $.ajax({
- url : '/api/district?did='+id,
- type : "post",
- cache : false,
- dataType : "json",
- async:false,
- global : true,
- success : function(data) {
- storage.setItem("district_"+id,JSON.stringify(data.districtList));
- //districtCity(selectDom,data.districtList);
- },
- error : function(err) {}
- });
- }
-
- districtCity=JSON.parse(storage["district_"+id]);
-
- var html='';var cityName='';
- if(typeof selected!=='undefined'){
- if(selectDom=='departurecity'){
- cityName=selected.departurecity;
-
- }else{
- cityName=selected.arrivalscity.substring(1);
- }
- }
-
- for(let i=0;i<districtCity.length;i++){
-
- if(typeof selected!=='undefined'&&cityName==districtCity[i].name){
-
- html+='<option selected value='+districtCity[i].name+'>'+districtCity[i].name+'</option>';
- }else{
- html+='<option value='+districtCity[i].name+'>'+districtCity[i].name+'</option>';
- }
- }
- $("select["+selectDom+"]").html(html);
- }
- function emptyJson(data) {
- if (data === "{}" || JSON.stringify(data) === "{}") {
- return true;
- } else {
- return false;
- }
- }
|