order.js 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. var util = require('../../../utils/util.js');
  2. var mall = require('../../../api/mall.js');
  3. var app = getApp();
  4. Page({
  5. data: {
  6. orderList: [],
  7. showType: 0,
  8. page: 1,
  9. limit: 10,
  10. totalPages: 1,
  11. myqr_show:false,//我的分享二维码
  12. myqr_url:null,
  13. myqr_blur:0,//背景模糊值
  14. myqr_width:0,
  15. hasLogin:false,
  16. goodsId:''
  17. },
  18. onLoad: function(options) {
  19. // 页面初始化 options为页面跳转所带来的参数
  20. // let that = this
  21. // try {
  22. // var tab = wx.getStorageSync('tab');
  23. // this.setData({
  24. // showType: tab
  25. // });
  26. // } catch (e) {}
  27. this.getOrderList();
  28. },
  29. getOrderList() {
  30. wx.showLoading({
  31. title: '加载中',
  32. });
  33. let that = this;
  34. util.request(mall.OrderList, {
  35. showType: that.data.showType,
  36. page: that.data.page,
  37. limit: that.data.limit
  38. }).then(function(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.list),
  44. totalPages: res.data.pages
  45. });
  46. }
  47. });
  48. },
  49. onReachBottom() {
  50. if (this.data.totalPages > this.data.page) {
  51. this.setData({
  52. page: this.data.page + 1
  53. });
  54. this.getOrderList();
  55. } else {
  56. wx.showToast({
  57. title: '没有更多订单了',
  58. icon: 'none',
  59. duration: 2000
  60. });
  61. return false;
  62. }
  63. },
  64. switchTab: function(event) {
  65. let showType = event.currentTarget.dataset.index;
  66. this.setData({
  67. orderList: [],
  68. showType: showType,
  69. page: 1,
  70. limit: 10,
  71. totalPages: 1
  72. });
  73. this.getOrderList();
  74. },
  75. onTabChange(e){
  76. let showType = e.detail.name;
  77. this.setData({
  78. orderList: [],
  79. showType: showType,
  80. page: 1,
  81. limit: 10,
  82. totalPages: 1
  83. });
  84. this.getOrderList();
  85. },
  86. viewService(e){
  87. let id=e.currentTarget.dataset.id;
  88. wx.navigateTo({
  89. url: '../serviceDetail/serviceDetail?orderId=' +id
  90. })
  91. },
  92. qrtouchstart:function(){
  93. this.setData({
  94. myqr_blur:0,
  95. myqr_show:false
  96. });
  97. },
  98. shareFriendOrCircle: function(e) {
  99. // let that = this;
  100. // if (!app.globalData.hasLogin) {
  101. // wx.navigateTo({
  102. // url: "/pages/auth/login/login"
  103. // });
  104. // return;
  105. // }
  106. // //获取分享id 用来追踪链接
  107. // //引荐人和非引荐人的 链接不同
  108. // let imgUrl = that.data.goods.shareWxUrl ? that.data.goods.shareWxUrl : that.data.goods.gallery[0];
  109. // var path = '/pages/goods/goods?id=' + that.data.id + '&rId=' + that.data.userInfo.id;
  110. // if (that.data.userInfo.isDis) { //是引荐人
  111. // path = '/pages/goods/goods?id=' + that.data.id + '&shareId=' + that.data.wxShareId;
  112. // }
  113. // this.hidePoster();
  114. // return {
  115. // title: that.data.goods.name,
  116. // desc: that.data.myqr_ads,
  117. // path: path,
  118. // imageUrl: imgUrl
  119. // }
  120. },
  121. // 保存分享图
  122. saveShare: function() {
  123. let that = this;
  124. wx.showLoading({
  125. title: '图片保存中',
  126. });
  127. console.log(that.data);
  128. wx.downloadFile({
  129. url: that.data.myqr_url,
  130. success: function(res) {
  131. console.log(res)
  132. wx.saveImageToPhotosAlbum({
  133. filePath: res.tempFilePath,
  134. success: function(res) {
  135. wx.hideLoading();
  136. wx.showModal({
  137. title: '存图成功',
  138. content: '图片成功保存到相册了,可以分享到朋友圈了',
  139. showCancel: false,
  140. confirmText: '好的',
  141. confirmColor: '#a78845',
  142. success: function(res) {
  143. if (res.confirm) {
  144. console.log('用户点击确定');
  145. that.setData({
  146. myqr_show:false,
  147. myqr_blur:0
  148. });
  149. }
  150. }
  151. })
  152. },
  153. fail: function(res) {
  154. wx.hideLoading();
  155. wx.showModal({
  156. title: '警告',
  157. content: '不授权无法保存',
  158. showCancel: false
  159. })
  160. that.setData({
  161. myqr_show:false,
  162. myqr_blur:0
  163. });
  164. }
  165. })
  166. },
  167. fail: function(res) {
  168. wx.hideLoading();
  169. console.log(res);
  170. }
  171. })
  172. },
  173. // “去付款”按钮点击效果
  174. payOrder: function(e) {
  175. let that = this;
  176. let id = e.currentTarget.dataset.id;
  177. util.request(mall.OrderPrepay, {
  178. orderId: id
  179. }, 'POST').then(function(res) {
  180. if (res.errno === 0) {
  181. const payParam = res.data;
  182. console.log("支付过程开始");
  183. wx.requestPayment({
  184. 'timeStamp': payParam.timeStamp,
  185. 'nonceStr': payParam.nonceStr,
  186. 'package': payParam.packageValue,
  187. 'signType': payParam.signType,
  188. 'paySign': payParam.paySign,
  189. 'success': function(res) {
  190. console.log("支付过程成功");
  191. that.setData({
  192. orderList: [],
  193. page: 1,
  194. limit: 10,
  195. totalPages: 1
  196. });
  197. that.getOrderList();
  198. // wx.redirectTo({
  199. // url: '/pages/mall/order/order'
  200. // });
  201. // util.redirect('/pages/mall/order/order');
  202. },
  203. 'fail': function(res) {
  204. console.log("支付过程失败");
  205. util.showErrorToast('支付失败');
  206. },
  207. 'complete': function(res) {
  208. console.log("支付过程结束")
  209. }
  210. });
  211. }
  212. });
  213. },
  214. // “删除”点击效果
  215. deleteOrder: function(e) {
  216. let that = this;
  217. let id = e.currentTarget.dataset.id;
  218. wx.showModal({
  219. title: '',
  220. content: '确定要删除此订单?',
  221. success: function(res) {
  222. if (res.confirm) {
  223. util.request(mall.OrderDelete, {
  224. orderId: id
  225. }, 'POST').then(res=> {
  226. if (res.errno === 0) {
  227. wx.showToast({
  228. title: '删除订单成功'
  229. });
  230. that.setData({
  231. orderList: [],
  232. page: 1,
  233. limit: 10,
  234. totalPages: 1
  235. });
  236. that.getOrderList();
  237. // wx.redirectTo({
  238. // url: '/pages/mall/order/order'
  239. // });
  240. // util.redirect('/pages/mall/order/order');
  241. } else {
  242. util.showErrorToast(res.errmsg);
  243. }
  244. });
  245. }
  246. }
  247. });
  248. },
  249. // “取消订单”点击效果
  250. cancelOrder: function(e) {
  251. let that = this;
  252. let id = e.currentTarget.dataset.id;
  253. wx.showModal({
  254. title: '',
  255. content: '确定要取消此订单?',
  256. success: function(res) {
  257. if (res.confirm) {
  258. util.request(mall.OrderCancel, {
  259. orderId: id
  260. }, 'POST').then(function(res) {
  261. if (res.errno === 0) {
  262. wx.showToast({
  263. title: '取消订单成功'
  264. });
  265. that.setData({
  266. orderList: [],
  267. page: 1,
  268. limit: 10,
  269. totalPages: 1
  270. });
  271. that.getOrderList();
  272. // wx.redirectTo({
  273. // url: '/pages/mall/order/order'
  274. // });
  275. // util.redirect('/pages/ucenter/order/order');
  276. } else {
  277. util.showErrorToast(res.errmsg);
  278. }
  279. });
  280. }
  281. }
  282. });
  283. },
  284. // “待上门”点击效果
  285. confirmOrder: function(e) {
  286. let that = this;
  287. let id = e.currentTarget.dataset.id;
  288. wx.showModal({
  289. title: '',
  290. content: '确认上门服务?',
  291. success: function(res) {
  292. if (res.confirm) {
  293. util.request(mall.OrderConfirm, {
  294. orderId: id
  295. }, 'POST').then(function(res) {
  296. if (res.errno === 0) {
  297. wx.showToast({
  298. title: '确认上门成功!'
  299. });
  300. util.redirect('/pages/ucenter/order/order');
  301. } else {
  302. util.showErrorToast(res.errmsg);
  303. }
  304. });
  305. }
  306. }
  307. });
  308. },
  309. // “取消订单并退款”点击效果
  310. refundOrder: function(e) {
  311. let that = this;
  312. let id = e.currentTarget.dataset.id;
  313. wx.showModal({
  314. title: '',
  315. content: '确定要申请退款么?',
  316. success: function(res) {
  317. if (res.confirm) {
  318. util.request(mall.OrderRefund, {
  319. orderId: id
  320. }, 'POST').then(function(res) {
  321. if (res.errno === 0) {
  322. wx.showToast({
  323. title: '申请成功'
  324. });
  325. that.setData({
  326. orderList: [],
  327. page: 1,
  328. limit: 10,
  329. totalPages: 1
  330. });
  331. that.getOrderList();
  332. // wx.redirectTo({
  333. // url: '/pages/mall/order/order'
  334. // });
  335. // util.redirect('/pages/mall/order/order');
  336. } else {
  337. util.showErrorToast(res.errmsg);
  338. }
  339. });
  340. }
  341. }
  342. });
  343. },
  344. onReady: function() {
  345. // 页面渲染完成
  346. },
  347. onShow: function() {
  348. // 页面显示
  349. // this.getOrderList();
  350. },
  351. onHide: function() {
  352. // 页面隐藏
  353. },
  354. onUnload: function() {
  355. // 页面关闭
  356. }
  357. })