grade-details.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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. const osType = this.data.isIOS ? 'IOS' : 'ANDROID';
  50. //开始发起团购
  51. httpRequestApi.SendGroupPurchas({
  52. productId,
  53. groupId,
  54. osType
  55. }).success((res) => {
  56. console.log('发起团购', res);
  57. this.setData({
  58. orderId: res.data.data.groupPurchaseOrder.id
  59. })
  60. if (res.data.message) {
  61. wx.showModal({
  62. title: '提示',
  63. content: res.data.message,
  64. success(res) {
  65. if (res.confirm) {
  66. console.log('用户点击确定')
  67. } else if (res.cancel) {
  68. console.log('用户点击取消')
  69. }
  70. }
  71. })
  72. return false;
  73. }
  74. // this.data.content[2].text = res.data.data.groupPurchaseOrder.organizerPrice === 0 ? '' : `在限定时间内内成功拼团,您将得到${res.data.data.groupPurchaseOrder.organizerPrice}元的奖励金哦。`
  75. // this.setData({
  76. // content: this.data.content
  77. // })
  78. // 如果已经拥有当前课程,则无需支付,直接进入拼团成功页面
  79. if (res.data.data.groupPurchaseOrder.groupType === 'PROMOTION') {
  80. let that = this;
  81. wx.showModal({
  82. title: '重新发起团购',
  83. content: '您会获得奖励哦',
  84. success(res) {
  85. console.log(res)
  86. that.popup.close();
  87. if (res.data.data.groupPurchaseOrder.headCount !== 1) {
  88. setTimeout(() => {
  89. wx.redirectTo({
  90. url: `/pages/groupPage/make-money/make-money?productId=${productId}&id=${res.data.data.groupPurchaseOrder.id}&groupId=${groupId}`
  91. })
  92. wx.setNavigationBarTitle({
  93. title: '拼团详情'
  94. })
  95. }, 1800)
  96. }
  97. }
  98. })
  99. } else if (this.data.isIOS) {
  100. let that = this;
  101. wx.showModal({
  102. title: '提示',
  103. content: '开团成功',
  104. success(res) {
  105. console.log(res)
  106. that.popup.close();
  107. setTimeout(() => {
  108. wx.navigateTo({
  109. url: `/pages/groupPage/collage-details/collage-details?orderId=${that.data.orderId}`
  110. })
  111. wx.setNavigationBarTitle({
  112. title: '拼团详情'
  113. })
  114. }, 1800)
  115. }
  116. })
  117. } else {
  118. //掉起支付
  119. this.prePayMap(res.data.data.prePayMap, res.data.data.groupPurchaseOrder.id, res.data.data.groupPurchaseOrder.headCount);
  120. }
  121. }).fail((error) => {
  122. })
  123. },
  124. //支付
  125. prePayMap: function (prePayMap, orderId, num) {
  126. console.log(prePayMap)
  127. const that = this;
  128. //console.log(new Date().getTime())
  129. wx.requestPayment({
  130. 'appId': prePayMap.appId,
  131. 'timeStamp': prePayMap.timeStamp,
  132. 'nonceStr': prePayMap.nonceStr,
  133. 'package': prePayMap.package,
  134. 'signType': 'MD5',
  135. 'paySign': prePayMap.sign,
  136. 'success': function (res) {
  137. console.log('支付成功', res)
  138. wx.showModal({
  139. title: '提示',
  140. content: '支付成功',
  141. success(res) {
  142. console.log(res)
  143. that.popup.close();
  144. if (num !== 1) {
  145. setTimeout(() => {
  146. wx.navigateTo({
  147. url: `/pages/groupPage/collage-details/collage-details?orderId=${orderId}`
  148. })
  149. wx.setNavigationBarTitle({
  150. title: '拼团详情'
  151. })
  152. }, 1800)
  153. }
  154. }
  155. })
  156. },
  157. 'fail': function (res) {
  158. console.log('支付失败', res)
  159. }
  160. })
  161. },
  162. /**
  163. * 生命周期函数--监听页面加载
  164. */
  165. onLoad: function (options) {
  166. console.log(options)
  167. if (options.share) {
  168. this.setData({
  169. share: options.share
  170. })
  171. }
  172. // const productId = options.productId;
  173. this.getBookInfo(options.productId);
  174. this.areYouBookSuper(options.productId)
  175. this.getGroupInfo(options.productId)
  176. // if (productId) {
  177. this.setData({
  178. productId: options.productId
  179. })
  180. // }
  181. },
  182. // 课本鉴权
  183. areYouBookSuper: function (productId) {
  184. const productArr = [];
  185. productArr.push(productId);
  186. httpRequestApi.areYouSuper(productArr).success(res => {
  187. console.log(res)
  188. this.setData({
  189. imSuper: res.data.data
  190. })
  191. })
  192. },
  193. getBookInfo: function (productId) {
  194. //课本详情
  195. httpRequestApi.getBookDetail(wx.getStorageSync('uid'), productId).success((res) => {
  196. console.log('课本详情', res.data.data);
  197. const bookInfo = res.data.data.product;
  198. const lessonList = res.data.data.lessonList;
  199. wx.setNavigationBarTitle({
  200. title: bookInfo.title
  201. })
  202. const data = app.towxml.toJson(
  203. bookInfo.description,
  204. 'markdown',
  205. this
  206. )
  207. this.setData({
  208. titleIcon: bookInfo.bgImg,
  209. title: bookInfo.title,
  210. bookInfo: bookInfo.description,
  211. article: data
  212. })
  213. const lessonTemp = [];
  214. lessonList.forEach(item => {
  215. const temp = {};
  216. temp.id = item.id;
  217. temp.title = item.title;
  218. temp.readNum = item.readCount;
  219. lessonTemp.push(temp);
  220. });
  221. this.setData({
  222. lessonList: lessonTemp
  223. });
  224. })
  225. },
  226. getGroupInfo: function (productId) {
  227. //团购内容
  228. httpRequestApi.getGroupPurchaseInfo(productId).success((res) => {
  229. console.log(res)
  230. this.setData({
  231. payList: res.data.data
  232. })
  233. })
  234. },
  235. goToClass: function (e) {
  236. let id = e.currentTarget.dataset.id;
  237. let title = e.currentTarget.dataset.title;
  238. wx.navigateTo({
  239. url: `../../main/class/class?id=${id}&title=${title}`
  240. })
  241. },
  242. /**
  243. * 生命周期函数--监听页面初次渲染完成
  244. */
  245. onReady: function () {
  246. //获取弹窗组件
  247. this.popup = this.selectComponent("#popup");
  248. }
  249. })