group-details.js 13 KB

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