group-details.js 17 KB

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