data-item.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  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. <view v-if="monthQuery" class="query-screen">
  9. <view>
  10. 数据组
  11. </view>
  12. <div style="margin: 20px 0;">
  13. <uni-data-select v-model="dataValue" :localdata="datasList" @change="dataValueChange"
  14. placeholder="请选择数据组"
  15. style="placeholder-style: font-size: 16px; color: #909399;"></uni-data-select>
  16. </div>
  17. <view>
  18. 点位
  19. </view>
  20. <zqs-select :list="dataItem" :multiple="true" label-key="label" value-key="value"
  21. v-model="queryParams.idList" @search="searchItem" @confirm="confirmItem" clearable
  22. placeholder="请选择点位" title="选择点位">
  23. </zqs-select>
  24. <view class="month">
  25. <view :class="monthCurrent===item.current?'month-select':'month-item'" v-for="item in monthList"
  26. :key="item.current" @click="monthChange(item.current)">
  27. {{item.name}}
  28. </view>
  29. </view>
  30. <uni-datetime-picker v-model="range" type="datetimerange" start-placeholder="起始时间"
  31. end-placeholder="终止时间" @change="handelDate" return-type="timestamp" />
  32. <view class="month-btn">
  33. <u-button class="reset" style="width:200rpx" @click="reset">重置</u-button>
  34. <u-button type="primary" style="width:200rpx" @click="handelQuery">确认</u-button>
  35. </view>
  36. </view>
  37. <view class="modal" v-if="monthQuery"></view>
  38. <u-empty v-if="!service.length" class="empty" icon="../../static/data.png" text="暂无数据">
  39. </u-empty>
  40. </view>
  41. <view style="width: 100%;height: 400px;">
  42. <l-echart ref="chartRef" @finished="initChart"></l-echart>
  43. </view>
  44. </view>
  45. </template>
  46. <script>
  47. import zqsSelectVue from '../../components/zqs-select/zqs-select.vue'
  48. import {
  49. getLastWeek,
  50. getLastMonth,
  51. getLast3Month,
  52. getLast6Month
  53. } from '@/utils/date.js'
  54. // nvue 不需要引入
  55. // #ifdef VUE2
  56. import * as echarts from '@/uni_modules/lime-echart/static/echarts.min';
  57. // #endif
  58. // #ifdef VUE3
  59. // #ifdef MP
  60. // 由于vue3 使用vite 不支持umd格式的包,小程序依然可以使用,但需要使用require
  61. const echarts = require('../../static/echarts.min');
  62. // #endif
  63. // #ifndef MP
  64. // 由于 vue3 使用vite 不支持umd格式的包,故引入npm的包
  65. import * as echarts from 'echarts/dist/echarts.esm';
  66. // #endif
  67. // #endif
  68. export default {
  69. components: {
  70. zqsSelectVue
  71. },
  72. data() {
  73. return {
  74. // 查询参数
  75. queryParams: {
  76. idList: [],
  77. startTime: null,
  78. endTime: null,
  79. },
  80. // 日期选择
  81. range: [],
  82. // 时间选择
  83. monthList: [{
  84. name: '近一周',
  85. current: 0
  86. },
  87. {
  88. name: '近1个月',
  89. current: 1
  90. },
  91. {
  92. name: '近3个月',
  93. current: 2
  94. },
  95. {
  96. name: '近6个月',
  97. current: 3
  98. }
  99. ],
  100. monthCurrent: 0,
  101. monthQuery: false,
  102. // 图表数据
  103. service: [],
  104. serviceTime: [],
  105. // 数据组数据
  106. datasList: [],
  107. dataValue: null,
  108. // 数据项数据
  109. dataItem: [],
  110. dataItem_Save: [],
  111. selItem: [],
  112. itemReadName: null,
  113. src: '',
  114. option: {}
  115. }
  116. },
  117. watch: {
  118. monthCurrent: {
  119. handler(val) {
  120. switch (val) {
  121. case 1:
  122. this.range = getLastMonth()
  123. break;
  124. case 2:
  125. this.range = getLast3Month()
  126. break;
  127. case 3:
  128. this.range = getLast6Month()
  129. break;
  130. default:
  131. this.range = getLastWeek()
  132. break;
  133. }
  134. this.handelDate(this.range)
  135. },
  136. immediate: true
  137. }
  138. },
  139. mounted() {
  140. this.getUserData()
  141. this.range = getLastWeek()
  142. },
  143. beforeDestroy() {
  144. },
  145. methods: {
  146. // 打开筛选
  147. openScreen() {
  148. this.monthQuery = !this.monthQuery
  149. },
  150. // 切换时间
  151. monthChange(current) {
  152. this.monthCurrent = current
  153. },
  154. //点位搜索
  155. searchItem(val) {
  156. //模糊搜索
  157. const regex = new RegExp(val, "i");
  158. this.dataItem = this.dataItem_Save.filter(item => regex.test(item.label));
  159. },
  160. //确认点位
  161. confirmItem(val) {
  162. //console.log(val)
  163. //console.log(this.selItem)
  164. },
  165. //获取当前登录人所有数据组
  166. getUserData() {
  167. uni.$http.get('/itemGroup/getAllItemGroup', {
  168. page: 1,
  169. limit: 9999
  170. }).then(res => {
  171. const data = res.data
  172. if (data.code === 200) {
  173. console.log(data)
  174. this.datasList = data.data.itemGroupList.map(item => {
  175. return {
  176. text: item.groupName,
  177. value: item.id
  178. }
  179. })
  180. } else {
  181. }
  182. })
  183. },
  184. //通过id获取数据组
  185. getDataListById(id) {
  186. uni.$http.get('/itemGroup/getItemGroupById', {
  187. id: id,
  188. }).then(res => {
  189. const data = res.data
  190. if (data.code === 200) {
  191. this.dataItem = data.data.itemList.map(item => {
  192. return {
  193. label: item.modbusConfig ? item.itemName : item.itemReadName,
  194. value: item.id
  195. }
  196. });
  197. this.dataItem_Save = this.dataItem
  198. }
  199. })
  200. },
  201. getChartOption() {
  202. let option = {
  203. xAxis: {
  204. type: 'category',
  205. data: [],
  206. axisLabel: {
  207. formatter: function(value) {
  208. return value.substring(11, 19) + "\n" + value.substring(0, 10).split('-').join('')
  209. }
  210. }
  211. },
  212. yAxis: {
  213. type: 'value'
  214. },
  215. legend: {
  216. type: 'scroll',
  217. top: 0
  218. },
  219. tooltip: {
  220. trigger: 'axis',
  221. axisPointer: {
  222. type: 'cross',
  223. lineStyle: {
  224. type: 'dashed'
  225. },
  226. label: {
  227. show: false
  228. }
  229. },
  230. textStyle: {
  231. color: '#ffffff'
  232. },
  233. confine: true,
  234. extraCssText: 'white-space: normal; word-break: break-all;',
  235. backgroundColor: 'rgba(108,106,120,0.9)',
  236. position: 'inside',
  237. // formatter: function(params) {
  238. // let result = ''
  239. // for (let i in params) {
  240. // let value = '--'
  241. // if (params[i].data !== null) {
  242. // value = params[i].data
  243. // }
  244. // result += '<br>' + params[i].seriesName + ':' +
  245. // value
  246. // }
  247. // return result
  248. // }
  249. },
  250. dataZoom: [{
  251. type: 'inside',
  252. start: 90,
  253. end: 100
  254. },
  255. {
  256. type: 'slider',
  257. show: true,
  258. start: 90,
  259. end: 100,
  260. bottom: 10
  261. }
  262. ],
  263. series: []
  264. };
  265. return option
  266. },
  267. async initChart() {
  268. console.log('initChart')
  269. const chart = await this.$refs.chartRef.init(echarts)
  270. chart.setOption(this.option)
  271. },
  272. //确认按钮查询
  273. handelQuery() {
  274. // 临时当前时间,需要改成选择时间----开始
  275. var date = new Date()
  276. var timestr = date.getHours() < 10 ? ('0' + date.getHours()) : date.getHours()
  277. timestr += ':'
  278. timestr += date.getMinutes() < 10 ? ('0' + date.getMinutes()) : date.getMinutes()
  279. timestr += ':'
  280. timestr += date.getSeconds() < 10 ? ('0' + date.getSeconds()) : date.getSeconds()
  281. // 临时当前时间,需要改成选择时间----结束
  282. //console.log(this.queryParams.idList)
  283. if (this.queryParams.idList.length == 0) {
  284. uni.showToast({
  285. title: '请选择点位',
  286. duration: 2000,
  287. icon: "error"
  288. });
  289. return;
  290. } else if (this.queryParams.idList.length > 6) {
  291. uni.showToast({
  292. title: '只能选择6个点位',
  293. duration: 2000,
  294. icon: "error"
  295. });
  296. return;
  297. }
  298. uni.$http.get('/itemGroup/getItemListValue', this.queryParams).then(res => {
  299. const data = res.data
  300. if (data.code === 200) {
  301. if (data.data) {
  302. let valueList=[],valueTimeList=[];
  303. valueTimeList = data.data[0].dataTimeList;
  304. let service=[]
  305. for(let dataList of data.data){
  306. let seriesData = {
  307. type:'line',
  308. name:dataList.describe!=null ? dataList.describe:dataList.itemReadName,
  309. data:dataList.dataValueList
  310. }
  311. service.push(seriesData)
  312. }
  313. this.service = service
  314. let optionData = this.getChartOption()
  315. optionData.xAxis.data = valueTimeList
  316. optionData.series = this.service
  317. this.option = optionData
  318. this.initChart()
  319. } else {
  320. this.service = []
  321. }
  322. } else {
  323. uni.showToast({
  324. title: data.msg,
  325. duration: 2000,
  326. icon: "error"
  327. });
  328. }
  329. })
  330. this.monthQuery = false
  331. },
  332. //选择日期
  333. handelDate(date) {
  334. this.queryParams.startTime = this.resolvingDate(date[0])
  335. this.queryParams.endTime = this.resolvingDate(date[1])
  336. },
  337. resolvingDate(date) {
  338. if (!date) {
  339. return;
  340. }
  341. //date是传入的时间
  342. let d = new Date(date);
  343. let month = (d.getMonth() + 1) < 10 ? '0' + (d.getMonth() + 1) : (d.getMonth() + 1);
  344. let day = d.getDate() < 10 ? '0' + d.getDate() : d.getDate();
  345. let hours = d.getHours() < 10 ? '0' + d.getHours() : d.getHours();
  346. let min = d.getMinutes() < 10 ? '0' + d.getMinutes() : d.getMinutes();
  347. let sec = d.getSeconds() < 10 ? '0' + d.getSeconds() : d.getSeconds();
  348. let times;
  349. times = d.getFullYear() + '-' + month + '-' + day + ' ' + hours + ':' + min + ':' + sec;
  350. return times
  351. },
  352. //重置按钮
  353. reset() {
  354. this.queryParams = {
  355. idList: [],
  356. startTime: null,
  357. endTime: null,
  358. }
  359. this.dataValue = null
  360. this.monthCurrent = 0
  361. this.monthQuery = false
  362. },
  363. //选择数据组
  364. dataValueChange(val) {
  365. this.getDataListById(val)
  366. },
  367. itemChange(val) {
  368. const item = this.dataItem.find(item => {
  369. return item.value === val
  370. })
  371. this.itemReadName = item.text
  372. }
  373. }
  374. }
  375. </script>
  376. <style lang="scss" scoped>
  377. iframe {
  378. border: none;
  379. }
  380. .webviewstyle {
  381. height: 100%;
  382. width: 100%;
  383. top: 400px;
  384. border: none;
  385. }
  386. .webview_style>uni-web-view>iframe {
  387. border: none;
  388. }
  389. .data {
  390. margin-top: 40rpx;
  391. height: 50vh;
  392. .data-screen {
  393. text-align: right;
  394. .screen-img {
  395. width: 40rpx;
  396. height: 40rpx;
  397. }
  398. }
  399. }
  400. .uni-select__input-placeholder {
  401. font-size: 14px;
  402. color: red;
  403. }
  404. .echarts {
  405. position: relative;
  406. .query-screen {
  407. width: 96vw;
  408. padding: 0 20rpx;
  409. background: #ffffff;
  410. position: absolute;
  411. top: 0;
  412. z-index: 999;
  413. .month {
  414. display: flex;
  415. justify-content: space-between;
  416. align-items: center;
  417. font-size: 28rpx;
  418. margin: 40rpx 0;
  419. .month-item {
  420. padding: 10rpx 20rpx;
  421. background: #ECECEC;
  422. color: #000000;
  423. border-radius: 12rpx;
  424. }
  425. .month-select {
  426. padding: 10rpx 20rpx;
  427. border-radius: 12rpx;
  428. background: #289BFF;
  429. color: #ffffff;
  430. }
  431. }
  432. .month-btn {
  433. display: flex;
  434. justify-content: space-around;
  435. margin-top: 40rpx;
  436. margin-bottom: 40rpx;
  437. .reset {
  438. background: #EAF4FF;
  439. color: #469DED;
  440. border: 1px solid #A3B8CB;
  441. }
  442. }
  443. }
  444. }
  445. .modal {
  446. width: 100%;
  447. height: 76vh;
  448. background: rgba(0, 0, 0, 0.5);
  449. position: absolute;
  450. top: 0;
  451. }
  452. </style>