my-group.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. // pages/groupPage/my-group/my-group.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. myGroupList: [],
  11. typeOf: '',
  12. title: '',
  13. headTextOne: '',
  14. headTextTwo: '',
  15. content: [],
  16. productId: '',
  17. orderId: '',
  18. groupId: '',
  19. closeFlags: [],
  20. ind: 0,
  21. timeList: [],
  22. line1: '您还没有拼过团哦',
  23. line2: '拼过团再来看看吧'
  24. },
  25. //跳转到团购详情页
  26. collageDetails: function ({
  27. currentTarget
  28. }) {
  29. const orderId = currentTarget.dataset.orderid;
  30. const productId = currentTarget.dataset.productid;
  31. const groupId = currentTarget.dataset.groupid;
  32. const uid = currentTarget.dataset.uid;
  33. const num = currentTarget.dataset.num;
  34. const ind = currentTarget.dataset.ind;
  35. this.setData({
  36. ind
  37. })
  38. console.log(num)
  39. if (!num) {
  40. wx.navigateTo({
  41. url: `/pages/groupPage/collage-details/collage-details?orderId=${orderId}`
  42. })
  43. } else {
  44. if (this.data.closeFlags[ind]) {
  45. this.popup.close();
  46. this.setData({
  47. productId,
  48. orderId,
  49. groupId
  50. })
  51. this.dialog(uid);
  52. } else {
  53. wx.navigateTo({
  54. url: `/pages/groupPage/collage-details/collage-details?orderId=${orderId}&read=true`
  55. })
  56. }
  57. }
  58. },
  59. /**
  60. * 生命周期函数--监听页面加载
  61. */
  62. onLoad: function (option) {
  63. // if (app.globalData.isIOS) {
  64. // wx.redirectTo({
  65. // url: '../../index/index'
  66. // })
  67. // return
  68. // }
  69. if (option && option.title) {
  70. wx.setNavigationBarTitle({
  71. title: option.title //页面标题为路由参数
  72. });
  73. this.setData({
  74. title: option.title
  75. });
  76. }
  77. this.getMyGroup();
  78. },
  79. // 获取我的拼团
  80. getMyGroup: function () {
  81. httpRequestApi.getMygroup().success((res) => {
  82. if (!res.data.data.list) {
  83. return
  84. }
  85. this.setData({
  86. myGroupList: [],
  87. myGroupList: [],
  88. timeList: []
  89. });
  90. console.log('我的团', res.data.data.list)
  91. res.data.data.list.forEach(element => {
  92. if (element.groupPurchaseOrder.status == 'SUCCESSED') {
  93. this.data.closeFlags.push(true);
  94. this.data.timeList.push(util.formatDate(element.groupPurchaseOrder.gmtModified, 4))
  95. } else {
  96. this.data.closeFlags.push(false);
  97. if (element.groupPurchaseOrder.closeTime - Date.parse(new Date()) < 0) {
  98. this.data.timeList.push('时间到了,')
  99. } else {
  100. this.data.timeList.push(util.lastHours(element.groupPurchaseOrder.closeTime - Date.parse(new Date())))
  101. }
  102. }
  103. });
  104. this.setData({
  105. closeFlags: this.data.closeFlags,
  106. myGroupList: res.data.data.list,
  107. timeList: this.data.timeList
  108. })
  109. }).fail(error => {
  110. console.log('错误', error)
  111. })
  112. },
  113. dialog: function (uid) {
  114. if (wx.getStorageSync('uid') == uid) {
  115. this.setData({
  116. typeOf: 'success',
  117. title: '恭喜',
  118. headTextOne: '您发起的团购拼团成功',
  119. headTextTwo: '领袖体质魅力无穷!',
  120. content: [{
  121. text: " 您可以继续发起新的团购",
  122. color: "#F97800"
  123. },
  124. {
  125. text: " 不再需要支付本课程费用",
  126. color: "#F97800"
  127. },
  128. {
  129. text: " 拼团成功,您将得到奖学金",
  130. color: "#F97800"
  131. }
  132. ],
  133. btnContent: '再接再厉 赚奖学金'
  134. })
  135. } else {
  136. this.setData({
  137. typeOf: 'success',
  138. title: '拼团成功',
  139. headTextOne: '您参与的团购拼团成功',
  140. headTextTwo: '感谢团长的分享',
  141. content: [{
  142. text: " 您也可以发起新的团购",
  143. color: "#F97800"
  144. },
  145. {
  146. text: "作为新的发起人",
  147. color: "#F97800"
  148. },
  149. {
  150. text: "您无需在支付本课程费用",
  151. color: "#F97800"
  152. },
  153. {
  154. text: "拼团成功,您将得到奖学金",
  155. color: "#F97800"
  156. }
  157. ],
  158. btnContent: '我也试试 赚奖学金'
  159. })
  160. }
  161. },
  162. close: function () {
  163. const ind = this.data.ind;
  164. this.data.closeFlags[ind] = false;
  165. this.setData({
  166. closeFlags: this.data.closeFlags
  167. })
  168. console.log(this.data.closeFlags)
  169. },
  170. //再次发起团
  171. group: function () {
  172. const productId = this.data.productId;
  173. const groupId = this.data.groupId;
  174. const id = this.data.orderId;
  175. wx.navigateTo({
  176. url: `/pages/groupPage/grade-details/grade-details?productId=${productId}`
  177. })
  178. //开始发起团购
  179. // httpRequestApi.SendGroupPurchas({
  180. // productId,
  181. // groupId
  182. // }).success((res) => {
  183. // console.log('发起团购', res);
  184. // if (res.data.message) {
  185. // wx.showModal({
  186. // title: '提示',
  187. // content: res.data.message,
  188. // success:(res) => {
  189. // }
  190. // })
  191. // return false;
  192. // }
  193. // wx.navigateTo({
  194. // url: `/pages/groupPage/make-money/make-money?productId=${productId}&id=${res.data.data.groupPurchaseOrder.id}&groupId=${groupId}`
  195. // })
  196. // // this.getMygroup();
  197. // }).fail((error) => {
  198. // })
  199. },
  200. /**
  201. * 生命周期函数--监听页面初次渲染完成
  202. */
  203. onReady: function () {
  204. this.popup = this.selectComponent("#popup");
  205. },
  206. /**
  207. * 用户点击右上角分享
  208. */
  209. onShareAppMessage: function () {
  210. },
  211. onPullDownRefresh: function () {
  212. this.onLoad();
  213. wx.showNavigationBarLoading() //在标题栏中显示加载
  214. //模拟加载
  215. setTimeout(function () {
  216. // complete
  217. wx.hideNavigationBarLoading() //完成停止加载
  218. wx.stopPullDownRefresh() //停止下拉刷新
  219. }, 1500);
  220. }
  221. })