data-item.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. <template>
  2. <view class="data">
  3. <view class="data-screen" @click="openScreen" style="padding-right:40rpx">
  4. <image class="screen-img" src="@/static/image/sx.png" alt="">
  5. <text>筛选</text>
  6. </view>
  7. <view class="echarts">
  8. <dataQuery v-if="service.length" :service="service" :serviceTime="serviceTime" />
  9. <view v-if="monthQuery" class="query-screen">
  10. <view>
  11. 报表时间选择
  12. </view>
  13. <div style="margin: 20px 0;">
  14. <uni-data-select v-model="dataValue" :localdata="datasList"
  15. @change="dataValueChange"></uni-data-select>
  16. </div>
  17. <uni-data-select v-model="queryParams.id" :localdata="dataItem"></uni-data-select>
  18. <view class="month">
  19. <view :class="monthCurrent===item.current?'month-select':'month-item'" v-for="item in monthList"
  20. :key="item.current" @click="monthChange(item.current)">
  21. {{item.name}}
  22. </view>
  23. </view>
  24. <uni-datetime-picker v-model="range" type="daterange" start-placeholder="起始时间" end-placeholder="终止时间"
  25. @change="handelDate" return-type="timestamp" />
  26. <view class="month-btn">
  27. <u-button class="reset" style="width:200rpx" @click="reset">重置</u-button>
  28. <u-button type="primary" style="width:200rpx" @click="handelQuery">确认</u-button>
  29. </view>
  30. </view>
  31. <view class="modal" v-if="monthQuery"></view>
  32. <u-empty v-if="!service.length" class="empty" icon="../../static/data.png" text="暂无数据">
  33. </u-empty>
  34. </view>
  35. </view>
  36. </template>
  37. <script>
  38. import dataQuery from '../../components/ecahrts/dataQuery.vue'
  39. import {
  40. getLastWeek,
  41. getLastMonth,
  42. getLast3Month,
  43. getLast6Month
  44. } from '@/utils/date.js'
  45. export default {
  46. components: {
  47. dataQuery
  48. },
  49. data() {
  50. return {
  51. // 查询参数
  52. queryParams: {
  53. id: null,
  54. startTime: null,
  55. endTime: null,
  56. valueType: 0,
  57. },
  58. // 日期选择
  59. range: [],
  60. // 时间选择
  61. monthList: [{
  62. name: '近一周',
  63. current: 0
  64. },
  65. {
  66. name: '近1个月',
  67. current: 1
  68. },
  69. {
  70. name: '近3个月',
  71. current: 2
  72. },
  73. {
  74. name: '近6个月',
  75. current: 3
  76. }
  77. ],
  78. monthCurrent: 0,
  79. monthQuery: false,
  80. // 图表数据
  81. service: [],
  82. serviceTime: [],
  83. // 数据组数据
  84. datasList: [],
  85. dataValue: null,
  86. // 数据项数据
  87. dataItem: []
  88. }
  89. },
  90. mounted() {
  91. this.getUserData()
  92. this.range = getLastWeek()
  93. },
  94. methods: {
  95. // 打开筛选
  96. openScreen() {
  97. this.monthQuery = !this.monthQuery
  98. },
  99. // 切换时间
  100. monthChange(current) {
  101. this.monthCurrent = current
  102. switch (current) {
  103. case 1:
  104. this.range = getLastMonth()
  105. break;
  106. case 2:
  107. this.range = getLast3Month()
  108. break;
  109. case 3:
  110. this.range = getLast6Month()
  111. break;
  112. default:
  113. this.range = getLastWeek()
  114. break;
  115. }
  116. },
  117. //获取当前登录人所有数据组
  118. getUserData() {
  119. uni.$http.get('/itemGroup/getAllItemGroup').then(res => {
  120. const data = res.data
  121. if (data.code === 200) {
  122. this.datasList = data.data.map(item => {
  123. return {
  124. text: item.groupName,
  125. value: item.id
  126. }
  127. })
  128. }
  129. })
  130. },
  131. //通过id获取数据组
  132. getDataListById(id) {
  133. uni.$http.get('/itemGroup/getItemGroupById/' + id).then(res => {
  134. const data = res.data
  135. if (data.code === 200) {
  136. this.dataItem = data.data.itemList.map(item => {
  137. return {
  138. text: item.itemName,
  139. value: item.id
  140. }
  141. })
  142. }
  143. })
  144. },
  145. //确认按钮查询
  146. handelQuery() {
  147. // 临时当前时间,需要改成选择时间----开始
  148. var date = new Date()
  149. var timestr = date.getHours() < 10 ? ('0' + date.getHours()) : date.getHours()
  150. timestr += ':'
  151. timestr += date.getMinutes() < 10 ? ('0' + date.getMinutes()) : date.getMinutes()
  152. timestr += ':'
  153. timestr += date.getSeconds() < 10 ? ('0' + date.getSeconds()) : date.getSeconds()
  154. // 临时当前时间,需要改成选择时间----结束
  155. this.queryParams.startTime = this.resolvingDate2(this.range[0]) + ' ' + timestr
  156. this.queryParams.endTime = this.resolvingDate2(this.range[1]) + ' ' + timestr
  157. uni.$http.get('/itemGroup/itemDataQuery', this.queryParams).then(res => {
  158. const data = res.data
  159. if (data.code === 200) {
  160. const {
  161. valueList,
  162. valueTimeList
  163. } = data.data
  164. const service = [{
  165. name: "数据项列表",
  166. data: valueList
  167. }]
  168. this.service = service
  169. this.serviceTime = valueTimeList
  170. }
  171. })
  172. this.monthQuery = false
  173. },
  174. //选择日期
  175. handelDate(date) {
  176. this.queryParams.startTime = this.resolvingDate(date[0])
  177. this.queryParams.endTime = this.resolvingDate(date[1])
  178. },
  179. resolvingDate2(date) {
  180. if (!date) {
  181. return;
  182. }
  183. //date是传入的时间
  184. let d = new Date(date);
  185. let month = (d.getMonth() + 1) < 10 ? '0' + (d.getMonth() + 1) : (d.getMonth() + 1);
  186. let day = d.getDate() < 10 ? '0' + d.getDate() : d.getDate();
  187. let hours = d.getHours() < 10 ? '0' + d.getHours() : d.getHours();
  188. let min = d.getMinutes() < 10 ? '0' + d.getMinutes() : d.getMinutes();
  189. let sec = d.getSeconds() < 10 ? '0' + d.getSeconds() : d.getSeconds();
  190. let times;
  191. times = d.getFullYear() + '-' + month + '-' + day;
  192. return times
  193. },
  194. resolvingDate(date) {
  195. if (!date) {
  196. return;
  197. }
  198. //date是传入的时间
  199. let d = new Date(date);
  200. let month = (d.getMonth() + 1) < 10 ? '0' + (d.getMonth() + 1) : (d.getMonth() + 1);
  201. let day = d.getDate() < 10 ? '0' + d.getDate() : d.getDate();
  202. let hours = d.getHours() < 10 ? '0' + d.getHours() : d.getHours();
  203. let min = d.getMinutes() < 10 ? '0' + d.getMinutes() : d.getMinutes();
  204. let sec = d.getSeconds() < 10 ? '0' + d.getSeconds() : d.getSeconds();
  205. let times;
  206. times = d.getFullYear() + '-' + month + '-' + day + ' ' + hours + ':' + min + ':' + sec;
  207. return times
  208. },
  209. //重置按钮
  210. reset() {
  211. this.queryParams = {
  212. id: null,
  213. startTime: null,
  214. endTime: null,
  215. valueType: 0
  216. }
  217. this.dataValue = null
  218. this.monthCurrent = 0
  219. this.monthQuery = false
  220. },
  221. //选择数据组
  222. dataValueChange(val) {
  223. this.getDataListById(val)
  224. }
  225. }
  226. }
  227. </script>
  228. <style lang="scss" scoped>
  229. .data {
  230. margin-top: 40rpx;
  231. .data-screen {
  232. text-align: right;
  233. .screen-img {
  234. width: 40rpx;
  235. height: 40rpx;
  236. }
  237. }
  238. }
  239. .echarts {
  240. position: relative;
  241. .query-screen {
  242. width: 96vw;
  243. padding: 0 20rpx;
  244. background: #ffffff;
  245. position: absolute;
  246. top: 0;
  247. z-index: 999;
  248. .month {
  249. display: flex;
  250. justify-content: space-between;
  251. align-items: center;
  252. font-size: 28rpx;
  253. margin: 40rpx 0;
  254. .month-item {
  255. padding: 10rpx 20rpx;
  256. background: #ECECEC;
  257. color: #000000;
  258. border-radius: 12rpx;
  259. }
  260. .month-select {
  261. padding: 10rpx 20rpx;
  262. border-radius: 12rpx;
  263. background: #289BFF;
  264. color: #ffffff;
  265. }
  266. }
  267. .month-btn {
  268. display: flex;
  269. justify-content: space-around;
  270. margin-top: 40rpx;
  271. margin-bottom: 40rpx;
  272. .reset {
  273. background: #EAF4FF;
  274. color: #469DED;
  275. border: 1px solid #A3B8CB;
  276. }
  277. }
  278. }
  279. }
  280. .modal {
  281. width: 100%;
  282. height: 76vh;
  283. background: rgba(0, 0, 0, 0.5);
  284. position: absolute;
  285. top: 0;
  286. }
  287. </style>