grade-details.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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. this.data.content[2].text = res.data.data.groupPurchaseOrder.organizerPrice === 0 ? '' : `在限定时间内内成功拼团,您将得到${res.data.data.groupPurchaseOrder.organizerPrice}元的奖励金哦。`
  58. this.setData({
  59. content: this.data.content
  60. })
  61. // 如果已经拥有当前课程,则无需支付,直接进入拼团成功页面
  62. if (res.data.data.groupPurchaseOrder.group === 'PROMOTION') {
  63. wx.showModal({
  64. title: '重新发起团购',
  65. content: '您会获得奖励哦',
  66. success(res) {
  67. console.log(res)
  68. that.popup.close();
  69. if (res.data.data.groupPurchaseOrder.headCount !== 1) {
  70. setTimeout(() => {
  71. wx.navigateTo({
  72. url: `/pages/groupPage/collage-details/collage-details?orderId=${res.data.data.groupPurchaseOrder.id}`
  73. })
  74. wx.setNavigationBarTitle({
  75. title: '拼团详情'
  76. })
  77. }, 3000)
  78. }
  79. }
  80. })
  81. } else {
  82. //掉起支付
  83. this.prePayMap(res.data.data.prePayMap, res.data.data.groupPurchaseOrder.id, res.data.data.groupPurchaseOrder.headCount);
  84. }
  85. }).fail((error) => {
  86. })
  87. },
  88. //支付
  89. prePayMap: function (prePayMap, orderId, num) {
  90. console.log(prePayMap)
  91. const that = this;
  92. //console.log(new Date().getTime())
  93. wx.requestPayment({
  94. 'appId': prePayMap.appId,
  95. 'timeStamp': prePayMap.timeStamp,
  96. 'nonceStr': prePayMap.nonceStr,
  97. 'package': prePayMap.package,
  98. 'signType': 'MD5',
  99. 'paySign': prePayMap.sign,
  100. 'success': function (res) {
  101. console.log('支付成功')
  102. wx.showModal({
  103. title: '提示',
  104. content: '支付成功',
  105. success(res) {
  106. console.log(res)
  107. that.popup.close();
  108. if (num !== 1) {
  109. setTimeout(() => {
  110. wx.navigateTo({
  111. url: `/pages/groupPage/collage-details/collage-details?orderId=${orderId}`
  112. })
  113. wx.setNavigationBarTitle({
  114. title: '拼团详情'
  115. })
  116. }, 3000)
  117. }
  118. }
  119. })
  120. },
  121. 'fail': function (res) {
  122. console.log('支付失败', res)
  123. }
  124. })
  125. },
  126. /**
  127. * 生命周期函数--监听页面加载
  128. */
  129. onLoad: function (options) {
  130. console.log(options)
  131. // wx.setNavigationBarTitle({
  132. // title: options.title
  133. // })
  134. const productId = options.productId;
  135. if (productId) {
  136. this.setData({
  137. productId
  138. })
  139. }
  140. //课本详情
  141. httpRequestApi.getBookDetail(wx.getStorageSync('uid'), productId).success((res) => {
  142. console.log('课本详情', res.data.data);
  143. const bookInfo = res.data.data.product;
  144. const lessonList = res.data.data.lessonList;
  145. wx.setNavigationBarTitle({
  146. title: bookInfo.title
  147. })
  148. this.setData({
  149. titleIcon: bookInfo.bgImg,
  150. title: bookInfo.title,
  151. bookInfo: bookInfo.description
  152. })
  153. const lessonTemp = [];
  154. lessonList.forEach(item => {
  155. const temp = {};
  156. temp.id = item.id;
  157. temp.title = item.title;
  158. temp.readNum = item.readCount;
  159. lessonTemp.push(temp);
  160. });
  161. this.setData({
  162. lessonList: lessonTemp
  163. });
  164. }).fail((error) => {
  165. })
  166. //支付详情
  167. httpRequestApi.getGroupPurchaseInfo(productId).success((res) => {
  168. console.log('支付详情', res.data.data);
  169. this.setData({
  170. payList: res.data.data
  171. })
  172. }).fail((error) => {
  173. })
  174. },
  175. goToClass: function (e) {
  176. let id = e.currentTarget.dataset.id;
  177. let title = e.currentTarget.dataset.title;
  178. wx.navigateTo({
  179. url: `../../main/class/class?id=${id}&title=${title}`
  180. })
  181. },
  182. /**
  183. * 生命周期函数--监听页面初次渲染完成
  184. */
  185. onReady: function () {
  186. //获取弹窗组件
  187. this.popup = this.selectComponent("#popup");
  188. },
  189. /**
  190. * 生命周期函数--监听页面显示
  191. */
  192. onShow: function () {
  193. },
  194. /**
  195. * 生命周期函数--监听页面隐藏
  196. */
  197. onHide: function () {
  198. },
  199. /**
  200. * 生命周期函数--监听页面卸载
  201. */
  202. onUnload: function () {
  203. },
  204. /**
  205. * 页面相关事件处理函数--监听用户下拉动作
  206. */
  207. onPullDownRefresh: function () {
  208. },
  209. /**
  210. * 页面上拉触底事件的处理函数
  211. */
  212. onReachBottom: function () {
  213. },
  214. /**
  215. * 用户点击右上角分享
  216. */
  217. onShareAppMessage: function () {
  218. }
  219. })