group-details.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  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. // 团员进入collage页面
  191. const myUid = wx.getStorageSync('uid');
  192. if (myUid === groupOrder.organizer) {
  193. wx.redirectTo({
  194. url: `../collage-details/collage-details?orderId=${orderId}&goBackHome=${this.data.goBackHome}`
  195. })
  196. return;
  197. }
  198. res.data.data.joinUserList.forEach(item => {
  199. if (item.uid === myUid) {
  200. wx.redirectTo({
  201. url: `../collage-details/collage-details?orderId=${groupId}&goBackHome=${this.data.goBackHome}`
  202. })
  203. return;
  204. }
  205. })
  206. const surplusNum = groupOrder.headcount - groupOrder.joinCount;
  207. this.setData({
  208. organizerUid: groupOrder.organizer,
  209. ifGroupSuccessed: groupOrder.status === 'SUCCESSED' ? true : false
  210. })
  211. for (var i = 0; i < surplusNum; i++) {
  212. this.data.surplusList.push(1);
  213. }
  214. // 剩余时间 如果团购已结束则不显示
  215. let timeLast = '';
  216. const stillGoing = groupOrder.closeTime - Date.parse(new Date()) <= 0 ? false : true
  217. if (stillGoing) {
  218. timeLast = util.lastHours(groupOrder.closeTime - Date.parse(new Date()));
  219. }
  220. this.setData({
  221. groupPurchaseInfo: res.data.data.groupPurchaseInfo,
  222. organizer: res.data.data.organizer,
  223. surplusNum,
  224. joinUserList: res.data.data.joinUserList,
  225. surplusList: this.data.surplusList,
  226. timeLast,
  227. stillGoing,
  228. productId: groupOrder.productId,
  229. groupId: groupOrder.groupId,
  230. rewardMoney: res.data.data.groupPurchaseInfo.organizerPrice / 100,
  231. dataLoading: false,
  232. groupOsType: groupOrder.os,
  233. isLoading: false
  234. })
  235. if (this.data.article === '') {
  236. this.getBooksInfo(res.data.data.groupPurchaseOrder.productId)
  237. }
  238. httpRequestApi.userIntoPage('pages/groupPage/group-details/group-details','团购详情页面').success((res)=>{
  239. })
  240. if (groupOrder.groupType === 'PROMOTION') {
  241. this.setData({
  242. colonelName: res.data.data.organizer.wechatName,
  243. promotion: true
  244. // joinUserList: this.data.joinUserList
  245. })
  246. }
  247. })
  248. },
  249. // 去详情页面
  250. goToDetail: function (detailId) {
  251. setTimeout(() => {
  252. wx.redirectTo({
  253. url: `/pages/groupPage/collage-details/collage-details?orderId=${detailId}&goBackHome=true`
  254. })
  255. wx.setNavigationBarTitle({
  256. title: '拼团详情'
  257. })
  258. }, 1000)
  259. },
  260. //跳到课程
  261. goToClass: function (e) {
  262. let id = e.currentTarget.dataset.id;
  263. let title = e.currentTarget.dataset.title;
  264. wx.navigateTo({
  265. url: `../../main/class/class?id=${id}&title=${title}`
  266. })
  267. },
  268. //再次发起团
  269. group: function () {
  270. // const orderId = this.data.orderId;
  271. // this.goToDetail(orderId);
  272. wx.navigateTo({
  273. url: `/pages/groupPage/grade-details/grade-details?productId=${this.data.productId}`
  274. })
  275. //拼团是否成功并弹窗
  276. // httpRequestApi.groupSuccess(orderId).success(res => {
  277. // console.log('团购是否成功', res.data.data)
  278. // debugger;
  279. // const status = res.data.data.status;
  280. // const uid = res.data.data.uid;
  281. // }).fail(error => {
  282. // console.log('错误', eroor)
  283. // })
  284. //this.openGroup();
  285. },
  286. /**
  287. * 生命周期函数--监听页面加载
  288. */
  289. onLoad: function (options) {
  290. console.log(this.data.isIOS)
  291. this.setData({
  292. options:options
  293. })
  294. if (options.scene || options.shareId) {
  295. console.log(123)
  296. this.setData({
  297. isLoading: true
  298. })
  299. }
  300. console.log('onload', options)
  301. wx.setNavigationBarTitle({
  302. title: '拼团详情'
  303. })
  304. getOpenidSessionKey((res) => {
  305. if (options.orderId) {
  306. const orderId = options.id;
  307. this.setData({
  308. orderId
  309. })
  310. this.getGroupInfo(orderId);
  311. } else {
  312. // 从分享页面进入的
  313. const orderId = options.productId ? options.productId : options.scene ? options.scene.replace('QR', '') : options.shareId;
  314. this.setData({
  315. orderId
  316. })
  317. this.getGroupInfo(orderId);
  318. }
  319. if (options.scene || options.shareId) {
  320. this.setData({
  321. goBackHome: true
  322. })
  323. }
  324. }, (error) => {
  325. this.setData({
  326. hide: !this.data.hide,
  327. onLoadOption: options
  328. })
  329. return;
  330. });
  331. },
  332. // 页面滚动
  333. pageScroll: function (e) {
  334. console.log(e.target.offsetTop)
  335. if (e.target.offsetTop < 600) {
  336. this.setData({
  337. hideBottomBtn: true
  338. })
  339. }
  340. if (e.target.offsetTop > 600) {
  341. this.setData({
  342. hideBottomBtn: false
  343. })
  344. }
  345. // if(e.target.offsetTop > 600){
  346. // this.setData({
  347. // btnClass: 'middle-btn'
  348. // })
  349. // }
  350. },
  351. // 鉴权
  352. areYouSuperSecond: function (productId) {
  353. httpRequestApi.areYouSuperSecond(productId).success(() => {
  354. console.log(res)
  355. this.setData({
  356. imSuper: res.data.data.auth ? true : false,
  357. haveCreatedHelp: res.data.data.createdShare, // 创建过助力团
  358. haveJoinHelp: res.data.data.joinShare, // 参加过助力团
  359. })
  360. });
  361. // 增加一条记录
  362. const data = {
  363. "shareTypeEnum": "POSTER",
  364. "shareContentEnum": "GROUP",
  365. "productId": productId
  366. }
  367. if (this.data.option.shareId) {
  368. data.shareTypeEnum = 'LINK'
  369. httpRequestApi.shareTagRecord(data).success(res => {
  370. console.log(res)
  371. })
  372. }
  373. if (this.data.option.scene) {
  374. httpRequestApi.shareTagRecord(data).success(res => {
  375. console.log(res)
  376. })
  377. }
  378. },
  379. // 下拉刷新
  380. onPullDownRefresh: function () {
  381. //当前在团购页下拉加载
  382. this.setData({
  383. surplusList: []
  384. }, () => {
  385. this.getGroupInfo(this.data.orderId);
  386. })
  387. wx.showNavigationBarLoading() //在标题栏中显示加载
  388. //模拟加载
  389. setTimeout(function () {
  390. wx.hideNavigationBarLoading() //完成停止加载
  391. wx.stopPullDownRefresh() //停止下拉刷新
  392. }, 1500);
  393. },
  394. // 获取课本详情
  395. getBooksInfo: function (productId) {
  396. //课本详情
  397. httpRequestApi.getBookDetail(wx.getStorageSync('uid'), productId).success((res) => {
  398. console.log('课本详情', res.data.data);
  399. const bookInfo = res.data.data.product;
  400. const lessonList = res.data.data.lessonList;
  401. const data = app.towxml.toJson(
  402. bookInfo.description,
  403. 'markdown',
  404. this
  405. )
  406. this.setData({
  407. titleIcon: bookInfo.bgImg,
  408. title: bookInfo.title,
  409. bookInfo: bookInfo.description,
  410. article: data
  411. })
  412. const lessonTemp = [];
  413. lessonList.forEach(item => {
  414. const temp = {};
  415. temp.id = item.id;
  416. temp.title = item.title;
  417. temp.readNum = item.readCount;
  418. lessonTemp.push(temp);
  419. });
  420. this.setData({
  421. lessonList: lessonTemp,
  422. });
  423. }).fail((error) => {
  424. })
  425. // //全部课本
  426. // httpRequestApi.getAllBooks(1, 10).success((res) => {
  427. // console.log('全部课', res.data.data.list)
  428. // res.data.data.list.forEach(element => {
  429. // this.data.selectFlag.push(true);
  430. // });
  431. // this.setData({
  432. // bookList: res.data.data.list,
  433. // selectFlag: this.data.selectFlag
  434. // })
  435. // }).fail((error) => {
  436. // console.log('错误', error)
  437. // })
  438. },
  439. /**
  440. * 生命周期函数--监听页面初次渲染完成
  441. */
  442. onReady: function () {
  443. this.popup = this.selectComponent("#popupup");
  444. },
  445. judgeUser: function (callBack) {
  446. },
  447. modalConfirmHandler: function () {
  448. this.setData({
  449. isModalShow: false
  450. })
  451. if (this.data.modalType === 'image') {
  452. this.goToDetail();
  453. }
  454. },
  455. modalCloseHandler: function () {
  456. this.setData({
  457. isModalShow: false
  458. })
  459. if (this.data.modalType === 'image') {
  460. this.goToDetail();
  461. }
  462. },
  463. })