payResult.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. isRefusedLogin: wx.getStorageSync('isRefusedLogin')
  68. }, 'POST').then(function (res) {
  69. if (res.errno === 0) {
  70. wx.setStorageSync('storeId', wx.getStorageSync('storeId'));
  71. wx.setStorageSync('merchSn', wx.getStorageSync('merchSn'));
  72. that.reLoad();
  73. }
  74. });
  75. this.getOrderDetail();
  76. }
  77. } else {
  78. wx.navigateTo({
  79. url: '/pages/auth/btnAuth/btnAuth',
  80. })
  81. }
  82. },
  83. onHide: function () {
  84. // 页面隐藏
  85. },
  86. onUnload: function () {
  87. // 页面关闭
  88. },
  89. reLoad: function () {
  90. let that = this;
  91. if (wx.getStorageSync('storeId')) {
  92. if (wx.getStorageSync('userId')) {
  93. wx.request({
  94. url: api.updateLoginUser,
  95. data: {
  96. userId: wx.getStorageSync('userId'), storeId: wx.getStorageSync('storeId'), merchSn: wx.getStorageSync('merchSn')
  97. },
  98. method: 'POST',
  99. header: {
  100. 'Content-Type': 'application/json'
  101. },
  102. success: function (wxRes) {
  103. if (wxRes.data.errno === 0) {
  104. // console.log("用户信息更新成功");
  105. }
  106. },
  107. fail: function (err) {
  108. console.log("failed");
  109. }
  110. });
  111. }
  112. }
  113. },
  114. onShareAppMessage: function () {
  115. var that = this;
  116. // console.log("url:" + that.data.goods.list_pic_url);
  117. // var userId = wx.getStorageSync('userId');
  118. // console.log("userId:" + userId);
  119. return {
  120. title: '中网跨境电商商品分类',
  121. // desc: '分享有机会获得优惠券',
  122. desc: '中网跨境电商商品分类页进行购买',
  123. imageUrl: '/static/imgys/share.png',
  124. path: '/pages/catalog/catalog?sourceKey=' + that.data.orderIds + '&referrer=' + wx.getStorageSync('userId'),
  125. success: function (res) {
  126. console.log("转发成功");
  127. // 转发成功
  128. that.setData({
  129. openCoupon: true
  130. });
  131. },
  132. fail: function (res) {
  133. // 转发失败
  134. console.log("转发失败");
  135. }
  136. }
  137. },
  138. /**
  139. * 用户分享领券
  140. */
  141. shareCoupon: function () {
  142. var that = this;
  143. // {sourceKey: util.uuid()}
  144. util.request(api.CouponTransActivit,
  145. { sourceKey: that.data.orderIds}).then(function (res) {
  146. if (res.errno === 0) {
  147. that.setData({
  148. openCoupon: false
  149. });
  150. wx.showToast({
  151. title: '领券成功',
  152. duration: 2000
  153. });
  154. setTimeout(function () {
  155. wx.switchTab({
  156. url: '/pages/catalog/catalog',
  157. });
  158. }, 2000);
  159. // wx.redirectTo({ url: '/pages/ucenter/coupon/coupon' });
  160. } else if (res.errno === 1) {
  161. that.setData({
  162. openCoupon: false
  163. });
  164. util.showErrorToast(res.errmsg);
  165. } else if (res.errno === 2) {
  166. // 已经领取过了
  167. that.setData({
  168. openCoupon: false
  169. });
  170. util.showErrorToast(res.errmsg);
  171. }
  172. });
  173. },
  174. closeCoupon: function () {
  175. var that = this;
  176. that.setData({
  177. openCoupon: false
  178. });
  179. }
  180. })