userOrderConfirm.js 11 KB

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