group-details.js 11 KB

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