grade-details.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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. {
  16. text: "转发给自己的朋友们,分享好课,",
  17. color: "#000"
  18. },
  19. {
  20. text: " 追随您一起学习进步。您的魅力不是吹的!",
  21. color: "#000"
  22. },
  23. {
  24. text: "在限定时间内内成功拼团,您将得到xx元的奖励金哦。",
  25. color: "#FF4600"
  26. }
  27. ]
  28. },
  29. //获取团购信息并掉起支付
  30. pay: function ({ currentTarget }) {
  31. const productId = this.data.productId;
  32. const groupId = currentTarget.dataset.id;
  33. //开始发起团购
  34. httpRequestApi.SendGroupPurchas({
  35. productId,
  36. groupId
  37. }).success( (res) =>{
  38. console.log('发起团购',res);
  39. // wx.navigateTo({
  40. // url: `/pages/groupPage/collage-details/collage-details`
  41. // })
  42. if(res.data.message) {
  43. wx.showModal({
  44. title: '提示',
  45. content: res.data.message,
  46. success (res) {
  47. if (res.confirm) {
  48. console.log('用户点击确定')
  49. } else if (res.cancel) {
  50. console.log('用户点击取消')
  51. }
  52. }
  53. })
  54. return false;
  55. }
  56. //掉起支付
  57. this.prePayMap(res.data.data.prePayMap, res.data.data.groupPurchaseOrder.id);
  58. }).fail( (error) => {
  59. })
  60. },
  61. //支付
  62. prePayMap: function (prePayMap, orderId) {
  63. console.log(prePayMap)
  64. const that = this;
  65. //console.log(new Date().getTime())
  66. wx.requestPayment(
  67. {
  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. /**
  143. * 生命周期函数--监听页面初次渲染完成
  144. */
  145. onReady: function () {
  146. //获取弹窗组件
  147. this.popup = this.selectComponent("#popup");
  148. },
  149. /**
  150. * 生命周期函数--监听页面显示
  151. */
  152. onShow: function () {
  153. },
  154. /**
  155. * 生命周期函数--监听页面隐藏
  156. */
  157. onHide: function () {
  158. },
  159. /**
  160. * 生命周期函数--监听页面卸载
  161. */
  162. onUnload: function () {
  163. },
  164. /**
  165. * 页面相关事件处理函数--监听用户下拉动作
  166. */
  167. onPullDownRefresh: function () {
  168. },
  169. /**
  170. * 页面上拉触底事件的处理函数
  171. */
  172. onReachBottom: function () {
  173. },
  174. /**
  175. * 用户点击右上角分享
  176. */
  177. onShareAppMessage: function () {
  178. }
  179. })