grade-details.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. // pages/grade-details/grade-details.js
  2. import httpRequestApi from '../../../utils/APIClient';
  3. const app = getApp();
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. productId: '',
  10. payList: [],
  11. titleIcon: '',
  12. title: '',
  13. bookInfo: '',
  14. lessonList: [],
  15. content: [{
  16. text: "转发给自己的朋友们,分享好课,",
  17. color: "#000"
  18. },
  19. {
  20. text: " 追随您一起学习进步。您的魅力不是吹的!",
  21. color: "#000"
  22. },
  23. {
  24. text: `在限定时间内成功拼团,您将得到xx元的奖励金哦。`,
  25. color: "#FF4600"
  26. }
  27. ],
  28. share: false,
  29. isIPX: app.globalData.isIPX
  30. },
  31. //获取团购信息并掉起支付
  32. pay: function ({
  33. currentTarget
  34. }) {
  35. const productId = this.data.productId;
  36. const groupId = currentTarget.dataset.id;
  37. //开始发起团购
  38. httpRequestApi.SendGroupPurchas({
  39. productId,
  40. groupId
  41. }).success((res) => {
  42. console.log('发起团购', res);
  43. // wx.navigateTo({
  44. // url: `/pages/groupPage/collage-details/collage-details`
  45. // })
  46. if (res.data.message) {
  47. wx.showModal({
  48. title: '提示',
  49. content: res.data.message,
  50. success(res) {
  51. if (res.confirm) {
  52. console.log('用户点击确定')
  53. } else if (res.cancel) {
  54. console.log('用户点击取消')
  55. }
  56. }
  57. })
  58. return false;
  59. }
  60. this.data.content[2].text = res.data.data.groupPurchaseOrder.organizerPrice === 0 ? '' : `在限定时间内内成功拼团,您将得到${res.data.data.groupPurchaseOrder.organizerPrice}元的奖励金哦。`
  61. this.setData({
  62. content: this.data.content
  63. })
  64. // 如果已经拥有当前课程,则无需支付,直接进入拼团成功页面
  65. if (res.data.data.groupPurchaseOrder.group === 'PROMOTION') {
  66. wx.showModal({
  67. title: '重新发起团购',
  68. content: '您会获得奖励哦',
  69. success(res) {
  70. console.log(res)
  71. that.popup.close();
  72. if (res.data.data.groupPurchaseOrder.headCount !== 1) {
  73. setTimeout(() => {
  74. wx.navigateTo({
  75. url: `/pages/groupPage/make-money/make-money?productId=${productId}&id=${res.data.data.groupPurchaseOrder.id}&groupId=${groupId}`
  76. })
  77. wx.setNavigationBarTitle({
  78. title: '拼团详情'
  79. })
  80. }, 3000)
  81. }
  82. }
  83. })
  84. } else {
  85. //掉起支付
  86. this.prePayMap(res.data.data.prePayMap, res.data.data.groupPurchaseOrder.id, res.data.data.groupPurchaseOrder.headCount);
  87. }
  88. }).fail((error) => {
  89. })
  90. },
  91. //支付
  92. prePayMap: function (prePayMap, orderId, num) {
  93. console.log(prePayMap)
  94. const that = this;
  95. //console.log(new Date().getTime())
  96. wx.requestPayment({
  97. 'appId': prePayMap.appId,
  98. 'timeStamp': prePayMap.timeStamp,
  99. 'nonceStr': prePayMap.nonceStr,
  100. 'package': prePayMap.package,
  101. 'signType': 'MD5',
  102. 'paySign': prePayMap.sign,
  103. 'success': function (res) {
  104. console.log('支付成功',res)
  105. wx.showModal({
  106. title: '提示',
  107. content: '支付成功',
  108. success(res) {
  109. console.log(res)
  110. that.popup.close();
  111. if (num !== 1) {
  112. setTimeout(() => {
  113. wx.navigateTo({
  114. url: `/pages/groupPage/collage-details/collage-details?orderId=${orderId}`
  115. })
  116. wx.setNavigationBarTitle({
  117. title: '拼团详情'
  118. })
  119. }, 3000)
  120. }
  121. }
  122. })
  123. },
  124. 'fail': function (res) {
  125. console.log('支付失败', res)
  126. }
  127. })
  128. },
  129. /**
  130. * 生命周期函数--监听页面加载
  131. */
  132. onLoad: function (options) {
  133. console.log(options)
  134. if(options.share){
  135. this.setData({
  136. share: options.share
  137. })
  138. }
  139. // wx.setNavigationBarTitle({
  140. // title: options.title
  141. // })
  142. const productId = options.productId;
  143. if (productId) {
  144. this.setData({
  145. productId
  146. })
  147. }
  148. //课本详情
  149. httpRequestApi.getBookDetail(wx.getStorageSync('uid'), productId).success((res) => {
  150. console.log('课本详情', res.data.data);
  151. const bookInfo = res.data.data.product;
  152. const lessonList = res.data.data.lessonList;
  153. wx.setNavigationBarTitle({
  154. title: bookInfo.title
  155. })
  156. this.setData({
  157. titleIcon: bookInfo.bgImg,
  158. title: bookInfo.title,
  159. bookInfo: bookInfo.description
  160. })
  161. const lessonTemp = [];
  162. lessonList.forEach(item => {
  163. const temp = {};
  164. temp.id = item.id;
  165. temp.title = item.title;
  166. temp.readNum = item.readCount;
  167. lessonTemp.push(temp);
  168. });
  169. this.setData({
  170. lessonList: lessonTemp
  171. });
  172. }).fail((error) => {
  173. })
  174. //支付详情
  175. httpRequestApi.getGroupPurchaseInfo(productId).success((res) => {
  176. console.log('支付详情', res.data.data);
  177. this.setData({
  178. payList: res.data.data
  179. })
  180. }).fail((error) => {
  181. })
  182. },
  183. goToClass: function (e) {
  184. let id = e.currentTarget.dataset.id;
  185. let title = e.currentTarget.dataset.title;
  186. wx.navigateTo({
  187. url: `../../main/class/class?id=${id}&title=${title}`
  188. })
  189. },
  190. /**
  191. * 生命周期函数--监听页面初次渲染完成
  192. */
  193. onReady: function () {
  194. //获取弹窗组件
  195. this.popup = this.selectComponent("#popup");
  196. },
  197. /**
  198. * 生命周期函数--监听页面显示
  199. */
  200. onShow: function () {
  201. },
  202. /**
  203. * 生命周期函数--监听页面隐藏
  204. */
  205. onHide: function () {
  206. },
  207. /**
  208. * 生命周期函数--监听页面卸载
  209. */
  210. onUnload: function () {
  211. },
  212. /**
  213. * 页面相关事件处理函数--监听用户下拉动作
  214. */
  215. onPullDownRefresh: function () {
  216. },
  217. /**
  218. * 页面上拉触底事件的处理函数
  219. */
  220. onReachBottom: function () {
  221. },
  222. /**
  223. * 用户点击右上角分享
  224. */
  225. onShareAppMessage: function () {
  226. }
  227. })