group-details.js 11 KB

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