group-details.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509
  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. bookList: [],
  33. sendGroupFlag: true,
  34. selectFlag: [],
  35. flag: true,
  36. colonelName: '',
  37. article: '',
  38. alertFlag: false,
  39. stillGoing: true,
  40. surplusNum: '1',
  41. timeList: ['6', '6', '6'],
  42. modalType: "image",
  43. isModalShow: false,
  44. modalCloseShow: false,
  45. modalText: [{
  46. text: '您已经参加过本次团购',
  47. type: 'bigOrange'
  48. },
  49. {
  50. text: '快喊朋友们一起助力',
  51. type: 'bigOrange'
  52. }
  53. ],
  54. },
  55. //tab切换
  56. tabSwitch: function () {
  57. this.setData({
  58. flag: !this.data.flag
  59. })
  60. },
  61. jurisdiction: function () {
  62. //隐藏弹框
  63. this.setData({
  64. hide: !this.data.hide
  65. })
  66. //登录页信息
  67. this.onLoad(this.data.onLoadOption);
  68. },
  69. //发起团购
  70. sendGroup: function () {
  71. this.setData({
  72. sendGroupFlag: !this.data.sendGroupFlag
  73. })
  74. },
  75. //选中团购课程
  76. selectImg: function ({
  77. currentTarget
  78. }) {
  79. const ind = currentTarget.dataset.ind;
  80. //判断单选
  81. this.data.selectFlag.forEach((item, index) => {
  82. if (index == ind) {
  83. this.data.selectFlag[ind] = !this.data.selectFlag[ind];
  84. } else {
  85. this.data.selectFlag[index] = true;
  86. }
  87. })
  88. this.setData({
  89. selectFlag: this.data.selectFlag
  90. })
  91. },
  92. //点击确定
  93. sure: function () {
  94. this.data.selectFlag.forEach((item, index) => {
  95. if (!item) {
  96. const productId = this.data.bookList[index].id;
  97. const title = this.data.bookList[index].title
  98. this.setData({
  99. sendGroupFlag: !this.data.sendGroupFlag
  100. })
  101. wx.navigateTo({
  102. url: `/pages/groupPage/grade-details/grade-details?productId=${productId}&title=${title}`
  103. })
  104. }
  105. })
  106. },
  107. //参团
  108. jionGroup: function () {
  109. if (app.globalData.isIOS) {
  110. this.showAlert();
  111. return;
  112. }
  113. const orderId = this.data.orderId;
  114. //开始发起团购
  115. httpRequestApi.JoinGroupPurchas(orderId).success((res) => {
  116. console.log('参加团购', res);
  117. if (res.data.message) {
  118. if (res.data.code === 801) {
  119. this.setData({
  120. isModalShow: true,
  121. modalType: 'text'
  122. })
  123. } else {
  124. wx.showModal({
  125. title: '提示',
  126. content: res.data.message,
  127. success(res) {
  128. if (res.confirm) {
  129. console.log('用户点击确定')
  130. } else if (res.cancel) {
  131. console.log('用户点击取消')
  132. }
  133. }
  134. })
  135. }
  136. return false;
  137. }
  138. //掉起支付
  139. this.prePayMap(res.data.data.prePayMap, 'join');
  140. }).fail((error) => {
  141. })
  142. },
  143. showAlert: function () {
  144. this.setData({
  145. alertFlag: !this.data.alertFlag
  146. })
  147. },
  148. //支付
  149. prePayMap: function (prePayMap, type) {
  150. console.log(prePayMap)
  151. // const that = this;
  152. this.setData({
  153. joinGroupType: type
  154. })
  155. wx.requestPayment({
  156. 'appId': prePayMap.appId,
  157. 'timeStamp': prePayMap.timeStamp,
  158. 'nonceStr': prePayMap.nonceStr,
  159. 'package': prePayMap.package,
  160. 'signType': 'MD5',
  161. 'paySign': prePayMap.sign,
  162. 'success': res => {
  163. console.log('支付成功')
  164. this.setData({
  165. isModalShow: true
  166. })
  167. // const type1 = type;
  168. // wx.showModal({
  169. // title: '提示',
  170. // content: '支付成功',
  171. // success(res) {
  172. // //获取拼团信息
  173. // console.log(that.data.orderId)
  174. // wx.showLoading({
  175. // title: '支付查询中...',
  176. // mask: true
  177. // })
  178. // setTimeout(() => {
  179. // wx.hideLoading();
  180. // console.log(that.data.orderId)
  181. // that.jionSuccess(that.data.orderId, type1);
  182. // // that.groupSuccess(orderId, detailId);
  183. // }, 800)
  184. // }
  185. // })
  186. },
  187. 'fail': function (res) {
  188. console.log('支付失败', res)
  189. }
  190. })
  191. },
  192. //拼团详情
  193. jionSuccess: function (orderId, type) {
  194. httpRequestApi.getMygroupInfo(orderId).success(res => {
  195. // 通过分享进入的用户,如果已经参加过本次团购,则跳转进入邀请好友的页面
  196. if (this.data.goBackHome) {
  197. const joinUser = res.data.data.joinUserList;
  198. const groupId = res.data.data.groupPurchaseOrder.id;
  199. const myUid = wx.getStorageSync('uid');
  200. if (myUid === res.data.data.organizer.uid) {
  201. wx.redirectTo({
  202. url: `../collage-details/collage-details?orderId=${groupId}&goBackHome=${this.data.goBackHome}`
  203. })
  204. return;
  205. }
  206. joinUser.forEach(item => {
  207. if (item.uid === myUid) {
  208. wx.redirectTo({
  209. url: `../collage-details/collage-details?orderId=${groupId}&goBackHome=${this.data.goBackHome}`
  210. })
  211. return;
  212. }
  213. })
  214. }
  215. console.log('拼团详情', res);
  216. const groupOrder = res.data.data.groupPurchaseOrder;
  217. const surplusNum = groupOrder.headcount - groupOrder.joinCount;
  218. if (this.data.article === '') {
  219. this.getBooksInfo(res.data.data.groupPurchaseOrder.productId)
  220. }
  221. this.setData({
  222. organizer: groupOrder.organizer,
  223. productId: res.data.data.groupPurchaseOrder.productId
  224. })
  225. if (type === 'join') {
  226. this.data.surplusList.pop();
  227. if (groupOrder.status === 'SUCCESSED') {
  228. this.showSuccess(groupOrder.organizer, groupOrder.organizerPrice)
  229. } else {
  230. this.goToDetail(groupOrder.id)
  231. }
  232. } else if (type === 'create') {
  233. this.showSuccess(groupOrder.organizer, groupOrder.organizerPrice)
  234. this.setData({
  235. orderId: groupOrder.id
  236. })
  237. } else {
  238. for (var i = 0; i < surplusNum; i++) {
  239. this.data.surplusList.push(1);
  240. }
  241. }
  242. let timeList = [];
  243. const stillGoing = groupOrder.closeTime - Date.parse(new Date()) <= 0 ? false : true
  244. if (stillGoing) {
  245. timeList = util.lastHoursInGroup(groupOrder.closeTime - Date.parse(new Date()));
  246. console.log(timeList)
  247. }
  248. // 分享进来的并且团购失效 就跳转到详情页面
  249. // if(this.data.goBackHome && (surplusNum ===0 || !stillGoing) ){
  250. // console.log(' productID>>>>>>>>>>>>>>>>'+ res.data.data.groupPurchaseOrder.productId)
  251. // wx.navigateTo({
  252. // url: `/pages/groupPage/grade-details/grade-details?productId=${res.data.data.groupPurchaseOrder.productId}`
  253. // })
  254. // }
  255. this.setData({
  256. surplusNum,
  257. joinUserList: res.data.data.joinUserList,
  258. surplusList: this.data.surplusList,
  259. timeList,
  260. stillGoing
  261. })
  262. if (groupOrder.groupType === 'PROMOTION') {
  263. //this.data.joinUserList.unshift(res.data.data.organizer);
  264. this.setData({
  265. colonelName: res.data.data.organizer.wechatName
  266. })
  267. //this.data.surplusList.pop();
  268. this.setData({
  269. joinUserList: this.data.joinUserList,
  270. //surplusList: this.data.surplusList,
  271. surplusNum: this.data.surplusNum
  272. })
  273. }
  274. }).fail(error => {
  275. console.log('错误', error)
  276. })
  277. },
  278. // 弹成功信息框
  279. showSuccess: function (organizerUid, price) {
  280. debugger;
  281. if (wx.getStorageSync('uid') == organizerUid) {
  282. this.setData({
  283. typeOf: 'success',
  284. titles: '恭喜 !',
  285. headTextOne: '您发起的团购拼团成功',
  286. headTextTwo: '领袖体质魅力无穷!',
  287. content: [{
  288. text: " 您可以继续发起新的团购,",
  289. color: "#F97800"
  290. },
  291. {
  292. text: " 不再需要支付本课程费用",
  293. color: "#F97800"
  294. },
  295. {
  296. text: `拼团成功,您将得到奖学金`,
  297. color: "#F97800"
  298. }
  299. ],
  300. btnContent: '再接再厉 赚奖学金'
  301. }, () => {
  302. this.popup.close()
  303. })
  304. } else {
  305. this.setData({
  306. typeOf: 'success',
  307. titles: '拼团成功 ! ',
  308. headTextOne: '您参与的团购拼团成功',
  309. headTextTwo: '感谢团长的分享',
  310. content: [{
  311. text: " 您也可以发起新的团购",
  312. color: "#F97800"
  313. },
  314. {
  315. text: "作为新的发起人",
  316. color: "#F97800"
  317. },
  318. {
  319. text: " 您无需在支付本课程费用 ",
  320. color: "#F97800"
  321. },
  322. {
  323. text: `拼团成功,您将得到奖学金`,
  324. color: "#F97800"
  325. }
  326. ],
  327. btnContent: '我也试试 赚奖学金'
  328. }, () => {
  329. this.popup.close()
  330. })
  331. }
  332. },
  333. // 去详情页面
  334. goToDetail: function (detailId) {
  335. setTimeout(() => {
  336. wx.redirectTo({
  337. url: `/pages/groupPage/collage-details/collage-details?orderId=${detailId}&goBackHome=true`
  338. })
  339. wx.setNavigationBarTitle({
  340. title: '拼团详情'
  341. })
  342. }, 1000)
  343. },
  344. //跳到课程
  345. goToClass: function (e) {
  346. let id = e.currentTarget.dataset.id;
  347. let title = e.currentTarget.dataset.title;
  348. wx.navigateTo({
  349. url: `../../main/class/class?id=${id}&title=${title}`
  350. })
  351. },
  352. //再次发起团
  353. group: function () {
  354. // const orderId = this.data.orderId;
  355. // this.goToDetail(orderId);
  356. wx.navigateTo({
  357. url: `/pages/groupPage/grade-details/grade-details?productId=${this.data.productId}`
  358. })
  359. //拼团是否成功并弹窗
  360. // httpRequestApi.groupSuccess(orderId).success(res => {
  361. // console.log('团购是否成功', res.data.data)
  362. // debugger;
  363. // const status = res.data.data.status;
  364. // const uid = res.data.data.uid;
  365. // }).fail(error => {
  366. // console.log('错误', eroor)
  367. // })
  368. //this.openGroup();
  369. },
  370. /**
  371. * 生命周期函数--监听页面加载
  372. */
  373. onLoad: function (options) {
  374. // if (app.globalData.isIOS) {
  375. // wx.redirectTo({
  376. // url: '../../index/index'
  377. // })
  378. // return
  379. // }
  380. console.log('onload', options)
  381. wx.setNavigationBarTitle({
  382. title: '拼团详情'
  383. })
  384. getOpenidSessionKey((res) => {
  385. if (options.orderId) {
  386. const orderId = options.id;
  387. this.setData({
  388. orderId
  389. })
  390. this.jionSuccess(orderId);
  391. } else {
  392. // 从分享页面进入的
  393. const orderId = options.productId ? options.productId : options.scene ? options.scene.replace('QR', '') : options.shareId;
  394. this.setData({
  395. orderId
  396. })
  397. this.jionSuccess(orderId);
  398. }
  399. if (options.scene || options.shareId) {
  400. this.setData({
  401. goBackHome: true
  402. })
  403. }
  404. }, (error) => {
  405. this.setData({
  406. hide: !this.data.hide,
  407. onLoadOption: options
  408. })
  409. return;
  410. });
  411. },
  412. // 下拉刷新
  413. onPullDownRefresh: function () {
  414. //当前在团购页下拉加载
  415. this.setData({
  416. surplusList: []
  417. }, () => {
  418. this.jionSuccess(this.data.orderId);
  419. })
  420. wx.showNavigationBarLoading() //在标题栏中显示加载
  421. //模拟加载
  422. setTimeout(function () {
  423. wx.hideNavigationBarLoading() //完成停止加载
  424. wx.stopPullDownRefresh() //停止下拉刷新
  425. }, 1500);
  426. },
  427. // 获取课本详情
  428. getBooksInfo: function (productId) {
  429. //课本详情
  430. httpRequestApi.getBookDetail(wx.getStorageSync('uid'), productId).success((res) => {
  431. console.log('课本详情', res.data.data);
  432. const bookInfo = res.data.data.product;
  433. const lessonList = res.data.data.lessonList;
  434. const data = app.towxml.toJson(
  435. bookInfo.description,
  436. 'markdown',
  437. this
  438. )
  439. this.setData({
  440. titleIcon: bookInfo.bgImg,
  441. title: bookInfo.title,
  442. bookInfo: bookInfo.description,
  443. article: data
  444. })
  445. const lessonTemp = [];
  446. lessonList.forEach(item => {
  447. const temp = {};
  448. temp.id = item.id;
  449. temp.title = item.title;
  450. temp.readNum = item.readCount;
  451. lessonTemp.push(temp);
  452. });
  453. this.setData({
  454. lessonList: lessonTemp,
  455. });
  456. }).fail((error) => {
  457. })
  458. //全部课本
  459. httpRequestApi.getAllBooks(1, 10).success((res) => {
  460. console.log('全部课', res.data.data.list)
  461. res.data.data.list.forEach(element => {
  462. this.data.selectFlag.push(true);
  463. });
  464. this.setData({
  465. bookList: res.data.data.list,
  466. selectFlag: this.data.selectFlag
  467. })
  468. }).fail((error) => {
  469. console.log('错误', error)
  470. })
  471. },
  472. /**
  473. * 生命周期函数--监听页面初次渲染完成
  474. */
  475. onReady: function () {
  476. this.popup = this.selectComponent("#popupup");
  477. },
  478. judgeUser: function (callBack) {
  479. },
  480. modalConfirmHandler: function () {
  481. this.setData({
  482. isModalShow: false
  483. })
  484. if (this.data.modalType === 'image') {
  485. this.jionSuccess(this.data.orderId, this.data.joinGroupType);
  486. }
  487. },
  488. modalCloseHandler: function () {
  489. this.setData({
  490. isModalShow: false
  491. })
  492. if (this.data.modalType === 'image') {
  493. this.jionSuccess(this.data.orderId, this.data.joinGroupType);
  494. }
  495. },
  496. })