order_list.js 14 KB

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