group-details.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  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. flag: true,
  33. colonelName: '',
  34. article: '',
  35. alertFlag: false,
  36. stillGoing: true,
  37. surplusNum: '1',
  38. timeList: ['6', '6', '6'],
  39. modalType: "image",
  40. isModalShow: false,
  41. modalCloseShow: false,
  42. modalText: [{
  43. text: '您已经参加过本次团购',
  44. type: 'bigOrange'
  45. },
  46. {
  47. text: '快喊朋友们一起助力',
  48. type: 'bigOrange'
  49. }
  50. ],
  51. groupStatus: false,
  52. formIsANAsshole: true,
  53. dataLoading: true,
  54. isLoading: false,
  55. isIOS: app.globalData.isIOS,
  56. damnDialogLine1: '您已拥有本课三年使用权或曾获得过体验权',
  57. // damnDialogLine2:'',
  58. damnDialogShow: false,
  59. knowFlag: true,
  60. menuFlag: false,
  61. ifGroupSuccessed: false,
  62. groupOSType: 'IOS',
  63. hideBottomBtn: true
  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. jionGroup: function (e) {
  91. console.log(this.data.haveTapJoin)
  92. if (this.data.haveTapJoin) {
  93. return false
  94. }
  95. this.setData({
  96. haveTapJoin: true
  97. })
  98. const orderId = this.data.orderId;
  99. const formId = e.detail.formId
  100. console.log(e)
  101. //开始发起团购
  102. httpRequestApi.JoinGroupPurchas(orderId, formId).success((res) => {
  103. console.log('参加团购', res);
  104. if (res.data.message) {
  105. switch (res.data.code) {
  106. case 801:
  107. this.setData({
  108. isModalShow: true,
  109. modalType: 'text',
  110. haveTapJoin: false
  111. })
  112. break;
  113. case 802:
  114. this.setData({
  115. damnDialogShow: true,
  116. haveTapJoin: false
  117. })
  118. break;
  119. case 806:
  120. console.log(this.data.haveTapJoin)
  121. wx.pageScrollTo({
  122. scrollTop: 0,
  123. duration: 17
  124. })
  125. this.setData({
  126. alertFlag: true,
  127. haveTapJoin: false
  128. })
  129. break;
  130. default:
  131. wx.showModal({
  132. title: '提示',
  133. content: res.data.message,
  134. success(res) {
  135. if (res.confirm) {
  136. console.log('用户点击确定')
  137. } else if (res.cancel) {
  138. console.log('用户点击取消')
  139. }
  140. this.setData({
  141. haveTapJoin: false
  142. })
  143. }
  144. })
  145. break;
  146. }
  147. return false;
  148. }
  149. //掉起支付
  150. if (res.data.data.groupPurchaseOrder.os === 'IOS') {
  151. this.getGroupInfo(res.data.data.groupPurchaseOrder.id);
  152. } else {
  153. this.prePayMap(res.data.data.prePayMap);
  154. }
  155. })
  156. },
  157. showAlert: function () {
  158. this.setData({
  159. alertFlag: !this.data.alertFlag
  160. })
  161. },
  162. //支付
  163. prePayMap: function (prePayMap) {
  164. console.log(prePayMap)
  165. wx.requestPayment({
  166. 'appId': prePayMap.appId,
  167. 'timeStamp': prePayMap.timeStamp,
  168. 'nonceStr': prePayMap.nonceStr,
  169. 'package': prePayMap.package,
  170. 'signType': 'MD5',
  171. 'paySign': prePayMap.sign,
  172. 'success': res => {
  173. this.setData({
  174. isModalShow: true,
  175. haveTapJoin: false
  176. })
  177. },
  178. 'fail': res => {
  179. console.log('支付失败', res)
  180. this.setData({
  181. haveTapJoin: false
  182. })
  183. }
  184. })
  185. },
  186. //拼团详情
  187. getGroupInfo: function (orderId) {
  188. httpRequestApi.getMygroupInfo(orderId).success(res => {
  189. const groupOrder = res.data.data.groupPurchaseOrder;
  190. if (groupOrder.os === 'ANDROID' && app.globalData.isIOS) {
  191. wx.redirectTo({
  192. url: `/pages/groupPage/grade-details/grade-details?productId=${res.data.data.groupPurchaseOrder.productId}&goBackHome=1`
  193. })
  194. return;
  195. }
  196. // 团员进入collage页面
  197. const myUid = wx.getStorageSync('uid');
  198. if (myUid === groupOrder.organizer) {
  199. wx.redirectTo({
  200. url: `../collage-details/collage-details?orderId=${orderId}&goBackHome=${this.data.goBackHome}`
  201. })
  202. return;
  203. }
  204. res.data.data.joinUserList.forEach(item => {
  205. if (item.uid === myUid) {
  206. wx.redirectTo({
  207. url: `../collage-details/collage-details?orderId=${orderId}&goBackHome=${this.data.goBackHome}`
  208. })
  209. return;
  210. }
  211. })
  212. const surplusNum = groupOrder.headcount - groupOrder.joinCount;
  213. this.setData({
  214. organizerUid: groupOrder.organizer,
  215. ifGroupSuccessed: groupOrder.status === 'SUCCESSED' ? true : false
  216. })
  217. for (var i = 0; i < surplusNum; i++) {
  218. this.data.surplusList.push(1);
  219. }
  220. // 剩余时间 如果团购已结束则不显示
  221. let timeLast = '';
  222. const stillGoing = groupOrder.closeTime - Date.parse(new Date()) <= 0 ? false : true
  223. if (stillGoing) {
  224. timeLast = util.lastHours(groupOrder.closeTime - Date.parse(new Date()));
  225. }
  226. this.setData({
  227. groupPurchaseInfo: res.data.data.groupPurchaseInfo,
  228. organizer: res.data.data.organizer,
  229. surplusNum,
  230. joinUserList: res.data.data.joinUserList,
  231. surplusList: this.data.surplusList,
  232. timeLast,
  233. stillGoing,
  234. productId: groupOrder.productId,
  235. groupId: groupOrder.groupId,
  236. rewardMoney: res.data.data.groupPurchaseInfo.organizerPrice / 100,
  237. dataLoading: false,
  238. groupOsType: groupOrder.os,
  239. isLoading: false
  240. })
  241. if (this.data.article === '') {
  242. this.getBooksInfo(res.data.data.groupPurchaseOrder.productId)
  243. }
  244. httpRequestApi.userIntoPage('pages/groupPage/group-details/group-details','团购详情页面').success((res)=>{
  245. })
  246. if (groupOrder.groupType === 'PROMOTION') {
  247. this.setData({
  248. colonelName: res.data.data.organizer.wechatName,
  249. promotion: true
  250. // joinUserList: this.data.joinUserList
  251. })
  252. }
  253. })
  254. },
  255. // 去详情页面
  256. goToDetail: function (detailId) {
  257. setTimeout(() => {
  258. wx.redirectTo({
  259. url: `/pages/groupPage/collage-details/collage-details?orderId=${this.data.orderId}&goBackHome=true`
  260. })
  261. wx.setNavigationBarTitle({
  262. title: '拼团详情'
  263. })
  264. }, 1000)
  265. },
  266. //跳到课程
  267. goToClass: function (e) {
  268. let id = e.currentTarget.dataset.id;
  269. let title = e.currentTarget.dataset.title;
  270. wx.navigateTo({
  271. url: `../../main/class/class?id=${id}&title=${title}`
  272. })
  273. },
  274. //再次发起团
  275. group: function () {
  276. // const orderId = this.data.orderId;
  277. // this.goToDetail(orderId);
  278. wx.navigateTo({
  279. url: `/pages/groupPage/grade-details/grade-details?productId=${this.data.productId}`
  280. })
  281. //拼团是否成功并弹窗
  282. // httpRequestApi.groupSuccess(orderId).success(res => {
  283. // console.log('团购是否成功', res.data.data)
  284. // debugger;
  285. // const status = res.data.data.status;
  286. // const uid = res.data.data.uid;
  287. // }).fail(error => {
  288. // console.log('错误', eroor)
  289. // })
  290. //this.openGroup();
  291. },
  292. /**
  293. * 生命周期函数--监听页面加载
  294. */
  295. onLoad: function (options) {
  296. console.log(this.data.isIOS)
  297. this.setData({
  298. options:options
  299. })
  300. if (options.scene || options.shareId) {
  301. console.log(123)
  302. this.setData({
  303. isLoading: true
  304. })
  305. }
  306. console.log('onload', options)
  307. wx.setNavigationBarTitle({
  308. title: '拼团详情'
  309. })
  310. getOpenidSessionKey((res) => {
  311. if (options.orderId) {
  312. const orderId = options.id;
  313. this.setData({
  314. orderId
  315. })
  316. this.getGroupInfo(orderId);
  317. } else {
  318. // 从分享页面进入的
  319. const orderId = options.productId ? options.productId : options.scene ? options.scene.replace('QR', '') : options.shareId;
  320. this.setData({
  321. orderId
  322. })
  323. this.getGroupInfo(orderId);
  324. }
  325. if (options.scene || options.shareId) {
  326. this.setData({
  327. goBackHome: true
  328. })
  329. }
  330. }, (error) => {
  331. this.setData({
  332. hide: !this.data.hide,
  333. onLoadOption: options
  334. })
  335. return;
  336. });
  337. },
  338. // 页面滚动
  339. pageScroll: function (e) {
  340. console.log(e.target.offsetTop)
  341. if (e.target.offsetTop < 600) {
  342. this.setData({
  343. hideBottomBtn: true
  344. })
  345. }
  346. if (e.target.offsetTop > 600) {
  347. this.setData({
  348. hideBottomBtn: false
  349. })
  350. }
  351. // if(e.target.offsetTop > 600){
  352. // this.setData({
  353. // btnClass: 'middle-btn'
  354. // })
  355. // }
  356. },
  357. // 鉴权
  358. areYouSuperSecond: function (productId) {
  359. httpRequestApi.areYouSuperSecond(productId).success(() => {
  360. console.log(res)
  361. this.setData({
  362. imSuper: res.data.data.auth ? true : false,
  363. haveCreatedHelp: res.data.data.createdShare, // 创建过助力团
  364. haveJoinHelp: res.data.data.joinShare, // 参加过助力团
  365. })
  366. });
  367. // 增加一条记录
  368. const data = {
  369. "shareTypeEnum": "POSTER",
  370. "shareContentEnum": "GROUP",
  371. "productId": productId
  372. }
  373. if (this.data.option.shareId) {
  374. data.shareTypeEnum = 'LINK'
  375. httpRequestApi.shareTagRecord(data).success(res => {
  376. console.log(res)
  377. })
  378. }
  379. if (this.data.option.scene) {
  380. httpRequestApi.shareTagRecord(data).success(res => {
  381. console.log(res)
  382. })
  383. }
  384. },
  385. // 下拉刷新
  386. onPullDownRefresh: function () {
  387. //当前在团购页下拉加载
  388. this.setData({
  389. surplusList: []
  390. }, () => {
  391. this.getGroupInfo(this.data.orderId);
  392. })
  393. wx.showNavigationBarLoading() //在标题栏中显示加载
  394. //模拟加载
  395. setTimeout(function () {
  396. wx.hideNavigationBarLoading() //完成停止加载
  397. wx.stopPullDownRefresh() //停止下拉刷新
  398. }, 1500);
  399. },
  400. // 获取课本详情
  401. getBooksInfo: function (productId) {
  402. //课本详情
  403. httpRequestApi.getBookDetail(wx.getStorageSync('uid'), productId).success((res) => {
  404. console.log('课本详情', res.data.data);
  405. const bookInfo = res.data.data.product;
  406. const lessonList = res.data.data.lessonList;
  407. const data = app.towxml.toJson(
  408. bookInfo.description,
  409. 'markdown',
  410. this
  411. )
  412. this.setData({
  413. titleIcon: bookInfo.bgImg,
  414. title: bookInfo.title,
  415. bookInfo: bookInfo.description,
  416. article: data
  417. })
  418. const lessonTemp = [];
  419. lessonList.forEach(item => {
  420. const temp = {};
  421. temp.id = item.id;
  422. temp.title = item.title;
  423. temp.readNum = item.readCount;
  424. lessonTemp.push(temp);
  425. });
  426. this.setData({
  427. lessonList: lessonTemp,
  428. });
  429. }).fail((error) => {
  430. })
  431. // //全部课本
  432. // httpRequestApi.getAllBooks(1, 10).success((res) => {
  433. // console.log('全部课', res.data.data.list)
  434. // res.data.data.list.forEach(element => {
  435. // this.data.selectFlag.push(true);
  436. // });
  437. // this.setData({
  438. // bookList: res.data.data.list,
  439. // selectFlag: this.data.selectFlag
  440. // })
  441. // }).fail((error) => {
  442. // console.log('错误', error)
  443. // })
  444. },
  445. /**
  446. * 生命周期函数--监听页面初次渲染完成
  447. */
  448. onReady: function () {
  449. this.popup = this.selectComponent("#popupup");
  450. },
  451. judgeUser: function (callBack) {
  452. },
  453. modalConfirmHandler: function () {
  454. this.setData({
  455. isModalShow: false
  456. })
  457. if (this.data.modalType === 'image') {
  458. this.goToDetail();
  459. }
  460. },
  461. modalCloseHandler: function () {
  462. this.setData({
  463. isModalShow: false
  464. })
  465. if (this.data.modalType === 'image') {
  466. this.goToDetail();
  467. }
  468. },
  469. })