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. wx.setStorageSync('userSourseType','group')
  332. this.setData({
  333. hide: !this.data.hide,
  334. onLoadOption: options
  335. })
  336. return;
  337. });
  338. },
  339. // 页面滚动
  340. pageScroll: function (e) {
  341. console.log(e.target.offsetTop)
  342. if (e.target.offsetTop < 600) {
  343. this.setData({
  344. hideBottomBtn: true
  345. })
  346. }
  347. if (e.target.offsetTop > 600) {
  348. this.setData({
  349. hideBottomBtn: false
  350. })
  351. }
  352. // if(e.target.offsetTop > 600){
  353. // this.setData({
  354. // btnClass: 'middle-btn'
  355. // })
  356. // }
  357. },
  358. // 鉴权
  359. areYouSuperSecond: function (productId) {
  360. httpRequestApi.areYouSuperSecond(productId).success(() => {
  361. console.log(res)
  362. this.setData({
  363. imSuper: res.data.data.auth ? true : false,
  364. haveCreatedHelp: res.data.data.createdShare, // 创建过助力团
  365. haveJoinHelp: res.data.data.joinShare, // 参加过助力团
  366. })
  367. });
  368. // 增加一条记录
  369. const data = {
  370. "shareTypeEnum": "POSTER",
  371. "shareContentEnum": "GROUP",
  372. "productId": productId
  373. }
  374. if (this.data.option.shareId) {
  375. data.shareTypeEnum = 'LINK'
  376. httpRequestApi.shareTagRecord(data).success(res => {
  377. console.log(res)
  378. })
  379. }
  380. if (this.data.option.scene) {
  381. httpRequestApi.shareTagRecord(data).success(res => {
  382. console.log(res)
  383. })
  384. }
  385. },
  386. // 下拉刷新
  387. onPullDownRefresh: function () {
  388. //当前在团购页下拉加载
  389. this.setData({
  390. surplusList: []
  391. }, () => {
  392. this.getGroupInfo(this.data.orderId);
  393. })
  394. wx.showNavigationBarLoading() //在标题栏中显示加载
  395. //模拟加载
  396. setTimeout(function () {
  397. wx.hideNavigationBarLoading() //完成停止加载
  398. wx.stopPullDownRefresh() //停止下拉刷新
  399. }, 1500);
  400. },
  401. // 获取课本详情
  402. getBooksInfo: function (productId) {
  403. //课本详情
  404. httpRequestApi.getBookDetail(wx.getStorageSync('uid'), productId).success((res) => {
  405. console.log('课本详情', res.data.data);
  406. const bookInfo = res.data.data.product;
  407. const lessonList = res.data.data.lessonList;
  408. const data = app.towxml.toJson(
  409. bookInfo.description,
  410. 'markdown',
  411. this
  412. )
  413. this.setData({
  414. titleIcon: bookInfo.bgImg,
  415. title: bookInfo.title,
  416. bookInfo: bookInfo.description,
  417. article: data
  418. })
  419. const lessonTemp = [];
  420. lessonList.forEach(item => {
  421. const temp = {};
  422. temp.id = item.id;
  423. temp.title = item.title;
  424. temp.readNum = item.readCount;
  425. lessonTemp.push(temp);
  426. });
  427. this.setData({
  428. lessonList: lessonTemp,
  429. });
  430. }).fail((error) => {
  431. })
  432. // //全部课本
  433. // httpRequestApi.getAllBooks(1, 10).success((res) => {
  434. // console.log('全部课', res.data.data.list)
  435. // res.data.data.list.forEach(element => {
  436. // this.data.selectFlag.push(true);
  437. // });
  438. // this.setData({
  439. // bookList: res.data.data.list,
  440. // selectFlag: this.data.selectFlag
  441. // })
  442. // }).fail((error) => {
  443. // console.log('错误', error)
  444. // })
  445. },
  446. /**
  447. * 生命周期函数--监听页面初次渲染完成
  448. */
  449. onReady: function () {
  450. this.popup = this.selectComponent("#popupup");
  451. },
  452. judgeUser: function (callBack) {
  453. },
  454. modalConfirmHandler: function () {
  455. this.setData({
  456. isModalShow: false
  457. })
  458. if (this.data.modalType === 'image') {
  459. this.goToDetail();
  460. }
  461. },
  462. modalCloseHandler: function () {
  463. this.setData({
  464. isModalShow: false
  465. })
  466. if (this.data.modalType === 'image') {
  467. this.goToDetail();
  468. }
  469. },
  470. })