group-details.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  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. title: '',
  26. headTextOne: '',
  27. headTextTwo: '',
  28. content: [],
  29. organizer: '',
  30. hide: true,
  31. isIPX: app.globalData.isIPX
  32. },
  33. jurisdiction: function () {
  34. //隐藏弹框
  35. this.setData({
  36. hide: !this.data.hide
  37. })
  38. //登录页信息
  39. this.onLoad();
  40. },
  41. //跳转到年级
  42. gradeDetails: function () {
  43. // wx.navigateTo({
  44. // url: '/pages/groupPage/grade-details/grade-details'
  45. // })
  46. // wx.setNavigationBarTitle({
  47. // title: '限量优惠团购'
  48. // })
  49. },
  50. //开团
  51. openGroup: function () {
  52. const productId = this.data.productId;
  53. const groupId = this.data.groupId;
  54. //开始发起团购
  55. httpRequestApi.SendGroupPurchas({
  56. productId,
  57. groupId
  58. }).success((res) => {
  59. console.log('发起团购', res);
  60. if (res.data.message) {
  61. wx.showModal({
  62. title: '提示',
  63. content: res.data.message,
  64. success(res) {
  65. if (res.confirm) {
  66. console.log('用户点击确定')
  67. } else if (res.cancel) {
  68. console.log('用户点击取消')
  69. }
  70. }
  71. })
  72. return false;
  73. }
  74. debugger;
  75. if (res.data.data.groupPurchaseOrder.groupType === 'BASE') {
  76. //掉起支付
  77. this.prePayMap(res.data.data.prePayMap, 'create');
  78. }else {
  79. wx.navigateTo({
  80. url: `/pages/groupPage/make-money/make-money?productId=${productId}&id=${res.data.data.groupPurchaseOrder.id}&groupId=${groupId}`
  81. })
  82. }
  83. }).fail((error) => {
  84. })
  85. },
  86. //参团
  87. jionGroup: function () {
  88. const orderId = this.data.orderId;
  89. //开始发起团购
  90. httpRequestApi.JoinGroupPurchas(orderId).success((res) => {
  91. console.log('参加团购', res);
  92. if (res.data.message) {
  93. wx.showModal({
  94. title: '提示',
  95. content: res.data.message,
  96. success(res) {
  97. if (res.confirm) {
  98. console.log('用户点击确定')
  99. } else if (res.cancel) {
  100. console.log('用户点击取消')
  101. }
  102. }
  103. })
  104. return false;
  105. }
  106. //掉起支付
  107. this.prePayMap(res.data.data.prePayMap, 'join');
  108. }).fail((error) => {
  109. })
  110. },
  111. //支付
  112. prePayMap: function (prePayMap, type) {
  113. console.log(prePayMap)
  114. const that = this;
  115. wx.requestPayment({
  116. 'appId': prePayMap.appId,
  117. 'timeStamp': prePayMap.timeStamp,
  118. 'nonceStr': prePayMap.nonceStr,
  119. 'package': prePayMap.package,
  120. 'signType': 'MD5',
  121. 'paySign': prePayMap.sign,
  122. 'success': function (res) {
  123. console.log('支付成功')
  124. const type1 = type;
  125. wx.showModal({
  126. title: '提示',
  127. content: '支付成功',
  128. success(res) {
  129. //获取拼团信息
  130. console.log(that.data.orderId)
  131. wx.showLoading({
  132. title: '支付查询中...',
  133. mask: true
  134. })
  135. setTimeout(() => {
  136. wx.hideLoading();
  137. console.log(that.data.orderId)
  138. that.jionSuccess(that.data.orderId, type1);
  139. // that.groupSuccess(orderId, detailId);
  140. }, 2000)
  141. }
  142. })
  143. },
  144. 'fail': function (res) {
  145. console.log('支付失败', res)
  146. }
  147. })
  148. },
  149. //拼团详情
  150. jionSuccess: function (orderId, type) {
  151. httpRequestApi.getMygroupInfo(orderId).success(res => {
  152. console.log('拼团详情', res.data.data);
  153. const groupOrder = res.data.data.groupPurchaseOrder;
  154. const surplusNum = groupOrder.headcount - groupOrder.joinCount;
  155. this.setData({
  156. organizer: groupOrder.organizer,
  157. })
  158. if (type === 'join') {
  159. this.data.surplusList.pop();
  160. if (groupOrder.status === 'SUCCESSED') {
  161. this.showSuccess(groupOrder.organizer, groupOrder.organizerPrice)
  162. } else {
  163. this.goToDetail(groupOrder.id)
  164. }
  165. } else {
  166. for (var i = 0; i < surplusNum; i++) {
  167. this.data.surplusList.push(1);
  168. }
  169. }
  170. console.log(groupOrder.closeTime - groupOrder.gmtModified)
  171. //时间转换
  172. let timeNow = new Date()
  173. // const timeList = util.formatTime(groupOrder.closeTime - groupOrder.gmtModified);
  174. const timeList = util.formatTime(groupOrder.closeTime - Date.parse(new Date()));
  175. this.setData({
  176. surplusNum,
  177. joinUserList: res.data.data.joinUserList,
  178. surplusList: this.data.surplusList,
  179. timeList,
  180. })
  181. if(groupOrder.groupType === 'PROMOTION'){
  182. this.data.joinUserList.unshift(res.data.data.organizer);
  183. //this.data.surplusList.pop();
  184. this.setData({
  185. joinUserList: this.data.joinUserList,
  186. //surplusList: this.data.surplusList,
  187. surplusNum: this.data.surplusNum
  188. })
  189. }
  190. console.log(this.data.joinUserList)
  191. // this.groupSuccess(res.data.data.groupPurchaseOrder.productId, detailId);
  192. }).fail(error => {
  193. console.log('错误', error)
  194. })
  195. },
  196. // 弹成功信息框
  197. showSuccess: function (organizerUid, price) {
  198. if (wx.getStorageSync('uid') == organizerUid) {
  199. this.setData({
  200. typeOf: 'success',
  201. title: '恭喜 !',
  202. headTextOne: '您发起的团购拼团成功',
  203. content: [{
  204. text: "领袖体质魅力无穷!",
  205. color: "#000"
  206. },
  207. {
  208. text: " 您可以继续发起新的团购,",
  209. color: "#000"
  210. },
  211. {
  212. text: " 不再需要支付本课程费用,拼团成功,",
  213. color: "#FF9B00"
  214. },
  215. {
  216. text: `您将得到${price / 100}元奖励。`,
  217. color: "#FF0000"
  218. }
  219. ],
  220. },()=>{
  221. this.popup.close()
  222. })
  223. } else {
  224. this.setData({
  225. typeOf: 'success',
  226. title: '拼团成功 ! ',
  227. headTextOne: '您参与的团购拼团成功',
  228. headTextTwo: '',
  229. content: [{
  230. text: "感谢团长的分享",
  231. color: "#000"
  232. },
  233. {
  234. text: " 您也可以发起新的团购分享给需要的朋友们,",
  235. color: "#000"
  236. },
  237. {
  238. text: "作为新的发起人,您无需在支付本课程费用;",
  239. color: "#FF0000"
  240. },
  241. {
  242. text: `团购成功,您将得到${price/ 100}元奖励。`,
  243. color: "#FF0000"
  244. }
  245. ],
  246. },()=>{
  247. this.popup.close()
  248. })
  249. }
  250. },
  251. // 去详情页面
  252. goToDetail: function (detailId) {
  253. setTimeout(() => {
  254. wx.navigateTo({
  255. url: `/pages/groupPage/collage-details/collage-details?orderId=${detailId}`
  256. })
  257. wx.setNavigationBarTitle({
  258. title: '拼团详情'
  259. })
  260. }, 3000)
  261. },
  262. //跳到课程
  263. goToClass: function (e) {
  264. let id = e.currentTarget.dataset.id;
  265. let title = e.currentTarget.dataset.title;
  266. wx.navigateTo({
  267. url: `../../main/class/class?id=${id}&title=${title}`
  268. })
  269. },
  270. //拼团是否成功并弹窗
  271. // groupSuccess: function (orderId, detailId) {
  272. // httpRequestApi.groupSuccess(orderId).success(res => {
  273. // console.log('团购是否成功', res.data.data)
  274. // const status = res.data.data.status;
  275. // const uid = res.data.data.uid;
  276. // if (status === 'SUCCESSED') {
  277. // if (wx.getStorageSync('uid') == uid) {
  278. // this.setData({
  279. // typeOf: 'success',
  280. // title: '恭喜 !',
  281. // headTextOne: '您发起的团购拼团成功',
  282. // content: [{
  283. // text: "领袖体质魅力无穷!",
  284. // color: "#000"
  285. // },
  286. // {
  287. // text: " 您可以继续发起新的团购,",
  288. // color: "#000"
  289. // },
  290. // {
  291. // text: " 不再需要支付本课程费用,拼团成功,",
  292. // color: "#FF9B00"
  293. // },
  294. // {
  295. // text: " 您将得到xxx元奖励。",
  296. // color: "#FF0000"
  297. // }
  298. // ],
  299. // })
  300. // } else {
  301. // this.setData({
  302. // typeOf: 'success',
  303. // title: '拼团成功 ! ',
  304. // headTextOne: '您参与的团购拼团成功',
  305. // headTextTwo: '订单号:12344',
  306. // content: [{
  307. // text: "感谢团长的分享",
  308. // color: "#000"
  309. // },
  310. // {
  311. // text: " 您也可以发起新的团购分享给需要的朋友们,",
  312. // color: "#000"
  313. // },
  314. // {
  315. // text: "作为新的发起人,您无需在支付本课程费用;",
  316. // color: "#FF0000"
  317. // },
  318. // {
  319. // text: "团购成功,您将得到xxx元奖励。",
  320. // color: "#FF0000"
  321. // }
  322. // ],
  323. // })
  324. // }
  325. // } else {
  326. // setTimeout(() => {
  327. // wx.navigateTo({
  328. // url: `/pages/groupPage/collage-details/collage-details?orderId=${detailId}`
  329. // })
  330. // wx.setNavigationBarTitle({
  331. // title: '拼团详情'
  332. // })
  333. // }, 3000)
  334. // }
  335. // }).fail(error => {
  336. // console.log('错误', eroor)
  337. // })
  338. // },
  339. //再次发起团
  340. group: function () {
  341. this.openGroup();
  342. },
  343. /**
  344. * 生命周期函数--监听页面加载
  345. */
  346. onLoad: function (options) {
  347. getOpenidSessionKey((res) => {}, (error) => {
  348. this.setData({
  349. hide: !this.data.hide
  350. })
  351. return;
  352. });
  353. wx.setNavigationBarTitle({
  354. title: '拼团详情'
  355. })
  356. if (!options.productId) return false;
  357. const productId = options.productId;
  358. const groupId = options.groupId;
  359. const orderId = options.id;
  360. this.setData({
  361. productId,
  362. groupId,
  363. orderId
  364. })
  365. //课本详情
  366. httpRequestApi.getBookDetail(wx.getStorageSync('uid'), productId).success((res) => {
  367. console.log('课本详情', res.data.data);
  368. const bookInfo = res.data.data.product;
  369. const lessonList = res.data.data.lessonList;
  370. this.setData({
  371. titleIcon: bookInfo.bgImg,
  372. title: bookInfo.title,
  373. bookInfo: bookInfo.description
  374. })
  375. const lessonTemp = [];
  376. lessonList.forEach(item => {
  377. const temp = {};
  378. temp.id = item.id;
  379. temp.title = item.title;
  380. temp.readNum = item.readCount;
  381. lessonTemp.push(temp);
  382. });
  383. this.setData({
  384. lessonList: lessonTemp
  385. });
  386. }).fail((error) => {
  387. })
  388. //获取拼团信息
  389. this.jionSuccess(orderId);
  390. },
  391. /**
  392. * 生命周期函数--监听页面初次渲染完成
  393. */
  394. onReady: function () {
  395. this.popup = this.selectComponent("#popupup");
  396. },
  397. /**
  398. * 生命周期函数--监听页面显示
  399. */
  400. onShow: function () {
  401. },
  402. /**
  403. * 生命周期函数--监听页面隐藏
  404. */
  405. onHide: function () {
  406. },
  407. /**
  408. * 生命周期函数--监听页面卸载
  409. */
  410. onUnload: function () {
  411. },
  412. /**
  413. * 页面相关事件处理函数--监听用户下拉动作
  414. */
  415. onPullDownRefresh: function () {
  416. },
  417. /**
  418. * 页面上拉触底事件的处理函数
  419. */
  420. onReachBottom: function () {
  421. },
  422. /**
  423. * 用户点击右上角分享
  424. */
  425. onShareAppMessage: function () {
  426. }
  427. })