group-details.js 12 KB

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