order.js 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  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. let channel=e.currentTarget.dataset.channel;
  177. util.request(api.OrderPrepay, {
  178. orderId: id
  179. }, 'POST').then(function(res) {
  180. if (res.errno === 0) {
  181. const payParam = res.data;
  182. console.log("支付过程开始");
  183. if(channel=='102'){
  184. wx.requestOrderPayment({
  185. 'timeStamp': payParam.timeStamp,
  186. 'nonceStr': payParam.nonceStr,
  187. 'package': payParam.packageValue,
  188. 'signType': payParam.signType,
  189. 'paySign': payParam.paySign,
  190. 'success': function(res) {
  191. console.log("支付过程成功");
  192. util.redirect('/pages/ucenter/order/order');
  193. },
  194. 'fail': function(res) {
  195. console.log("支付过程失败");
  196. util.showErrorToast('支付失败');
  197. },
  198. 'complete': function(res) {
  199. console.log("支付过程结束")
  200. }
  201. });
  202. }else{
  203. wx.requestPayment({
  204. 'timeStamp': payParam.timeStamp,
  205. 'nonceStr': payParam.nonceStr,
  206. 'package': payParam.packageValue,
  207. 'signType': payParam.signType,
  208. 'paySign': payParam.paySign,
  209. 'success': function(res) {
  210. console.log("支付过程成功");
  211. util.redirect('/pages/ucenter/order/order');
  212. },
  213. 'fail': function(res) {
  214. console.log("支付过程失败");
  215. util.showErrorToast('支付失败');
  216. },
  217. 'complete': function(res) {
  218. console.log("支付过程结束")
  219. }
  220. });
  221. }
  222. }
  223. });
  224. },
  225. // “删除”点击效果
  226. deleteOrder: function(e) {
  227. let that = this;
  228. let id = e.currentTarget.dataset.id;
  229. wx.showModal({
  230. title: '',
  231. content: '确定要删除此订单?',
  232. success: function(res) {
  233. if (res.confirm) {
  234. util.request(api.OrderDelete, {
  235. orderId: id
  236. }, 'POST').then(function(res) {
  237. if (res.errno === 0) {
  238. wx.showToast({
  239. title: '删除订单成功'
  240. });
  241. util.redirect('/pages/ucenter/order/order');
  242. } else {
  243. util.showErrorToast(res.errmsg);
  244. }
  245. });
  246. }
  247. }
  248. });
  249. },
  250. // “取消订单”点击效果
  251. cancelOrder: function(e) {
  252. let that = this;
  253. let id = e.currentTarget.dataset.id;
  254. wx.showModal({
  255. title: '',
  256. content: '确定要取消此订单?',
  257. success: function(res) {
  258. if (res.confirm) {
  259. util.request(api.OrderCancel, {
  260. orderId: id
  261. }, 'POST').then(function(res) {
  262. if (res.errno === 0) {
  263. wx.showToast({
  264. title: '取消订单成功'
  265. });
  266. util.redirect('/pages/ucenter/order/order');
  267. } else {
  268. util.showErrorToast(res.errmsg);
  269. }
  270. });
  271. }
  272. }
  273. });
  274. },
  275. // “待上门”点击效果
  276. confirmOrder: function(e) {
  277. let that = this;
  278. let id = e.currentTarget.dataset.id;
  279. wx.showModal({
  280. title: '',
  281. content: '确认上门服务?',
  282. success: function(res) {
  283. if (res.confirm) {
  284. util.request(api.OrderConfirm, {
  285. orderId: id
  286. }, 'POST').then(function(res) {
  287. if (res.errno === 0) {
  288. wx.showToast({
  289. title: '确认上门成功!'
  290. });
  291. util.redirect('/pages/ucenter/order/order');
  292. } else {
  293. util.showErrorToast(res.errmsg);
  294. }
  295. });
  296. }
  297. }
  298. });
  299. },
  300. // “取消订单并退款”点击效果
  301. refundOrder: function(e) {
  302. let that = this;
  303. let id = e.currentTarget.dataset.id;
  304. wx.showModal({
  305. title: '',
  306. content: '确定要取消此订单?',
  307. success: function(res) {
  308. if (res.confirm) {
  309. util.request(api.OrderRefund, {
  310. orderId: id
  311. }, 'POST').then(function(res) {
  312. if (res.errno === 0) {
  313. wx.showToast({
  314. title: '取消订单成功'
  315. });
  316. util.redirect('/pages/ucenter/order/order');
  317. } else {
  318. util.showErrorToast(res.errmsg);
  319. }
  320. });
  321. }
  322. }
  323. });
  324. },
  325. onReady: function() {
  326. // 页面渲染完成
  327. },
  328. onShow: function() {
  329. // 页面显示
  330. this.setData({
  331. orderList: [],
  332. page: 1,
  333. });
  334. this.getOrderList();
  335. },
  336. onHide: function() {
  337. // 页面隐藏
  338. },
  339. onUnload: function() {
  340. // 页面关闭
  341. }
  342. })