data-item.vue 7.9 KB

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