order.js 11 KB

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