order.js 8.0 KB

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