group-details.js 12 KB

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