group-details.js 14 KB

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