grade-details.js 6.9 KB

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