itinerary2func.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. //构建编辑行程单
  2. function buildStrokeTable(sessionItinerary){
  3. let table=$("table[stroke]");
  4. let html='';let nodeCount=0;let dataId=0;
  5. let explanationHtml='';
  6. sessionItinerary.forEach(function(value,index){
  7. dataId=Object.keys(value)[0];
  8. nodeCount=index+1;
  9. html+=`<tbody strokeNode id="node_${dataId}" ><tr><th colspan="2" class="taC">行程${nodeCount}#详细
  10. <a href="#" dataID="${dataId}" stroke='delNode' class="fR text-danger">删除</a>
  11. </th></tr>`;
  12. html+=buildItinerary(value[dataId],dataId,index);
  13. 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>`;
  14. explanationHtml+=`行程${nodeCount}#\n`;
  15. for(let i=0;i<value[dataId].length;i++){
  16. if(i==0){
  17. explanationHtml+=`${value[dataId][i].departuredate}${value[dataId][i].arrivalsdate} ${value[dataId][i].departurecity}${value[dataId][i].arrivalscity} \n`;
  18. }else{
  19. let previousIndex=i-1;
  20. explanationHtml+=`${value[dataId][previousIndex].arrivalsdate.substring(1)}${value[dataId][i].arrivalsdate} ${value[dataId][previousIndex].arrivalscity.substring(1)}${value[dataId][i].arrivalscity} \n`;
  21. }
  22. }
  23. })
  24. table.html(html);
  25. $('#explanation').val(explanationHtml);
  26. }
  27. //设置行程详情--列表页
  28. function buildItinerary(list,strokeId,strokeIndex){
  29. var html='';
  30. for(let i=0;i<list.length;i++){
  31. if(i==0){
  32. 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+'';
  33. }else{
  34. let previousIndex=i-1;
  35. 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+'';
  36. }
  37. html+='<div class="fR"><a href="#route-add" ediStroke data-toggle="modal" dataId="'+i+'" strokeIndex="'+strokeIndex+'" strokeId="'+strokeId+'" >编辑</a>&nbsp;<a href="#" dataId="'+i+'" strokeIndex="'+strokeIndex+'" strokeId="'+strokeId+'" removeitinerary class="colRed">移除</a></div></th></tr>';
  38. let feeTraveItem=list[i].feeTraveItem;
  39. let price=0;let detail='';
  40. for(let k=0;k<feeTraveItem.length;k++){
  41. price+=parseFloat(feeTraveItem[k].price);
  42. if(!(typeof feeTraveItem[k].detail==='undefined')){
  43. detail=feeTraveItem[k].detail.replace(new RegExp("\n", "gm"), '<br/>');
  44. }
  45. html+='<tr><th>'+feeTraveItem[k].name+'<p class="colGray">'+detail+'</p></th><td width="200" class="taR">¥'+feeTraveItem[k].price+'</td></tr>';
  46. }
  47. html+='<tr><th class="taR">合计</th><td class="colGreen taR">¥'+price+'</td></tr>';
  48. }
  49. return html;
  50. }
  51. //构建总行程单
  52. function buildItineraryProcess(data){
  53. let html='';
  54. let strokeJson=data;
  55. if(typeof data==='string'){
  56. strokeJson=JSON.parse(data);
  57. }
  58. let dataJson;
  59. strokeJson.forEach(function(value,index){
  60. dataId=Object.keys(value)[0];
  61. dataJson=value[dataId];
  62. let last=dataJson.length-1;
  63. let n=0;var ln=index+1;
  64. html+=`<li>行程${ln}#</li>`;
  65. for(let i=0;i<dataJson.length;i++){
  66. let price=0;
  67. for(let p=0;p<dataJson[i].feeTraveItem.length;p++){
  68. price+=parseFloat(dataJson[i].feeTraveItem[p].price);
  69. }
  70. price=price.toFixed(2);
  71. let city='';
  72. if(i==0){
  73. city=dataJson[i].departurecity;
  74. }else{
  75. n=i-1;
  76. city=dataJson[n].arrivalscity.substring(1);
  77. }
  78. html+=`<li>
  79. <div class="itineraryList">
  80. <div class="addressName"><i class="contactsMark icon-">P</i> <b>${city}</b></div>
  81. <div class="pointLine">
  82. <div class="priceList">
  83. <span class="priceTitle">金额</span>
  84. <span class="price colGreen">¥${price}</span>
  85. </div>
  86. <div class="timeList">
  87. <span class="timeTitle">时间</span>
  88. <span class="time">${dataJson[i].departuredate}${dataJson[i].arrivalsdate}</span>
  89. </div>
  90. </div>
  91. </div>
  92. </li>`;
  93. if(i===last){
  94. let arrivalscity=dataJson[i].arrivalscity.substring(1);
  95. html+=`<li>
  96. <div class="itineraryList">
  97. <div class="addressName"><i class="contactsMark icon-">P</i> <b>${arrivalscity}</b></div>
  98. </div>
  99. </li>`;
  100. //html+=`<div class="addressName fL"><i class="contactsMark icon-">P</i><b>${arrivalscity}</b></div>`;
  101. }
  102. }
  103. html+=`<li><br/></li>`;
  104. })
  105. $("ul[itineraryinfo]").html(html);
  106. }
  107. //重新计算费用单金额
  108. function fnTotTravelPrice(){
  109. var itineraryStr=sessionStorage.getItem(sessionStorageList);
  110. //重新赋值行程详情
  111. $("#itinerary").val(itineraryStr);
  112. //var sessionItinerary= JSON.parse(itineraryStr);
  113. var strokeJson= JSON.parse(itineraryStr);
  114. var priceList=[];
  115. strokeJson.forEach(function(value,index){
  116. dataId=Object.keys(value)[0];
  117. var sessionItinerary=value[dataId];
  118. for(let i=0;i<sessionItinerary.length;i++){
  119. let feeTraveItem=sessionItinerary[i].feeTraveItem;
  120. for(let k=0;k<feeTraveItem.length;k++){
  121. if(typeof priceList[feeTraveItem[k].id]==='undefined'){
  122. priceList[feeTraveItem[k].id]=0;
  123. }
  124. priceList[feeTraveItem[k].id]+=parseFloat(feeTraveItem[k].price);
  125. }
  126. }
  127. })
  128. $("input[id^='travel_']").val(0);
  129. $("td span").html(0);
  130. let travelResult=0;
  131. for(let i=0;i<priceList.length;i++){
  132. if(typeof priceList[i]==='number'){
  133. $("span[travelprice_"+i+"]").html(priceList[i].toFixed(2));
  134. $("#travel_"+i+"").val(priceList[i].toFixed(2));
  135. travelResult+=priceList[i];
  136. }
  137. }
  138. $("#travelResult").html(travelResult.toFixed(2));
  139. $("#RS").html(travelResult.toFixed(2));
  140. }
  141. //构建费用说明
  142. function buildFeeTravelItem(feeTraveItem){
  143. var html='';let detail='';
  144. for(let i=0;i<feeTraveItem.length;i++){
  145. html+='<tr class="remove" ><th>'+feeTraveItem[i].name+'</th>';
  146. if(!(typeof feeTraveItem[i].detail==='undefined')){
  147. detail=feeTraveItem[i].detail.replace(new RegExp("<br/>", "gm"), '\n');
  148. }
  149. 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>'+
  150. '<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>';
  151. //html+='<td><textarea type="text" itemDetail_'+feeTraveItem[i].id+' placeholder="填写费用说明">'+feeTraveItem[i].detail+'</textarea> </td>';
  152. html+='<td><a href="#" removeFeeTravelItem >移除</a></td></tr>';
  153. }
  154. $("tbody[feeTravelItem]").html(html);
  155. }
  156. //获得对应的行程单
  157. function getItineraryData(dataString,dataID){
  158. strokeList=JSON.parse(dataString);
  159. let sessionItinerary={};let keyId=0;
  160. strokeList.forEach(function(value,index){
  161. keyId=Object.keys(value)[0];
  162. if(keyId===dataID){
  163. sessionItinerary=value;
  164. }
  165. })
  166. return sessionItinerary[dataID];
  167. }
  168. function setUnDisabled(){
  169. //禁用出发地
  170. $('select[departureprovince]').removeAttr("disabled");
  171. $('select[departurecity]').removeAttr("disabled");
  172. $('input[departuredate]').removeAttr("disabled");
  173. }
  174. function setDisabled(sessionItinerary){
  175. if(sessionItinerary!==''){
  176. let si=JSON.parse(sessionItinerary);
  177. $('input[departuredate]').val(si.arrivalsdate.substring(1));
  178. }
  179. //禁用出发地
  180. $('select[departureprovince]').attr("disabled","disabled");
  181. $('select[departurecity]').attr("disabled","disabled");
  182. $('input[departuredate]').attr("disabled","disabled");
  183. }
  184. //获得设置行程单的相关内容
  185. function fnGetItineraryData(){
  186. var departurecity=$("select[departurecity] option:selected").text();
  187. var arrivalscity=$("select[arrivalscity] option:selected").text();
  188. var departureprovince=$("select[departureprovince] option:selected").text();
  189. var arrivalsprovince=$("select[arrivalsprovince] option:selected").text();
  190. var departuredate=$("input[departuredate]").val();
  191. var arrivalsdate=$("input[arrivalsdate]").val();
  192. var feeTravePriceList=$("tbody[feeTravelItem]").find('input[type=number]');
  193. //var feeTraveDetailList=$("tbody[feeTravelItem]").find('input[type=text]');
  194. var feeTraveDetailList=$("tbody[feeTravelItem]").find('textarea');
  195. if(arrivalscity!==''){
  196. arrivalscity='-'+arrivalscity;
  197. }
  198. if(arrivalsdate!==''){
  199. arrivalsdate='~'+arrivalsdate;
  200. }
  201. var feeTraveItem=[];
  202. for(let i=0;i<feeTravePriceList.length;i++){
  203. feeTraveItem.push({'id':$(feeTravePriceList[i]).attr('dataId'),'name':$(feeTravePriceList[i]).attr('data'),'price':$(feeTravePriceList[i]).val(),'detail':$(feeTraveDetailList[i]).val()});
  204. }
  205. var itinerary={'departuredate':departuredate,'departureprovince':departureprovince,'departurecity':departurecity,'arrivalsdate':arrivalsdate,'arrivalsprovince':arrivalsprovince,'arrivalscity':arrivalscity,'feeTraveItem':feeTraveItem};
  206. return itinerary;
  207. }
  208. //--设置省份下拉
  209. function districtTop(selected){
  210. var storage=window.localStorage;
  211. if(typeof storage["districtTop"]==='undefined'||storage["districtTop"]===''){
  212. $.ajax({
  213. url : '/api/district',
  214. type : "post",
  215. cache : false,
  216. dataType : "json",
  217. global : true,
  218. success : function(data) {
  219. storage.setItem("districtTop",JSON.stringify(data.districtList));
  220. //districtTop(data.districtList);
  221. districtTopHtml(data.districtList,selected);
  222. },
  223. error : function(err) {}
  224. });
  225. }else{
  226. districtTopHtml(JSON.parse(storage["districtTop"]),selected);
  227. }
  228. }
  229. function districtTopHtml(districtTop,selected){
  230. //var districtTop=JSON.parse(storage["districtTop"]);
  231. //console.log(districtTop.length);
  232. var html='';
  233. for(let i=0;i<districtTop.length;i++){
  234. if(typeof selected!=='undefined'&&selected.departureprovince==districtTop[i].name){
  235. html+='<option selected value='+districtTop[i].id+'>'+districtTop[i].name+'</option>';
  236. }else{
  237. html+='<option value='+districtTop[i].id+'>'+districtTop[i].name+'</option>';
  238. }
  239. }
  240. $("select[departureProvince]").html(html);
  241. html='';
  242. for(let i=0;i<districtTop.length;i++){
  243. if(typeof selected!=='undefined'&&selected.arrivalsprovince==districtTop[i].name){
  244. html+='<option selected value='+districtTop[i].id+'>'+districtTop[i].name+'</option>';
  245. }else{
  246. html+='<option value='+districtTop[i].id+'>'+districtTop[i].name+'</option>';
  247. }
  248. }
  249. $("select[arrivalsProvince]").html(html);
  250. }
  251. //设置城市下来菜单-存储数据
  252. function districtCityBuild(selectDom,obj,selected){
  253. var storage=window.localStorage;
  254. var id=$('select['+obj+']').val();
  255. if(typeof storage["district_"+id]==='undefined'||storage["district_"+id]===''){
  256. $.ajax({
  257. url : '/api/district?did='+id,
  258. type : "post",
  259. cache : false,
  260. dataType : "json",
  261. async:false,
  262. global : true,
  263. success : function(data) {
  264. storage.setItem("district_"+id,JSON.stringify(data.districtList));
  265. //districtCity(selectDom,data.districtList);
  266. },
  267. error : function(err) {}
  268. });
  269. }
  270. districtCity=JSON.parse(storage["district_"+id]);
  271. var html='';var cityName='';
  272. if(typeof selected!=='undefined'){
  273. if(selectDom=='departurecity'){
  274. cityName=selected.departurecity;
  275. }else{
  276. cityName=selected.arrivalscity.substring(1);
  277. }
  278. }
  279. for(let i=0;i<districtCity.length;i++){
  280. if(typeof selected!=='undefined'&&cityName==districtCity[i].name){
  281. html+='<option selected value='+districtCity[i].name+'>'+districtCity[i].name+'</option>';
  282. }else{
  283. html+='<option value='+districtCity[i].name+'>'+districtCity[i].name+'</option>';
  284. }
  285. }
  286. $("select["+selectDom+"]").html(html);
  287. }
  288. function emptyJson(data) {
  289. if (data === "{}" || JSON.stringify(data) === "{}") {
  290. return true;
  291. } else {
  292. return false;
  293. }
  294. }