integralOrderConfirm.js 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. var exchangeId = mobile.getUrlVars('exchangeId');
  2. var qty = mobile.getUrlVars('qty');
  3. var list=[];
  4. var addrlist=[];
  5. var arr=[];
  6. var hours=[{
  7. "text": "09:00-11:00",
  8. "value": "09:00-11:00"
  9. },
  10. {
  11. "text": "11:00-13:00",
  12. "value": "11:00-13:00"
  13. },
  14. {
  15. "text": "13:00-15:00",
  16. "value": "13:00-15:00"
  17. },{
  18. "text": "15:00-17:00",
  19. "value": "15:00-17:00"
  20. },{
  21. "text": "17:00-19:00",
  22. "value": "17:00-19:00"
  23. }];
  24. var cityData = [{
  25. value: '110000',
  26. text: '北京市',
  27. children: [{
  28. value: "110101",
  29. text: "东城区"
  30. }]
  31. }]
  32. var begin;
  33. var end;
  34. mui.init();
  35. mui.ready(function(){
  36. getProduct();
  37. getAddressList();
  38. initHours();
  39. var options={
  40. "type": "hour",
  41. "customData": {
  42. "h": arr
  43. },
  44. "labels": ["年", "月", "日", "时段"],
  45. "beginDate":begin,
  46. "endDate":end
  47. };
  48. var picker = new mui.PopPicker({
  49. layer: 2
  50. });
  51. picker.setData(arr);
  52. $("#deliveryTime").on("tap",function(){
  53. picker.show(function(items) {
  54. $("#deliveryTime").val(items[0].value + " " + items[1].text);
  55. });
  56. });
  57. $("#addr").on("tap",function(){
  58. $('#addrList').addClass('mui-active');
  59. });
  60. $("#addrList").on("tap",'.mui-icon-left-nav',function(){
  61. $('#addrList').removeClass('mui-active');
  62. });
  63. $("#addrList").on("tap",'.mui-btn-link',function(){
  64. location.href=base+'/mobile/userAddress.jsp';
  65. });
  66. $("#inrange").on("tap",'li',function(){
  67. var item = addrlist[$(this).index()];
  68. $('#addr').html('<li class="mui-table-view-cell" data-id="'+item.id+'"><a class="mui-navigate-right">'+
  69. '<p class="color1"><span class="mr15">'+item.consignee+'</span><span class="phone">'+item.mobile+'</span></p>'+
  70. '<p class="color2 mui-ellipsis-2">'+mobile.nullToSpace(item.district)+mobile.nullToSpace(item.address)+mobile.nullToSpace(item.house_num)+'</p></a></li>');
  71. $('#addrList').removeClass('mui-active');
  72. });
  73. $("#saveOrder").on("tap",function(){
  74. var addressId = $('#addr').find('li').attr('data-id');
  75. var timeStr = $('#deliveryTime').val();
  76. var userMsg = $('#userMsg').val();
  77. if(!addressId){
  78. layer.open({content:'请选择送水地址',time:3});
  79. return;
  80. }
  81. if(!timeStr){
  82. layer.open({content:'请选择送水时间',time:3});
  83. return;
  84. }
  85. var deliveryDate = timeStr.substring(0,10);
  86. var deliveryTime = timeStr.substring(11,timeStr.length);
  87. mobile.ajaxPost(base+'/userOrder/saveIntegral',{
  88. exchangeId:exchangeId,
  89. addressId:addressId,
  90. deliveryDate:deliveryDate,
  91. deliveryTime:deliveryTime,
  92. userMsg:userMsg,
  93. qty:qty
  94. },function(json){
  95. if(json.data){
  96. history.replaceState(null, "", base+"/mobile/userOrder.jsp?orderStatus=20");
  97. location.href=base+"/mobile/userOrderDetail.jsp?id="+json.data;
  98. }else{
  99. layer.open({content:'提交失败,请重试',time:3});
  100. }
  101. });
  102. });
  103. });
  104. function getProduct(){
  105. mobile.ajaxPost(base+'/productExchange/getListForOrder',{exchangeId:exchangeId,qty:qty},function(json){
  106. var sumPrice=0;
  107. if(json.data&&json.data.length>0){
  108. list = json.data;
  109. var html= [];
  110. $.each(json.data,function(id,item){
  111. html.push('<li class="mui-table-view-cell">');
  112. html.push('<div class="mui-pull-left product-img">');
  113. html.push('<img src="'+imgUrl+item.product_main_img+'">');
  114. html.push('</div>');
  115. html.push('<div class="mui-media-body pl10">');
  116. html.push('<p class="product-title mb10">'+item.product_name+'</p>');
  117. html.push('<p class="product-price items">');
  118. html.push('<em class="item fs16">'+item.exchange_integral+'积分</em>');
  119. html.push('<span class="color2">x'+item.product_qty+'</span>');
  120. html.push('</p>');
  121. html.push('</div>');
  122. html.push('</li>');
  123. sumPrice+=parseInt(item.exchange_integral)*item.product_qty
  124. });
  125. $('#product').html(html.join(''));
  126. $('#sumPrice .product-price').html('<em class="fs16">'+mobile.toDecimal(sumPrice)+'积分</em>');
  127. $('#payPrice').html('<em class="fs16">'+mobile.toDecimal(sumPrice)+'</em>');
  128. $('.mui-content').removeClass('mui-hidden');
  129. }else{
  130. $('.mui-content').empty();
  131. mobile.tip('.mui-content','暂无可结算商品');
  132. $('.mui-bar-tab').hide();
  133. $('.mui-content').removeClass('mui-hidden');
  134. }
  135. });
  136. }
  137. //获取地址列表
  138. function getAddressList() {
  139. mobile.ajaxPost(base + '/userAddress/getList', {}, function(json) {
  140. if(json.data&&json.data.length){
  141. $.each(json.data,function(id,item){
  142. var html = [];
  143. html.push('<li class="mui-table-view-cell">');
  144. html.push('<a class="mui-navigate-right">');
  145. html.push('<p class="color1">');
  146. html.push('<span class="mr15">'+item.consignee+'</span>');
  147. html.push('<span class="phone">'+item.mobile+'</span>');
  148. html.push('</p>');
  149. if(item.is_default=='1'){
  150. html.push('<p class="color2 mui-ellipsis-2 pr15"><span class="main-color">[默认] </span>');
  151. }else{
  152. html.push('<p class="color2 mui-ellipsis-2 pr15">');
  153. }
  154. html.push(''+mobile.nullToSpace(item.district)+mobile.nullToSpace(item.address)+mobile.nullToSpace(item.house_num)+'</p>');
  155. html.push('</a>');
  156. html.push('</li>');
  157. var map = new BMap.Map("allmap");
  158. var pointA = new BMap.Point(item.longitude,item.latitude);
  159. var pointB = new BMap.Point(117.950, 28.463);
  160. var distance = parseInt(map.getDistance(pointA,pointB));
  161. if(distance<=10*1000){
  162. addrlist.push(item);
  163. $("#inrange").append(html.join(""));
  164. }else{
  165. $("#outrange").append(html.join(""));
  166. }
  167. });
  168. }else{
  169. $('#addr').html('<li class="mui-table-view-cell"><a class="mui-navigate-right">'+
  170. '<p class="color1">选择送水地址</p></a></li>');
  171. $('#addrList mui-table-view').html('');
  172. mobile.tip('#addrList .mui-content','暂无送水地址');
  173. }
  174. if($("#inrange li").length!=0){
  175. $("#inrange").removeClass("mui-hidden");
  176. var item = addrlist[0];
  177. $('#addr').html('<li class="mui-table-view-cell" data-id="'+item.id+'"><a class="mui-navigate-right">'+
  178. '<p class="color1"><span class="mr15">'+item.consignee+'</span><span class="phone">'+item.mobile+'</span></p>'+
  179. '<p class="color2 mui-ellipsis-2">'+mobile.nullToSpace(item.district)+mobile.nullToSpace(item.address)+mobile.nullToSpace(item.house_num)+'</p></a></li>');
  180. }
  181. if($("#outrange li").length!=0){
  182. $("#outrange").removeClass("mui-hidden");
  183. $("#outrangelbl").removeClass("mui-hidden");
  184. }
  185. });
  186. }
  187. function initHours(){
  188. var h = new Date().getHours();
  189. console.info(h);
  190. var m = new Date().getMinutes();
  191. console.info(m);
  192. if(h>0&&h<9){
  193. var children = [];
  194. var obj = new Object();
  195. obj.value = new Date().format("yyyy-MM-dd");
  196. obj.text = new Date().format("MM月dd日") + " "+mobile.getWeek(new Date())+" 今天";
  197. children = hours;
  198. obj.children = children;
  199. arr.push(obj);
  200. }else if (h>=9&&h<11){
  201. var children = [];
  202. var obj = new Object();
  203. obj.value = new Date().format("yyyy-MM-dd");
  204. obj.text = new Date().format("MM月dd日") + " "+mobile.getWeek(new Date())+" 今天";
  205. var o = new Object();
  206. o.text = full(h)+":"+full(m)+"-"+full(h+2)+":"+full(m);
  207. o.value = full(h)+":"+full(m)+"-"+full(h+2)+":"+full(m);
  208. children.push(o);
  209. children.push(hours[2]);
  210. children.push(hours[3]);
  211. children.push(hours[4]);
  212. obj.children = children;
  213. arr.push(obj);
  214. }else if(h>=11&&h<13){
  215. var children = [];
  216. var obj = new Object();
  217. obj.value = new Date().format("yyyy-MM-dd");
  218. obj.text = new Date().format("MM月dd日") + " "+mobile.getWeek(new Date())+" 今天";
  219. var o = new Object();
  220. o.text = full(h)+":"+full(m)+"-"+full(h+2)+":"+full(m);
  221. o.value = full(h)+":"+full(m)+"-"+full(h+2)+":"+full(m);
  222. children.push(o);
  223. children.push(hours[3]);
  224. children.push(hours[4]);
  225. obj.children = children;
  226. arr.push(obj);
  227. }else if(h>=13&&h<15){
  228. var children = [];
  229. var obj = new Object();
  230. obj.value = new Date().format("yyyy-MM-dd");
  231. obj.text = new Date().format("MM月dd日") + " "+mobile.getWeek(new Date())+" 今天";
  232. var o = new Object();
  233. o.text = full(h)+":"+full(m)+"-"+full(h+2)+":"+full(m);
  234. o.value = full(h)+":"+full(m)+"-"+full(h+2)+":"+full(m);
  235. children.push(o);
  236. children.push(hours[4]);
  237. obj.children = children;
  238. arr.push(obj);
  239. var children = [];
  240. obj = new Object();
  241. obj.value = mobile.addDate(new Date(),1).format("yyyy-MM-dd");
  242. obj.text = mobile.addDate(new Date(),1).format("MM月dd日") + " "+mobile.getWeek(mobile.addDate(new Date(),1))+" 明天";
  243. children = hours;
  244. obj.children = children;
  245. arr.push(obj);
  246. }else if(h>=15&&h<17){
  247. var children = [];
  248. var obj = new Object();
  249. obj.value = new Date().format("yyyy-MM-dd");
  250. obj.text = new Date().format("MM月dd日") + " "+mobile.getWeek(new Date())+" 今天";
  251. var o = new Object();
  252. o.text = full(h)+":"+full(m)+"-"+full(h+2)+":"+full(m);
  253. o.value = full(h)+":"+full(m)+"-"+full(h+2)+":"+full(m);
  254. children.push(o);
  255. obj.children = children;
  256. arr.push(obj);
  257. var children = [];
  258. obj = new Object();
  259. obj.value = mobile.addDate(new Date(),1).format("yyyy-MM-dd");
  260. obj.text = mobile.addDate(new Date(),1).format("MM月dd日") + " "+mobile.getWeek(mobile.addDate(new Date(),1))+" 明天";
  261. children = hours;
  262. obj.children = children;
  263. arr.push(obj);
  264. }else if(h>=17){
  265. var children = [];
  266. var obj = new Object();
  267. obj.value = mobile.addDate(new Date(),1).format("yyyy-MM-dd");
  268. obj.text = mobile.addDate(new Date(),1).format("MM月dd日") + " "+mobile.getWeek(mobile.addDate(new Date(),1))+" 明天";
  269. children = hours;
  270. obj.children = children;
  271. arr.push(obj);
  272. }
  273. }
  274. function full(i){
  275. if(i<10){
  276. return '0'+i;
  277. }else{
  278. return i+''
  279. }
  280. }