group-details.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  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. if (groupOrder.groupType === 'PROMOTION') {
  239. this.setData({
  240. colonelName: res.data.data.organizer.wechatName,
  241. promotion: true
  242. // joinUserList: this.data.joinUserList
  243. })
  244. }
  245. })
  246. },
  247. // 去详情页面
  248. goToDetail: function (detailId) {
  249. setTimeout(() => {
  250. wx.redirectTo({
  251. url: `/pages/groupPage/collage-details/collage-details?orderId=${detailId}&goBackHome=true`
  252. })
  253. wx.setNavigationBarTitle({
  254. title: '拼团详情'
  255. })
  256. }, 1000)
  257. },
  258. //跳到课程
  259. goToClass: function (e) {
  260. let id = e.currentTarget.dataset.id;
  261. let title = e.currentTarget.dataset.title;
  262. wx.navigateTo({
  263. url: `../../main/class/class?id=${id}&title=${title}`
  264. })
  265. },
  266. //再次发起团
  267. group: function () {
  268. // const orderId = this.data.orderId;
  269. // this.goToDetail(orderId);
  270. wx.navigateTo({
  271. url: `/pages/groupPage/grade-details/grade-details?productId=${this.data.productId}`
  272. })
  273. //拼团是否成功并弹窗
  274. // httpRequestApi.groupSuccess(orderId).success(res => {
  275. // console.log('团购是否成功', res.data.data)
  276. // debugger;
  277. // const status = res.data.data.status;
  278. // const uid = res.data.data.uid;
  279. // }).fail(error => {
  280. // console.log('错误', eroor)
  281. // })
  282. //this.openGroup();
  283. },
  284. /**
  285. * 生命周期函数--监听页面加载
  286. */
  287. onLoad: function (options) {
  288. console.log(this.data.isIOS)
  289. if (options.scene || options.shareId) {
  290. console.log(123)
  291. this.setData({
  292. isLoading: true
  293. })
  294. }
  295. console.log('onload', options)
  296. wx.setNavigationBarTitle({
  297. title: '拼团详情'
  298. })
  299. getOpenidSessionKey((res) => {
  300. if (options.orderId) {
  301. const orderId = options.id;
  302. this.setData({
  303. orderId
  304. })
  305. this.getGroupInfo(orderId);
  306. } else {
  307. // 从分享页面进入的
  308. const orderId = options.productId ? options.productId : options.scene ? options.scene.replace('QR', '') : options.shareId;
  309. this.setData({
  310. orderId
  311. })
  312. this.getGroupInfo(orderId);
  313. }
  314. if (options.scene || options.shareId) {
  315. this.setData({
  316. goBackHome: true
  317. })
  318. }
  319. }, (error) => {
  320. this.setData({
  321. hide: !this.data.hide,
  322. onLoadOption: options
  323. })
  324. return;
  325. });
  326. },
  327. // 页面滚动
  328. pageScroll: function (e) {
  329. console.log(e.target.offsetTop)
  330. if (e.target.offsetTop < 600) {
  331. this.setData({
  332. hideBottomBtn: true
  333. })
  334. }
  335. if (e.target.offsetTop > 600) {
  336. this.setData({
  337. hideBottomBtn: false
  338. })
  339. }
  340. // if(e.target.offsetTop > 600){
  341. // this.setData({
  342. // btnClass: 'middle-btn'
  343. // })
  344. // }
  345. },
  346. // 鉴权
  347. areYouSuperSecond: function (productId) {
  348. httpRequestApi.areYouSuperSecond(productId).success(() => {
  349. console.log(res)
  350. this.setData({
  351. imSuper: res.data.data.auth ? true : false,
  352. haveCreatedHelp: res.data.data.createdShare, // 创建过助力团
  353. haveJoinHelp: res.data.data.joinShare, // 参加过助力团
  354. })
  355. });
  356. },
  357. // 下拉刷新
  358. onPullDownRefresh: function () {
  359. //当前在团购页下拉加载
  360. this.setData({
  361. surplusList: []
  362. }, () => {
  363. this.getGroupInfo(this.data.orderId);
  364. })
  365. wx.showNavigationBarLoading() //在标题栏中显示加载
  366. //模拟加载
  367. setTimeout(function () {
  368. wx.hideNavigationBarLoading() //完成停止加载
  369. wx.stopPullDownRefresh() //停止下拉刷新
  370. }, 1500);
  371. },
  372. // 获取课本详情
  373. getBooksInfo: function (productId) {
  374. //课本详情
  375. httpRequestApi.getBookDetail(wx.getStorageSync('uid'), productId).success((res) => {
  376. console.log('课本详情', res.data.data);
  377. const bookInfo = res.data.data.product;
  378. const lessonList = res.data.data.lessonList;
  379. const data = app.towxml.toJson(
  380. bookInfo.description,
  381. 'markdown',
  382. this
  383. )
  384. this.setData({
  385. titleIcon: bookInfo.bgImg,
  386. title: bookInfo.title,
  387. bookInfo: bookInfo.description,
  388. article: data
  389. })
  390. const lessonTemp = [];
  391. lessonList.forEach(item => {
  392. const temp = {};
  393. temp.id = item.id;
  394. temp.title = item.title;
  395. temp.readNum = item.readCount;
  396. lessonTemp.push(temp);
  397. });
  398. this.setData({
  399. lessonList: lessonTemp,
  400. });
  401. }).fail((error) => {
  402. })
  403. // //全部课本
  404. // httpRequestApi.getAllBooks(1, 10).success((res) => {
  405. // console.log('全部课', res.data.data.list)
  406. // res.data.data.list.forEach(element => {
  407. // this.data.selectFlag.push(true);
  408. // });
  409. // this.setData({
  410. // bookList: res.data.data.list,
  411. // selectFlag: this.data.selectFlag
  412. // })
  413. // }).fail((error) => {
  414. // console.log('错误', error)
  415. // })
  416. },
  417. /**
  418. * 生命周期函数--监听页面初次渲染完成
  419. */
  420. onReady: function () {
  421. this.popup = this.selectComponent("#popupup");
  422. },
  423. judgeUser: function (callBack) {
  424. },
  425. modalConfirmHandler: function () {
  426. this.setData({
  427. isModalShow: false
  428. })
  429. if (this.data.modalType === 'image') {
  430. this.goToDetail();
  431. }
  432. },
  433. modalCloseHandler: function () {
  434. this.setData({
  435. isModalShow: false
  436. })
  437. if (this.data.modalType === 'image') {
  438. this.goToDetail();
  439. }
  440. },
  441. })