grade-details.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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.groupPurchaseOrderDetail.orderId);
  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. if (res.confirm) {
  81. that.popup.close();
  82. setTimeout(() => {
  83. wx.navigateTo({
  84. url: `/pages/groupPage/collage-details/collage-details?orderId=${orderId}`
  85. })
  86. wx.setNavigationBarTitle({
  87. title: '拼团详情'
  88. })
  89. }, 1000)
  90. } else if (res.cancel) {
  91. that.popup.close();
  92. setTimeout(() => {
  93. wx.navigateTo({
  94. url: `/pages/groupPage/collage-details/collage-details?orderId=${orderId}`
  95. })
  96. wx.setNavigationBarTitle({
  97. title: '拼团详情'
  98. })
  99. }, 1000)
  100. }
  101. }
  102. })
  103. },
  104. 'fail':function(res){
  105. console.log('支付失败', res)
  106. }
  107. })
  108. },
  109. /**
  110. * 生命周期函数--监听页面加载
  111. */
  112. onLoad: function (options) {
  113. wx.setNavigationBarTitle({
  114. title: options.title
  115. })
  116. const productId = options.productId;
  117. if(productId) {
  118. this.setData({
  119. productId
  120. })
  121. }
  122. //课本详情
  123. httpRequestApi.getBookDetail(productId).success( (res) =>{
  124. console.log('课本详情',res.data.data);
  125. const bookInfo = res.data.data.product;
  126. const lessonList = res.data.data.lessonList;
  127. this.setData({
  128. titleIcon: bookInfo.bgImg,
  129. title: bookInfo.title,
  130. bookInfo: bookInfo.description
  131. })
  132. const lessonTemp = [];
  133. lessonList.forEach(item => {
  134. const temp = {};
  135. temp.id = item.id;
  136. temp.title = item.title;
  137. temp.readNum = item.readCount;
  138. lessonTemp.push(temp);
  139. });
  140. this.setData({
  141. lessonList: lessonTemp
  142. });
  143. }).fail( (error) => {
  144. })
  145. //支付详情
  146. httpRequestApi.getGroupPurchaseInfo(productId).success( (res) =>{
  147. console.log('支付详情',res.data.data);
  148. this.setData({
  149. payList: res.data.data
  150. })
  151. }).fail( (error) => {
  152. })
  153. },
  154. /**
  155. * 生命周期函数--监听页面初次渲染完成
  156. */
  157. onReady: function () {
  158. //获取弹窗组件
  159. this.popup = this.selectComponent("#popup");
  160. },
  161. /**
  162. * 生命周期函数--监听页面显示
  163. */
  164. onShow: function () {
  165. },
  166. /**
  167. * 生命周期函数--监听页面隐藏
  168. */
  169. onHide: function () {
  170. },
  171. /**
  172. * 生命周期函数--监听页面卸载
  173. */
  174. onUnload: function () {
  175. },
  176. /**
  177. * 页面相关事件处理函数--监听用户下拉动作
  178. */
  179. onPullDownRefresh: function () {
  180. },
  181. /**
  182. * 页面上拉触底事件的处理函数
  183. */
  184. onReachBottom: function () {
  185. },
  186. /**
  187. * 用户点击右上角分享
  188. */
  189. onShareAppMessage: function () {
  190. }
  191. })