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. 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. if (groupOrder.status === 'SUCCESSED') {
  159. this.showSuccess(groupOrder.organizer, groupOrder.organizerPrice)
  160. } else {
  161. this.goToDetail(groupOrder.id)
  162. }
  163. } else {
  164. debugger;
  165. for (var i = 0; i < surplusNum; i++) {
  166. this.data.surplusList.push(1);
  167. }
  168. }
  169. console.log(groupOrder.closeTime - groupOrder.gmtModified)
  170. //时间转换
  171. let timeNow = new Date()
  172. // const timeList = util.formatTime(groupOrder.closeTime - groupOrder.gmtModified);
  173. const timeList = util.formatTime(groupOrder.closeTime - Date.parse(new Date()));
  174. this.setData({
  175. surplusNum,
  176. joinUserList: res.data.data.joinUserList,
  177. surplusList: this.data.surplusList,
  178. timeList,
  179. })
  180. if(groupOrder.groupType === 'PROMOTION'){
  181. this.data.joinUserList.unshift(res.data.data.organizer);
  182. //this.data.surplusList.pop();
  183. this.setData({
  184. joinUserList: this.data.joinUserList,
  185. //surplusList: this.data.surplusList,
  186. surplusNum: this.data.surplusNum
  187. })
  188. }
  189. console.log(this.data.joinUserList)
  190. // this.groupSuccess(res.data.data.groupPurchaseOrder.productId, detailId);
  191. }).fail(error => {
  192. console.log('错误', error)
  193. })
  194. },
  195. // 弹成功信息框
  196. showSuccess: function (organizerUid, price) {
  197. if (wx.getStorageSync('uid') == organizerUid) {
  198. this.setData({
  199. typeOf: 'success',
  200. title: '恭喜 !',
  201. headTextOne: '您发起的团购拼团成功',
  202. content: [{
  203. text: "领袖体质魅力无穷!",
  204. color: "#000"
  205. },
  206. {
  207. text: " 您可以继续发起新的团购,",
  208. color: "#000"
  209. },
  210. {
  211. text: " 不再需要支付本课程费用,拼团成功,",
  212. color: "#FF9B00"
  213. },
  214. {
  215. text: `您将得到${price / 100}元奖励。`,
  216. color: "#FF0000"
  217. }
  218. ],
  219. },()=>{
  220. this.popup.close()
  221. })
  222. } else {
  223. debugger;
  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. // wx.navigateTo({
  343. // url: `/pages/groupPage/make-money/make-money?productId=${this.data.productId}&id=${this.data.orderId}&groupId=${this.data.groupId}`
  344. // })
  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. })