group-details.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  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. debugger;
  135. httpRequestApi.getMygroupInfo(orderId).success(res => {
  136. console.log('拼团详情', res.data.data);
  137. const surplusNum = res.data.data.groupPurchaseOrder.headcount - res.data.data.groupPurchaseOrder.joinCount;
  138. if (type === 'join') {
  139. this.data.surplusList.pop();
  140. if (res.data.data.groupPurchaseOrder.status === 'SUCCESSED') {
  141. this.showSuccess(res.data.data.groupPurchaseOrder.organizer, res.data.data.groupPurchaseOrder.organizerPrice)
  142. } else {
  143. this.goToDetail(res.data.data.groupPurchaseOrder.id)
  144. }
  145. } else {
  146. for (var i = 0; i < surplusNum; i++) {
  147. this.data.surplusList.push(1);
  148. }
  149. }
  150. console.log(res.data.data.groupPurchaseOrder.closeTime - res.data.data.groupPurchaseOrder.gmtModified)
  151. //时间转换
  152. const timeList = util.formatTime(res.data.data.groupPurchaseOrder.closeTime - res.data.data.groupPurchaseOrder.gmtModified);
  153. console.log(timeList)
  154. this.setData({
  155. surplusNum,
  156. joinUserList: res.data.data.joinUserList,
  157. surplusList: this.data.surplusList,
  158. timeList,
  159. })
  160. // this.groupSuccess(res.data.data.groupPurchaseOrder.productId, detailId);
  161. }).fail(error => {
  162. console.log('错误', error)
  163. })
  164. },
  165. // 弹成功信息框
  166. showSuccess: function (organizerUid, price) {
  167. if (wx.getStorageSync('uid') == organizerUid) {
  168. this.setData({
  169. typeOf: 'success',
  170. title: '恭喜 !',
  171. headTextOne: '您发起的团购拼团成功',
  172. content: [{
  173. text: "领袖体质魅力无穷!",
  174. color: "#000"
  175. },
  176. {
  177. text: " 您可以继续发起新的团购,",
  178. color: "#000"
  179. },
  180. {
  181. text: " 不再需要支付本课程费用,拼团成功,",
  182. color: "#FF9B00"
  183. },
  184. {
  185. text: `您将得到${price / 100}元奖励。`,
  186. color: "#FF0000"
  187. }
  188. ],
  189. },()=>{
  190. this.popup.close()
  191. })
  192. } else {
  193. this.setData({
  194. typeOf: 'success',
  195. title: '拼团成功 ! ',
  196. headTextOne: '您参与的团购拼团成功',
  197. headTextTwo: '',
  198. content: [{
  199. text: "感谢团长的分享",
  200. color: "#000"
  201. },
  202. {
  203. text: " 您也可以发起新的团购分享给需要的朋友们,",
  204. color: "#000"
  205. },
  206. {
  207. text: "作为新的发起人,您无需在支付本课程费用;",
  208. color: "#FF0000"
  209. },
  210. {
  211. text: `团购成功,您将得到${price/ 100}元奖励。`,
  212. color: "#FF0000"
  213. }
  214. ],
  215. },()=>{
  216. this.popup.close()
  217. })
  218. }
  219. },
  220. // 去详情页面
  221. goToDetail: function (detailId) {
  222. setTimeout(() => {
  223. wx.navigateTo({
  224. url: `/pages/groupPage/collage-details/collage-details?orderId=${detailId}`
  225. })
  226. wx.setNavigationBarTitle({
  227. title: '拼团详情'
  228. })
  229. }, 3000)
  230. },
  231. //拼团是否成功并弹窗
  232. // groupSuccess: function (orderId, detailId) {
  233. // httpRequestApi.groupSuccess(orderId).success(res => {
  234. // console.log('团购是否成功', res.data.data)
  235. // const status = res.data.data.status;
  236. // const uid = res.data.data.uid;
  237. // if (status === 'SUCCESSED') {
  238. // if (wx.getStorageSync('uid') == uid) {
  239. // this.setData({
  240. // typeOf: 'success',
  241. // title: '恭喜 !',
  242. // headTextOne: '您发起的团购拼团成功',
  243. // content: [{
  244. // text: "领袖体质魅力无穷!",
  245. // color: "#000"
  246. // },
  247. // {
  248. // text: " 您可以继续发起新的团购,",
  249. // color: "#000"
  250. // },
  251. // {
  252. // text: " 不再需要支付本课程费用,拼团成功,",
  253. // color: "#FF9B00"
  254. // },
  255. // {
  256. // text: " 您将得到xxx元奖励。",
  257. // color: "#FF0000"
  258. // }
  259. // ],
  260. // })
  261. // } else {
  262. // this.setData({
  263. // typeOf: 'success',
  264. // title: '拼团成功 ! ',
  265. // headTextOne: '您参与的团购拼团成功',
  266. // headTextTwo: '订单号:12344',
  267. // content: [{
  268. // text: "感谢团长的分享",
  269. // color: "#000"
  270. // },
  271. // {
  272. // text: " 您也可以发起新的团购分享给需要的朋友们,",
  273. // color: "#000"
  274. // },
  275. // {
  276. // text: "作为新的发起人,您无需在支付本课程费用;",
  277. // color: "#FF0000"
  278. // },
  279. // {
  280. // text: "团购成功,您将得到xxx元奖励。",
  281. // color: "#FF0000"
  282. // }
  283. // ],
  284. // })
  285. // }
  286. // } else {
  287. // setTimeout(() => {
  288. // wx.navigateTo({
  289. // url: `/pages/groupPage/collage-details/collage-details?orderId=${detailId}`
  290. // })
  291. // wx.setNavigationBarTitle({
  292. // title: '拼团详情'
  293. // })
  294. // }, 3000)
  295. // }
  296. // }).fail(error => {
  297. // console.log('错误', eroor)
  298. // })
  299. // },
  300. //再次发起团
  301. group: function () {
  302. wx.showModal({
  303. title: '提示',
  304. content: '再次发起团',
  305. success(res) {
  306. if (res.confirm) {
  307. console.log('用户点击确定')
  308. } else if (res.cancel) {
  309. console.log('用户点击取消')
  310. }
  311. }
  312. })
  313. },
  314. /**
  315. * 生命周期函数--监听页面加载
  316. */
  317. onLoad: function (options) {
  318. wx.setNavigationBarTitle({
  319. title: '拼团详情'
  320. })
  321. if (!options.productId) return false;
  322. const productId = options.productId;
  323. const groupId = options.groupId;
  324. const orderId = options.id;
  325. this.setData({
  326. productId,
  327. groupId,
  328. orderId
  329. })
  330. //课本详情
  331. httpRequestApi.getBookDetail(wx.getStorageSync('uid'), productId).success((res) => {
  332. console.log('课本详情', res.data.data);
  333. const bookInfo = res.data.data.product;
  334. const lessonList = res.data.data.lessonList;
  335. this.setData({
  336. titleIcon: bookInfo.bgImg,
  337. title: bookInfo.title,
  338. bookInfo: bookInfo.description
  339. })
  340. const lessonTemp = [];
  341. lessonList.forEach(item => {
  342. const temp = {};
  343. temp.id = item.id;
  344. temp.title = item.title;
  345. temp.readNum = item.readCount;
  346. lessonTemp.push(temp);
  347. });
  348. this.setData({
  349. lessonList: lessonTemp
  350. });
  351. }).fail((error) => {
  352. })
  353. //获取拼团信息
  354. this.jionSuccess(orderId);
  355. },
  356. /**
  357. * 生命周期函数--监听页面初次渲染完成
  358. */
  359. onReady: function () {
  360. this.popup = this.selectComponent("#popupup");
  361. },
  362. /**
  363. * 生命周期函数--监听页面显示
  364. */
  365. onShow: function () {
  366. },
  367. /**
  368. * 生命周期函数--监听页面隐藏
  369. */
  370. onHide: function () {
  371. },
  372. /**
  373. * 生命周期函数--监听页面卸载
  374. */
  375. onUnload: function () {
  376. },
  377. /**
  378. * 页面相关事件处理函数--监听用户下拉动作
  379. */
  380. onPullDownRefresh: function () {
  381. },
  382. /**
  383. * 页面上拉触底事件的处理函数
  384. */
  385. onReachBottom: function () {
  386. },
  387. /**
  388. * 用户点击右上角分享
  389. */
  390. onShareAppMessage: function () {
  391. }
  392. })