index.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. <template>
  2. <div class="sameAnalysis">
  3. <div class="sameContent1">
  4. <div style="display: flex">
  5. <el-select
  6. v-model="store.state.siteId"
  7. @change="siteChange"
  8. placeholder="选择站点"
  9. filterable
  10. >
  11. <el-option
  12. v-for="item in store.state.siteList"
  13. :key="item.id"
  14. :label="item.siteName"
  15. :value="item.id"
  16. ></el-option>
  17. </el-select>
  18. </div>
  19. <div class="sameSwitch">
  20. <el-tree
  21. ref="tree"
  22. :data="store.state.deviceList"
  23. show-checkbox
  24. node-key="id"
  25. accordion
  26. :check-strictly="true"
  27. :props="defaultProps"
  28. @check="currentChecked"
  29. />
  30. </div>
  31. </div>
  32. <div class="sameContent2">
  33. <div class="sameDivOne">
  34. <div class="sameDivTwo">
  35. <div class="block">
  36. <span class="demonstration">选择时间范围:</span>
  37. <el-date-picker
  38. v-model="dateTime"
  39. type="datetimerange"
  40. range-separator="➥"
  41. start-placeholder="开始时间"
  42. end-placeholder="结束时间"
  43. ></el-date-picker>
  44. </div>
  45. </div>
  46. <el-radio-group
  47. v-model="listTabPosition"
  48. @change="listTabsChange(listTabPosition)"
  49. style="display: flex"
  50. >
  51. <el-radio-button label="allValue">所有值</el-radio-button>
  52. <el-radio-button label="dailyValue">每日值</el-radio-button>
  53. <el-radio-button label="monthValue">每月值</el-radio-button>
  54. <el-select
  55. v-model="valueCalculation"
  56. placeholder="Select"
  57. style="width: 100px; margin-left: 10px"
  58. v-if="typeSrarch"
  59. >
  60. <el-option
  61. v-for="item in options"
  62. :key="item.value"
  63. :label="item.label"
  64. :value="item.value"
  65. ></el-option>
  66. </el-select>
  67. <div style="margin-left: 10px">
  68. <el-button
  69. icon="el-icon-searchData"
  70. type="primary"
  71. style="padding: 7px 12px"
  72. @click="searchData()"
  73. >
  74. 查询
  75. </el-button>
  76. </div>
  77. </el-radio-group>
  78. </div>
  79. <div class="sameEcharts">
  80. <echarts
  81. :ecahrtsData="ecahrtsData"
  82. :typeSrarch="typeSrarch"
  83. v-if="flag && ecahrtsData[0]"
  84. ></echarts>
  85. </div>
  86. </div>
  87. </div>
  88. </template>
  89. <script>
  90. import { useStore } from 'vuex'
  91. import { defineComponent, ref, onMounted } from 'vue'
  92. import echarts from './ehcarts/index.vue'
  93. import { ElNotification } from 'element-plus'
  94. import * as api from '@/api/dataManage/sameAnalysis.js'
  95. import { ElMessage } from 'element-plus'
  96. export default defineComponent({
  97. name: 'sameAnalysis',
  98. components: { echarts },
  99. props: {},
  100. setup() {
  101. const store = useStore()
  102. const listTabPosition = ref('allValue') //tabs切换
  103. const treeCheckedList = ref([])
  104. const treeData = ref([])
  105. const tree = ref(null)
  106. const typeSrarch = ref(0)
  107. const flag = ref(false)
  108. const valueCalculation = ref()
  109. const dateTime = ref('')
  110. const ecahrtsData = ref({})
  111. const listTabsChange = (value) => {
  112. console.log(value)
  113. if (value == 'allValue') {
  114. typeSrarch.value = 0
  115. } else if (value == 'dailyValue') {
  116. typeSrarch.value = 1
  117. valueCalculation.value = 1
  118. } else {
  119. typeSrarch.value = 2
  120. valueCalculation.value = 1
  121. }
  122. }
  123. const currentChecked = (nodeObj, SelectedObj) => {
  124. nodeObj, SelectedObj
  125. treeCheckedList.value = SelectedObj.checkedNodes
  126. treeCheckedList.value = []
  127. SelectedObj.checkedNodes.forEach((item) => {
  128. treeCheckedList.value.push(item.deviceCode)
  129. remove(treeCheckedList.value, item.deviceCode)
  130. })
  131. }
  132. function remove(arr, item) {
  133. let newArr = arr.filter((ele) => {
  134. return ele !== item
  135. })
  136. return newArr
  137. }
  138. function searchData() {
  139. if (!dateTime.value) {
  140. ElNotification({
  141. title: '提示',
  142. message: '请选择开始和结束时间',
  143. type: 'warning',
  144. })
  145. return
  146. }
  147. if (treeCheckedList.value.length > 0) {
  148. console.log('', store.state.deviceList)
  149. console.log('treeCheckedList')
  150. console.log(treeCheckedList.value)
  151. store.commit('TimeAll_function', dateTime.value)
  152. const time = store.state.Time_Data
  153. api
  154. .yearOnYearList({
  155. startTime: time[0],
  156. endTime: time[1],
  157. type: typeSrarch.value,
  158. valueCalculation: typeSrarch.value ? valueCalculation.value : 0,
  159. displayField: treeCheckedList.value,
  160. })
  161. .then((requset) => {
  162. if (requset.status === 'SUCCESS') {
  163. flag.value = true
  164. ecahrtsData.value = requset.data
  165. if (!ecahrtsData.value[0]) {
  166. ElMessage.error('暂无结果')
  167. }
  168. } else {
  169. ElMessage.error(requset.msg)
  170. }
  171. })
  172. } else {
  173. console.log('', 1)
  174. ElNotification({
  175. title: '提示',
  176. message: '请选择测点',
  177. type: 'warning',
  178. })
  179. }
  180. }
  181. //通过站点切换下拉框 change事件改变 tree树中的数据
  182. const siteChange = () => {
  183. store.commit('publicDeviceList')
  184. }
  185. onMounted(() => {})
  186. return {
  187. store,
  188. listTabPosition,
  189. tree,
  190. treeData,
  191. defaultProps: {
  192. children: 'children',
  193. label: 'deviceName',
  194. deviceCode: 'deviceCode',
  195. id: 'id',
  196. },
  197. flag,
  198. remove,
  199. dateTime,
  200. searchData,
  201. currentChecked,
  202. siteChange,
  203. listTabsChange,
  204. typeSrarch,
  205. options: ref([
  206. {
  207. value: 1,
  208. label: '平均值',
  209. },
  210. {
  211. value: 2,
  212. label: '最大值',
  213. },
  214. {
  215. value: 3,
  216. label: '最小值',
  217. },
  218. {
  219. value: 4,
  220. label: '累计值',
  221. },
  222. ]),
  223. valueCalculation,
  224. ecahrtsData,
  225. }
  226. },
  227. })
  228. </script>
  229. <style lang="scss" scoped>
  230. .sameAnalysis {
  231. display: flex;
  232. height: calc(100vh - 130px);
  233. // padding: 30px;
  234. // margin-top: 50px;
  235. .sameContent1 {
  236. background-color: #fff;
  237. width: 15%;
  238. height: 100%;
  239. margin-right: 25px;
  240. padding: 20px;
  241. min-width: 200px;
  242. overflow-y: auto;
  243. .sameSwitch {
  244. margin-top: 20px;
  245. width: 100%;
  246. height: 20px;
  247. cursor: pointer;
  248. .sameSwitchOne {
  249. display: flex;
  250. border: 0.5px solid silver;
  251. padding: 8px;
  252. font-size: 13px;
  253. div:nth-child(1) {
  254. width: 100%;
  255. }
  256. }
  257. .sameSwitchOne:hover {
  258. background-color: #409eff;
  259. }
  260. .sameSwitchOne:focus {
  261. background-color: #409eff;
  262. }
  263. }
  264. }
  265. .sameContent2 {
  266. background-color: #fff;
  267. width: 85%;
  268. min-width: 845px;
  269. height: 100%;
  270. .sameDivOne {
  271. display: flex;
  272. margin: 15px 0px 15px 15px;
  273. .sameDivTwo {
  274. font-weight: 600;
  275. color: #9d9d9d;
  276. margin-right: 20px;
  277. }
  278. }
  279. }
  280. }
  281. </style>
  282. <style lang="less">
  283. .sameSwitch {
  284. .el-tree-node__content .el-checkbox__input {
  285. display: none;
  286. }
  287. .el-tree-node
  288. .el-tree-node__children
  289. .el-tree-node__content
  290. .el-checkbox__input {
  291. display: block;
  292. }
  293. }
  294. </style>