payResult.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. var util = require('../../utils/util.js');
  2. var api = require('../../config/api.js');
  3. var app = getApp();
  4. Page({
  5. data: {
  6. status: false,
  7. orderId: 0,
  8. orderInfo: {},
  9. openCoupon: false,
  10. orderIds: [],
  11. orderGoods: [],
  12. actualPrice: 0
  13. },
  14. onLoad: function (options) {
  15. // 页面初始化 options为页面跳转所带来的参数
  16. this.setData({
  17. status: parseInt(options.status),
  18. // orderId: parseInt(options.orderId)
  19. orderIds: options.orderIds
  20. });
  21. },
  22. getOrderDetail() {
  23. let that = this;
  24. wx.showLoading({
  25. title: '加载中...',
  26. });
  27. util.request(api.OrderDetailList, {
  28. orderIds: that.data.orderIds,
  29. status:that.data.status
  30. }).then(function (res) {
  31. if (res.errno === 0) {
  32. wx.hideLoading();
  33. console.log(res.data);
  34. that.setData({
  35. actualPrice: res.data.actualPrice,
  36. orderGoods: res.data.orderGoods,
  37. });
  38. //团购订单,1期暂时不实现
  39. // if (that.data.status && res.data.orderInfo.order_type == 2) {
  40. // util.request(api.GroupOpenDetail, {
  41. // detailId: res.data.orderInfo.activity_id
  42. // }).then(function (resData) {
  43. // let url = '/pages/joinGroup/joinGroup?openId=' + resData.data.open_id + '&groupId=' + resData.data.group_id
  44. // + '&goodsId=' + resData.data.goods_id
  45. // + '&min_open_group=' + resData.data.min_open_group
  46. // + '&attend_num=' + resData.data.attend_num
  47. // + '&end_time=' + resData.data.end_time;
  48. // console.log(url);
  49. // wx.redirectTo({
  50. // url: url
  51. // })
  52. // })
  53. // }
  54. }
  55. });
  56. },
  57. onReady: function () {
  58. },
  59. onShow: function () {
  60. let that = this;
  61. // 页面显示
  62. if (wx.getStorageSync('userInfo') || wx.getStorageSync('token')) {
  63. if (wx.getStorageSync('storeId')) {
  64. util.request(api.ChooseStoreId, {
  65. storeId: wx.getStorageSync('storeId'),
  66. merchSn: wx.getStorageSync('merchSn')
  67. }, 'POST').then(function (res) {
  68. if (res.errno === 0) {
  69. wx.setStorageSync('storeId', wx.getStorageSync('storeId'));
  70. wx.setStorageSync('merchSn', wx.getStorageSync('merchSn'));
  71. that.reLoad();
  72. }
  73. });
  74. this.getOrderDetail();
  75. }
  76. } else {
  77. wx.navigateTo({
  78. url: '/pages/auth/btnAuth/btnAuth',
  79. })
  80. }
  81. },
  82. onHide: function () {
  83. // 页面隐藏
  84. },
  85. onUnload: function () {
  86. // 页面关闭
  87. },
  88. reLoad: function () {
  89. let that = this;
  90. if (wx.getStorageSync('storeId')) {
  91. if (wx.getStorageSync('userId')) {
  92. wx.request({
  93. url: api.updateLoginUser,
  94. data: {
  95. userId: wx.getStorageSync('userId'), storeId: wx.getStorageSync('storeId'), merchSn: wx.getStorageSync('merchSn')
  96. },
  97. method: 'POST',
  98. header: {
  99. 'Content-Type': 'application/json'
  100. },
  101. success: function (wxRes) {
  102. if (wxRes.data.errno === 0) {
  103. // console.log("用户信息更新成功");
  104. }
  105. },
  106. fail: function (err) {
  107. console.log("failed");
  108. }
  109. });
  110. }
  111. }
  112. },
  113. onShareAppMessage: function () {
  114. var that = this;
  115. // console.log("url:" + that.data.goods.list_pic_url);
  116. // var userId = wx.getStorageSync('userId');
  117. // console.log("userId:" + userId);
  118. return {
  119. title: '商业版',
  120. desc: '分享有机会获得优惠券',
  121. imageUrl: '/static/imgys/share.png',
  122. path: '/pages/catalog/catalog?sourceKey=' + that.data.orderIds + '&referrer=' + wx.getStorageSync('userId'),
  123. success: function (res) {
  124. console.log("转发成功");
  125. // 转发成功
  126. that.setData({
  127. openCoupon: true
  128. });
  129. },
  130. fail: function (res) {
  131. // 转发失败
  132. console.log("转发失败");
  133. }
  134. }
  135. },
  136. /**
  137. * 用户分享领券
  138. */
  139. shareCoupon: function () {
  140. var that = this;
  141. // {sourceKey: util.uuid()}
  142. util.request(api.CouponTransActivit,
  143. { sourceKey: that.data.orderIds}).then(function (res) {
  144. if (res.errno === 0) {
  145. that.setData({
  146. openCoupon: false
  147. });
  148. wx.showToast({
  149. title: '领券成功',
  150. duration: 2000
  151. });
  152. setTimeout(function () {
  153. wx.switchTab({
  154. url: '/pages/catalog/catalog',
  155. });
  156. }, 2000);
  157. // wx.redirectTo({ url: '/pages/ucenter/coupon/coupon' });
  158. } else if (res.errno === 1) {
  159. that.setData({
  160. openCoupon: false
  161. });
  162. util.showErrorToast(res.errmsg);
  163. } else if (res.errno === 2) {
  164. // 已经领取过了
  165. that.setData({
  166. openCoupon: false
  167. });
  168. util.showErrorToast(res.errmsg);
  169. }
  170. });
  171. },
  172. closeCoupon: function () {
  173. var that = this;
  174. that.setData({
  175. openCoupon: false
  176. });
  177. }
  178. })