group-details.js 18 KB

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