grade-details.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. // pages/grade-details/grade-details.js
  2. import httpRequestApi from '../../../utils/APIClient';
  3. const app = getApp();
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. productId: '',
  10. payList: [],
  11. titleIcon: '',
  12. title: '',
  13. bookInfo: '',
  14. lessonList: [],
  15. content: [{
  16. text: "转发给自己的朋友们",
  17. color: "#000"
  18. },
  19. {
  20. text: " 分享好课,追随您一起学习进步",
  21. color: "#000"
  22. },
  23. {
  24. text: " 您的魅力不是吹的!",
  25. color: "#000"
  26. },
  27. {
  28. text: `在限定时间内成功拼团,您将得到奖学金。`,
  29. color: "#FF4600"
  30. }
  31. ],
  32. share: false,
  33. isIPX: app.globalData.isIPX,
  34. isIOS: app.globalData.isIOS,
  35. flag: true
  36. },
  37. //tab切换
  38. tabSwitch: function () {
  39. this.setData({
  40. flag: !this.data.flag
  41. })
  42. },
  43. //获取团购信息并掉起支付
  44. pay: function ({
  45. currentTarget
  46. }) {
  47. const productId = this.data.productId;
  48. const groupId = currentTarget.dataset.id;
  49. //开始发起团购
  50. httpRequestApi.SendGroupPurchas({
  51. productId,
  52. groupId
  53. }).success((res) => {
  54. console.log('发起团购', res);
  55. // wx.navigateTo({
  56. // url: `/pages/groupPage/collage-details/collage-details`
  57. // })
  58. if (res.data.message) {
  59. wx.showModal({
  60. title: '提示',
  61. content: res.data.message,
  62. success(res) {
  63. if (res.confirm) {
  64. console.log('用户点击确定')
  65. } else if (res.cancel) {
  66. console.log('用户点击取消')
  67. }
  68. }
  69. })
  70. return false;
  71. }
  72. this.data.content[2].text = res.data.data.groupPurchaseOrder.organizerPrice === 0 ? '' : `在限定时间内内成功拼团,您将得到${res.data.data.groupPurchaseOrder.organizerPrice}元的奖励金哦。`
  73. this.setData({
  74. content: this.data.content
  75. })
  76. // 如果已经拥有当前课程,则无需支付,直接进入拼团成功页面
  77. if (res.data.data.groupPurchaseOrder.group === 'PROMOTION') {
  78. wx.showModal({
  79. title: '重新发起团购',
  80. content: '您会获得奖励哦',
  81. success(res) {
  82. console.log(res)
  83. that.popup.close();
  84. if (res.data.data.groupPurchaseOrder.headCount !== 1) {
  85. setTimeout(() => {
  86. wx.navigateTo({
  87. url: `/pages/groupPage/make-money/make-money?productId=${productId}&id=${res.data.data.groupPurchaseOrder.id}&groupId=${groupId}`
  88. })
  89. wx.setNavigationBarTitle({
  90. title: '拼团详情'
  91. })
  92. }, 3000)
  93. }
  94. }
  95. })
  96. } else {
  97. //掉起支付
  98. this.prePayMap(res.data.data.prePayMap, res.data.data.groupPurchaseOrder.id, res.data.data.groupPurchaseOrder.headCount);
  99. }
  100. }).fail((error) => {
  101. })
  102. },
  103. //支付
  104. prePayMap: function (prePayMap, orderId, num) {
  105. console.log(prePayMap)
  106. const that = this;
  107. //console.log(new Date().getTime())
  108. wx.requestPayment({
  109. 'appId': prePayMap.appId,
  110. 'timeStamp': prePayMap.timeStamp,
  111. 'nonceStr': prePayMap.nonceStr,
  112. 'package': prePayMap.package,
  113. 'signType': 'MD5',
  114. 'paySign': prePayMap.sign,
  115. 'success': function (res) {
  116. console.log('支付成功',res)
  117. wx.showModal({
  118. title: '提示',
  119. content: '支付成功',
  120. success(res) {
  121. console.log(res)
  122. that.popup.close();
  123. if (num !== 1) {
  124. setTimeout(() => {
  125. wx.navigateTo({
  126. url: `/pages/groupPage/collage-details/collage-details?orderId=${orderId}`
  127. })
  128. wx.setNavigationBarTitle({
  129. title: '拼团详情'
  130. })
  131. }, 3000)
  132. }
  133. }
  134. })
  135. },
  136. 'fail': function (res) {
  137. console.log('支付失败', res)
  138. }
  139. })
  140. },
  141. /**
  142. * 生命周期函数--监听页面加载
  143. */
  144. onLoad: function (options) {
  145. // if (app.globalData.isIOS) {
  146. // wx.redirectTo({
  147. // url: '../../index/index'
  148. // })
  149. // return
  150. // }
  151. console.log(options)
  152. if(options.share){
  153. this.setData({
  154. share: options.share
  155. })
  156. }
  157. // wx.setNavigationBarTitle({
  158. // title: options.title
  159. // })
  160. const productId = options.productId;
  161. if (productId) {
  162. this.setData({
  163. productId
  164. })
  165. }
  166. //课本详情
  167. httpRequestApi.getBookDetail(wx.getStorageSync('uid'), productId).success((res) => {
  168. console.log('课本详情', res.data.data);
  169. const bookInfo = res.data.data.product;
  170. const lessonList = res.data.data.lessonList;
  171. wx.setNavigationBarTitle({
  172. title: bookInfo.title
  173. })
  174. const data = app.towxml.toJson(
  175. bookInfo.description,
  176. 'markdown',
  177. this
  178. )
  179. // data.theme = 'light';
  180. // this.setData({
  181. // article: data
  182. // })
  183. this.setData({
  184. titleIcon: bookInfo.bgImg,
  185. title: bookInfo.title,
  186. bookInfo: bookInfo.description,
  187. article: data
  188. })
  189. const lessonTemp = [];
  190. lessonList.forEach(item => {
  191. const temp = {};
  192. temp.id = item.id;
  193. temp.title = item.title;
  194. temp.readNum = item.readCount;
  195. lessonTemp.push(temp);
  196. });
  197. this.setData({
  198. lessonList: lessonTemp
  199. });
  200. }).fail((error) => {
  201. })
  202. //支付详情
  203. httpRequestApi.getGroupPurchaseInfo(productId).success((res) => {
  204. console.log('支付详情', res.data.data);
  205. this.setData({
  206. payList: res.data.data
  207. })
  208. }).fail((error) => {
  209. })
  210. },
  211. goToClass: function (e) {
  212. let id = e.currentTarget.dataset.id;
  213. let title = e.currentTarget.dataset.title;
  214. wx.navigateTo({
  215. url: `../../main/class/class?id=${id}&title=${title}`
  216. })
  217. },
  218. /**
  219. * 生命周期函数--监听页面初次渲染完成
  220. */
  221. onReady: function () {
  222. //获取弹窗组件
  223. this.popup = this.selectComponent("#popup");
  224. },
  225. /**
  226. * 生命周期函数--监听页面显示
  227. */
  228. onShow: function () {
  229. },
  230. /**
  231. * 生命周期函数--监听页面隐藏
  232. */
  233. onHide: function () {
  234. },
  235. /**
  236. * 生命周期函数--监听页面卸载
  237. */
  238. onUnload: function () {
  239. },
  240. /**
  241. * 页面相关事件处理函数--监听用户下拉动作
  242. */
  243. onPullDownRefresh: function () {
  244. },
  245. /**
  246. * 页面上拉触底事件的处理函数
  247. */
  248. onReachBottom: function () {
  249. },
  250. /**
  251. * 用户点击右上角分享
  252. */
  253. onShareAppMessage: function () {
  254. }
  255. })