group-details.js 12 KB

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