userOrderDetail.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. var id=mobile.getUrlVars("id");
  2. var order;
  3. var money = 0;
  4. var product;
  5. var orderDate=[];
  6. mui.init();
  7. mui.ready(function(){
  8. getById();
  9. $("#product").on("tap","li",function(e){
  10. location.href=base+"/mobile/productDetail.jsp?id="+$(this).attr("data-id");
  11. });
  12. $("#pay").on("tap",".mui-input-row",function(e){
  13. var list = $(this).find("input[type='radio']");
  14. list.each(function(){
  15. this.checked = true;
  16. });
  17. });
  18. $("#pay-btn").on("tap",function(e){
  19. var i=-1;
  20. $('input[type="radio"]').each(function(){
  21. if(this.checked){
  22. i = $(this).parent().index();
  23. }
  24. });
  25. if(i==1){
  26. if(parseFloat(money)<parseFloat(order.order_amt)){
  27. layer.open({content: "余额不足",time: 3});
  28. return;
  29. }
  30. mobile.ajaxPost(base+'/userOrder/moneyPay',{id:id},function(json){
  31. if(json.success){
  32. layer.open({content: '支付成功',time: 3});
  33. setTimeout(function() {
  34. window.location.reload();
  35. }, 1000);
  36. }else{
  37. layer.open({content: json.msg,time: 3});
  38. }
  39. });
  40. }else{
  41. mobile.ajaxPost(base+'/userOrder/pay',{id:id},function(json){
  42. if(json.success){
  43. var data=json.data;
  44. if (typeof WeixinJSBridge == "undefined"){
  45. if( document.addEventListener ){
  46. document.addEventListener('WeixinJSBridgeReady', onBridgeReady(data), false);
  47. }else if (document.attachEvent){
  48. document.attachEvent('WeixinJSBridgeReady', onBridgeReady(data));
  49. document.attachEvent('onWeixinJSBridgeReady', onBridgeReady(data));
  50. }
  51. }else{
  52. onBridgeReady(data);
  53. }
  54. }else{
  55. layer.open({content: json.msg,time: 3});
  56. }
  57. });
  58. }
  59. });
  60. $("#use-btn").on("tap",function(e){
  61. if($("#password").val()==""){
  62. layer.open({content:'请输入核销密码',time:3});
  63. return;
  64. }
  65. mobile.ajaxPost(base+'/userOrder/useOrder',{id:id,password:$("#password").val(),useNum:$('.mui-input-numbox').val()},function(json){
  66. if(json.success){
  67. layer.open({content:'核销成功',time:1});
  68. setTimeout(function() {
  69. location.reload();
  70. }, 1000);
  71. }else{
  72. layer.open({content: json.msg,time: 3});
  73. }
  74. });
  75. });
  76. $("#order-btn").on("tap",function(e){
  77. if($("#order_date").val()==""){
  78. layer.open({content:'请选择预约日期',time:3});
  79. return;
  80. }
  81. mobile.ajaxPost(base+'/userOrder/orderDate',{id:id,productId:product.id,orderDate:$("#order_date").val()},function(json){
  82. if(json.success){
  83. layer.open({content: "预约成功,请在"+$("#order_date").val()+"当天使用",time: 2});
  84. setTimeout(function() {
  85. location.reload();
  86. }, 2000);
  87. }else{
  88. layer.open({content: json.msg,time: 3});
  89. }
  90. });
  91. });
  92. $("#comment .icon-chucuo1").on("click",function(){
  93. $("#comment").remove();
  94. });
  95. $("#comment .main").on("tap",function(){
  96. location.href=base+"/mobile/index.jsp";
  97. });
  98. $("#comment .comment").on("tap",function(){
  99. location.href=base+"/mobile/userOrderComment.jsp?id="+order.id;
  100. });
  101. $("#reorder-btn").on("tap",function(e){
  102. var html=[];
  103. html.push('<select id="orderDate" style="border: 1px solid rgba(0, 0, 0, .2)!important;">');
  104. $.each(orderDate, function (id,item) {
  105. html.push('<option value="'+item+'">'+item+'</option>');
  106. });
  107. html.push('</select>');
  108. mui.alert(html.join(""), '选择预约日期', function() {
  109. if($("#orderDate").val()==""){
  110. layer.open({content:'请选择预约日期',time:3});
  111. return;
  112. }
  113. mobile.ajaxPost(base+'/userOrder/orderDate',{id:id,productId:product.id,orderDate:$("#orderDate").val()},function(json){
  114. if(json.success){
  115. layer.open({content: "预约成功,请在"+$("#orderDate").val()+"当天使用",time: 2});
  116. setTimeout(function() {
  117. location.reload();
  118. }, 2000);
  119. }else{
  120. layer.open({content: json.msg,time: 3});
  121. }
  122. });
  123. });
  124. });
  125. });
  126. function getById(){
  127. mobile.ajaxPost(base+'/userOrder/getById',{id:id},function(json){
  128. order = json.data;
  129. product = order.list[0];
  130. var html= [];
  131. $.each(order.list,function(id,item){
  132. html.push('<li class="mui-table-view-cell mui-media" data-id="'+item.id+'">');
  133. html.push('<div class="product-img mui-pull-left">');
  134. html.push('<img src="'+imgUrl+item.product_main_img+'">');
  135. if(item.order_hour<=0){
  136. html.push('<span class="img-icon">免预约</span>')
  137. }
  138. html.push('</div>');
  139. html.push('<div class="mui-media-body pl10">');
  140. html.push('<p class="product-merchant mui-ellipsis">'+item.merchant_name+'</p>');
  141. html.push('<p class="product-title mui-ellipsis-2">'+item.product_name+'</p>');
  142. html.push('<p class="product-price items">');
  143. html.push('<em class="item"><b>¥</b>'+item.product_price+'<span class="del-line color3 ml5">'+item.product_old_price+'元</span></em>');
  144. html.push('<span class="color2 fs14">x'+item.product_qty+'</span></p>');
  145. html.push('</div>');
  146. html.push('</li>');
  147. });
  148. if(order.order_status=="10"){
  149. $('#pay_amt').prev().html('需付款');
  150. $('.mui-title').html('待付款');
  151. $('#pay_amt').html('<em class="fs16"><b>¥</b>'+order.order_amt+'</em>');
  152. $("#pay").removeClass("mui-hidden");
  153. var interval= setInterval(function() {
  154. var leftTime = (new Date(order.create_time.replace(/-/g, "/"))) - (new Date()) + 5*60*1000;
  155. var days = parseInt(leftTime / 1000 / 60 / 60 / 24 , 10); //计算剩余的天数
  156. var hours = parseInt(leftTime / 1000 / 60 / 60 % 24 , 10); //计算剩余的小时
  157. var minutes = parseInt(leftTime / 1000 / 60 % 60, 10);//计算剩余的分钟
  158. var seconds = parseInt(leftTime / 1000 % 60, 10);//计算剩余的秒数
  159. hours = checkTime(hours);
  160. minutes = checkTime(minutes);
  161. seconds = checkTime(seconds);
  162. if(leftTime<0){
  163. $(".left-time").html("订单失效,请重新下单");
  164. location.href=base+"/mobile/productDetail.jsp?id="+order.list[0].id;
  165. }else{
  166. $(".left-time").html("请在" + minutes+"分"+seconds+"秒内付款,否则订单会失效");
  167. }
  168. }, 1000);
  169. getMoney();
  170. }else if(order.order_status=="20"){
  171. if (product.order_num&&!order.order_date){
  172. getOrderDate();
  173. $("#order").removeClass("mui-hidden");
  174. $('#pay_amt').prev().html('已付款');
  175. $('.mui-title').html('待预约');
  176. $('#pay_amt').html('<em class="fs16"><b>¥</b>'+mobile.nullToZore(order.pay_amt)+'</em>');
  177. if (product.product_type!='30'){
  178. if(new Date(product.use_time.replace(/-/g, "/"))>new Date()){
  179. $(".use_time").html("请在"+product.use_time+"前使用");
  180. }else{
  181. $(".use_time").html("使用时间已截止");
  182. }
  183. }
  184. }else{
  185. $("#tip").removeClass("mui-hidden");
  186. $("#use").removeClass("mui-hidden");
  187. $('#pay_amt').prev().html('已付款');
  188. $('.mui-title').html('待使用');
  189. $('#pay_amt').html('<em class="fs16"><b>¥</b>'+mobile.nullToZore(order.pay_amt)+'</em>');
  190. if (product.product_type!='30'){
  191. if(new Date(product.use_time.replace(/-/g, "/"))>new Date()){
  192. if (order.order_date){
  193. $(".use_time").html("请在"+order.order_date+"当天使用");
  194. $("#reorder-btn").removeClass("mui-hidden");
  195. getOrderDate();
  196. }else{
  197. $(".use_time").html("请在"+product.use_time+"前使用");
  198. }
  199. }else{
  200. $(".use_time").html("使用时间已截止");
  201. }
  202. }
  203. var nbox = mui('.mui-numbox').numbox();
  204. nbox.options["max"]=product.surplus_qty;
  205. $('#surplus-qty').html("<span class='color-red'>剩余"+product.surplus_qty+"份</span>");
  206. if (product.product_qty>1){
  207. $('#use-num').show();
  208. $('#surplus-qty').show();
  209. }
  210. }
  211. }else if(order.order_status=="30"){
  212. $('#pay_amt').prev().html('已付款');
  213. $('.mui-title').html('交易成功');
  214. $('#pay_amt').html('<em class="fs16"><b>¥</b>'+mobile.nullToZore(order.pay_amt)+'</em>');
  215. if(order.comment_flag!="1"){
  216. $(".integral").html(parseInt(order.pay_amt)+"积分");
  217. $("#comment").removeClass("mui-hidden");
  218. }
  219. }else{
  220. $('.mui-title').html('订单失效');
  221. }
  222. if(order.order_type=="10"){
  223. $("#sumPrice").removeClass("mui-hidden");
  224. }else if(order.order_type=="20"){
  225. $("#sumIntegral").removeClass("mui-hidden");
  226. }
  227. $('.mui-content').removeClass('mui-hidden');
  228. $('#product').html(html.join(''));
  229. });
  230. }
  231. //获取余额
  232. function getMoney() {
  233. mobile.ajaxPost(base + '/userMoney/getMoney', {}, function(json) {
  234. money = json.data;
  235. $('#money').html("¥"+json.data);
  236. },"");
  237. }
  238. //获取余额
  239. function getOrderDate() {
  240. mobile.ajaxPost(base + '/userOrder/getOrderDate', {productId: product.id}, function(json) {
  241. if (json.data&&json.data.length>0){
  242. orderDate = json.data;
  243. $.each(json.data, function (id,item) {
  244. $("#order_date").append('<option value="'+item+'">'+item+'</option>');
  245. })
  246. }
  247. },"");
  248. }
  249. function onBridgeReady(json){
  250. WeixinJSBridge.invoke(
  251. 'getBrandWCPayRequest',
  252. json,
  253. function(res){
  254. if(res.err_msg == "get_brand_wcpay_request:ok" ) {
  255. queryOrder();
  256. }else{
  257. layer.open({content: '支付失败',time: 3});
  258. }
  259. }
  260. );
  261. }
  262. function queryOrder(){
  263. mobile.ajaxPost(base+'/userOrder/queryOrder',{id:id},function(json){
  264. if(json.success){
  265. var data=json.data;
  266. if(data.trade_state=="SUCCESS"){
  267. layer.open({content: '支付成功',time: 3});
  268. setTimeout(function() {
  269. window.location.reload();
  270. }, 1000);
  271. }else{
  272. layer.open({content: '支付失败',time: 3});
  273. }
  274. }else{
  275. layer.open({content: json.msg,time: 3});
  276. }
  277. });
  278. }
  279. function checkTime(i){ // 将0-9的数字前面加上0,例1变为01
  280. if(i<10) {
  281. i = "0" + i;
  282. }
  283. return i;
  284. }