group-details.js 11 KB

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