group-details.js 12 KB

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