grade-details.js 6.1 KB

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