group-details.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  1. // pages/group-details/group-details.js
  2. import {
  3. getOpenidSessionKey
  4. } from '../../../utils/httpUtil';
  5. import httpRequestApi from '../../../utils/APIClient';
  6. import util from '../../../utils/util';
  7. const app = getApp();
  8. Page({
  9. /**
  10. * 页面的初始数据
  11. */
  12. data: {
  13. titleIcon: '',
  14. title: '',
  15. bookInfo: '',
  16. lessonList: [],
  17. surplusNum: '',
  18. joinUserList: [],
  19. surplusList: [],
  20. timeList: [],
  21. productId: '',
  22. groupId: '',
  23. orderId: '',
  24. typeOf: '',
  25. titles: '',
  26. headTextOne: '',
  27. headTextTwo: '',
  28. content: [],
  29. organizer: '',
  30. hide: true,
  31. isIPX: app.globalData.isIPX,
  32. bookList: [],
  33. sendGroupFlag: true,
  34. selectFlag: [],
  35. flag: true,
  36. colonelName: '',
  37. article: '',
  38. alertFlag: false,
  39. stillGoing: true,
  40. surplusNum: '1',
  41. timeList: ['6', '6', '6'],
  42. modalType: "image",
  43. isModalShow: false,
  44. modalCloseShow: false,
  45. modalText: [{
  46. text: '您已经参加过本次团购',
  47. type: 'bigOrange'
  48. },
  49. {
  50. text: '快喊朋友们一起助力',
  51. type: 'bigOrange'
  52. }
  53. ],
  54. groupStatus: false,
  55. formIsANAsshole: true,
  56. dataLoading: true,
  57. isLoading: false,
  58. isIOS: app.globalData.isIOS,
  59. damnDialogLine1: '您已拥有本课三年使用权或曾获得过体验权',
  60. // damnDialogLine2:'',
  61. damnDialogShow: false,
  62. knowFlag: true,
  63. menuFlag: false
  64. },
  65. //tab切换
  66. //tab切换
  67. tabSwitch: function (e) {
  68. if (e.currentTarget.dataset.flag === "know" && this.data.knowFlag === false) {
  69. this.setData({
  70. knowFlag: true,
  71. menuFlag: false
  72. })
  73. }
  74. if (e.currentTarget.dataset.flag === "menu" && this.data.menuFlag === false) {
  75. this.setData({
  76. knowFlag: false,
  77. menuFlag: true
  78. })
  79. }
  80. },
  81. jurisdiction: function () {
  82. //隐藏弹框
  83. this.setData({
  84. hide: !this.data.hide
  85. })
  86. //登录页信息
  87. this.onLoad(this.data.onLoadOption);
  88. },
  89. // 审核一定要通过啊
  90. //发起团购
  91. sendGroup: function () {
  92. this.setData({
  93. sendGroupFlag: !this.data.sendGroupFlag
  94. })
  95. },
  96. //选中团购课程
  97. selectImg: function ({
  98. currentTarget
  99. }) {
  100. const ind = currentTarget.dataset.ind;
  101. //判断单选
  102. this.data.selectFlag.forEach((item, index) => {
  103. if (index == ind) {
  104. this.data.selectFlag[ind] = !this.data.selectFlag[ind];
  105. } else {
  106. this.data.selectFlag[index] = true;
  107. }
  108. })
  109. this.setData({
  110. selectFlag: this.data.selectFlag
  111. })
  112. },
  113. //点击确定
  114. sure: function () {
  115. this.data.selectFlag.forEach((item, index) => {
  116. if (!item) {
  117. const productId = this.data.bookList[index].id;
  118. const title = this.data.bookList[index].title
  119. this.setData({
  120. sendGroupFlag: !this.data.sendGroupFlag
  121. })
  122. wx.navigateTo({
  123. url: `/pages/groupPage/grade-details/grade-details?productId=${productId}&title=${title}`
  124. })
  125. }
  126. })
  127. },
  128. //参团
  129. jionGroup: function (e) {
  130. // if (app.globalData.isIOS) {
  131. // this.showAlert();
  132. // return;
  133. // }
  134. console.log(this.data.haveTapJoin)
  135. if (this.data.haveTapJoin) {
  136. return false
  137. }
  138. this.setData({
  139. haveTapJoin: true
  140. })
  141. const orderId = this.data.orderId;
  142. const formId = e.detail.formId
  143. console.log(e)
  144. //开始发起团购
  145. httpRequestApi.JoinGroupPurchas(orderId, formId).success((res) => {
  146. console.log('参加团购', res);
  147. if (res.data.message) {
  148. // if (res.data.code === 801) {
  149. // this.setData({
  150. // isModalShow: true,
  151. // modalType: 'text'
  152. // })
  153. // } else {
  154. // wx.showModal({
  155. // title: '提示',
  156. // content: res.data.message,
  157. // success(res) {
  158. // if (res.confirm) {
  159. // console.log('用户点击确定')
  160. // } else if (res.cancel) {
  161. // console.log('用户点击取消')
  162. // }
  163. // }
  164. // })
  165. // }
  166. switch (res.data.code) {
  167. case 801:
  168. this.setData({
  169. isModalShow: true,
  170. modalType: 'text',
  171. haveTapJoin: false
  172. })
  173. break;
  174. case 802:
  175. this.setData({
  176. // damnDialogLine1:'您已拥有本课程使用权',
  177. // damnDialogLine2:'快去朗读吧',
  178. damnDialogShow: true,
  179. haveTapJoin: false
  180. })
  181. break;
  182. case 806:
  183. console.log(this.data.haveTapJoin)
  184. wx.pageScrollTo({
  185. scrollTop: 0,
  186. duration: 17
  187. })
  188. this.setData({
  189. // isModalShow: true,
  190. // modalType: 'text'
  191. alertFlag: true,
  192. haveTapJoin: false
  193. })
  194. // wx.navigateTo({
  195. // url:'/pages/groupPage/my-group/my-group'
  196. // })
  197. break;
  198. default:
  199. wx.showModal({
  200. title: '提示',
  201. content: res.data.message,
  202. success(res) {
  203. if (res.confirm) {
  204. console.log('用户点击确定')
  205. } else if (res.cancel) {
  206. console.log('用户点击取消')
  207. }
  208. this.setData({
  209. haveTapJoin: false
  210. })
  211. }
  212. })
  213. break;
  214. }
  215. return false;
  216. }
  217. //掉起支付
  218. if (res.data.data.groupPurchaseOrder.os === 'IOS') {
  219. this.jionSuccess(res.data.data.groupPurchaseOrder.id, 'join');
  220. } else {
  221. this.prePayMap(res.data.data.prePayMap, 'join');
  222. }
  223. }).fail((error) => {
  224. })
  225. },
  226. showAlert: function () {
  227. this.setData({
  228. alertFlag: !this.data.alertFlag
  229. })
  230. },
  231. //支付
  232. prePayMap: function (prePayMap, type) {
  233. console.log(prePayMap)
  234. // const that = this;
  235. this.setData({
  236. joinGroupType: type
  237. })
  238. wx.requestPayment({
  239. 'appId': prePayMap.appId,
  240. 'timeStamp': prePayMap.timeStamp,
  241. 'nonceStr': prePayMap.nonceStr,
  242. 'package': prePayMap.package,
  243. 'signType': 'MD5',
  244. 'paySign': prePayMap.sign,
  245. 'success': res => {
  246. console.log('支付成功')
  247. this.setData({
  248. isModalShow: true,
  249. haveTapJoin: false
  250. })
  251. // const type1 = type;
  252. // wx.showModal({
  253. // title: '提示',
  254. // content: '支付成功',
  255. // success(res) {
  256. // //获取拼团信息
  257. // console.log(that.data.orderId)
  258. // wx.showLoading({
  259. // title: '支付查询中...',
  260. // mask: true
  261. // })
  262. // setTimeout(() => {
  263. // wx.hideLoading();
  264. // console.log(that.data.orderId)
  265. // that.jionSuccess(that.data.orderId, type1);
  266. // // that.groupSuccess(orderId, detailId);
  267. // }, 800)
  268. // }
  269. // })
  270. },
  271. 'fail': res => {
  272. console.log('支付失败', res)
  273. this.setData({
  274. haveTapJoin: false
  275. })
  276. }
  277. })
  278. },
  279. //拼团详情
  280. jionSuccess: function (orderId, type) {
  281. httpRequestApi.getMygroupInfo(orderId).success(res => {
  282. this.data.surplusList = [];
  283. // 通过分享进入的用户,如果已经参加过本次团购,则跳转进入邀请好友的页面
  284. console.log(res)
  285. // if (this.data.goBackHome) {
  286. const joinUser = res.data.data.joinUserList;
  287. const groupId = res.data.data.groupPurchaseOrder.id;
  288. const myUid = wx.getStorageSync('uid');
  289. this.setData({
  290. haveTapJoin: false
  291. })
  292. if (myUid === res.data.data.organizer.uid) {
  293. wx.redirectTo({
  294. url: `../collage-details/collage-details?orderId=${groupId}&goBackHome=${this.data.goBackHome}`
  295. })
  296. return;
  297. }
  298. joinUser.forEach(item => {
  299. if (item.uid === myUid) {
  300. wx.redirectTo({
  301. url: `../collage-details/collage-details?orderId=${groupId}&goBackHome=${this.data.goBackHome}`
  302. })
  303. return;
  304. }
  305. })
  306. // }
  307. console.log('拼团详情', res);
  308. const groupOrder = res.data.data.groupPurchaseOrder;
  309. const surplusNum = groupOrder.headcount - groupOrder.joinCount;
  310. if (this.data.article === '') {
  311. this.getBooksInfo(res.data.data.groupPurchaseOrder.productId)
  312. }
  313. this.setData({
  314. organizer: groupOrder.organizer,
  315. productId: res.data.data.groupPurchaseOrder.productId
  316. })
  317. for (var i = 0; i < surplusNum; i++) {
  318. this.data.surplusList.push(1);
  319. }
  320. if (type === 'join') {
  321. // this.data.surplusList.pop();
  322. if (groupOrder.status === 'SUCCESSED') {
  323. this.showSuccess(groupOrder.organizer, groupOrder.organizerPrice)
  324. } else {
  325. this.goToDetail(groupOrder.id)
  326. }
  327. } else if (type === 'create') {
  328. this.showSuccess(groupOrder.organizer, groupOrder.organizerPrice)
  329. this.setData({
  330. orderId: groupOrder.id
  331. })
  332. } else {
  333. // for (var i = 0; i < surplusNum; i++) {
  334. // this.data.surplusList.push(1);
  335. // }
  336. }
  337. let timeList = [];
  338. // || groupOrder.status ==='SUCCESSED'
  339. const stillGoing = groupOrder.closeTime - Date.parse(new Date()) <= 0 ? false : true
  340. if (stillGoing) {
  341. timeList = util.lastHoursInGroup(groupOrder.closeTime - Date.parse(new Date()));
  342. console.log(timeList)
  343. }
  344. // 分享进来的并且团购失效 就跳转到详情页面
  345. // if(this.data.goBackHome && (surplusNum ===0 || !stillGoing) ){
  346. // console.log(' productID>>>>>>>>>>>>>>>>'+ res.data.data.groupPurchaseOrder.productId)
  347. // wx.navigateTo({
  348. // url: `/pages/groupPage/grade-details/grade-details?productId=${res.data.data.groupPurchaseOrder.productId}`
  349. // })
  350. // }
  351. // const groupStatus = false;
  352. if (groupOrder.status === 'SUCCESSED') {
  353. this.data.groupStatus = true
  354. }
  355. this.setData({
  356. surplusNum,
  357. joinUserList: res.data.data.joinUserList,
  358. surplusList: this.data.surplusList,
  359. timeList,
  360. stillGoing,
  361. groupStatus: this.data.groupStatus,
  362. dataLoading: false,
  363. groupOSType: groupOrder.os,
  364. isLoading: false
  365. }, () => {
  366. if (groupOrder.os === 'ANDROID' && app.globalData.isIOS) {
  367. wx.redirectTo({
  368. url: `/pages/groupPage/grade-details/grade-details?productId=${res.data.data.groupPurchaseOrder.productId}&goBackHome=1`
  369. })
  370. }
  371. })
  372. if (groupOrder.groupType === 'PROMOTION') {
  373. //this.data.joinUserList.unshift(res.data.data.organizer);
  374. this.setData({
  375. colonelName: res.data.data.organizer.wechatName
  376. })
  377. //this.data.surplusList.pop();
  378. this.setData({
  379. joinUserList: this.data.joinUserList,
  380. //surplusList: this.data.surplusList,
  381. surplusNum: this.data.surplusNum
  382. })
  383. }
  384. }).fail(error => {
  385. console.log('错误', error)
  386. })
  387. },
  388. // 弹成功信息框
  389. showSuccess: function (organizerUid, price) {
  390. if (wx.getStorageSync('uid') == organizerUid) {
  391. this.setData({
  392. typeOf: 'success',
  393. titles: '恭喜 !',
  394. headTextOne: '您发起的团购拼团成功',
  395. headTextTwo: '领袖体质魅力无穷!',
  396. content: [{
  397. text: " 您可以继续发起新的团购,",
  398. color: "#F97800"
  399. },
  400. {
  401. text: " 不再需要支付本课程费用",
  402. color: "#F97800"
  403. },
  404. {
  405. text: `拼团成功,您将得到奖学金`,
  406. color: "#F97800"
  407. }
  408. ],
  409. btnContent: '再接再厉 赚奖学金'
  410. }, () => {
  411. this.popup.close()
  412. })
  413. } else {
  414. this.setData({
  415. typeOf: 'success',
  416. titles: '拼团成功 ! ',
  417. headTextOne: '您参与的团购拼团成功',
  418. headTextTwo: '感谢团长的分享',
  419. content: [{
  420. text: " 您也可以发起新的团购",
  421. color: "#F97800"
  422. },
  423. {
  424. text: "作为新的发起人",
  425. color: "#F97800"
  426. },
  427. {
  428. text: " 您无需在支付本课程费用 ",
  429. color: "#F97800"
  430. },
  431. {
  432. text: `拼团成功,您将得到奖学金`,
  433. color: "#F97800"
  434. }
  435. ],
  436. btnContent: '我也试试 赚奖学金'
  437. }, () => {
  438. this.popup.close()
  439. })
  440. }
  441. },
  442. // 去详情页面
  443. goToDetail: function (detailId) {
  444. setTimeout(() => {
  445. wx.redirectTo({
  446. url: `/pages/groupPage/collage-details/collage-details?orderId=${detailId}&goBackHome=true`
  447. })
  448. wx.setNavigationBarTitle({
  449. title: '拼团详情'
  450. })
  451. }, 1000)
  452. },
  453. //跳到课程
  454. goToClass: function (e) {
  455. let id = e.currentTarget.dataset.id;
  456. let title = e.currentTarget.dataset.title;
  457. wx.navigateTo({
  458. url: `../../main/class/class?id=${id}&title=${title}`
  459. })
  460. },
  461. //再次发起团
  462. group: function () {
  463. // const orderId = this.data.orderId;
  464. // this.goToDetail(orderId);
  465. wx.navigateTo({
  466. url: `/pages/groupPage/grade-details/grade-details?productId=${this.data.productId}`
  467. })
  468. //拼团是否成功并弹窗
  469. // httpRequestApi.groupSuccess(orderId).success(res => {
  470. // console.log('团购是否成功', res.data.data)
  471. // debugger;
  472. // const status = res.data.data.status;
  473. // const uid = res.data.data.uid;
  474. // }).fail(error => {
  475. // console.log('错误', eroor)
  476. // })
  477. //this.openGroup();
  478. },
  479. /**
  480. * 生命周期函数--监听页面加载
  481. */
  482. onLoad: function (options) {
  483. console.log(this.data.isIOS)
  484. if (options.scene || options.shareId) {
  485. console.log(123)
  486. this.setData({
  487. isLoading: true
  488. })
  489. }
  490. console.log('onload', options)
  491. wx.setNavigationBarTitle({
  492. title: '拼团详情'
  493. })
  494. getOpenidSessionKey((res) => {
  495. if (options.orderId) {
  496. const orderId = options.id;
  497. this.setData({
  498. orderId
  499. })
  500. this.jionSuccess(orderId);
  501. } else {
  502. // 从分享页面进入的
  503. const orderId = options.productId ? options.productId : options.scene ? options.scene.replace('QR', '') : options.shareId;
  504. this.setData({
  505. orderId
  506. })
  507. this.jionSuccess(orderId);
  508. }
  509. if (options.scene || options.shareId) {
  510. this.setData({
  511. goBackHome: true
  512. })
  513. }
  514. }, (error) => {
  515. this.setData({
  516. hide: !this.data.hide,
  517. onLoadOption: options
  518. })
  519. return;
  520. });
  521. },
  522. // 鉴权
  523. areYouSuperSecond: function (productId) {
  524. httpRequestApi.areYouSuperSecond(productId).success(() => {
  525. console.log(res)
  526. this.setData({
  527. imSuper: res.data.data.auth ? true : false,
  528. haveCreatedHelp: res.data.data.createdShare, // 创建过助力团
  529. haveJoinHelp: res.data.data.joinShare, // 参加过助力团
  530. })
  531. });
  532. },
  533. // 下拉刷新
  534. onPullDownRefresh: function () {
  535. //当前在团购页下拉加载
  536. this.setData({
  537. surplusList: []
  538. }, () => {
  539. this.jionSuccess(this.data.orderId);
  540. })
  541. wx.showNavigationBarLoading() //在标题栏中显示加载
  542. //模拟加载
  543. setTimeout(function () {
  544. wx.hideNavigationBarLoading() //完成停止加载
  545. wx.stopPullDownRefresh() //停止下拉刷新
  546. }, 1500);
  547. },
  548. // 获取课本详情
  549. getBooksInfo: function (productId) {
  550. //课本详情
  551. httpRequestApi.getBookDetail(wx.getStorageSync('uid'), productId).success((res) => {
  552. console.log('课本详情', res.data.data);
  553. const bookInfo = res.data.data.product;
  554. const lessonList = res.data.data.lessonList;
  555. const data = app.towxml.toJson(
  556. bookInfo.description,
  557. 'markdown',
  558. this
  559. )
  560. this.setData({
  561. titleIcon: bookInfo.bgImg,
  562. title: bookInfo.title,
  563. bookInfo: bookInfo.description,
  564. article: data
  565. })
  566. const lessonTemp = [];
  567. lessonList.forEach(item => {
  568. const temp = {};
  569. temp.id = item.id;
  570. temp.title = item.title;
  571. temp.readNum = item.readCount;
  572. lessonTemp.push(temp);
  573. });
  574. this.setData({
  575. lessonList: lessonTemp,
  576. });
  577. }).fail((error) => {
  578. })
  579. //全部课本
  580. httpRequestApi.getAllBooks(1, 10).success((res) => {
  581. console.log('全部课', res.data.data.list)
  582. res.data.data.list.forEach(element => {
  583. this.data.selectFlag.push(true);
  584. });
  585. this.setData({
  586. bookList: res.data.data.list,
  587. selectFlag: this.data.selectFlag
  588. })
  589. }).fail((error) => {
  590. console.log('错误', error)
  591. })
  592. },
  593. /**
  594. * 生命周期函数--监听页面初次渲染完成
  595. */
  596. onReady: function () {
  597. this.popup = this.selectComponent("#popupup");
  598. },
  599. judgeUser: function (callBack) {
  600. },
  601. modalConfirmHandler: function () {
  602. this.setData({
  603. isModalShow: false
  604. })
  605. if (this.data.modalType === 'image') {
  606. this.jionSuccess(this.data.orderId, this.data.joinGroupType);
  607. }
  608. },
  609. modalCloseHandler: function () {
  610. this.setData({
  611. isModalShow: false
  612. })
  613. if (this.data.modalType === 'image') {
  614. this.jionSuccess(this.data.orderId, this.data.joinGroupType);
  615. }
  616. },
  617. })