my-group.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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. this.getMyGroup();
  74. },
  75. // 获取我的拼团
  76. getMyGroup: function(){
  77. httpRequestApi.getMygroup().success((res) => {
  78. if(!res.data.data.list){
  79. return
  80. }
  81. this.setData({
  82. myGroupList: [],
  83. myGroupList: [],
  84. timeList: []
  85. });
  86. console.log('我的团', res.data.data.list)
  87. res.data.data.list.forEach(element => {
  88. if(element.groupPurchaseOrder.status == 'SUCCESSED') {
  89. this.data.closeFlags.push(true);
  90. this.data.timeList.push(util.formatDate(element.groupPurchaseOrder.gmtModified, 4))
  91. }else {
  92. this.data.closeFlags.push(false);
  93. if(element.groupPurchaseOrder.closeTime - Date.parse(new Date()) < 0 ) {
  94. this.data.timeList.push('时间到了,')
  95. } else {
  96. this.data.timeList.push(util.formatTime(element.groupPurchaseOrder.closeTime - Date.parse(new Date())).join(':'))
  97. }
  98. }
  99. });
  100. this.setData({
  101. closeFlags: this.data.closeFlags,
  102. myGroupList: res.data.data.list,
  103. timeList: this.data.timeList
  104. })
  105. }).fail( error => {
  106. console.log('错误', error)
  107. })
  108. },
  109. dialog: function (uid) {
  110. if(wx.getStorageSync('uid') == uid) {
  111. this.setData({
  112. typeOf: 'success',
  113. title: '恭喜',
  114. headTextOne: '您发起的团购拼团成功',
  115. headTextTwo: '领袖体质魅力无穷!',
  116. content: [
  117. {
  118. text: " 您可以继续发起新的团购",
  119. color: "#F97800"
  120. },
  121. {
  122. text: " 不再需要支付本课程费用",
  123. color: "#F97800"
  124. },
  125. {
  126. text: " 拼团成功,您将得到奖学金",
  127. color: "#F97800"
  128. }
  129. ],
  130. btnContent: '再接再厉 赚奖学金'
  131. })
  132. }else {
  133. this.setData({
  134. typeOf: 'success',
  135. title: '拼团成功',
  136. headTextOne: '您参与的团购拼团成功',
  137. headTextTwo: '感谢团长的分享',
  138. content: [
  139. {
  140. text: " 您也可以发起新的团购",
  141. color: "#F97800"
  142. },
  143. {
  144. text: "作为新的发起人",
  145. color: "#F97800"
  146. },
  147. {
  148. text: "您无需在支付本课程费用",
  149. color: "#F97800"
  150. },
  151. {
  152. text: "拼团成功,您将得到奖学金",
  153. color: "#F97800"
  154. }
  155. ],
  156. btnContent: '我也试试 赚奖学金'
  157. })
  158. }
  159. },
  160. close: function () {
  161. const ind = this.data.ind;
  162. this.data.closeFlags[ind] = false;
  163. this.setData({
  164. closeFlags: this.data.closeFlags
  165. })
  166. console.log(this.data.closeFlags)
  167. },
  168. //再次发起团
  169. group: function () {
  170. const productId = this.data.productId;
  171. const groupId = this.data.groupId;
  172. const id = this.data.orderId;
  173. //开始发起团购
  174. httpRequestApi.SendGroupPurchas({
  175. productId,
  176. groupId
  177. }).success((res) => {
  178. console.log('发起团购', res);
  179. if (res.data.message) {
  180. wx.showModal({
  181. title: '提示',
  182. content: res.data.message,
  183. success:(res) => {
  184. }
  185. })
  186. return false;
  187. }
  188. wx.navigateTo({
  189. url: `/pages/groupPage/make-money/make-money?productId=${productId}&id=${res.data.data.groupPurchaseOrder.id}&groupId=${groupId}`
  190. })
  191. // this.getMygroup();
  192. }).fail((error) => {
  193. })
  194. },
  195. /**
  196. * 生命周期函数--监听页面初次渲染完成
  197. */
  198. onReady: function () {
  199. this.popup = this.selectComponent("#popup");
  200. },
  201. /**
  202. * 用户点击右上角分享
  203. */
  204. onShareAppMessage: function () {
  205. },
  206. onPullDownRefresh: function () {
  207. this.onLoad();
  208. wx.showNavigationBarLoading() //在标题栏中显示加载
  209. //模拟加载
  210. setTimeout(function()
  211. {
  212. // complete
  213. wx.hideNavigationBarLoading() //完成停止加载
  214. wx.stopPullDownRefresh() //停止下拉刷新
  215. },1500);
  216. }
  217. })