data-item.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  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:1000rpx;"></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. itemReadName: 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.itemReadName,
  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}&itemReadName=${this.itemReadName}`
  184. if (data.data) {
  185. const {
  186. valueList,
  187. valueTimeList
  188. } = data.data
  189. const service = [{
  190. // name: this.itemName,
  191. name: this.itemReadName,
  192. data: valueList
  193. }]
  194. this.service = service
  195. this.serviceTime = valueTimeList
  196. } else {
  197. this.service = []
  198. this.serviceTime = []
  199. }
  200. } else {
  201. uni.showToast({
  202. title: data.msg,
  203. duration: 2000,
  204. icon: "error"
  205. });
  206. }
  207. })
  208. this.monthQuery = false
  209. },
  210. //选择日期
  211. handelDate(date) {
  212. this.queryParams.startTime = this.resolvingDate(date[0])
  213. this.queryParams.endTime = this.resolvingDate(date[1])
  214. },
  215. resolvingDate(date) {
  216. if (!date) {
  217. return;
  218. }
  219. //date是传入的时间
  220. let d = new Date(date);
  221. let month = (d.getMonth() + 1) < 10 ? '0' + (d.getMonth() + 1) : (d.getMonth() + 1);
  222. let day = d.getDate() < 10 ? '0' + d.getDate() : d.getDate();
  223. let hours = d.getHours() < 10 ? '0' + d.getHours() : d.getHours();
  224. let min = d.getMinutes() < 10 ? '0' + d.getMinutes() : d.getMinutes();
  225. let sec = d.getSeconds() < 10 ? '0' + d.getSeconds() : d.getSeconds();
  226. let times;
  227. times = d.getFullYear() + '-' + month + '-' + day + ' ' + hours + ':' + min + ':' + sec;
  228. return times
  229. },
  230. //重置按钮
  231. reset() {
  232. this.queryParams = {
  233. id: null,
  234. startTime: null,
  235. endTime: null,
  236. valueType: 0
  237. }
  238. this.dataValue = null
  239. this.monthCurrent = 0
  240. this.monthQuery = false
  241. },
  242. //选择数据组
  243. dataValueChange(val) {
  244. this.getDataListById(val)
  245. },
  246. itemChange(val) {
  247. const item = this.dataItem.find(item => {
  248. return item.value === val
  249. })
  250. this.itemReadName = item.text
  251. }
  252. }
  253. }
  254. </script>
  255. <style lang="scss" scoped>
  256. .data {
  257. margin-top: 40rpx;
  258. height: 50vh;
  259. .data-screen {
  260. text-align: right;
  261. .screen-img {
  262. width: 40rpx;
  263. height: 40rpx;
  264. }
  265. }
  266. }
  267. .echarts {
  268. position: relative;
  269. .query-screen {
  270. width: 96vw;
  271. padding: 0 20rpx;
  272. background: #ffffff;
  273. position: absolute;
  274. top: 0;
  275. z-index: 999;
  276. .month {
  277. display: flex;
  278. justify-content: space-between;
  279. align-items: center;
  280. font-size: 28rpx;
  281. margin: 40rpx 0;
  282. .month-item {
  283. padding: 10rpx 20rpx;
  284. background: #ECECEC;
  285. color: #000000;
  286. border-radius: 12rpx;
  287. }
  288. .month-select {
  289. padding: 10rpx 20rpx;
  290. border-radius: 12rpx;
  291. background: #289BFF;
  292. color: #ffffff;
  293. }
  294. }
  295. .month-btn {
  296. display: flex;
  297. justify-content: space-around;
  298. margin-top: 40rpx;
  299. margin-bottom: 40rpx;
  300. .reset {
  301. background: #EAF4FF;
  302. color: #469DED;
  303. border: 1px solid #A3B8CB;
  304. }
  305. }
  306. }
  307. }
  308. .modal {
  309. width: 100%;
  310. height: 76vh;
  311. background: rgba(0, 0, 0, 0.5);
  312. position: absolute;
  313. top: 0;
  314. }
  315. </style>