collage-details.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. // pages/groupPage/collage-details/collage-details.js
  2. import httpRequestApi from '../../../utils/APIClient';
  3. import util from '../../../utils/util';
  4. const app = getApp()
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. groupPurchaseInfo: {},
  11. organizer: {},
  12. surplusNum: '',
  13. joinUserList: [],
  14. surplusList: [],
  15. timeList: [],
  16. productId: '',
  17. orderId: '',
  18. groupId: '',
  19. content: [{
  20. text: "转发给自己的朋友们",
  21. color: "#000"
  22. },
  23. {
  24. text: " 分享好课,追随您一起学习进步",
  25. color: "#000"
  26. },
  27. {
  28. text: " 您的魅力不是吹的",
  29. color: "#000"
  30. },
  31. {
  32. text: "在限定时间内成功拼团,您将得到奖学金。",
  33. color: "#FF4600"
  34. }
  35. ],
  36. read: false,
  37. organizerUid: '',
  38. colonelName: '',
  39. rewardMoney: '',
  40. goBackHome: false,
  41. dataLoading: true
  42. },
  43. //显示分享页
  44. openShare: function () {
  45. if (this.data.read) {
  46. const productId = this.data.productId;
  47. const id = this.data.orderId;
  48. const groupId = this.data.groupId;
  49. wx.navigateTo({
  50. url: `/pages/groupPage/grade-details/grade-details?productId=${productId}&id=${id}&groupId=${groupId}&share=true`
  51. })
  52. } else {
  53. this.shareDialog = this.selectComponent("#share-dialog");
  54. const data = {
  55. avatar: this.data.organizer.avatar,
  56. author: this.data.organizer.wechatName,
  57. iconImg: this.data.groupPurchaseInfo.bgImg,
  58. title: this.data.groupPurchaseInfo.productTitle,
  59. path: `pages/groupPage/group-details/group-details`,
  60. scene: `QR${this.data.orderId}`,
  61. groupPurchaseInfo: this.data.groupPurchaseInfo,
  62. groupType: this.data.groupOsType
  63. }
  64. this.shareDialog.share(data);
  65. }
  66. },
  67. // 下拉刷新
  68. onPullDownRefresh: function () {
  69. this.setData({
  70. surplusList: []
  71. }, () => {
  72. this.getInfo();
  73. })
  74. wx.showNavigationBarLoading() //在标题栏中显示加载
  75. //模拟加载
  76. setTimeout(function () {
  77. wx.hideNavigationBarLoading() //完成停止加载
  78. wx.stopPullDownRefresh() //停止下拉刷新
  79. }, 1500);
  80. },
  81. /**
  82. * 生命周期函数--监听页面加载
  83. */
  84. onLoad: function (options) {
  85. // if (app.globalData.isIOS) {
  86. // wx.redirectTo({
  87. // url: '../../index/index'
  88. // })
  89. // return
  90. // }
  91. if (options.read) {
  92. this.setData({
  93. read: options.read
  94. })
  95. }
  96. if (options.goBackHome == 'true') {
  97. this.setData({
  98. goBackHome: true
  99. })
  100. }
  101. // options.scene = 'QR1541862338777268';
  102. wx.setNavigationBarTitle({
  103. title: '拼团详情'
  104. })
  105. console.log(options);
  106. console.log(options.orderId);
  107. const orderId = options.orderId ? options.orderId : options.scene.replace('QR', '');
  108. // if (options.orderId) {
  109. // return false;
  110. // }
  111. console.log(orderId)
  112. this.setData({
  113. orderId
  114. }, () => {
  115. this.getInfo()
  116. })
  117. },
  118. getInfo: function () {
  119. httpRequestApi.getMygroupInfo(this.data.orderId).success(res => {
  120. console.log(res);
  121. const groupOrder = res.data.data.groupPurchaseOrder;
  122. const surplusNum = groupOrder.headcount - groupOrder.joinCount;
  123. this.setData({
  124. organizerUid: groupOrder.organizer,
  125. read: groupOrder.status === 'SUCCESSED' ? true : false
  126. })
  127. for (var i = 0; i < surplusNum; i++) {
  128. this.data.surplusList.push(1);
  129. }
  130. //console.log(res.data.data.groupPurchaseOrder.closeTime - res.data.data.groupPurchaseOrder.gmtModified)
  131. //时间转换
  132. let timeList = [];
  133. const stillGoing = groupOrder.closeTime - Date.parse(new Date()) <= 0 ? false : true
  134. if (stillGoing) {
  135. timeList = util.lastHoursInGroup(groupOrder.closeTime - Date.parse(new Date()));
  136. }
  137. // const timeList = util.formatTime(groupOrder.closeTime - Date.parse(new Date()));
  138. // console.log(timeList)
  139. //res.data.data.joinUserList.unshift(res.data.data.organizer);
  140. this.setData({
  141. groupPurchaseInfo: res.data.data.groupPurchaseInfo,
  142. organizer: res.data.data.organizer,
  143. surplusNum,
  144. joinUserList: res.data.data.joinUserList,
  145. surplusList: this.data.surplusList,
  146. timeList,
  147. stillGoing,
  148. productId: groupOrder.productId,
  149. groupId: groupOrder.groupId,
  150. rewardMoney: res.data.data.groupPurchaseInfo.organizerPrice / 100,
  151. dataLoading: false,
  152. groupOsType: groupOrder.os
  153. })
  154. if (groupOrder.groupType === 'PROMOTION') {
  155. //this.data.joinUserList.unshift(res.data.data.organizer);
  156. this.setData({
  157. colonelName: res.data.data.organizer.wechatName
  158. })
  159. this.setData({
  160. joinUserList: this.data.joinUserList,
  161. })
  162. }
  163. })
  164. },
  165. /**
  166. * 生命周期函数--监听页面初次渲染完成
  167. */
  168. onReady: function () {
  169. this.shareDialog = this.selectComponent("#share-dialog");
  170. },
  171. /**
  172. * 用户点击右上角分享
  173. */
  174. onShareAppMessage: function (ops) {
  175. if (ops.from === 'button') {
  176. console.log(ops.target)
  177. }
  178. const id = this.data.orderId;
  179. const data = {
  180. shareTypeEnum: 'LINK',
  181. shareContentEnum: 'GROUP',
  182. productId: this.data.productId
  183. }
  184. httpRequestApi.shareRecord(data).success((res) => {
  185. console.log(res)
  186. })
  187. return {
  188. title: '老师同学都在玩的配音show,你还在等什么?',
  189. path: `pages/groupPage/group-details/group-details?share=true&shareId=${id}`,
  190. imageUrl: `https://efunbox.lingjiao.cn/reader/resource/share/group_${this.data.productId}.jpg`,
  191. }
  192. }
  193. })