grade-details.js 4.6 KB

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