group-details.js 17 KB

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