order.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  1. var util = require('../../../utils/util.js');
  2. var api = require('../../../config/api.js');
  3. var app = getApp();
  4. Page({
  5. data: {
  6. timer: '',
  7. orderList: [],
  8. showType: 2,
  9. page: 1,
  10. limit: 10,
  11. totalPages: 1,
  12. myqr_show: false,
  13. //我的分享二维码
  14. myqr_url: null,
  15. myqr_blur: 0,
  16. //背景模糊值
  17. myqr_width: 0,
  18. hasLogin: false,
  19. goodsId: ''
  20. },
  21. onLoad: function (options) {
  22. // 页面初始化 options为页面跳转所带来的参数
  23. if (options.tab) {
  24. this.setData({
  25. showType: options.tab
  26. });
  27. }
  28. },
  29. getOrderList() {
  30. wx.showLoading({
  31. title: '加载中'
  32. });
  33. let that = this;
  34. util.request(api.OrderList, {
  35. showType: that.data.showType,
  36. page: that.data.page,
  37. limit: that.data.limit
  38. }).then(res => {
  39. wx.hideLoading();
  40. if (res.errno === 0) {
  41. console.log(res.data);
  42. that.setData({
  43. orderList: that.data.orderList.concat(res.data.data),
  44. totalPages: res.data.pages
  45. });
  46. clearInterval(this.data.timer);
  47. // 如果有未支付订单,倒计时定时器
  48. let isHasOver = this.data.orderList.some(item => {
  49. return item.payOverTime > 0;
  50. });
  51. console.log(isHasOver);
  52. if (isHasOver) {
  53. let timer = setInterval(() => {
  54. let list = this.data.orderList;
  55. let newList = [];
  56. list.forEach(item => {
  57. let obj = item;
  58. if (item.payOverTime > 0) {
  59. obj.payOverTime = item.payOverTime - 1;
  60. }
  61. newList.push(obj);
  62. });
  63. this.setData({
  64. orderList: newList
  65. });
  66. }, 1000);
  67. this.setData({
  68. timer: timer
  69. });
  70. }
  71. }
  72. });
  73. },
  74. onHide: function () {
  75. console.log('onHide');
  76. clearInterval(this.data.timer);
  77. },
  78. onUnload: function () {
  79. console.log('onunload');
  80. clearInterval(this.data.timer);
  81. },
  82. onReachBottom() {
  83. if (this.data.totalPages > this.data.page) {
  84. this.setData({
  85. page: this.data.page + 1
  86. });
  87. this.getOrderList();
  88. } else if (this.data.orderList.length > 0) {
  89. wx.showToast({
  90. title: '没有更多订单了',
  91. icon: 'none',
  92. duration: 2000
  93. });
  94. return false;
  95. }
  96. },
  97. orderDetail(e) {
  98. let id = e.currentTarget.dataset.id;
  99. wx.navigateTo({
  100. url: '/pages/ucenter/orderDetail/orderDetail?id=' + id
  101. });
  102. },
  103. switchTab: function (event) {
  104. let showType = event.currentTarget.dataset.index;
  105. this.setData({
  106. orderList: [],
  107. showType: showType,
  108. page: 1,
  109. // limit: 10,
  110. totalPages: 1
  111. });
  112. this.getOrderList();
  113. },
  114. onTabChange(e) {
  115. // let showType = e.detail.name;
  116. let showType = e.currentTarget.dataset.tab;
  117. this.setData({
  118. orderList: [],
  119. showType: showType,
  120. page: 1,
  121. // limit: 10,
  122. totalPages: 1
  123. });
  124. this.getOrderList();
  125. },
  126. appointServiceOld(e) {
  127. let id = e.currentTarget.dataset.id;
  128. let addressId = e.currentTarget.dataset.aid;
  129. let type = e.currentTarget.dataset.type;
  130. if (type && type == 5) {
  131. wx.navigateTo({
  132. url: "/pages/ucenter/coupon/couponGoods?id=1"
  133. });
  134. return;
  135. }
  136. if (addressId == null || addressId == 0)
  137. wx.navigateTo({
  138. url: '/pages/ucenter/appointOrder/appointOrder?orderId=' + id
  139. });
  140. else //买约分离 没有地址的预约
  141. wx.navigateTo({
  142. url: '/pages/ucenter/serviceDetail/serviceDetail?orderId=' + id
  143. });
  144. },
  145. appointService(e) {
  146. let id = e.currentTarget.dataset.id;
  147. let addressId = e.currentTarget.dataset.aid;
  148. let type = e.currentTarget.dataset.type;
  149. let detailId = e.currentTarget.dataset.detail;
  150. wx.navigateTo({
  151. url: '/pages/ucenter/appointOrder/appointOrder?orderId=' + id + '&serviceId=' + detailId
  152. });
  153. },
  154. qrtouchstart: function () {
  155. this.setData({
  156. myqr_blur: 0,
  157. myqr_show: false
  158. });
  159. },
  160. shareFriendOrCircle: function (e) {
  161. // let that = this;
  162. // if (!app.globalData.hasLogin) {
  163. // wx.navigateTo({
  164. // url: "/pages/auth/login/login"
  165. // });
  166. // return;
  167. // }
  168. // //获取分享id 用来追踪链接
  169. // //引荐人和非引荐人的 链接不同
  170. // let imgUrl = that.data.goods.shareWxUrl ? that.data.goods.shareWxUrl : that.data.goods.gallery[0];
  171. // var path = '/pages/goods/goods?id=' + that.data.id + '&rId=' + that.data.userInfo.id;
  172. // if (that.data.userInfo.isDis) { //是引荐人
  173. // path = '/pages/goods/goods?id=' + that.data.id + '&shareId=' + that.data.wxShareId;
  174. // }
  175. // this.hidePoster();
  176. // return {
  177. // title: that.data.goods.name,
  178. // desc: that.data.myqr_ads,
  179. // path: path,
  180. // imageUrl: imgUrl
  181. // }
  182. },
  183. // 保存分享图
  184. saveShare: function () {
  185. let that = this;
  186. wx.showLoading({
  187. title: '图片保存中'
  188. });
  189. console.log(that.data);
  190. wx.downloadFile({
  191. url: that.data.myqr_url,
  192. success: function (res) {
  193. console.log(res);
  194. wx.saveImageToPhotosAlbum({
  195. filePath: res.tempFilePath,
  196. success: function (res) {
  197. wx.hideLoading();
  198. wx.showModal({
  199. title: '存图成功',
  200. content: '图片成功保存到相册了,可以分享到朋友圈了',
  201. showCancel: false,
  202. confirmText: '好的',
  203. confirmColor: '#a78845',
  204. success: function (res) {
  205. if (res.confirm) {
  206. console.log('用户点击确定');
  207. that.setData({
  208. myqr_show: false,
  209. myqr_blur: 0
  210. });
  211. }
  212. }
  213. });
  214. },
  215. fail: function (res) {
  216. wx.hideLoading();
  217. wx.showModal({
  218. title: '警告',
  219. content: '不授权无法保存',
  220. showCancel: false
  221. });
  222. that.setData({
  223. myqr_show: false,
  224. myqr_blur: 0
  225. });
  226. }
  227. });
  228. },
  229. fail: function (res) {
  230. wx.hideLoading();
  231. console.log(res);
  232. }
  233. });
  234. },
  235. // “去付款”按钮点击效果
  236. payOrder: function (e) {
  237. let that = this;
  238. let id = e.currentTarget.dataset.id;
  239. let ordern = e.currentTarget.dataset.sn;
  240. util.request(api.OrderPayCheck, {
  241. orderId: id
  242. }, 'POST').then(function (res) {
  243. if (res.errno === 0) {
  244. const outOrderNo = res.data;
  245. console.log(res);
  246. wx.continueToPay({
  247. // orderId: this.data.orderId, // 内部订单号
  248. outOrderNo: outOrderNo, // 外部订单号 2个订单号必填一个
  249. success: res => {
  250. console.log(res);
  251. const {
  252. orderId,
  253. outOrderNo
  254. } = res;
  255. console.log('success res', res);
  256. console.log('orderId', orderId, 'outOrderNo', outOrderNo);
  257. wx.redirectTo({
  258. url: '/pages/ucenter/order/order'
  259. });
  260. },
  261. fail: res => {
  262. console.log(res);
  263. const {
  264. orderId,
  265. outOrderNo,
  266. errNo,
  267. errMsg,
  268. errLogId
  269. } = res;
  270. if (errLogId) {
  271. console.log('查询订单信息失败', errNo, errMsg, errLogId);
  272. }
  273. if (orderId || outOrderNo) {
  274. console.log('支付失败', errNo, errMsg, orderId, outOrderNo);
  275. console.log('订单号' + outOrderNo);
  276. // wx.navigateTo({
  277. // url: '/pages/ucenter/orderDetail/orderDetail?id='+outOrderNo
  278. // });
  279. }
  280. util.showErrorToast('支付失败');
  281. },
  282. });
  283. }
  284. });
  285. },
  286. payOrder(e) {
  287. let that = this;
  288. let id = e.currentTarget.dataset.id;
  289. util.request(api.OrderPrepay, {
  290. orderId: id
  291. }, 'POST').then(function (res) {
  292. if (res.errno === 0) {
  293. const payParam = res.data;
  294. console.log("支付过程开始")
  295. wx.requestPayment({
  296. 'timeStamp': payParam.timeStamp,
  297. 'nonceStr': payParam.nonceStr,
  298. 'package': payParam.packageValue,
  299. 'signType': payParam.signType,
  300. 'paySign': payParam.paySign,
  301. 'success': function (res) {
  302. console.log("支付过程成功")
  303. wx.redirectTo({
  304. url: '/pages/ucenter/order/order'
  305. });
  306. },
  307. 'fail': function (res) {
  308. console.log("支付过程失败")
  309. util.showErrorToast('支付失败');
  310. },
  311. 'complete': function (res) {
  312. console.log("支付过程结束")
  313. }
  314. });
  315. }else{
  316. wx.showToast({
  317. title: res.errmsg,
  318. icon: 'none'
  319. });
  320. }
  321. });
  322. },
  323. // “删除”点击效果
  324. deleteOrder: function (e) {
  325. let that = this;
  326. let id = e.currentTarget.dataset.id;
  327. wx.showModal({
  328. title: '',
  329. content: '确定要删除此订单?',
  330. success: function (res) {
  331. if (res.confirm) {
  332. util.request(api.OrderDelete, {
  333. orderId: id
  334. }, 'POST').then(function (res) {
  335. if (res.errno === 0) {
  336. wx.showToast({
  337. title: '删除订单成功'
  338. });
  339. util.redirect('/pages/ucenter/order/order');
  340. } else {
  341. util.showErrorToast(res.errmsg);
  342. }
  343. });
  344. }
  345. }
  346. });
  347. },
  348. // “取消订单”点击效果
  349. cancelOrder: function (e) {
  350. let that = this;
  351. let id = e.currentTarget.dataset.id;
  352. wx.showModal({
  353. title: '',
  354. content: '确定要取消此订单?',
  355. success: function (res) {
  356. if (res.confirm) {
  357. util.request(api.OrderCancel, {
  358. orderId: id
  359. }, 'POST').then(function (res) {
  360. if (res.errno === 0) {
  361. wx.showToast({
  362. title: '取消订单成功'
  363. });
  364. util.redirect('/pages/ucenter/order/order');
  365. } else {
  366. util.showErrorToast(res.errmsg);
  367. }
  368. });
  369. }
  370. }
  371. });
  372. },
  373. // “待上门”点击效果
  374. confirmOrder: function (e) {
  375. let that = this;
  376. let id = e.currentTarget.dataset.id;
  377. wx.showModal({
  378. title: '',
  379. content: '确认上门服务?',
  380. success: function (res) {
  381. if (res.confirm) {
  382. util.request(api.OrderConfirm, {
  383. orderId: id
  384. }, 'POST').then(function (res) {
  385. if (res.errno === 0) {
  386. wx.showToast({
  387. title: '确认上门成功!'
  388. });
  389. util.redirect('/pages/ucenter/order/order');
  390. } else {
  391. util.showErrorToast(res.errmsg);
  392. }
  393. });
  394. }
  395. }
  396. });
  397. },
  398. // “取消订单并退款”点击效果
  399. refundOrderOld: function (e) {
  400. let that = this;
  401. let id = e.currentTarget.dataset.id;
  402. wx.showModal({
  403. title: '',
  404. content: '确定要取消此订单?',
  405. success: function (res) {
  406. if (res.confirm) {
  407. util.request(api.OrderRefund, {
  408. orderId: id
  409. }, 'POST').then(function (res) {
  410. if (res.errno === 0) {
  411. wx.showToast({
  412. title: '取消订单成功'
  413. });
  414. util.redirect('/pages/ucenter/order/order');
  415. } else {
  416. util.showErrorToast(res.errmsg);
  417. }
  418. });
  419. }
  420. }
  421. });
  422. },
  423. refundOrderOld: function (e) {
  424. let id = e.currentTarget.dataset.id;
  425. },
  426. refundOrder: function (e) {
  427. let id = e.currentTarget.dataset.id;
  428. wx.navigateTo({
  429. url: '/pages/ucenter/applyRefund/applyRefund?id=' + id,
  430. });
  431. },
  432. onReady: function () {
  433. // 页面渲染完成
  434. },
  435. onShow: function () {
  436. // 页面显示
  437. this.setData({
  438. orderList: [],
  439. page: 1,
  440. });
  441. // wx.pageScrollTo({
  442. // scrollTop: 0,
  443. // duration: 1000,
  444. // });
  445. this.getOrderList();
  446. },
  447. buyAgain(e) {
  448. let id = e.currentTarget.dataset.id;
  449. wx.navigateTo({
  450. url: '/pages/goods/goods?id=' + id,
  451. });
  452. },
  453. goCheck(e) {
  454. let id = e.currentTarget.dataset.id;
  455. wx.navigateTo({
  456. url: '/pages/ucenter/orderDetail/orderDetail?id=' + id
  457. });
  458. },
  459. handleInit(event) {
  460. const {
  461. status
  462. } = event.detail;
  463. console.log(status);
  464. },
  465. handleSuccess(event) {
  466. const {
  467. result
  468. } = event.detail;
  469. // 团购订单不支持查看评价,此时可决定按钮是否展示
  470. console.log(result);
  471. },
  472. handleError(event) {
  473. const {
  474. errMsg,
  475. errNo
  476. } = event.detail;
  477. // errNo(错误码,对应某种具体报错原因)
  478. // errMsg(报错信息)
  479. console.log(errMsg, errNo);
  480. },
  481. goAppoint(e) {
  482. let id = e.currentTarget.dataset.id;
  483. let detailId = e.currentTarget.dataset.detail;
  484. wx.navigateTo({
  485. url: '/pages/ucenter/appointOrder/appointOrder?orderId=' + id + '&serviceId=' + detailId
  486. });
  487. },
  488. });