grade-details.js 11 KB

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