grade-details.js 9.9 KB

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