C_ranking.js 4.1 KB

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