data-item.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  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="datetimerange" start-placeholder="起始时间"
  25. end-placeholder="终止时间" @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. watch: {
  91. monthCurrent: {
  92. handler(val) {
  93. switch (val) {
  94. case 1:
  95. this.range = getLastMonth()
  96. break;
  97. case 2:
  98. this.range = getLast3Month()
  99. break;
  100. case 3:
  101. this.range = getLast6Month()
  102. break;
  103. default:
  104. this.range = getLastWeek()
  105. break;
  106. }
  107. this.handelDate(this.range)
  108. },
  109. immediate: true
  110. }
  111. },
  112. mounted() {
  113. this.getUserData()
  114. this.range = getLastWeek()
  115. },
  116. methods: {
  117. // 打开筛选
  118. openScreen() {
  119. this.monthQuery = !this.monthQuery
  120. },
  121. // 切换时间
  122. monthChange(current) {
  123. this.monthCurrent = current
  124. },
  125. //获取当前登录人所有数据组
  126. getUserData() {
  127. uni.$http.get('/itemGroup/getAllItemGroup', {
  128. readMode: 0
  129. }).then(res => {
  130. const data = res.data
  131. if (data.code === 200) {
  132. this.datasList = data.data.map(item => {
  133. return {
  134. text: item.groupName,
  135. value: item.id
  136. }
  137. })
  138. }
  139. })
  140. },
  141. //通过id获取数据组
  142. getDataListById(id) {
  143. uni.$http.get('/itemGroup/getItemGroupById', {
  144. id: id,
  145. itemType: 1
  146. }).then(res => {
  147. const data = res.data
  148. if (data.code === 200) {
  149. this.dataItem = data.data.itemList.map(item => {
  150. return {
  151. text: item.itemName,
  152. value: item.id
  153. }
  154. })
  155. }
  156. })
  157. },
  158. //确认按钮查询
  159. handelQuery() {
  160. // 临时当前时间,需要改成选择时间----开始
  161. var date = new Date()
  162. var timestr = date.getHours() < 10 ? ('0' + date.getHours()) : date.getHours()
  163. timestr += ':'
  164. timestr += date.getMinutes() < 10 ? ('0' + date.getMinutes()) : date.getMinutes()
  165. timestr += ':'
  166. timestr += date.getSeconds() < 10 ? ('0' + date.getSeconds()) : date.getSeconds()
  167. // 临时当前时间,需要改成选择时间----结束
  168. // this.queryParams.startTime = this.resolvingDate2(this.range[0]) + ' ' + timestr
  169. // this.queryParams.endTime = this.resolvingDate2(this.range[1]) + ' ' + timestr
  170. uni.$http.get('/itemGroup/itemDataQuery', this.queryParams).then(res => {
  171. const data = res.data
  172. if (data.code === 200) {
  173. if (data.data) {
  174. const {
  175. valueList,
  176. valueTimeList
  177. } = data.data
  178. const service = [{
  179. name: "数据项列表",
  180. data: valueList
  181. }]
  182. this.service = service
  183. this.serviceTime = valueTimeList
  184. } else {
  185. this.service = []
  186. this.serviceTime = []
  187. }
  188. }
  189. })
  190. this.monthQuery = false
  191. },
  192. //选择日期
  193. handelDate(date) {
  194. this.queryParams.startTime = this.resolvingDate(date[0])
  195. this.queryParams.endTime = this.resolvingDate(date[1])
  196. },
  197. resolvingDate2(date) {
  198. if (!date) {
  199. return;
  200. }
  201. //date是传入的时间
  202. let d = new Date(date);
  203. let month = (d.getMonth() + 1) < 10 ? '0' + (d.getMonth() + 1) : (d.getMonth() + 1);
  204. let day = d.getDate() < 10 ? '0' + d.getDate() : d.getDate();
  205. let hours = d.getHours() < 10 ? '0' + d.getHours() : d.getHours();
  206. let min = d.getMinutes() < 10 ? '0' + d.getMinutes() : d.getMinutes();
  207. let sec = d.getSeconds() < 10 ? '0' + d.getSeconds() : d.getSeconds();
  208. let times;
  209. times = d.getFullYear() + '-' + month + '-' + day;
  210. return times
  211. },
  212. resolvingDate(date) {
  213. if (!date) {
  214. return;
  215. }
  216. //date是传入的时间
  217. let d = new Date(date);
  218. let month = (d.getMonth() + 1) < 10 ? '0' + (d.getMonth() + 1) : (d.getMonth() + 1);
  219. let day = d.getDate() < 10 ? '0' + d.getDate() : d.getDate();
  220. let hours = d.getHours() < 10 ? '0' + d.getHours() : d.getHours();
  221. let min = d.getMinutes() < 10 ? '0' + d.getMinutes() : d.getMinutes();
  222. let sec = d.getSeconds() < 10 ? '0' + d.getSeconds() : d.getSeconds();
  223. let times;
  224. times = d.getFullYear() + '-' + month + '-' + day + ' ' + hours + ':' + min + ':' + sec;
  225. return times
  226. },
  227. //重置按钮
  228. reset() {
  229. this.queryParams = {
  230. id: null,
  231. startTime: null,
  232. endTime: null,
  233. valueType: 0
  234. }
  235. this.dataValue = null
  236. this.monthCurrent = 0
  237. this.monthQuery = false
  238. },
  239. //选择数据组
  240. dataValueChange(val) {
  241. this.getDataListById(val)
  242. }
  243. }
  244. }
  245. </script>
  246. <style lang="scss" scoped>
  247. .data {
  248. margin-top: 40rpx;
  249. .data-screen {
  250. text-align: right;
  251. .screen-img {
  252. width: 40rpx;
  253. height: 40rpx;
  254. }
  255. }
  256. }
  257. .echarts {
  258. position: relative;
  259. .query-screen {
  260. width: 96vw;
  261. padding: 0 20rpx;
  262. background: #ffffff;
  263. position: absolute;
  264. top: 0;
  265. z-index: 999;
  266. .month {
  267. display: flex;
  268. justify-content: space-between;
  269. align-items: center;
  270. font-size: 28rpx;
  271. margin: 40rpx 0;
  272. .month-item {
  273. padding: 10rpx 20rpx;
  274. background: #ECECEC;
  275. color: #000000;
  276. border-radius: 12rpx;
  277. }
  278. .month-select {
  279. padding: 10rpx 20rpx;
  280. border-radius: 12rpx;
  281. background: #289BFF;
  282. color: #ffffff;
  283. }
  284. }
  285. .month-btn {
  286. display: flex;
  287. justify-content: space-around;
  288. margin-top: 40rpx;
  289. margin-bottom: 40rpx;
  290. .reset {
  291. background: #EAF4FF;
  292. color: #469DED;
  293. border: 1px solid #A3B8CB;
  294. }
  295. }
  296. }
  297. }
  298. .modal {
  299. width: 100%;
  300. height: 76vh;
  301. background: rgba(0, 0, 0, 0.5);
  302. position: absolute;
  303. top: 0;
  304. }
  305. </style>