group-details.js 12 KB

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