group-details.js 12 KB

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