group-details.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  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. this.setData({
  270. typeOf: 'success',
  271. title: '拼团成功 ! ',
  272. headTextOne: '您参与的团购拼团成功',
  273. headTextTwo: '',
  274. content: [{
  275. text: "感谢团长的分享",
  276. color: "#000"
  277. },
  278. {
  279. text: " 您也可以发起新的团购分享给需要的朋友们,",
  280. color: "#000"
  281. },
  282. {
  283. text: "作为新的发起人,您无需在支付本课程费用;",
  284. color: "#FF0000"
  285. },
  286. {
  287. text: `团购成功,您将得到${price/ 100}元奖励。`,
  288. color: "#FF0000"
  289. }
  290. ],
  291. },()=>{
  292. this.popup.close()
  293. })
  294. }
  295. },
  296. // 去详情页面
  297. goToDetail: function (detailId) {
  298. setTimeout(() => {
  299. wx.navigateTo({
  300. url: `/pages/groupPage/collage-details/collage-details?orderId=${detailId}`
  301. })
  302. wx.setNavigationBarTitle({
  303. title: '拼团详情'
  304. })
  305. }, 3000)
  306. },
  307. //跳到课程
  308. goToClass: function (e) {
  309. let id = e.currentTarget.dataset.id;
  310. let title = e.currentTarget.dataset.title;
  311. wx.navigateTo({
  312. url: `../../main/class/class?id=${id}&title=${title}`
  313. })
  314. },
  315. //再次发起团
  316. group: function () {
  317. const orderId = this.data.orderId;
  318. this.goToDetail(orderId);
  319. //拼团是否成功并弹窗
  320. // httpRequestApi.groupSuccess(orderId).success(res => {
  321. // console.log('团购是否成功', res.data.data)
  322. // debugger;
  323. // const status = res.data.data.status;
  324. // const uid = res.data.data.uid;
  325. // }).fail(error => {
  326. // console.log('错误', eroor)
  327. // })
  328. //this.openGroup();
  329. },
  330. /**
  331. * 生命周期函数--监听页面加载
  332. */
  333. onLoad: function (options) {
  334. getOpenidSessionKey((res) => {}, (error) => {
  335. this.setData({
  336. hide: !this.data.hide
  337. })
  338. return;
  339. });
  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. httpRequestApi.getAllBooks(1, 10).success((res) => {
  377. console.log('全部课',res.data.data.list)
  378. res.data.data.list.forEach(element => {
  379. this.data.selectFlag.push(true);
  380. });
  381. this.setData({
  382. bookList: res.data.data.list,
  383. selectFlag: this.data.selectFlag
  384. })
  385. }).fail((error) => {
  386. console.log('错误',error)
  387. })
  388. //获取拼团信息
  389. this.jionSuccess(orderId);
  390. },
  391. /**
  392. * 生命周期函数--监听页面初次渲染完成
  393. */
  394. onReady: function () {
  395. this.popup = this.selectComponent("#popupup");
  396. },
  397. /**
  398. * 生命周期函数--监听页面显示
  399. */
  400. onShow: function () {
  401. },
  402. /**
  403. * 生命周期函数--监听页面隐藏
  404. */
  405. onHide: function () {
  406. },
  407. /**
  408. * 生命周期函数--监听页面卸载
  409. */
  410. onUnload: function () {
  411. },
  412. /**
  413. * 页面相关事件处理函数--监听用户下拉动作
  414. */
  415. onPullDownRefresh: function () {
  416. },
  417. /**
  418. * 页面上拉触底事件的处理函数
  419. */
  420. onReachBottom: function () {
  421. },
  422. /**
  423. * 用户点击右上角分享
  424. */
  425. onShareAppMessage: function () {
  426. }
  427. })