group-details.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  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, res.data.data.groupPurchaseOrderDetail.orderId);
  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, res.data.data.orderId);
  88. }).fail( (error) => {
  89. })
  90. },
  91. //支付
  92. prePayMap: function (prePayMap, orderId) {
  93. console.log(prePayMap)
  94. const that = this;
  95. wx.requestPayment(
  96. {
  97. 'appId': prePayMap.appId,
  98. 'timeStamp': prePayMap.timeStamp,
  99. 'nonceStr': prePayMap.nonceStr,
  100. 'package': prePayMap.package,
  101. 'signType': 'MD5',
  102. 'paySign': prePayMap.sign,
  103. 'success':function(res){
  104. console.log('支付成功')
  105. wx.showModal({
  106. title: '提示',
  107. content: '支付成功',
  108. success (res) {
  109. if (res.confirm) {
  110. //获取拼团信息
  111. this.jionSuccess(this.data.orderId);
  112. this.groupSuccess(orderId);
  113. } else if (res.cancel) {
  114. //获取拼团信息
  115. this.jionSuccess(this.data.orderId);
  116. this.groupSuccess(orderId);
  117. }
  118. }
  119. })
  120. },
  121. 'fail':function(res){
  122. console.log('支付失败', res)
  123. }
  124. })
  125. },
  126. //跳转到拼团详情
  127. collage: function () {
  128. },
  129. //拼团详情
  130. jionSuccess: function (orderId) {
  131. httpRequestApi.getMygroupInfo(orderId).success( res => {
  132. console.log('拼团详情', res.data.data);
  133. const surplusNum = res.data.data.groupPurchaseOrder.headcount - res.data.data.groupPurchaseOrder.joinCount;
  134. for(var i = 0; i < surplusNum; i++) {
  135. this.data.surplusList.push(1);
  136. }
  137. console.log(res.data.data.groupPurchaseOrder.closeTimed - res.data.data.groupPurchaseOrder.gmtCreated)
  138. //时间转换
  139. const timeList = util.formatTime(res.data.data.groupPurchaseOrder.closeTimed - res.data.data.groupPurchaseOrder.gmtCreated);
  140. this.setData({
  141. surplusNum,
  142. joinUserList: res.data.data.joinUserList,
  143. surplusList: this.data.surplusList,
  144. timeList,
  145. })
  146. }).fail( error => {
  147. console.log('错误', error)
  148. })
  149. },
  150. //拼团是否成功并弹窗
  151. groupSuccess: function (orderId) {
  152. httpRequestApi.groupSuccess(orderId).success( res => {
  153. console.log('团购是否成功',res.data.data)
  154. const status = res.data.data.status;
  155. const uid = res.data.data.uid;
  156. if(status == 'successed') {
  157. if(wx.getStorageSync(uid) == uid) {
  158. this.setData({
  159. typeOf: 'success',
  160. title: '恭喜 !',
  161. headTextOne: '您发起的团购拼团成功',
  162. content: [
  163. {
  164. text: "领袖体质魅力无穷!",
  165. color: "#000"
  166. },
  167. {
  168. text: " 您可以继续发起新的团购,",
  169. color: "#000"
  170. },
  171. {
  172. text: " 不再需要支付本课程费用,拼团成功,",
  173. color: "#FF9B00"
  174. },
  175. {
  176. text: " 您将得到xxx元奖励。",
  177. color: "#FF0000"
  178. }
  179. ],
  180. })
  181. }else {
  182. this.setData({
  183. typeOf: 'success',
  184. title: '拼团成功 ! ',
  185. headTextOne: '您参与的团购拼团成功',
  186. headTextTwo: '订单号:12344',
  187. content: [
  188. {
  189. text: "感谢团长的分享",
  190. color: "#000"
  191. },
  192. {
  193. text: " 您也可以发起新的团购分享给需要的朋友们,",
  194. color: "#000"
  195. },
  196. {
  197. text: "作为新的发起人,您无需在支付本课程费用;",
  198. color: "#FF0000"
  199. },
  200. {
  201. text: "团购成功,您将得到xxx元奖励。",
  202. color: "#FF0000"
  203. }
  204. ],
  205. })
  206. }
  207. }else {
  208. setTimeout(() => {
  209. wx.navigateTo({
  210. url: `/pages/groupPage/collage-details/collage-details?orderId=${orderId}`
  211. })
  212. wx.setNavigationBarTitle({
  213. title: '拼团详情'
  214. })
  215. }, 1000)
  216. }
  217. }).fail( error => {
  218. console.log('错误', eroor)
  219. })
  220. },
  221. //再次发起团
  222. group: function () {
  223. wx.showModal({
  224. title: '提示',
  225. content: '再次发起团',
  226. success (res) {
  227. if (res.confirm) {
  228. console.log('用户点击确定')
  229. } else if (res.cancel) {
  230. console.log('用户点击取消')
  231. }
  232. }
  233. })
  234. },
  235. /**
  236. * 生命周期函数--监听页面加载
  237. */
  238. onLoad: function (options) {
  239. wx.setNavigationBarTitle({
  240. title: '拼团详情'
  241. })
  242. if(!options.productId) return false;
  243. const productId = options.productId;
  244. const groupId = options.groupId;
  245. const orderId = options.id;
  246. this.setData({
  247. productId,
  248. groupId,
  249. orderId
  250. })
  251. //课本详情
  252. httpRequestApi.getBookDetail(wx.getStorageSync('uid'), productId).success( (res) =>{
  253. console.log('课本详情',res.data.data);
  254. const bookInfo = res.data.data.product;
  255. const lessonList = res.data.data.lessonList;
  256. this.setData({
  257. titleIcon: bookInfo.bgImg,
  258. title: bookInfo.title,
  259. bookInfo: bookInfo.description
  260. })
  261. const lessonTemp = [];
  262. lessonList.forEach(item => {
  263. const temp = {};
  264. temp.id = item.id;
  265. temp.title = item.title;
  266. temp.readNum = item.readCount;
  267. lessonTemp.push(temp);
  268. });
  269. this.setData({
  270. lessonList: lessonTemp
  271. });
  272. }).fail( (error) => {
  273. })
  274. //获取拼团信息
  275. this.jionSuccess(orderId);
  276. },
  277. /**
  278. * 生命周期函数--监听页面初次渲染完成
  279. */
  280. onReady: function () {
  281. },
  282. /**
  283. * 生命周期函数--监听页面显示
  284. */
  285. onShow: function () {
  286. },
  287. /**
  288. * 生命周期函数--监听页面隐藏
  289. */
  290. onHide: function () {
  291. },
  292. /**
  293. * 生命周期函数--监听页面卸载
  294. */
  295. onUnload: function () {
  296. },
  297. /**
  298. * 页面相关事件处理函数--监听用户下拉动作
  299. */
  300. onPullDownRefresh: function () {
  301. },
  302. /**
  303. * 页面上拉触底事件的处理函数
  304. */
  305. onReachBottom: function () {
  306. },
  307. /**
  308. * 用户点击右上角分享
  309. */
  310. onShareAppMessage: function () {
  311. }
  312. })