C_ranking.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. var app = getApp()
  2. var that;
  3. Page({
  4. data: {
  5. month: app.globalData.month,
  6. showRuleTwo: false,//显示规则组件
  7. ruleVal: "规则分类",
  8. date:app.globalData.month,
  9. isPx: true,
  10. id: '',
  11. page: 1,
  12. dateType: 1,
  13. },
  14. onLoad(e) {
  15. that = this;
  16. if (e.date_interval == 3) {
  17. this.setData({
  18. dateType: e.date_interval,
  19. month:app.globalData.year,
  20. date:app.globalData.year,
  21. })
  22. } else if (e.date_interval == 2) { // 传进入如果是季度
  23. this.setData({
  24. month:app.globalData.year+String(this.getJ()+1),
  25. dateType: e.date_interval
  26. })
  27. } else {
  28. this.setData({
  29. month:app.globalData.year+String(app.globalData.month_tow),
  30. dateType: e.date_interval
  31. })
  32. }
  33. if (e.id) {
  34. this.setData({ id: e.id });
  35. dd.setNavigationBar({ title: e.name });
  36. this.getData();
  37. }
  38. },
  39. // 获取当前是第几季
  40. getJ() {
  41. var getYearWeek = function (a, b, c) {
  42. var date1 = new Date(a, parseInt(b) - 1, c), date2 = new Date(a, 0, 1),
  43. d = Math.round((date1.valueOf() - date2.valueOf()) / 86400000)
  44. return Math.ceil((d + ((date2.getDay() + 1) - 1)) / 7)
  45. }
  46. var today = new Date()// 获取当前时间
  47. var y = today.getFullYear()
  48. var m = today.getMonth() + 1
  49. var d = today.getDate()
  50. var week, quarter = ''
  51. var result = getYearWeek(y, m, d)
  52. if (m < 4) {
  53. quarter = 1
  54. week = result
  55. } else if (m < 7) {
  56. quarter = 2
  57. week = result - getYearWeek(y, 4, 1)
  58. var day = new Date(y, 4, 1)
  59. if (day.getDay() > 1) {
  60. week += 1
  61. }
  62. } else if (m < 10) {
  63. quarter = 3
  64. week = result - getYearWeek(y, 7, 1)
  65. var day = new Date(y, 7, 1)
  66. if (day.getDay() > 1) {
  67. week += 1
  68. }
  69. } else {
  70. quarter = 4
  71. week = result - getYearWeek(y, 10, 1)
  72. var day = new Date(y, 10, 1)
  73. if (day.getDay() > 1) {
  74. week += 1
  75. }
  76. }
  77. return quarter - 1
  78. },
  79. getData(is) {
  80. var data = {
  81. date: that.data.month,
  82. page: that.data.page,
  83. page_size: 10,
  84. sort: that.data.isPx ? 'asc' : 'desc',
  85. // type: 'normal',
  86. group_id: that.data.id,
  87. }
  88. app.$get('api/integral/statistics/groups/rank',data).then((res) => {
  89. var data = res.data.data.list;
  90. if (is) {
  91. if (data.length == 0) {
  92. return;
  93. }
  94. var list = that.data.list;
  95. this.setData({
  96. list: list.concat(data)
  97. })
  98. } else {
  99. this.setData({
  100. list: data
  101. })
  102. }
  103. })
  104. },
  105. //上啦加载
  106. onScrollToLower() {
  107. this.setData({ page: ++that.data.page })
  108. this.getData(true);
  109. },
  110. selectDay() {
  111. var str="yyyy-MM";
  112. if(this.data.dateType==3){
  113. str="yyyy"
  114. }
  115. this.setData({ showDate: true })
  116. dd.datePicker({
  117. format: str,
  118. currentDate: this.data.date,
  119. success: (res) => {
  120. if(res.date&&that.data.dateType!=3){
  121. var str=res.date.substr(0,4)
  122. var str2=res.date.substr(res.date.length-2,2)
  123. this.setData({
  124. month: String(str)+String(str2),
  125. date:res.date
  126. })
  127. this.getData();
  128. }else{
  129. this.setData({
  130. month: res.date,
  131. date:res.date
  132. })
  133. this.getData();
  134. }
  135. },
  136. complete: (res) => {
  137. that.setData({
  138. showDate: false
  139. })
  140. }
  141. });
  142. },
  143. //显示规则组件
  144. selectRule() {
  145. this.setData({
  146. showRuleTwo: true
  147. })
  148. },
  149. selectIsPx() {
  150. this.setData({
  151. isPx: !this.data.isPx,
  152. page: 1
  153. })
  154. this.getData();
  155. },
  156. //打开兴趣
  157. openDetail(e) {
  158. var item = e.target.dataset.item;
  159. dd.navigateTo({
  160. url: '../prizeBuckleDetail/prizeBuckleDetail?item=' + item
  161. })
  162. },
  163. //关闭弹窗
  164. onClose() {
  165. this.setData({
  166. showRuleTwo: false
  167. })
  168. },
  169. //选择规则
  170. onConfirmRule(data) {
  171. this.setData({ rule_id: data.id, page: 1, ruleVal: data.name })
  172. this.getData();
  173. },
  174. });