group-details.js 8.5 KB

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