group-details.js 11 KB

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