group-details.js 11 KB

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