my-group.js 6.1 KB

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