index.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. <template>
  2. <div>
  3. <!-- <el-button
  4. :type="btnSelected == '1' ? 'primary' : 'default'"
  5. size="mini"
  6. @click="timeBtnClick(1)"
  7. >24小时</el-button
  8. > -->
  9. <!-- <el-button
  10. :type="btnSelected == '1' ? 'primary' : 'default'"
  11. size="mini"
  12. @click="timeBtnClick(1)"
  13. >本周</el-button
  14. > -->
  15. <!-- <el-button
  16. :type="btnSelected == '2' ? 'primary' : 'default'"
  17. size="mini"
  18. @click="timeBtnClick(2)"
  19. >近一月</el-button
  20. >
  21. <el-button
  22. :type="btnSelected == '3' ? 'primary' : 'default'"
  23. size="mini"
  24. @click="timeBtnClick(3)"
  25. >近半年</el-button
  26. >
  27. <el-button
  28. :type="btnSelected == '4' ? 'primary' : 'default'"
  29. size="mini"
  30. @click="timeBtnClick(4)"
  31. >近一年</el-button
  32. > -->
  33. <!-- <el-date-picker
  34. style="cursor: pointer"
  35. size="mini"
  36. v-model="timeRange"
  37. type="daterange"
  38. range-separator="至"
  39. start-placeholder="开始日期"
  40. end-placeholder="结束日期"
  41. @change="DateChange"
  42. ></el-date-picker> -->
  43. <!-- 测试 -->
  44. <el-button
  45. :type="btnSelected == '1' ? 'primary' : 'default'"
  46. size="mini"
  47. @click="timeBtnClick(1)"
  48. >近一天</el-button
  49. >
  50. <el-button
  51. :type="btnSelected == '2' ? 'primary' : 'default'"
  52. size="mini"
  53. @click="timeBtnClick(2)"
  54. >近七天</el-button
  55. >
  56. <el-button
  57. :type="btnSelected == '3' ? 'primary' : 'default'"
  58. size="mini"
  59. @click="timeBtnClick(3)"
  60. >近一月</el-button
  61. >
  62. <el-button
  63. :type="btnSelected == '4' ? 'primary' : 'default'"
  64. size="mini"
  65. @click="timeBtnClick(4)"
  66. >近三月</el-button
  67. >
  68. <!-- 测试 -->
  69. <el-date-picker
  70. style="cursor: pointer; margin: 0 0 0 4px"
  71. size="mini"
  72. v-model="timeRange"
  73. type="daterange"
  74. align="right"
  75. unlink-panels
  76. range-separator="至"
  77. start-placeholder="开始日期"
  78. end-placeholder="结束日期"
  79. @change="DateChange"
  80. :picker-options="pickerOptions"
  81. >
  82. </el-date-picker>
  83. </div>
  84. </template>
  85. <script>
  86. export default {
  87. data() {
  88. var that = this;
  89. return {
  90. num: 1,
  91. btnSelected: "1",
  92. timeScreen: "1",
  93. queryInfo: {
  94. begin: "",
  95. end: "",
  96. },
  97. timeRange: "",
  98. pickerOptions: {
  99. shortcuts: [
  100. // {
  101. // text: "最近一周",
  102. // onClick(picker) {
  103. // const end = new Date();
  104. // const start = new Date();
  105. // start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
  106. // picker.$emit("pick", [start, end]);
  107. // that.queryInfo.begin = start;
  108. // that.queryInfo.end = end;
  109. // },
  110. // },
  111. // {
  112. // text: "最近一个月",
  113. // onClick(picker) {
  114. // const end = new Date();
  115. // const start = new Date();
  116. // start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
  117. // picker.$emit("pick", [start, end]);
  118. // that.queryInfo.begin = start;
  119. // that.queryInfo.end = end;
  120. // },
  121. // },
  122. // {
  123. // text: "最近三个月",
  124. // onClick(picker) {
  125. // const end = new Date();
  126. // const start = new Date();
  127. // start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
  128. // picker.$emit("pick", [start, end]);
  129. // that.queryInfo.begin = start;
  130. // that.queryInfo.end = end;
  131. // },
  132. // },
  133. {
  134. text: "最近半年",
  135. onClick(picker) {
  136. const end = new Date();
  137. const start = new Date();
  138. start.setTime(start.getTime() - 3600 * 1000 * 24 * 180);
  139. picker.$emit("pick", [start, end]);
  140. that.queryInfo.begin = start;
  141. that.queryInfo.end = end;
  142. },
  143. },
  144. {
  145. text: "最近一年",
  146. onClick(picker) {
  147. const end = new Date();
  148. const start = new Date();
  149. start.setTime(start.getTime() - 3600 * 1000 * 24 * 360);
  150. picker.$emit("pick", [start, end]);
  151. that.queryInfo.begin = start;
  152. that.queryInfo.end = end;
  153. },
  154. },
  155. ],
  156. },
  157. };
  158. },
  159. mounted() {
  160. this.timeBtnClick(1);
  161. },
  162. methods: {
  163. //筛选时间
  164. timeBtnClick(i) {
  165. var now = new Date();
  166. var nowTime = now.getTime();
  167. var day = now.getDay();
  168. var longTime = 24 * 60 * 60 * 1000;
  169. var n = longTime * 7 * (0 || 0);
  170. var aa = nowTime - (day - 1) * longTime + n; //开始
  171. var bb = nowTime + (7 - day) * longTime + n; //结束
  172. // 开始
  173. aa = new Date(aa);
  174. var x = aa.getFullYear();
  175. var k = aa.getMonth() + 1;
  176. var b = aa.getDate();
  177. k = k < 10 ? "0" + k : k;
  178. b = b < 10 ? "0" + b : b;
  179. var mm =
  180. new Date().getMinutes() < 10
  181. ? "0" + new Date().getMinutes()
  182. : new Date().getMinutes();
  183. var dayA = x + "-" + k + "-" + b;
  184. // console.log(dayA);
  185. // 结束
  186. bb = new Date(bb);
  187. var y = bb.getFullYear();
  188. var m = bb.getMonth() + 1;
  189. var d = bb.getDate();
  190. m = m < 10 ? "0" + m : m;
  191. d = d < 10 ? "0" + d : d;
  192. var day = y + "-" + m + "-" + d;
  193. // console.log(day);
  194. this.btnSelected = i;
  195. this.timeRange = "";
  196. if (i == 1) {
  197. // 24小时
  198. this.queryInfo.begin = parseInt((Date.now() - 24 * 3600000) / 1000);
  199. this.queryInfo.end = parseInt((Date.now() + 24) / 1000);
  200. } else if (i == 2) {
  201. // 近七天
  202. this.queryInfo.begin = parseInt(
  203. (Date.now() - 24 * 3600000 * 7) / 1000
  204. );
  205. this.queryInfo.end = parseInt((Date.now() + 24 * 3600000) / 1000);
  206. } else if (i == 3) {
  207. // 近一个月
  208. // this.queryInfo.begin = parseInt(
  209. // (Date.now() - 24 * 3600000 * 30 * 6) / 1000
  210. // );
  211. this.queryInfo.begin = parseInt(
  212. (Date.now() - 24 * 3600000 * 30) / 1000
  213. );
  214. // this.queryInfo.begin = parseInt(
  215. // (Date.now() - 24 * 3600000 * 30 * 6) / 1000
  216. // );
  217. this.queryInfo.end = parseInt((Date.now() + 24 * 3600000) / 1000);
  218. } else if (i == 4) {
  219. // 近三个月
  220. // this.queryInfo.begin = parseInt(
  221. // (Date.now() - 24 * 3600000 * 30 * 12) / 1000
  222. // );
  223. this.queryInfo.begin = parseInt(
  224. (Date.now() - 24 * 3600000 * 30 * 3) / 1000
  225. );
  226. this.queryInfo.end = parseInt((Date.now() + 24 * 3600000) / 1000);
  227. }
  228. console.log(this.queryInfo.begin)
  229. this.$emit("dateChange", this.queryInfo);
  230. this.$emit("btnSelected", this.btnSelected);
  231. },
  232. DateChange() {
  233. console.log(this.timeRange);
  234. this.btnSelected = null;
  235. if (this.timeRange) {
  236. this.queryInfo.begin = parseInt(
  237. new Date(this.timeRange[0]).getTime() / 1000
  238. );
  239. this.queryInfo.end = parseInt(
  240. new Date(this.timeRange[1]).getTime() / 1000
  241. );
  242. } else {
  243. this.btnSelected = 2;
  244. this.queryInfo.begin = parseInt(
  245. (Date.now() - 24 * 3600000 * 30) / 1000
  246. );
  247. this.queryInfo.end = parseInt((Date.now() + 24 * 3600000) / 1000);
  248. }
  249. this.$emit("dateChange", this.queryInfo);
  250. this.$emit("btnSelected", this.btnSelected);
  251. if (this.timeRange == null) {
  252. this.$emit("timeScreen", null);
  253. } else {
  254. this.$emit("timeScreen", this.timeScreen);
  255. }
  256. },
  257. say() {
  258. this.num++;
  259. console.log(this.num+"-------------------------------");
  260. if (this.num > 5 || this.num == 5) {
  261. console.log("停止");
  262. this.num = 0;
  263. } else {
  264. console.log(this.num);
  265. this.timeBtnClick(this.num);
  266. }
  267. this.$emit("timeScreen", null);
  268. },
  269. },
  270. };
  271. </script>
  272. <style lang='less' scoped>
  273. </style>