index.vue 9.2 KB

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