group-details.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659
  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. httpRequestApi.userIntoPage('pages/groupPage/group-details/group-details','团购详情页面').success((res)=>{
  373. })
  374. if (groupOrder.groupType === 'PROMOTION') {
  375. //this.data.joinUserList.unshift(res.data.data.organizer);
  376. this.setData({
  377. colonelName: res.data.data.organizer.wechatName
  378. })
  379. //this.data.surplusList.pop();
  380. this.setData({
  381. joinUserList: this.data.joinUserList,
  382. //surplusList: this.data.surplusList,
  383. surplusNum: this.data.surplusNum
  384. })
  385. }
  386. }).fail(error => {
  387. console.log('错误', error)
  388. })
  389. },
  390. // 弹成功信息框
  391. showSuccess: function (organizerUid, price) {
  392. if (wx.getStorageSync('uid') == organizerUid) {
  393. this.setData({
  394. typeOf: 'success',
  395. titles: '恭喜 !',
  396. headTextOne: '您发起的团购拼团成功',
  397. headTextTwo: '领袖体质魅力无穷!',
  398. content: [{
  399. text: " 您可以继续发起新的团购,",
  400. color: "#F97800"
  401. },
  402. {
  403. text: " 不再需要支付本课程费用",
  404. color: "#F97800"
  405. },
  406. {
  407. text: `拼团成功,您将得到奖学金`,
  408. color: "#F97800"
  409. }
  410. ],
  411. btnContent: '再接再厉 赚奖学金'
  412. }, () => {
  413. this.popup.close()
  414. })
  415. } else {
  416. this.setData({
  417. typeOf: 'success',
  418. titles: '拼团成功 ! ',
  419. headTextOne: '您参与的团购拼团成功',
  420. headTextTwo: '感谢团长的分享',
  421. content: [{
  422. text: " 您也可以发起新的团购",
  423. color: "#F97800"
  424. },
  425. {
  426. text: "作为新的发起人",
  427. color: "#F97800"
  428. },
  429. {
  430. text: " 您无需在支付本课程费用 ",
  431. color: "#F97800"
  432. },
  433. {
  434. text: `拼团成功,您将得到奖学金`,
  435. color: "#F97800"
  436. }
  437. ],
  438. btnContent: '我也试试 赚奖学金'
  439. }, () => {
  440. this.popup.close()
  441. })
  442. }
  443. },
  444. // 去详情页面
  445. goToDetail: function (detailId) {
  446. setTimeout(() => {
  447. wx.redirectTo({
  448. url: `/pages/groupPage/collage-details/collage-details?orderId=${detailId}&goBackHome=true`
  449. })
  450. wx.setNavigationBarTitle({
  451. title: '拼团详情'
  452. })
  453. }, 1000)
  454. },
  455. //跳到课程
  456. goToClass: function (e) {
  457. let id = e.currentTarget.dataset.id;
  458. let title = e.currentTarget.dataset.title;
  459. wx.navigateTo({
  460. url: `../../main/class/class?id=${id}&title=${title}`
  461. })
  462. },
  463. //再次发起团
  464. group: function () {
  465. // const orderId = this.data.orderId;
  466. // this.goToDetail(orderId);
  467. wx.navigateTo({
  468. url: `/pages/groupPage/grade-details/grade-details?productId=${this.data.productId}`
  469. })
  470. //拼团是否成功并弹窗
  471. // httpRequestApi.groupSuccess(orderId).success(res => {
  472. // console.log('团购是否成功', res.data.data)
  473. // debugger;
  474. // const status = res.data.data.status;
  475. // const uid = res.data.data.uid;
  476. // }).fail(error => {
  477. // console.log('错误', eroor)
  478. // })
  479. //this.openGroup();
  480. },
  481. /**
  482. * 生命周期函数--监听页面加载
  483. */
  484. onLoad: function (options) {
  485. console.log(this.data.isIOS)
  486. this.setData({
  487. options:options
  488. })
  489. if (options.scene || options.shareId) {
  490. console.log(123)
  491. this.setData({
  492. isLoading: true
  493. })
  494. }
  495. console.log('onload', options)
  496. wx.setNavigationBarTitle({
  497. title: '拼团详情'
  498. })
  499. getOpenidSessionKey((res) => {
  500. if (options.orderId) {
  501. const orderId = options.id;
  502. this.setData({
  503. orderId
  504. })
  505. this.jionSuccess(orderId);
  506. } else {
  507. // 从分享页面进入的
  508. const orderId = options.productId ? options.productId : options.scene ? options.scene.replace('QR', '') : options.shareId;
  509. this.setData({
  510. orderId
  511. })
  512. this.jionSuccess(orderId);
  513. }
  514. if (options.scene || options.shareId) {
  515. this.setData({
  516. goBackHome: true
  517. })
  518. }
  519. }, (error) => {
  520. this.setData({
  521. hide: !this.data.hide,
  522. onLoadOption: options
  523. })
  524. return;
  525. });
  526. },
  527. // 鉴权
  528. areYouSuperSecond: function (productId) {
  529. httpRequestApi.areYouSuperSecond(productId).success(() => {
  530. console.log(res)
  531. this.setData({
  532. imSuper: res.data.data.auth ? true : false,
  533. haveCreatedHelp: res.data.data.createdShare, // 创建过助力团
  534. haveJoinHelp: res.data.data.joinShare, // 参加过助力团
  535. })
  536. });
  537. // 增加一条记录
  538. const data = {
  539. "shareTypeEnum": "POSTER",
  540. "shareContentEnum": "GROUP",
  541. "productId": productId
  542. }
  543. if (this.data.option.shareId) {
  544. data.shareTypeEnum = 'LINK'
  545. httpRequestApi.shareTagRecord(data).success(res => {
  546. console.log(res)
  547. })
  548. }
  549. if (this.data.option.scene) {
  550. httpRequestApi.shareTagRecord(data).success(res => {
  551. console.log(res)
  552. })
  553. }
  554. },
  555. // 下拉刷新
  556. onPullDownRefresh: function () {
  557. //当前在团购页下拉加载
  558. this.setData({
  559. surplusList: []
  560. }, () => {
  561. this.jionSuccess(this.data.orderId);
  562. })
  563. wx.showNavigationBarLoading() //在标题栏中显示加载
  564. //模拟加载
  565. setTimeout(function () {
  566. wx.hideNavigationBarLoading() //完成停止加载
  567. wx.stopPullDownRefresh() //停止下拉刷新
  568. }, 1500);
  569. },
  570. // 获取课本详情
  571. getBooksInfo: function (productId) {
  572. //课本详情
  573. httpRequestApi.getBookDetail(wx.getStorageSync('uid'), productId).success((res) => {
  574. console.log('课本详情', res.data.data);
  575. const bookInfo = res.data.data.product;
  576. const lessonList = res.data.data.lessonList;
  577. const data = app.towxml.toJson(
  578. bookInfo.description,
  579. 'markdown',
  580. this
  581. )
  582. this.setData({
  583. titleIcon: bookInfo.bgImg,
  584. title: bookInfo.title,
  585. bookInfo: bookInfo.description,
  586. article: data
  587. })
  588. const lessonTemp = [];
  589. lessonList.forEach(item => {
  590. const temp = {};
  591. temp.id = item.id;
  592. temp.title = item.title;
  593. temp.readNum = item.readCount;
  594. lessonTemp.push(temp);
  595. });
  596. this.setData({
  597. lessonList: lessonTemp,
  598. });
  599. }).fail((error) => {
  600. })
  601. //全部课本
  602. httpRequestApi.getAllBooks(1, 10).success((res) => {
  603. console.log('全部课', res.data.data.list)
  604. res.data.data.list.forEach(element => {
  605. this.data.selectFlag.push(true);
  606. });
  607. this.setData({
  608. bookList: res.data.data.list,
  609. selectFlag: this.data.selectFlag
  610. })
  611. }).fail((error) => {
  612. console.log('错误', error)
  613. })
  614. },
  615. /**
  616. * 生命周期函数--监听页面初次渲染完成
  617. */
  618. onReady: function () {
  619. this.popup = this.selectComponent("#popupup");
  620. },
  621. judgeUser: function (callBack) {
  622. },
  623. modalConfirmHandler: function () {
  624. this.setData({
  625. isModalShow: false
  626. })
  627. if (this.data.modalType === 'image') {
  628. this.jionSuccess(this.data.orderId, this.data.joinGroupType);
  629. }
  630. },
  631. modalCloseHandler: function () {
  632. this.setData({
  633. isModalShow: false
  634. })
  635. if (this.data.modalType === 'image') {
  636. this.jionSuccess(this.data.orderId, this.data.joinGroupType);
  637. }
  638. },
  639. })