You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

346 lines
9.4 KiB

  1. //当前时间
  2. var tmonth = new Date();
  3. var year = tmonth.getFullYear();
  4. var month = tmonth.getMonth();
  5. var dom = $('.month');
  6. //中间变量 记录
  7. var tttmonth = '';
  8. var tyear = '';
  9. var newData=null;
  10. var select_length = "";
  11. //获取产品id
  12. //var pro_id=getPar(pro_id);
  13. //测试产品id
  14. var pro_id=getPar("pro_id");
  15. //可选开始日期 xxxx-xx-xx
  16. var select_start_time = "";
  17. //可选结束日期 xxxx-xx-xx
  18. var select_end_time = "";
  19. //可选开始日期数组 xxxx-xx-xx
  20. var select_start_time_arr = "";
  21. //可选结束日期数组 xxxx-xx-xx
  22. var select_end_time_arr = "";
  23. //可选日
  24. var select_start_day ="";
  25. //可选月
  26. var select_start_month ="";
  27. //可选年
  28. var select_start_year ="";
  29. //可选日
  30. var select_end_day ="";
  31. //可选月
  32. var select_end_month ="";
  33. //可选年
  34. var select_end_year ="";
  35. //价格数据
  36. var select_data;
  37. //选择的价格
  38. var select_price;
  39. //选择的日期
  40. var select_go_date;
  41. //价格
  42. var one_price = 0;
  43. window.onload = function(){
  44. //获取产品价格
  45. get_product_price();
  46. !dom.hasClass("amonth")&&dom.addClass("amonth");
  47. //当前日期
  48. var date1 = new Date(year,month);
  49. //当前月份
  50. var tomonth = new Date().getMonth();
  51. //后台开始月份
  52. var select_tomonth = select_start_month-1;
  53. var today = new Date().getDate();
  54. var dayhtml = [];
  55. var week = ["日","一","二","三","四","五","六"];
  56. for (var t=1;t<=3;t++){
  57. dayhtml.push('<div style="clear:both">');
  58. var date = date1;
  59. month = date.getMonth()+t-1;
  60. if (month>=11) {
  61. tyear = year+1;
  62. tttmonth = month-12 ;
  63. // month = 0;
  64. }else{
  65. tyear =year;
  66. tttmonth = month;
  67. }
  68. if(tttmonth==-1){
  69. tttmonth=11;
  70. tyear = year;
  71. }
  72. dayhtml.push('<div class="month_title"><span class="current_month">'+(tttmonth+1)+'月'+'</span><span class="current_year">'+tyear+'</span></div>')
  73. // dayhtml.push();
  74. // $.each(week,function(i,v){
  75. // dayhtml.push('<div class="aweek" style="float:left">'+week[i]+'</div>')
  76. // });
  77. var str = '';
  78. $.each(week,function(i,v){
  79. str += '<div class="aweek ub-f1 text_middle ui_p_t15 ui_p_b15">'+week[i]+'</div>';
  80. });
  81. dayhtml.push('<div class="ub" style="margin-left:0.2rem;margin-right:0.2rem;">'+str+'</div>')
  82. var nextdate = new Date(year,month)
  83. var firstweek = nextdate.getDay();
  84. // var firstweek = month.getDay();
  85. // var first = month.getDay();
  86. var allday = new Date(parseInt(year),(parseInt(month)+1),0).getDate();
  87. var daystr = '<div style="margin-left:0.2rem;margin-right:0.2rem;">';
  88. for(var i = 0;i<firstweek;i++){
  89. daystr+='<div class="aday"></div>'
  90. };
  91. var data_cur_str=''; //日期str
  92. var data_cur=''; //日期-
  93. // 得到去程日期
  94. var go_run_date=getPar('go_date');
  95. // var date1 = new Date(go_run_date.replace(/\-/g, '/'));
  96. // // 判断日期是否合理
  97. // var date1 = new Date(start_date.replace(/\-/g, '/'));
  98. // var date2 = new Date(end_date.replace(/\-/g, '/'));
  99. // if (date1>date2 || end_date=="") {
  100. // $('#id-date-picker-2').val(start_date);
  101. // }
  102. if (month==select_tomonth){
  103. for(i=1;i<=allday;i++){
  104. var t_m=(tttmonth+1);
  105. var t_m_str=t_m;
  106. var t_d_str=i;
  107. if(t_m<=9){
  108. t_m_str="0"+t_m;
  109. }
  110. if(i<=9){
  111. t_d_str="0"+i;
  112. }
  113. data_cur_str=t_m_str+"月"+t_d_str+'日';
  114. data_cur=tyear+"-"+(Array(2).join(0)+(tttmonth+1)).slice(-2)+"-"+(Array(2).join(0)+i).slice(-2);
  115. // if(data[data_cur]){
  116. // you
  117. // }else{
  118. //
  119. // }
  120. var run_day=go_run_date.substring(8);
  121. if(i<parseInt(run_day)){
  122. daystr+='<div style="font-size:0.14rem" class="aday disday">'+i+'</div>';
  123. }else{
  124. if(i<select_start_day){
  125. if(i==today){
  126. daystr+='<div style="font-size:0.14rem" data-cur-str="'+data_cur_str+'" data-cur="'+data_cur+'" class="aday disday today">今天</div>';
  127. }else{
  128. daystr+='<div style="font-size:0.14rem" class="aday disday">'+i+'</div>';
  129. }
  130. }else{
  131. if(i==today){
  132. daystr+='<div style="font-size:0.14rem" data-cur-str="'+data_cur_str+'" data-cur="'+data_cur+'" class="aday canday today"><div style="font-size:0.14rem">今天</div><div style="font-size:0.09rem;padding-right:0.04rem;top: -0.02rem;">¥123</div></div>';
  133. }else{
  134. daystr+='<div data-cur-str="'+data_cur_str+'" data-cur="'+data_cur+'"class="aday canday"><div style="font-size:0.14rem">'+i+'</div><div style="font-size:0.09rem;padding-right:0.04rem;top: -0.02rem;"></div></div>';
  135. }
  136. }
  137. }
  138. }
  139. }else if(month<select_tomonth){
  140. for(i=1;i<=allday;i++){
  141. daystr+='<div style="font-size:0.14rem" class="aday disday">'+i+'</div>'
  142. }
  143. }else{
  144. for(i=1;i<=allday;i++){
  145. var t_m=(tttmonth+1);
  146. var t_m_str=t_m;
  147. var t_d_str=i;
  148. if(t_m<=9){
  149. t_m_str="0"+t_m;
  150. }
  151. if(i<=9){
  152. t_d_str="0"+i;
  153. }
  154. data_cur_str=t_m_str+"月"+t_d_str+'日';
  155. data_cur=tyear+"-"+(Array(2).join(0)+(tttmonth+1)).slice(-2)+"-"+(Array(2).join(0)+i).slice(-2);
  156. daystr+='<div data-cur-str="'+data_cur_str+'" data-cur="'+data_cur+'"class="aday canday"><div style="font-size:0.14rem">'+i+'</div><div style="font-size:0.09rem;padding-right:0.04rem;top: -0.02rem;"></div></div>'
  157. }
  158. }
  159. daystr += "</div>";
  160. dayhtml.push(daystr);
  161. dayhtml.push('</div>');
  162. }
  163. dom.html(dayhtml.join(""))
  164. //选中去程的日期
  165. $(".canday").each(function(index,domE){
  166. if($(this).attr('data-cur')==getPar('go_date')){
  167. $(this).removeClass('select_day');
  168. $(this).removeClass('select_go_day');
  169. $(this).addClass('select_go_day');
  170. };
  171. if(index<select_length){
  172. var date_time = $(this).attr("data-cur");
  173. $(this).attr("one_price",parseInt(Math.ceil(select_data[index].price)));
  174. if((new Date(date_time).getDay() == 6)||(new Date(date_time).getDay() == 0)){
  175. $(this).children().eq(1).text("¥"+parseInt(Math.ceil(select_data[index].price)));
  176. $(this).children().eq(1).css("color","#519d9e");
  177. }else{
  178. $(this).children().eq(1).text("¥"+parseInt(Math.ceil(select_data[index].price)));
  179. $(this).children().eq(1).css("color","#519d9e");
  180. }
  181. }else{
  182. $(this).removeClass("canday");
  183. $(this).addClass("disday");
  184. $(this).children().eq(0).css("color","rgb(207,207,207)");
  185. }
  186. })
  187. $(".canday").on("click",function(){
  188. $(".canday").removeClass('select_day');
  189. $(this).addClass('select_day');
  190. select_go_date = $(this).attr("data-cur");
  191. one_price = $(this).attr("one_price");
  192. var people_number = $(".aticket").text();
  193. total_pirce = parseInt(people_number)*parseInt(Math.ceil(one_price));
  194. $("#total").text(total_pirce);
  195. })
  196. $("#loading_html").show();
  197. }
  198. //加
  199. $(".add").on("click",function(){
  200. var num =parseInt($(this).siblings("span").text());
  201. if(num>=20){
  202. $(".add").removeClass("bor_right");
  203. $(".add").addClass("bor_right_c");
  204. var people_number = $(".aticket").text();
  205. total_pirce = parseInt(people_number)*parseInt(Math.ceil(one_price));
  206. $("#total").text(total_pirce);
  207. $("#people_number").text("共"+people_number+"人");
  208. }else{
  209. var num = $(this).siblings("span").text();
  210. $(this).siblings("span").text(++num);
  211. $(".cut").removeClass("bor_left_c");
  212. $(".cut").addClass("bor_left");
  213. var people_number = $(".aticket").text();
  214. total_pirce = parseInt(people_number)*parseInt(Math.ceil(one_price));
  215. $("#total").text(total_pirce);
  216. $("#people_number").text("共"+people_number+"人");
  217. }
  218. });
  219. //减
  220. $(".cut").on("click",function(){
  221. var num = parseInt($(this).siblings("span").text());
  222. if(num==2){
  223. $(".cut").removeClass("bor_left");
  224. $(".cut").addClass("bor_left_c");
  225. var people_number = $(".aticket").text();
  226. total_pirce = parseInt(people_number)*parseInt(Math.ceil(one_price));
  227. $("#total").text(total_pirce);
  228. $("#people_number").text("共"+people_number+"人");
  229. }
  230. if(num==1){
  231. var people_number = $(".aticket").text();
  232. total_pirce = parseInt(people_number)*parseInt(Math.ceil(one_price));
  233. $("#total").text(total_pirce);
  234. $("#people_number").text("共"+people_number+"人");
  235. }else{
  236. $(this).siblings("span").text(--num);
  237. $(".add").removeClass("bor_right_c");
  238. $(".add").addClass("bor_right");
  239. var people_number = $(".aticket").text();
  240. total_pirce = parseInt(people_number)*parseInt(Math.ceil(one_price));
  241. $("#total").text(total_pirce);
  242. $("#people_number").text("共"+people_number+"人");
  243. }
  244. })
  245. function get_product_price(){
  246. $.ajax({
  247. url:base_api + "around/getDate", //请求地址
  248. data:{pro_id:pro_id},
  249. async:false,
  250. type: "post", //请求方式
  251. dataType: "json",
  252. success: function (data) {
  253. console.log(data);
  254. if(data.flag == true){
  255. select_data = data.data;
  256. var num = data.data.length-1;
  257. select_length = data.data.length;
  258. select_start_time = data.data[0].date;
  259. select_start_time_arr=select_start_time.split("-");
  260. select_end_time = data.data[num].date;
  261. select_end_time_arr=select_end_time.split("-");
  262. //可选日
  263. select_start_day = select_start_time_arr[2];
  264. //可选月
  265. select_start_month = select_start_time_arr[1];
  266. //可选年
  267. select_start_year = select_start_time_arr[0];
  268. //可选日
  269. select_end_day = select_end_time_arr[2];
  270. //可选月
  271. select_end_month = select_end_time_arr[1];
  272. //可选年
  273. select_end_year = select_end_time_arr[0];
  274. }else{
  275. alert(data.msg);
  276. }
  277. }
  278. });
  279. }
  280. function go_to_pay(){
  281. var peo_no = $("#people_no").text();
  282. if (select_go_date) {
  283. window.location.href="trave_around_fill_order.html?peo_no="+peo_no+"&go_date="+select_go_date+"&pro_id="+pro_id;
  284. }else{
  285. alert('请选择正确的日期!');
  286. return;
  287. }
  288. }