my-group.js 7.4 KB

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