group-details.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  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. debugger;
  161. if (groupOrder.status === 'SUCCESSED') {
  162. this.showSuccess(groupOrder.organizer, groupOrder.organizerPrice)
  163. } else {
  164. this.goToDetail(groupOrder.id)
  165. }
  166. } else {
  167. debugger;
  168. for (var i = 0; i < surplusNum; i++) {
  169. this.data.surplusList.push(1);
  170. }
  171. }
  172. console.log(groupOrder.closeTime - groupOrder.gmtModified)
  173. //时间转换
  174. let timeNow = new Date()
  175. // const timeList = util.formatTime(groupOrder.closeTime - groupOrder.gmtModified);
  176. const timeList = util.formatTime(groupOrder.closeTime - Date.parse(new Date()));
  177. this.setData({
  178. surplusNum,
  179. joinUserList: res.data.data.joinUserList,
  180. surplusList: this.data.surplusList,
  181. timeList,
  182. })
  183. if(groupOrder.groupType === 'PROMOTION'){
  184. this.data.joinUserList.unshift(res.data.data.organizer);
  185. //this.data.surplusList.pop();
  186. this.setData({
  187. joinUserList: this.data.joinUserList,
  188. //surplusList: this.data.surplusList,
  189. surplusNum: this.data.surplusNum
  190. })
  191. }
  192. console.log(this.data.joinUserList)
  193. // this.groupSuccess(res.data.data.groupPurchaseOrder.productId, detailId);
  194. }).fail(error => {
  195. console.log('错误', error)
  196. })
  197. },
  198. // 弹成功信息框
  199. showSuccess: function (organizerUid, price) {
  200. if (wx.getStorageSync('uid') == organizerUid) {
  201. this.setData({
  202. typeOf: 'success',
  203. title: '恭喜 !',
  204. headTextOne: '您发起的团购拼团成功',
  205. content: [{
  206. text: "领袖体质魅力无穷!",
  207. color: "#000"
  208. },
  209. {
  210. text: " 您可以继续发起新的团购,",
  211. color: "#000"
  212. },
  213. {
  214. text: " 不再需要支付本课程费用,拼团成功,",
  215. color: "#FF9B00"
  216. },
  217. {
  218. text: `您将得到${price / 100}元奖励。`,
  219. color: "#FF0000"
  220. }
  221. ],
  222. },()=>{
  223. this.popup.close()
  224. })
  225. } else {
  226. debugger;
  227. this.setData({
  228. typeOf: 'success',
  229. title: '拼团成功 ! ',
  230. headTextOne: '您参与的团购拼团成功',
  231. headTextTwo: '',
  232. content: [{
  233. text: "感谢团长的分享",
  234. color: "#000"
  235. },
  236. {
  237. text: " 您也可以发起新的团购分享给需要的朋友们,",
  238. color: "#000"
  239. },
  240. {
  241. text: "作为新的发起人,您无需在支付本课程费用;",
  242. color: "#FF0000"
  243. },
  244. {
  245. text: `团购成功,您将得到${price/ 100}元奖励。`,
  246. color: "#FF0000"
  247. }
  248. ],
  249. },()=>{
  250. this.popup.close()
  251. })
  252. }
  253. },
  254. // 去详情页面
  255. goToDetail: function (detailId) {
  256. setTimeout(() => {
  257. wx.navigateTo({
  258. url: `/pages/groupPage/collage-details/collage-details?orderId=${detailId}`
  259. })
  260. wx.setNavigationBarTitle({
  261. title: '拼团详情'
  262. })
  263. }, 3000)
  264. },
  265. //跳到课程
  266. goToClass: function (e) {
  267. let id = e.currentTarget.dataset.id;
  268. let title = e.currentTarget.dataset.title;
  269. wx.navigateTo({
  270. url: `../../main/class/class?id=${id}&title=${title}`
  271. })
  272. },
  273. //拼团是否成功并弹窗
  274. // groupSuccess: function (orderId, detailId) {
  275. // httpRequestApi.groupSuccess(orderId).success(res => {
  276. // console.log('团购是否成功', res.data.data)
  277. // const status = res.data.data.status;
  278. // const uid = res.data.data.uid;
  279. // if (status === 'SUCCESSED') {
  280. // if (wx.getStorageSync('uid') == uid) {
  281. // this.setData({
  282. // typeOf: 'success',
  283. // title: '恭喜 !',
  284. // headTextOne: '您发起的团购拼团成功',
  285. // content: [{
  286. // text: "领袖体质魅力无穷!",
  287. // color: "#000"
  288. // },
  289. // {
  290. // text: " 您可以继续发起新的团购,",
  291. // color: "#000"
  292. // },
  293. // {
  294. // text: " 不再需要支付本课程费用,拼团成功,",
  295. // color: "#FF9B00"
  296. // },
  297. // {
  298. // text: " 您将得到xxx元奖励。",
  299. // color: "#FF0000"
  300. // }
  301. // ],
  302. // })
  303. // } else {
  304. // this.setData({
  305. // typeOf: 'success',
  306. // title: '拼团成功 ! ',
  307. // headTextOne: '您参与的团购拼团成功',
  308. // headTextTwo: '订单号:12344',
  309. // content: [{
  310. // text: "感谢团长的分享",
  311. // color: "#000"
  312. // },
  313. // {
  314. // text: " 您也可以发起新的团购分享给需要的朋友们,",
  315. // color: "#000"
  316. // },
  317. // {
  318. // text: "作为新的发起人,您无需在支付本课程费用;",
  319. // color: "#FF0000"
  320. // },
  321. // {
  322. // text: "团购成功,您将得到xxx元奖励。",
  323. // color: "#FF0000"
  324. // }
  325. // ],
  326. // })
  327. // }
  328. // } else {
  329. // setTimeout(() => {
  330. // wx.navigateTo({
  331. // url: `/pages/groupPage/collage-details/collage-details?orderId=${detailId}`
  332. // })
  333. // wx.setNavigationBarTitle({
  334. // title: '拼团详情'
  335. // })
  336. // }, 3000)
  337. // }
  338. // }).fail(error => {
  339. // console.log('错误', eroor)
  340. // })
  341. // },
  342. //再次发起团
  343. group: function () {
  344. this.openGroup();
  345. },
  346. /**
  347. * 生命周期函数--监听页面加载
  348. */
  349. onLoad: function (options) {
  350. getOpenidSessionKey((res) => {}, (error) => {
  351. this.setData({
  352. hide: !this.data.hide
  353. })
  354. return;
  355. });
  356. wx.setNavigationBarTitle({
  357. title: '拼团详情'
  358. })
  359. if (!options.productId) return false;
  360. const productId = options.productId;
  361. const groupId = options.groupId;
  362. const orderId = options.id;
  363. this.setData({
  364. productId,
  365. groupId,
  366. orderId
  367. })
  368. //课本详情
  369. httpRequestApi.getBookDetail(wx.getStorageSync('uid'), productId).success((res) => {
  370. console.log('课本详情', res.data.data);
  371. const bookInfo = res.data.data.product;
  372. const lessonList = res.data.data.lessonList;
  373. this.setData({
  374. titleIcon: bookInfo.bgImg,
  375. title: bookInfo.title,
  376. bookInfo: bookInfo.description
  377. })
  378. const lessonTemp = [];
  379. lessonList.forEach(item => {
  380. const temp = {};
  381. temp.id = item.id;
  382. temp.title = item.title;
  383. temp.readNum = item.readCount;
  384. lessonTemp.push(temp);
  385. });
  386. this.setData({
  387. lessonList: lessonTemp
  388. });
  389. }).fail((error) => {
  390. })
  391. //获取拼团信息
  392. this.jionSuccess(orderId);
  393. },
  394. /**
  395. * 生命周期函数--监听页面初次渲染完成
  396. */
  397. onReady: function () {
  398. this.popup = this.selectComponent("#popupup");
  399. },
  400. /**
  401. * 生命周期函数--监听页面显示
  402. */
  403. onShow: function () {
  404. },
  405. /**
  406. * 生命周期函数--监听页面隐藏
  407. */
  408. onHide: function () {
  409. },
  410. /**
  411. * 生命周期函数--监听页面卸载
  412. */
  413. onUnload: function () {
  414. },
  415. /**
  416. * 页面相关事件处理函数--监听用户下拉动作
  417. */
  418. onPullDownRefresh: function () {
  419. },
  420. /**
  421. * 页面上拉触底事件的处理函数
  422. */
  423. onReachBottom: function () {
  424. },
  425. /**
  426. * 用户点击右上角分享
  427. */
  428. onShareAppMessage: function () {
  429. }
  430. })