grade-details.js 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  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. modalType: "text",
  39. isCloseShow: false,
  40. modalText: [{
  41. text: '您发起的团购尚未完成',
  42. type: 'bigOrange'
  43. },
  44. {
  45. text: '拼团成功,才能发起新的团购',
  46. type: 'bigOrange'
  47. },
  48. {
  49. text: '快喊朋友们一起助力',
  50. type: 'bigOrange'
  51. }
  52. ],
  53. isModalShow: false
  54. },
  55. //tab切换
  56. tabSwitch: function (e) {
  57. if(e.currentTarget.dataset.flag === "know" && this.data.knowFlag === false){
  58. this.setData({
  59. knowFlag: true,
  60. menuFlag: false
  61. })
  62. }
  63. if(e.currentTarget.dataset.flag === "menu" && this.data.menuFlag === false){
  64. this.setData({
  65. knowFlag: false,
  66. menuFlag: true
  67. })
  68. }
  69. },
  70. //获取团购信息并掉起支付
  71. pay: function ({
  72. currentTarget
  73. }) {
  74. const productId = this.data.productId;
  75. const groupId = currentTarget.dataset.id;
  76. const osType = this.data.isIOS ? 'IOS' : 'ANDROID';
  77. //开始发起团购
  78. httpRequestApi.SendGroupPurchas({
  79. productId,
  80. groupId,
  81. osType
  82. }).success((res) => {
  83. console.log('发起团购', res);
  84. if (res.data.message) {
  85. if(res.data.code == '803'){
  86. // this.setData({
  87. // modalType: 'text',
  88. // isModalShow: true
  89. // })
  90. wx.navigateTo({
  91. url:`/pages/groupPage/my-group/my-group`
  92. })
  93. }else{
  94. wx.showModal({
  95. title: '提示',
  96. content: res.data.message,
  97. success(res) {
  98. if (res.confirm) {
  99. console.log('用户点击确定')
  100. } else if (res.cancel) {
  101. console.log('用户点击取消')
  102. }
  103. }
  104. })
  105. }
  106. return false;
  107. }
  108. this.setData({
  109. orderId: res.data.data.groupPurchaseOrder.id
  110. })
  111. // 如果已经拥有当前课程,则无需支付,直接进入拼团成功页面
  112. if (res.data.data.groupPurchaseOrder.groupType === 'PROMOTION') {
  113. wx.redirectTo({
  114. url: `/pages/groupPage/make-money/make-money?productId=${productId}&id=${res.data.data.groupPurchaseOrder.id}&groupId=${groupId}`
  115. })
  116. wx.setNavigationBarTitle({
  117. title: '拼团详情'
  118. })
  119. // let that = this;
  120. // wx.showModal({
  121. // title: '重新发起团购',
  122. // content: '您会获得奖励哦',
  123. // success() {
  124. // console.log(res)
  125. // that.popup.close();
  126. // if (res.data.data.groupPurchaseOrder.headCount !== 1) {
  127. // setTimeout(() => {
  128. // wx.redirectTo({
  129. // url: `/pages/groupPage/make-money/make-money?productId=${productId}&id=${res.data.data.groupPurchaseOrder.id}&groupId=${groupId}`
  130. // })
  131. // wx.setNavigationBarTitle({
  132. // title: '拼团详情'
  133. // })
  134. // }, 1800)
  135. // }
  136. // }
  137. // })
  138. } else if (this.data.isIOS) {
  139. let that = this;
  140. wx.navigateTo({
  141. url: `/pages/groupPage/collage-details/collage-details?orderId=${that.data.orderId}`
  142. })
  143. wx.setNavigationBarTitle({
  144. title: '拼团详情'
  145. })
  146. // wx.showModal({
  147. // title: '提示',
  148. // content: '开团成功',
  149. // success(res) {
  150. // console.log(res)
  151. // that.popup.close();
  152. // setTimeout(() => {
  153. // wx.navigateTo({
  154. // url: `/pages/groupPage/collage-details/collage-details?orderId=${that.data.orderId}`
  155. // })
  156. // wx.setNavigationBarTitle({
  157. // title: '拼团详情'
  158. // })
  159. // }, 1800)
  160. // }
  161. // })
  162. } else {
  163. //掉起支付
  164. console.log(res.data.data.groupPurchaseOrder)
  165. this.setData({
  166. groupCount:res.data.data.groupPurchaseOrder.headcount
  167. })
  168. // this.prePayMap(res.data.data.prePayMap, res.data.data.groupPurchaseOrder.id, res.data.data.groupPurchaseOrder.headcount);
  169. this.prePayMap(res.data.data.prePayMap, res.data.data.groupPurchaseOrder.id);
  170. }
  171. }).fail((error) => {
  172. })
  173. },
  174. //支付
  175. prePayMap: function (prePayMap, orderId, num) {
  176. // this.setData({
  177. // modalType: 'image',
  178. // isModalShow: true
  179. // })
  180. // return
  181. console.log(prePayMap)
  182. console.log(orderId)
  183. console.log(num)
  184. const that = this;
  185. //console.log(new Date().getTime())
  186. wx.requestPayment({
  187. 'appId': prePayMap.appId,
  188. 'timeStamp': prePayMap.timeStamp,
  189. 'nonceStr': prePayMap.nonceStr,
  190. 'package': prePayMap.package,
  191. 'signType': 'MD5',
  192. 'paySign': prePayMap.sign,
  193. 'success': function (res) {
  194. that.setData({
  195. modalType: 'image',
  196. isModalShow: true
  197. })
  198. console.log('支付成功', res)
  199. // wx.showModal({
  200. // title: '提示',
  201. // content: '支付成功',
  202. // success(res) {
  203. // if (num !== 1) {
  204. // that.popup.close();
  205. // setTimeout(() => {
  206. // wx.navigateTo({
  207. // url: `/pages/groupPage/collage-details/collage-details?orderId=${orderId}`
  208. // })
  209. // wx.setNavigationBarTitle({
  210. // title: '拼团详情'
  211. // })
  212. // }, 1800)
  213. // } else {
  214. // wx.redirectTo({
  215. // url: `/pages/groupPage/grade-details/grade-details?productId=${that.data.productId}`
  216. // })
  217. // }
  218. // }
  219. // })
  220. },
  221. 'fail': function (res) {
  222. console.log('支付失败', res)
  223. }
  224. })
  225. },
  226. /**
  227. * 生命周期函数--监听页面加载
  228. */
  229. onLoad: function (options) {
  230. console.log(options)
  231. if (options.share) {
  232. this.setData({
  233. share: options.share
  234. })
  235. }
  236. // const productId = options.productId;
  237. this.getBookInfo(options.productId);
  238. this.areYouBookSuper(options.productId)
  239. this.getGroupInfo(options.productId)
  240. // if (productId) {
  241. this.setData({
  242. productId: options.productId
  243. })
  244. // }
  245. },
  246. // 课本鉴权
  247. areYouBookSuper: function (productId) {
  248. const productArr = [];
  249. productArr.push(productId);
  250. httpRequestApi.areYouSuper(productArr).success(res => {
  251. console.log(res)
  252. this.setData({
  253. imSuper: res.data.data
  254. })
  255. })
  256. },
  257. getBookInfo: function (productId) {
  258. //课本详情
  259. httpRequestApi.getBookDetail(wx.getStorageSync('uid'), productId).success((res) => {
  260. console.log('课本详情', res.data.data);
  261. const bookInfo = res.data.data.product;
  262. const lessonList = res.data.data.lessonList;
  263. wx.setNavigationBarTitle({
  264. title: '语文 ' + bookInfo.subTitle
  265. })
  266. const data = app.towxml.toJson(
  267. bookInfo.description,
  268. 'markdown',
  269. this
  270. )
  271. this.setData({
  272. titleIcon: bookInfo.bgImg,
  273. title: bookInfo.title,
  274. bookInfo: bookInfo.description,
  275. article: data
  276. })
  277. const lessonTemp = [];
  278. lessonList.forEach(item => {
  279. const temp = {};
  280. temp.id = item.id;
  281. temp.title = item.title;
  282. temp.readNum = item.readCount;
  283. lessonTemp.push(temp);
  284. });
  285. this.setData({
  286. lessonList: lessonTemp
  287. });
  288. })
  289. },
  290. getGroupInfo: function (productId) {
  291. //团购内容
  292. httpRequestApi.getGroupPurchaseInfo(productId).success((res) => {
  293. console.log(res)
  294. this.setData({
  295. payList: res.data.data
  296. })
  297. })
  298. },
  299. goToClass: function (e) {
  300. let id = e.currentTarget.dataset.id;
  301. let title = e.currentTarget.dataset.title;
  302. wx.navigateTo({
  303. url: `../../main/class/class?id=${id}&title=${title}`
  304. })
  305. },
  306. /**
  307. * 生命周期函数--监听页面初次渲染完成
  308. */
  309. onReady: function () {
  310. //获取弹窗组件
  311. this.popup = this.selectComponent("#popup");
  312. },
  313. modalConfirmHandler: function(){
  314. this.setData({
  315. isModalShow: false
  316. })
  317. if(this.data.modalType === 'image'){
  318. if (this.data.groupCount !== 1) {
  319. this.popup.close();
  320. setTimeout(() => {
  321. wx.navigateTo({
  322. url: `/pages/groupPage/collage-details/collage-details?orderId=${this.data.orderId}`
  323. })
  324. wx.setNavigationBarTitle({
  325. title: '拼团详情'
  326. })
  327. }, 1800)
  328. } else {
  329. wx.redirectTo({
  330. url: `/pages/groupPage/grade-details/grade-details?productId=${this.data.productId}`
  331. })
  332. }
  333. }
  334. },
  335. modalCloseHandler: function(){
  336. this.setData({
  337. isModalShow: false
  338. })
  339. }
  340. })