my-group.js 5.9 KB

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