order_list.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  1. var isPay = true; // 是否在请求支付,false表示正在请求,true可以请求
  2. var tabindex = 1;
  3. /**
  4. * 获取指定的URL参数值
  5. * URL:http://www.baidu.com/index?name=tyler
  6. * 参数:paramName URL参数
  7. * 调用方法:getParam("name")
  8. * 返回值:tyler
  9. */
  10. var search_str = "",
  11. pageNumber = 0,
  12. pagesize = 10;
  13. //初始化mui
  14. mui.init({
  15. pullRefresh: {
  16. container: '#pullrefresh_order_list',
  17. down: {
  18. // callback: pulldownRefresh
  19. },
  20. up: {
  21. contentrefresh: '正在加载...',
  22. callback: pullupRefresh
  23. }
  24. }
  25. });
  26. mui.ready(function() {
  27. tabindex = getParam("salesStatus");
  28. tabindex == null ? tabindex = '1' : tabindex;
  29. $(".tab-with-orderlist .icon-topay").removeClass('mui-active');
  30. switch(tabindex) {
  31. case "2":
  32. $(".tab-with-orderlist .icon-todelivery").addClass('mui-active');
  33. break;
  34. case "5":
  35. $(".tab-with-orderlist .icon-delivery").addClass('mui-active');
  36. break;
  37. case "-1":
  38. $(".tab-with-orderlist .icon-allorder").addClass('mui-active');
  39. break;
  40. default:
  41. $(".tab-with-orderlist .icon-topay").addClass('mui-active');
  42. break;
  43. }
  44. mui('#pullrefresh_order_list').pullRefresh().pullupLoading();
  45. getCartNum();
  46. document.querySelector('.loading-bg').style.display = 'none';
  47. });
  48. function SetRemainTime(setName, index, sys_second) {
  49. var setName = setInterval(function() {
  50. if(sys_second > 1) {
  51. sys_second -= 1;
  52. var minute = Math.floor((sys_second / 60));
  53. var second = Math.floor(sys_second % 60);
  54. //$("#testid"+index).html(second);
  55. $("#testid" + index).html(minute + "分" + second + "秒");
  56. } else {
  57. $("#timeli" + index).hide();
  58. $("#testid" + index).parent().parent().parent().hide();
  59. clearInterval(setName);
  60. }
  61. }, 1000);
  62. }
  63. /**
  64. * 上拉加载具体业务实现
  65. */
  66. function pullupRefresh() {
  67. ++pageNumber;
  68. var Status = ""
  69. var btnArray = ['否', '是'];
  70. tabindex == "-1" ? Status = "" : Status = tabindex;
  71. $.ajax(base_path + '/cart/selectShopOrder?dates=' + new Date().getTime(), {
  72. data: {
  73. "pageSize": pagesize,
  74. "text": search_str,
  75. "pageNO": pageNumber,
  76. "beginDate": $("#mydate").val(),
  77. "salesStatus": Status
  78. },
  79. dataType: 'json',
  80. type: 'post',
  81. timeout: 15000,
  82. xhrFields: {
  83. withCredentials: true
  84. },
  85. crossDomain: true,
  86. success: function(dt) {
  87. console.log(dt.isRedirect);
  88. if(dt.isRedirect) {
  89. location.href = dt.redirectURL;
  90. } else {
  91. if(dt.status) {
  92. var order_data = [];
  93. order_data = dt.data.orderList;
  94. //参数为true代表没有更多数据了。
  95. mui('#pullrefresh_order_list').pullRefresh().endPullupToRefresh(order_data.length < pagesize);
  96. var table = document.body.querySelector('.my-scroll-order'),
  97. str = "",
  98. str1 = "";
  99. mui(order_data).each(function(index) {
  100. var li = document.createElement('li');
  101. switch(this.salesStatus) {
  102. case "0":
  103. str = '<span>取消订单</span>';
  104. break;
  105. case "1":
  106. str = '<span class="cl-red">待付款</span><button type="button" id="orderPay" onclick="goOrderPay(\'' + this.salesOrderid + '\',' + this.efficacious + ');" class="mui-btn my-btn-danger mui-pull-right">去支付</button>';
  107. str1 = '<button type="button" id="orderPay" onclick="goOrderPay(\'' + this.salesOrderid + '\',' + this.efficacious + ');" class="mui-btn my-btn-danger mui-pull-right">去支付</button>';
  108. break;
  109. case "2":
  110. str = '<span>待发货</span>';
  111. break;
  112. case "3":
  113. str = '<span>退款申请中</span>';
  114. break;
  115. case "4":
  116. str = '<span>已退款</span>';
  117. break;
  118. case "5":
  119. str = '<span>已发货</span>';
  120. break;
  121. case "6":
  122. str = '<span>申请退货中</span>';
  123. break;
  124. case "7":
  125. str = '<span>退货中</span>';
  126. break;
  127. case "8":
  128. str = '<span>订单关闭</span>';
  129. break;
  130. case "9":
  131. str = '<span>换货中</span>';
  132. break;
  133. case "10":
  134. str = '<span>换货完成</span>';
  135. break;
  136. case "11":
  137. str = '<span>申请换货中</span>';
  138. break;
  139. default:
  140. str = '<span>订单完成</span>';
  141. break;
  142. }
  143. //var orderSalesStatus = this.salesStatus; //订单状态
  144. if(Status == "") {
  145. str1 = '状态:' + str;
  146. }
  147. var a = '<ul class="mui-table-view">',allcount=0;
  148. mui(this.orderItemList).each(function(index) {
  149. var pro_color = switchcolor(this.itemColorId);
  150. var colorImg = switchColorImg(this.itemColorId);
  151. allcount+=this.itemNum;
  152. /* CheckImgExists(this.itemProductPic) == false ? this.itemProductPic = '/iamberry/common/shop/images/chanpin-list-1.jpg' : this.itemProductPic; */
  153. // if(this.productStatus != 1) {
  154. // var itemNum = this.itemNum;
  155. // if(itemNum < 3){
  156. // itemNum = 1;
  157. // }
  158. // a += '<li class="mui-table-view-cell"><table class="my-tb-order"><tr><td rowspan="3"><div class="wh-80"><img class="wh-80" src="' + this.itemProductPic + '"></div></td><td rowspan="3">' + '赠送' + (this.itemNum / 3) + '套三年滤芯' + '<span class="cl-red"></span></td><td><span></td><td></td></tr><tr><td></td></tr><tr></tr></table></li>'
  159. // } else {
  160. // a += '<li class="mui-table-view-cell"><a proid="' + this.itemProductId + '" colorid="' + this.itemColorId + '" class="go_chanpin_details"><table class="my-table-order"><tbody><tr><td rowspan="3" style="width:26%"><div class="wh-80"><img src="' + colorImg + '"></div></td><td>' + this.itemProductName + '</td><td><span><h5 class="mui-text-center">x' + this.itemNum + '</h5></span></td></tr><tr><td><span><h5>颜色:' + pro_color + '</h5></span></td></tr><tr><td><span>单价:<span class="mui-h5">¥' + accDiv(this.itemProductDiscount, 100) + '</span></span></td><td></td></tr></tbody></table></a></li>'
  161. // }
  162. a += '<li class="mui-table-view-cell"><a proid="' + this.itemProductId + '" colorid="' + this.itemColorId + '" class="go_chanpin_details"><table class="my-table-order"><tbody><tr><td rowspan="3" style="width:26%"><div class="wh-80" style="margin: 5px 10px 0 0;"><img src="' + this.itemProductPic + '"></div></td><td>' + this.itemProductName + '</td></tr><tr><td><span><h5>' + this.productColor + ' x ' + this.itemNum + '</h5></span></td></tr><tr><td><span><span class="mui-h5">¥' + accDiv(this.itemProductDiscount, 100) + '</span></span></td><td></td></tr></tbody></table></a></li>'
  163. });
  164. //状态为1 的 ,表示代发货,,这里显示支付关闭倒计时;
  165. if(this.salesStatus == 1) {
  166. if(this.salesAdminRemark > 0) {
  167. a += '<li id="timeli' + index + '" class="mui-table-view-cell show_post_info">' +
  168. '<span class="mui-pull-left">支付倒计时:</span>' +
  169. '<span style="border:0;font-size:large;" class="my-btn-orange" id="testid' + index + '">' +
  170. '</span></li>';
  171. SetRemainTime("setName" + index, index, this.salesAdminRemark); //间隔函数,1秒执行
  172. }
  173. }
  174. a += '<li class="mui-table-view-cell"><div class="btn-zu">' + str1 + '<a class="mui-btn my-btn-orange mui-pull-right mr-5 go_order_details" value=' + this.salesOrderid + '>订单详情</a></div><div>共'+allcount+'件 合计:<span class="mui-h5 cl-red">¥' + accDiv(this.salesAmount, 100) + '</span></div></li>';
  175. this.salesPostFirm == null ? this.salesPostFirm = "" : this.salesPostFirm;
  176. if(this.salesPostFirm == 'sto') {
  177. this.salesPostFirm = '申通快递';
  178. }
  179. if(this.salesPostFirm == 'yto') {
  180. this.salesPostFirm = '圆通快递';
  181. }
  182. if(this.salesPostFirm == 'sf') {
  183. this.salesPostFirm = '顺丰快递';
  184. }
  185. if(this.salesPostFirm == 'zto') {
  186. this.salesPostFirm = '中通速递';
  187. }
  188. if(this.salesPostFirm == 'ems') {
  189. this.salesPostFirm = '邮政EMS';
  190. }
  191. if(this.salesPostFirm == 'zjs') {
  192. this.salesPostFirm = '宅急送';
  193. }
  194. if(this.salesPostFirm == 'yunda') {
  195. this.salesPostFirm = '韵达快递';
  196. }
  197. if(this.salesPostFirm == 'cces') {
  198. this.salesPostFirm = 'cces快递';
  199. }
  200. if(this.salesPostFirm == 'pick') {
  201. this.salesPostFirm = '上门提货';
  202. }
  203. if(this.salesPostFirm == 'htky') {
  204. this.salesPostFirm = '汇通快递';
  205. }
  206. if(this.salesPostFirm == 'ttkdex') {
  207. this.salesPostFirm = '天天快递';
  208. }
  209. if(this.salesPostFirm == 'stars') {
  210. this.salesPostFirm = '星晨急便';
  211. }
  212. if(this.salesPostFirm == 'jd') {
  213. this.salesPostFirm = '京东快递';
  214. }
  215. if(this.salesPostFirm == '01') {
  216. this.salesPostFirm = '其他';
  217. }
  218. if(this.salesPostFirm == '02') {
  219. this.salesPostFirm = '上门送货';
  220. }
  221. if(this.salesPostFirm == 'longbanwuliu') {
  222. this.salesPostFirm = '龙邦快递';
  223. }
  224. if(this.salesPostFirm == 'dbkd') {
  225. this.salesPostFirm = '德邦快递';
  226. }
  227. if(this.salesPostNum == null || this.salesPostNum == "") {
  228. this.salesPostNum = ""
  229. } else {
  230. a += '<li class="mui-table-view-cell show_post_info" postfirm="' + this.salesPostFirm + '" postnum="' + this.salesPostNum + '" gourl="order_list.html?salesStatus=' + Status + '"><span class="mui-pull-left">物流信息:</span>' + this.salesPostFirm + '&nbsp;&nbsp;&nbsp;<span>' + this.salesPostNum + '</span></li>';
  231. }
  232. li.innerHTML = a + '</ul>';
  233. table.appendChild(li);
  234. });
  235. } else {
  236. mui.confirm(dt.message + '是否重新加载页面?', '爱贝源-提示', btnArray, function(e) {
  237. if(e.index == 1) {
  238. location.reload(true);
  239. }
  240. });
  241. }
  242. }
  243. },
  244. error: function(xhr, type, errorThrown) {
  245. //异常处理;
  246. errorfn(xhr);
  247. }
  248. });
  249. }
  250. //function search_pullrefresh(str) {
  251. // if(str != null && str != '') {
  252. // if(!checkParameter(str)) {
  253. // mui.alert('您输入的格式有误,请重新输入!');
  254. // } else {
  255. // pageNumber = 0;
  256. // $('.my-scroll-order').empty();
  257. // search_str = str;
  258. // mui('#pullrefresh_order_list').pullRefresh().refresh(true);
  259. // mui('#pullrefresh_order_list').pullRefresh().pullupLoading();
  260. // }
  261. // } else {
  262. // pageNumber = 0;
  263. // $('.my-scroll-order').empty();
  264. // search_str = str;
  265. // mui('#pullrefresh_order_list').pullRefresh().refresh(true);
  266. // mui('#pullrefresh_order_list').pullRefresh().pullupLoading();
  267. // }
  268. //}
  269. //mui.os.ios ? listener_ipt() : keyup_fn();
  270. //
  271. //function keyup_fn() {
  272. // $('body').on('keyup', '#order-list-search', function(e) {
  273. // var currKey = 0,
  274. // e = e || event;
  275. // currKey = e.keyCode || e.which || e.charCode;
  276. // var keyName = String.fromCharCode(currKey);
  277. // if(currKey == "13") {
  278. // //传参数并加载数据
  279. // var str = $.trim($('#order-list-search').val());
  280. // search_pullrefresh(str);
  281. // }
  282. // });
  283. //}
  284. //
  285. //function listener_ipt() {
  286. // document.getElementById('order-list-search').onblur = function() {
  287. // //传参数并加载数据
  288. // var str = $.trim($('#order-list-search').val());
  289. // search_pullrefresh(str);
  290. // }
  291. //}
  292. mui.each(document.querySelectorAll('.tab-with-orderlist .mui-control-item'), function(index, el) {
  293. el.addEventListener('tap', function() {
  294. pageNumber = 0;
  295. switch(index) {
  296. case 0:
  297. tabindex = 1;
  298. break;
  299. case 1:
  300. tabindex = 2;
  301. break;
  302. case 2:
  303. tabindex = 5;
  304. break;
  305. default:
  306. tabindex = -1;
  307. break;
  308. }
  309. $('.my-scroll-order').empty();
  310. mui('#pullrefresh_order_list').pullRefresh().refresh(true);
  311. mui('#pullrefresh_order_list').pullRefresh().pullupLoading();
  312. }, false);
  313. });
  314. function goOrderPay(salesOrderid, efficacious) {
  315. var dataArgs = {
  316. "orderId": salesOrderid
  317. };
  318. if(!efficacious) {
  319. mui.alert("您的订单有商品下架,请重新生成订单购买!");
  320. return false;
  321. }
  322. $.ajax(base_path + '/cart/orderPay', { // 提交订单,准备支付
  323. data: dataArgs,
  324. dataType: 'json',
  325. type: 'POST',
  326. timeout: 15000,
  327. xhrFields: {
  328. withCredentials: true
  329. },
  330. crossDomain: true,
  331. success: function(dt) {
  332. if(dt.isRedirect) {
  333. location.href = dt.redirectURL;
  334. } else {
  335. layer.closeAll();
  336. if(dt.status) {
  337. var str = dt.data.info;
  338. var obj = JSON.parse("{" + str + "}");
  339. WeixinJSBridge.invoke('getBrandWCPayRequest', obj, function(res) {
  340. if(res.err_msg == 'get_brand_wcpay_request:ok') {
  341. var orderIds = {
  342. "orderId": dt.data.orderId
  343. };
  344. layer.open({
  345. type: 2,
  346. shadeClose: false,
  347. content: "正在请求加载订单信息..."
  348. }); // 调用加载弹出层
  349. $.ajax(base_path + '/order/checkOrderPaySuccess', { // 校验订单状态
  350. data: orderIds,
  351. dataType: 'json',
  352. type: 'post',
  353. timeout: 15000,
  354. xhrFields: {
  355. withCredentials: true
  356. },
  357. crossDomain: true,
  358. success: function(dt) {
  359. if(dt.isRedirect) {
  360. location.href = dt.redirectURL;
  361. } else {
  362. if(dt.status) { // 支付成功
  363. window.location.href = base_path + "/order/paySuccess?orderId=" + orderIds.orderId + "&dates=" + new Date().getTime();
  364. } else {
  365. setTimeout(checkOrderStatus(orderIds), 1000);
  366. }
  367. }
  368. },
  369. error: function(xhr, type, errorThrown) {
  370. isPay = true;
  371. layer.closeAll();
  372. mui.alert("您的网络异常,请刷新重试!");
  373. return;
  374. }
  375. });
  376. } else {
  377. isPay = true;
  378. mui.alert("对不起,支付失败!请稍后重试!" + dt.data.orderId + "支付失败!");
  379. window.location.href = "order_details.html?orderId=" + dt.data.orderId; // 前往订单详情
  380. }
  381. });
  382. } else {
  383. isPay = true;
  384. mui.alert(dt.message);
  385. }
  386. }
  387. },
  388. error: function(xhr, type, errorThrown) {
  389. isPay = true;
  390. layer.closeAll();
  391. mui.alert("您的网络异常,请刷新重试!");
  392. return;
  393. }
  394. });
  395. }
  396. function checkParameter(remark) {
  397. if(!/^[\u4e00-\u9fa5_a-zA-Z0-9-]+$/.test(remark)) {
  398. return false;
  399. }
  400. return true;
  401. }
  402. mui('body').on('tap', '#mydate', function() {
  403. var th = this;
  404. var picker = new mui.DtPicker({
  405. type: "date", //设置日历初始视图模式
  406. beginDate: new Date(2016, 7, 1), //设置开始日期
  407. endDate: new Date() //设置结束日期
  408. });
  409. console.log(picker)
  410. picker.show(function(rs) {
  411. pageNumber = 0;
  412. th.value = rs.text;
  413. picker.dispose();
  414. $('.my-scroll-order').empty();
  415. mui('#pullrefresh_order_list').pullRefresh().refresh(true);
  416. mui('#pullrefresh_order_list').pullRefresh().pullupLoading();
  417. });
  418. });
  419. mui("body").on('tap', '.mui-btn[data-id=btn-cancel]', function() {
  420. pageNumber = 0;
  421. document.getElementById('mydate').value = "";
  422. })
  423. mui("body").on('tap', '.my-right', function() {
  424. if($(".search-box").is(":hidden")) {
  425. $('.search-box').show();
  426. $(".tab-with-orderlist").css("margin-top", 107 + "px");
  427. $(".mui-bar-nav~.mui-content").css("padding-top", 156 + "px");
  428. } else {
  429. $('.search-box').hide();
  430. document.getElementById('mydate').value = "";
  431. $(".tab-with-orderlist").css("margin-top", 56 + "px");
  432. $(".mui-bar-nav~.mui-content").css("padding-top", 107 + "px");
  433. }
  434. })