group-details.js 12 KB

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