grade-details.js 7.2 KB

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