index.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. <template>
  2. <div class="demandAnalysis">
  3. <div class="demContent1">
  4. <div style="display: flex">
  5. <el-select
  6. v-model="store.state.siteId"
  7. @change="siteChange"
  8. placeholder="选择站点"
  9. >
  10. <el-option
  11. v-for="item in store.state.siteList"
  12. :key="item.id"
  13. :label="item.siteName"
  14. :value="item.id"
  15. ></el-option>
  16. </el-select>
  17. </div>
  18. <div class="demSwitch">
  19. <el-tree
  20. ref="tree"
  21. :data="deviceBoxData"
  22. show-checkbox
  23. node-key="id"
  24. @node-click="handleNodeClick"
  25. accordion
  26. :check-strictly="true"
  27. :props="defaultProps"
  28. highlight-current
  29. />
  30. </div>
  31. </div>
  32. <div class="demContent2">
  33. <div class="demDivOne">
  34. <div class="demDivTwo">
  35. <div class="block">
  36. <span class="demonstration" style="color: black">日期:</span>
  37. <el-date-picker
  38. v-model="dateTime"
  39. type="month"
  40. placeholder="请选择日期"
  41. ></el-date-picker>
  42. </div>
  43. </div>
  44. <el-radio-group
  45. v-model="listTabPosition"
  46. @change="listTabsChange(listTabPosition)"
  47. style="display: flex"
  48. >
  49. <el-radio-button label="cycleValue">电费结算周期</el-radio-button>
  50. <el-radio-button label="monthValue">自然月</el-radio-button>
  51. </el-radio-group>
  52. <div style="margin-left: 10px">
  53. <el-button icon="el-icon-search" type="primary" @click="searchData()">
  54. 查询
  55. </el-button>
  56. </div>
  57. </div>
  58. <div class="demEcharTable" v-if="flag">
  59. <div class="Echarts">
  60. <div class="ehcartOne">
  61. <i
  62. class="el-icon-s-data el-input__icon"
  63. style="font-size: 20px"
  64. ></i>
  65. <span style="font-size: 15px">{{}}每日最大需量趋势</span>
  66. </div>
  67. <div>
  68. <echarts :Height="Height" :echartsData="echartsData"></echarts>
  69. </div>
  70. </div>
  71. <div class="Tables">
  72. <el-table
  73. :data="tableData"
  74. :height="Height"
  75. style="width: 100%"
  76. id="tables1"
  77. border
  78. stripe
  79. >
  80. <el-table-column prop="listDate" label="日期" width="" align="center"/>
  81. <el-table-column prop="list" label="最大需量(kw)" width="" align="center"/>
  82. </el-table>
  83. </div>
  84. </div>
  85. </div>
  86. </div>
  87. </template>
  88. <script>
  89. import { useStore } from 'vuex'
  90. import { defineComponent, ref, reactive, toRefs, onMounted } from 'vue'
  91. import echarts from './ehcarts/index.vue'
  92. import { parseTime2 } from '@/utils'
  93. import * as api from '@/api/dataManage/demandAnalysis.js'
  94. import { ElMessage } from 'element-plus'
  95. import { ElNotification } from 'element-plus'
  96. export default defineComponent({
  97. name: 'demandAnalysis',
  98. components: { echarts },
  99. props: {},
  100. setup() {
  101. const store = useStore()
  102. const tableData=ref([])
  103. const deviceBoxData = ref([])
  104. const deviceChecked = ref([])
  105. const dateTime = ref(new Date())
  106. const typeSrarch = ref(1)
  107. const flag = ref(false)
  108. const echartsData = ref({})
  109. const siteOption = () => {
  110. console.log(store.state)
  111. }
  112. const listTabsChange = (value) => {
  113. value == 'monthValue' ? (typeSrarch.value = 2) : (typeSrarch.value = 1)
  114. console.log(value)
  115. }
  116. const handleNodeClick = (data, obj, node) => {
  117. data, node
  118. console.log(obj.data.deviceCode)
  119. deviceChecked.value = obj.data.deviceCode
  120. }
  121. const state = reactive({
  122. value1: '2021-5',
  123. })
  124. const Height = ref()
  125. Height.value = window.innerHeight - 250 + 'px'
  126. window.onresize = function () {
  127. Height.value = window.innerHeight - 250 + 'px'
  128. }
  129. //通过站点切换下拉框 change事件改变 tree树中的数据
  130. const siteChange = () => {
  131. store.commit('publicDeviceList')
  132. deviceBoxList()
  133. }
  134. function deviceBoxList() {
  135. api
  136. .deviceBoxList({
  137. siteId: store.state.siteId,
  138. })
  139. .then((requset) => {
  140. if (requset.status === 'SUCCESS') {
  141. deviceBoxData.value = requset.data
  142. deviceBoxData.value.forEach(function (i, index) {
  143. i.id = index
  144. i.children = []
  145. })
  146. console.log(deviceBoxData.value)
  147. } else {
  148. ElMessage.error(requset.msg)
  149. }
  150. })
  151. }
  152. function searchData() {
  153. if (deviceChecked.value.length > 0) {
  154. // alert(1)
  155. // store.commit('TimeAll_function', dateTime.value)
  156. // const time = store.state.Time_Data
  157. dateTime.value ? (dateTime.value = parseTime2(dateTime.value)) : ''
  158. api
  159. .demandAnalysis({
  160. cycle: typeSrarch.value,
  161. monthDate: dateTime.value,
  162. deviceCode: deviceChecked.value,
  163. })
  164. .then((requset) => {
  165. if (requset.status === 'SUCCESS') {
  166. flag.value = true
  167. echartsData.value = requset.data[0]
  168. //重组表格数据
  169. var list = requset.data[0].list
  170. var listDate = requset.data[0].listDate
  171. var newArr1 = []
  172. var newArr2 = []
  173. list.forEach((item) => {
  174. newArr1.push({ list: item })
  175. })
  176. listDate.forEach((item) => {
  177. newArr2.push({ listDate: item })
  178. })
  179. var newObj = newArr1.map((item, index) => {
  180. return { ...item, ...newArr2[index] }
  181. })
  182. tableData.value=newObj
  183. } else {
  184. ElMessage.error(requset.msg)
  185. }
  186. })
  187. } else {
  188. console.log('', 1)
  189. ElNotification({
  190. title: '提示',
  191. message: '请选择设备',
  192. type: 'warning',
  193. })
  194. }
  195. }
  196. onMounted(() => {
  197. deviceBoxList()
  198. })
  199. return {
  200. Height,
  201. ...toRefs(state), //时间选择默认参数
  202. siteValue: ref(1), //select站点选择
  203. listTabsChange, //单选change事件
  204. siteOption, //站点下拉change事件
  205. siteChange,
  206. searchData,
  207. handleNodeClick,
  208. store,
  209. listTabPosition: ref('cycleValue'), //单选按钮
  210. deviceBoxData,
  211. deviceChecked,
  212. dateTime,
  213. typeSrarch,
  214. flag,
  215. echartsData,
  216. data: [
  217. {
  218. id: 1,
  219. label: '设备1',
  220. children: [
  221. {
  222. id: 4,
  223. label: '母线停电次数',
  224. },
  225. {
  226. id: 4,
  227. label: '功率因数',
  228. },
  229. {
  230. id: 4,
  231. label: 'A相功率因数',
  232. },
  233. ],
  234. },
  235. ],
  236. options: ref([
  237. {
  238. value: 1,
  239. label: 'Option1',
  240. },
  241. {
  242. value: 2,
  243. label: 'Option2',
  244. },
  245. {
  246. value: 3,
  247. label: 'Option3',
  248. },
  249. {
  250. value: 4,
  251. label: 'Option4',
  252. },
  253. ]),
  254. defaultProps: {
  255. children: 'children',
  256. label: 'deviceName',
  257. deviceCode: 'deviceCode',
  258. id: 'id',
  259. },
  260. tableData
  261. }
  262. },
  263. })
  264. </script>
  265. <style lang="scss" scoped>
  266. .demandAnalysis {
  267. display: flex;
  268. height: calc(100vh - 130px);
  269. // padding: 30px;
  270. // margin-top: 50px;
  271. .demContent1 {
  272. background-color: #fff;
  273. width: 15%;
  274. height: 100%;
  275. margin-right: 25px;
  276. padding: 20px;
  277. min-width: 200px;
  278. .demSwitch {
  279. margin-top: 20px;
  280. width: 100%;
  281. height: 20px;
  282. cursor: pointer;
  283. .demSwitchOne {
  284. display: flex;
  285. border: 0.5px solid silver;
  286. padding: 8px;
  287. font-size: 13px;
  288. div:nth-child(1) {
  289. width: 100%;
  290. }
  291. }
  292. .demSwitchOne:hover {
  293. background-color: #409eff;
  294. }
  295. .demSwitchOne:focus {
  296. background-color: #409eff;
  297. }
  298. }
  299. }
  300. .demContent2 {
  301. background-color: #fff;
  302. width: 85%;
  303. min-width: 845px;
  304. height: 100%;
  305. .demDivOne {
  306. display: flex;
  307. margin: 15px 0px 15px 15px;
  308. .demDivTwo {
  309. font-weight: 600;
  310. color: #9d9d9d;
  311. margin-right: 20px;
  312. }
  313. }
  314. .demEcharTable {
  315. display: flex;
  316. .Echarts {
  317. width: 60%;
  318. margin-right: 5px;
  319. .ehcartOne {
  320. padding-left: 10px;
  321. background-color: rgb(233 233 233);
  322. border-bottom: 1px #bfbfbf solid;
  323. }
  324. }
  325. .Tables {
  326. width: 40%;
  327. display: flex;
  328. }
  329. }
  330. }
  331. }
  332. </style>
  333. <style>
  334. .el-table--scrollable-y .el-table__body-wrapper::-webkit-scrollbar {
  335. overflow-y: hidden;
  336. }
  337. </style>
  338. <style lang="less">
  339. .demSwitch {
  340. .el-tree-node__content .el-checkbox__input {
  341. display: none;
  342. }
  343. .el-tree-node
  344. .el-tree-node__children
  345. .el-tree-node__content
  346. .el-checkbox__input {
  347. display: block;
  348. }
  349. }
  350. </style>