data-item.vue 7.5 KB

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