order.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  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. getToolkitList() {
  50. wx.showLoading({
  51. title: '加载中',
  52. });
  53. let that = this;
  54. util.request(mall.ToolkitList, {
  55. page: that.data.page,
  56. size: that.data.limit,
  57. // disStatus:2
  58. }).then(function(res) {
  59. wx.hideLoading();
  60. if (res.errno === 0) {
  61. console.log(res.data);
  62. that.setData({
  63. orderList: that.data.orderList.concat(res.data.list),
  64. totalPages: res.data.pages
  65. });
  66. }
  67. });
  68. },
  69. onReachBottom() {
  70. if (this.data.totalPages > this.data.page) {
  71. this.setData({
  72. page: this.data.page + 1
  73. });
  74. if(this.data.showType!=6){
  75. this.getOrderList();
  76. }else{
  77. // 待领取订单
  78. this.getToolkitList();
  79. }
  80. } else {
  81. wx.showToast({
  82. title: '没有更多订单了',
  83. icon: 'none',
  84. duration: 2000
  85. });
  86. return false;
  87. }
  88. },
  89. onTabChange(e){
  90. let showType = e.detail.name;
  91. this.setData({
  92. orderList: [],
  93. showType: showType,
  94. page: 1,
  95. limit: 10,
  96. totalPages: 1
  97. });
  98. if(showType==6){
  99. this.getToolkitList();
  100. }else{
  101. this.getOrderList();
  102. }
  103. },
  104. viewService(e){
  105. let id=e.currentTarget.dataset.id;
  106. wx.navigateTo({
  107. url: '../serviceDetail/serviceDetail?orderId=' +id
  108. })
  109. },
  110. qrtouchstart:function(){
  111. this.setData({
  112. myqr_blur:0,
  113. myqr_show:false
  114. });
  115. },
  116. shareFriendOrCircle: function(e) {
  117. // let that = this;
  118. // if (!app.globalData.hasLogin) {
  119. // wx.navigateTo({
  120. // url: "/pages/auth/login/login"
  121. // });
  122. // return;
  123. // }
  124. // //获取分享id 用来追踪链接
  125. // //引荐人和非引荐人的 链接不同
  126. // let imgUrl = that.data.goods.shareWxUrl ? that.data.goods.shareWxUrl : that.data.goods.gallery[0];
  127. // var path = '/pages/goods/goods?id=' + that.data.id + '&rId=' + that.data.userInfo.id;
  128. // if (that.data.userInfo.isDis) { //是引荐人
  129. // path = '/pages/goods/goods?id=' + that.data.id + '&shareId=' + that.data.wxShareId;
  130. // }
  131. // this.hidePoster();
  132. // return {
  133. // title: that.data.goods.name,
  134. // desc: that.data.myqr_ads,
  135. // path: path,
  136. // imageUrl: imgUrl
  137. // }
  138. },
  139. // 保存分享图
  140. saveShare: function() {
  141. let that = this;
  142. wx.showLoading({
  143. title: '图片保存中',
  144. });
  145. console.log(that.data);
  146. wx.downloadFile({
  147. url: that.data.myqr_url,
  148. success: function(res) {
  149. console.log(res)
  150. wx.saveImageToPhotosAlbum({
  151. filePath: res.tempFilePath,
  152. success: function(res) {
  153. wx.hideLoading();
  154. wx.showModal({
  155. title: '存图成功',
  156. content: '图片成功保存到相册了,可以分享到朋友圈了',
  157. showCancel: false,
  158. confirmText: '好的',
  159. confirmColor: '#a78845',
  160. success: function(res) {
  161. if (res.confirm) {
  162. console.log('用户点击确定');
  163. that.setData({
  164. myqr_show:false,
  165. myqr_blur:0
  166. });
  167. }
  168. }
  169. })
  170. },
  171. fail: function(res) {
  172. wx.hideLoading();
  173. wx.showModal({
  174. title: '警告',
  175. content: '不授权无法保存',
  176. showCancel: false
  177. })
  178. that.setData({
  179. myqr_show:false,
  180. myqr_blur:0
  181. });
  182. }
  183. })
  184. },
  185. fail: function(res) {
  186. wx.hideLoading();
  187. console.log(res);
  188. }
  189. })
  190. },
  191. // “去付款”按钮点击效果
  192. payOrder: function(e) {
  193. let that = this;
  194. let id = e.currentTarget.dataset.id;
  195. util.request(mall.OrderPrepay, {
  196. orderId: id
  197. }, 'POST').then(function(res) {
  198. if (res.errno === 0) {
  199. const payParam = res.data;
  200. console.log("支付过程开始");
  201. wx.requestPayment({
  202. 'timeStamp': payParam.timeStamp,
  203. 'nonceStr': payParam.nonceStr,
  204. 'package': payParam.packageValue,
  205. 'signType': payParam.signType,
  206. 'paySign': payParam.paySign,
  207. 'success': function(res) {
  208. console.log("支付过程成功");
  209. that.setData({
  210. orderList: [],
  211. page: 1,
  212. limit: 10,
  213. totalPages: 1
  214. });
  215. that.getOrderList();
  216. // wx.redirectTo({
  217. // url: '/pages/mall/order/order'
  218. // });
  219. // util.redirect('/pages/mall/order/order');
  220. },
  221. 'fail': function(res) {
  222. console.log("支付过程失败");
  223. util.showErrorToast('支付失败');
  224. },
  225. 'complete': function(res) {
  226. console.log("支付过程结束")
  227. }
  228. });
  229. }
  230. });
  231. },
  232. // “删除”点击效果
  233. deleteOrder: function(e) {
  234. let that = this;
  235. let id = e.currentTarget.dataset.id;
  236. wx.showModal({
  237. title: '',
  238. content: '确定要删除此订单?',
  239. success: function(res) {
  240. if (res.confirm) {
  241. util.request(mall.OrderDelete, {
  242. orderId: id
  243. }, 'POST').then(res=> {
  244. if (res.errno === 0) {
  245. wx.showToast({
  246. title: '删除订单成功'
  247. });
  248. that.setData({
  249. orderList: [],
  250. page: 1,
  251. limit: 10,
  252. totalPages: 1
  253. });
  254. that.getOrderList();
  255. // wx.redirectTo({
  256. // url: '/pages/mall/order/order'
  257. // });
  258. // util.redirect('/pages/mall/order/order');
  259. } else {
  260. util.showErrorToast(res.errmsg);
  261. }
  262. });
  263. }
  264. }
  265. });
  266. },
  267. // “取消订单”点击效果
  268. cancelOrder: function(e) {
  269. let that = this;
  270. let id = e.currentTarget.dataset.id;
  271. wx.showModal({
  272. title: '',
  273. content: '确定要取消此订单?',
  274. success: function(res) {
  275. if (res.confirm) {
  276. util.request(mall.OrderCancel, {
  277. orderId: id
  278. }, 'POST').then(function(res) {
  279. if (res.errno === 0) {
  280. wx.showToast({
  281. title: '取消订单成功'
  282. });
  283. that.setData({
  284. orderList: [],
  285. page: 1,
  286. limit: 10,
  287. totalPages: 1
  288. });
  289. that.getOrderList();
  290. // wx.redirectTo({
  291. // url: '/pages/mall/order/order'
  292. // });
  293. // util.redirect('/pages/ucenter/order/order');
  294. } else {
  295. util.showErrorToast(res.errmsg);
  296. }
  297. });
  298. }
  299. }
  300. });
  301. },
  302. // “取消订单”点击效果
  303. cancelSpec: function(e) {
  304. let id = e.currentTarget.dataset.id;
  305. wx.showModal({
  306. title: '',
  307. content: '确定我不需要?',
  308. success: res=> {
  309. if (res.confirm) {
  310. util.request(mall.ToolkitReceive, {
  311. agree:false,
  312. toolkitId: id
  313. }, 'POST').then(resp=>{
  314. if (resp.errno === 0) {
  315. wx.showToast({
  316. title: '操作成功'
  317. });
  318. this.setData({
  319. orderList: [],
  320. page: 1,
  321. limit: 10,
  322. totalPages: 1
  323. });
  324. this.getToolkitList();
  325. } else {
  326. util.showErrorToast(res.errmsg);
  327. }
  328. });
  329. }
  330. }
  331. });
  332. },
  333. // “确认领取”点击效果
  334. confirmOrder: function(e) {
  335. let id = e.currentTarget.dataset.id;
  336. wx.showModal({
  337. title: '',
  338. content: '确认领取?',
  339. success:res => {
  340. if (res.confirm) {
  341. util.request(mall.OrderConfirm, {
  342. orderId: id
  343. }, 'POST').then(res=> {
  344. if (res.errno === 0) {
  345. wx.showToast({
  346. title: '操作成功!'
  347. });
  348. this.setData({
  349. orderList: [],
  350. page: 1,
  351. limit: 10,
  352. totalPages: 1
  353. });
  354. this.getOrderList();
  355. } else {
  356. util.showErrorToast(res.errmsg);
  357. }
  358. });
  359. }
  360. }
  361. });
  362. },
  363. // “取消订单并退款”点击效果
  364. refundOrder: function(e) {
  365. let that = this;
  366. let id = e.currentTarget.dataset.id;
  367. wx.showModal({
  368. title: '',
  369. content: '确定要申请退款么?',
  370. success: function(res) {
  371. if (res.confirm) {
  372. util.request(mall.OrderRefund, {
  373. orderId: id
  374. }, 'POST').then(function(res) {
  375. if (res.errno === 0) {
  376. wx.showToast({
  377. title: '申请成功'
  378. });
  379. that.setData({
  380. orderList: [],
  381. page: 1,
  382. limit: 10,
  383. totalPages: 1
  384. });
  385. that.getOrderList();
  386. // wx.redirectTo({
  387. // url: '/pages/mall/order/order'
  388. // });
  389. // util.redirect('/pages/mall/order/order');
  390. } else {
  391. util.showErrorToast(res.errmsg);
  392. }
  393. });
  394. }
  395. }
  396. });
  397. },
  398. confirmSpec(e){
  399. app.globalData.specRefresh=false;
  400. let id=e.currentTarget.dataset.id;
  401. wx.navigateTo({
  402. url: '/pages/mall/toolkitConfirm/toolkitConfirm?id='+id,
  403. })
  404. },
  405. onReady: function() {
  406. // 页面渲染完成
  407. },
  408. onShow: function() {
  409. // 页面显示
  410. // this.getOrderList();
  411. if(app.globalData.specRefresh&&this.data.showType==6){
  412. this.setData({
  413. orderList: [],
  414. page: 1,
  415. limit: 10,
  416. totalPages: 1
  417. });
  418. this.getToolkitList();
  419. }
  420. },
  421. onHide: function() {
  422. // 页面隐藏
  423. },
  424. onUnload: function() {
  425. // 页面关闭
  426. }
  427. })