储能智慧云平台web端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.vue 35KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151
  1. <template>
  2. <div>
  3. <div class="title">
  4. 收益报表
  5. <div class="title_time">{{ currentDate }}</div>
  6. </div>
  7. <el-card class="price_allocationcard" v-if="false">
  8. <div class="price_allocation">
  9. <el-icon><WarningFilled /></el-icon>&ensp; 站点汇总展示所有站点报表数据,支持按日展示31天,按月展示一年内数据。
  10. &ensp;&ensp;&ensp;&ensp;<el-icon><Close /></el-icon>
  11. </div>
  12. </el-card>
  13. <el-card>
  14. <el-tabs v-model="activeName" class="demo-tabs" @tab-click="handleClick">
  15. <el-tab-pane label="站点汇总" name="站点汇总">
  16. <div class="tabdiv">
  17. <div class="tabpanesite">
  18. <div class="tabpane">
  19. <div>时间范围:</div>
  20. <div class="tabpane1">
  21. <el-date-picker
  22. v-if="timetype != 'year'"
  23. v-model="timepicker"
  24. :type="timetype"
  25. :shortcuts="shortcuts"
  26. :format="format"
  27. :value-format="format"
  28. start-placeholder="开始时间"
  29. end-placeholder="结束时间"
  30. size="large"
  31. :disabled-date="pickerOptions"
  32. />
  33. <el-date-picker
  34. v-if="timetype == 'year'"
  35. v-model="timepicker"
  36. type="yearrange"
  37. :format="format"
  38. :value-format="format"
  39. :shortcuts="shortcuts"
  40. start-placeholder="开始时间"
  41. end-placeholder="结束时间"
  42. size="large"
  43. :disabled-date="pickerOptions"
  44. />
  45. <!-- <YearPicker
  46. v-if="timetype == 'year'"
  47. style="width: 300px"
  48. ref="statisticPicker"
  49. :label-width="50"
  50. :init-year="dateValue"
  51. :start-year1="timepicker[0]"
  52. :end-year2="timepicker[1]"
  53. @update-time-range="updateStatisticYear"
  54. /> -->
  55. <el-select
  56. v-model="daymonthyearvalue"
  57. placeholder="选择日期"
  58. size="large"
  59. style="width: 80px"
  60. @change="getdaymonthyear"
  61. >
  62. <el-option v-for="item in daymonthyear" :key="item.value" :label="item.label" :value="item.value" />
  63. </el-select>
  64. </div>
  65. &ensp;&ensp;
  66. <el-button type="primary" size="large" color="#0052d9" @click="gatSummary">查询</el-button>
  67. <el-button size="large" @click="onreset">重置</el-button>
  68. <!-- <el-button v-if="BUTTONS.export" size="large" @click="onexport" type="primary" plain>导出</el-button> -->
  69. </div>
  70. <div v-if="BUTTONS.export" class="exportright">
  71. <el-dropdown trigger="click" :hide-on-click="false" @visible-change="onclose">
  72. <el-button size="large" type="primary" plain>导出</el-button>
  73. <template #dropdown>
  74. <el-dropdown-menu v-for="(item, index) in columnList" :key="index">
  75. <el-dropdown-item>
  76. <el-checkbox @change="oncheck" v-model="item.ifcolumn" :label="item.label" size="large" />
  77. <template v-if="item.children">
  78. <template v-for="(items, i) in item.children" :key="i">
  79. <el-checkbox @change="onchildren" v-model="items.ifcolumn" :label="items.label" size="large" />
  80. </template>
  81. </template>
  82. </el-dropdown-item>
  83. </el-dropdown-menu>
  84. <div class="dropdown">
  85. <el-button @click="onexport" type="primary" plain>确定导出</el-button>
  86. </div>
  87. </template>
  88. </el-dropdown>
  89. </div>
  90. </div>
  91. &ensp;&ensp;
  92. <el-table :data="tableData.list" style="width: 100%" align="center" :show-overflow-tooltip="true">
  93. <!-- <el-table-column type="selection" width="55" /> -->
  94. <template v-for="(item, index) in columnList" :key="index">
  95. <el-table-column v-if="item.ifcolumn" :label="item.label" :prop="item.prop" align="center">
  96. <template v-if="item.children">
  97. <template v-for="(items, i) in item.children" :key="i">
  98. <el-table-column v-if="items.ifcolumn" :label="items.label" :prop="items.prop" align="center">
  99. </el-table-column>
  100. </template>
  101. </template>
  102. </el-table-column>
  103. </template>
  104. <!--
  105. <el-table :data="tableData.list" style="width: 100%" align="center" :show-overflow-tooltip="true">
  106. <el-table-column prop="stationName" label="站点名称" width="150" align="center" />
  107. <el-table-column label="充电量(kWh)" align="center">
  108. <el-table-column prop="chargeSharp" label="尖" align="center" />
  109. <el-table-column prop="chargePeak" label="峰" align="center" />
  110. <el-table-column prop="chargeShoulder" label="平" align="center" />
  111. <el-table-column prop="chargeValley" label="谷" align="center" />
  112. <el-table-column prop="chargeTotal" label="总" align="center" />
  113. </el-table-column>
  114. <el-table-column label="放电量(kWh)" align="center">
  115. <el-table-column prop="dischargeSharp" label="尖" align="center" />
  116. <el-table-column prop="dischargePeak" label="峰" align="center" />
  117. <el-table-column prop="dischargeShoulder" label="平" align="center" />
  118. <el-table-column prop="dischargeValley" label="谷" align="center" />
  119. <el-table-column prop="dischargeTotal" label="总" align="center" />
  120. </el-table-column>
  121. <el-table-column prop="overallEfficiency" label="综合效率(%)" width="150" align="center" />
  122. </el-table> -->
  123. </el-table>
  124. </div>
  125. </el-tab-pane>
  126. <el-tab-pane label="单站报表" name="单站报表">
  127. <div class="tabdiv">
  128. <div class="tabpane">
  129. <div class="tabpane_1">报表类型:</div>
  130. <div :class="reportformsindex == 2 ? 'tabpane_2' : 'tabpane_1'" @click="onreportforms(2)">日报表</div>
  131. <div :class="reportformsindex == 3 ? 'tabpane_2' : 'tabpane_1'" @click="onreportforms(3)">月报表</div>
  132. <div :class="reportformsindex == 4 ? 'tabpane_2' : 'tabpane_1'" @click="onreportforms(4)">年报表</div>
  133. </div>
  134. <div class="tabpanesite">
  135. <div class="selectsite">
  136. <div class="tabpane_1">选择站点:</div>
  137. <el-select v-model="Singlevalue" placeholder="选择站点" size="large" style="width: 240px" @change="postemsDevice">
  138. <el-option v-for="item in cities" :key="item.id" :label="item.stationName" :value="item.id" />
  139. </el-select>
  140. &ensp;&ensp;&ensp;&ensp; &ensp;&ensp;
  141. <div class="tabpane_1">选择日期:</div>
  142. <div>
  143. <el-date-picker
  144. v-if="pickertype != 'year'"
  145. v-model="starttime"
  146. :type="pickertype"
  147. :shortcuts="shortcuts"
  148. :format="format"
  149. :value-format="format"
  150. start-placeholder="开始时间"
  151. end-placeholder="结束时间"
  152. size="large"
  153. clearable
  154. :disabled-date="pickerOptions"
  155. />
  156. <el-date-picker
  157. v-if="pickertype == 'year'"
  158. v-model="starttime"
  159. type="yearrange"
  160. :format="format"
  161. :value-format="format"
  162. :shortcuts="shortcuts"
  163. start-placeholder="开始时间"
  164. end-placeholder="结束时间"
  165. size="large"
  166. :disabled-date="pickerOptions"
  167. />
  168. <!-- <YearPicker
  169. v-if="pickertype == 'year'"
  170. style="width: 300px"
  171. ref="statisticPicker"
  172. :label-width="50"
  173. :init-year="dateValue"
  174. :start-year1="starttime[0]"
  175. :end-year2="starttime[1]"
  176. @update-time-range="updateStatisticYear1"
  177. /> -->
  178. </div>
  179. &ensp;&ensp;
  180. <el-button type="primary" size="large" color="#0052d9" @click="onselectsite">查询</el-button>
  181. <el-button size="large" @click="onselectreset">重置</el-button>
  182. </div>
  183. <!-- <div style="margin-left: 14px" v-if="BUTTONS.export">
  184. <el-button size="large" @click="singleexport" type="primary" plain v-if="reportformsindex != 1">导出</el-button>
  185. </div> -->
  186. <div class="exportright" v-if="BUTTONS.export && reportformsindex != 1">
  187. <el-dropdown trigger="click" :hide-on-click="false" @visible-change="onsingleclose">
  188. <el-button size="large" type="primary" plain>导出</el-button>
  189. <template #dropdown>
  190. <el-dropdown-menu v-for="(item, index) in singlecolumnList" :key="index">
  191. <el-dropdown-item>
  192. <el-checkbox @change="onsingle" v-model="item.ifcolumn" :label="item.label" size="large" />
  193. <template v-if="item.children">
  194. <template v-for="(items, i) in item.children" :key="i">
  195. <el-checkbox @change="onsinglechildren" v-model="items.ifcolumn" :label="items.label" size="large" />
  196. </template>
  197. </template>
  198. </el-dropdown-item>
  199. </el-dropdown-menu>
  200. <div class="dropdown">
  201. <el-button @click="singleexport" type="primary" plain>确定导出</el-button>
  202. </div>
  203. </template>
  204. </el-dropdown>
  205. </div>
  206. </div>
  207. <div class="dailyreport">
  208. <el-table :data="betweenyear.list" style="width: 100%" align="center" :show-overflow-tooltip="true">
  209. <template v-for="(item, index) in singlecolumnList" :key="index">
  210. <el-table-column v-if="item.ifcolumn" :label="item.label" :prop="item.prop" align="center">
  211. <template v-if="item.children">
  212. <template v-for="(items, i) in item.children" :key="i">
  213. <el-table-column v-if="items.ifcolumn" :label="items.label" :prop="items.prop" align="center">
  214. </el-table-column>
  215. </template>
  216. </template>
  217. </el-table-column>
  218. </template>
  219. <!-- <el-table-column label="日期" width="150" align="center">
  220. <template #default="scope">
  221. <div v-if="scope.row.ymd">{{ scope.row.ymd }}</div>
  222. <div v-if="scope.row.ym">{{ scope.row.ym }}</div>
  223. <div v-if="scope.row.year">{{ scope.row.year }}</div>
  224. </template>
  225. </el-table-column>
  226. <el-table-column label="充电量(kWh)" align="center">
  227. <el-table-column prop="chargeSharp" label="尖" align="center" />
  228. <el-table-column prop="chargePeak" label="峰" align="center" />
  229. <el-table-column prop="chargeShoulder" label="平" align="center" />
  230. <el-table-column prop="chargeValley" label="谷" align="center" />
  231. <el-table-column prop="chargeTotal" label="总" align="center" />
  232. </el-table-column>
  233. <el-table-column label="放电量(kWh)" align="center">
  234. <el-table-column prop="dischargeSharp" label="尖" align="center" />
  235. <el-table-column prop="dischargePeak" label="峰" align="center" />
  236. <el-table-column prop="dischargeShoulder" label="平" align="center" />
  237. <el-table-column prop="dischargeValley" label="谷" align="center" />
  238. <el-table-column prop="dischargeTotal" label="总" align="center" />
  239. </el-table-column>
  240. <el-table-column prop="overallEfficiency" label="综合效率(%)" width="150" align="center" /> -->
  241. </el-table>
  242. </div>
  243. </div>
  244. </el-tab-pane>
  245. </el-tabs>
  246. </el-card>
  247. </div>
  248. </template>
  249. <!-- -->
  250. <script setup lang="ts">
  251. import { onMounted, Ref, ref } from "vue";
  252. import {
  253. stationstationName,
  254. singleincomeday,
  255. singleincomeyearMonth,
  256. singleincomeyear,
  257. incomeday,
  258. incomeyearMonth,
  259. incomeyear,
  260. reportsummarymonthEXcel,
  261. summaryearmonthEXcel,
  262. reportsummaryyearEXcel,
  263. reportsingleExcel,
  264. singlemonthExcel,
  265. singleyeaeExcel
  266. } from "@/api/home/Multisite";
  267. import { other, Station } from "@/api/interface";
  268. import { useAuthButtons } from "@/hooks/useAuthButtons";
  269. const { BUTTONS } = useAuthButtons();
  270. console.log(BUTTONS);
  271. // 表头
  272. const columnList = ref([
  273. {
  274. prop: "ymdHour",
  275. label: "日期",
  276. ifcolumn: true,
  277. children: null
  278. },
  279. {
  280. prop: "",
  281. label: "充电量(kWh)",
  282. ifcolumn: true,
  283. children: [
  284. {
  285. prop: "chargeSharp",
  286. label: "尖",
  287. ifcolumn: true
  288. },
  289. {
  290. prop: "chargePeak",
  291. label: "峰",
  292. ifcolumn: true
  293. },
  294. {
  295. prop: "chargeShoulder",
  296. label: "平",
  297. ifcolumn: true
  298. },
  299. {
  300. prop: "chargeValley",
  301. label: "谷",
  302. ifcolumn: true
  303. },
  304. {
  305. prop: "chargeTotal",
  306. label: "总",
  307. ifcolumn: true
  308. }
  309. ]
  310. },
  311. {
  312. prop: "",
  313. label: "放电量(kWh)",
  314. ifcolumn: true,
  315. children: [
  316. {
  317. prop: "dischargeSharp",
  318. label: "尖",
  319. ifcolumn: true
  320. },
  321. {
  322. prop: "dischargePeak",
  323. label: "峰",
  324. ifcolumn: true
  325. },
  326. {
  327. prop: "dischargeShoulder",
  328. label: "平",
  329. ifcolumn: true
  330. },
  331. {
  332. prop: "dischargeValley",
  333. label: "谷",
  334. ifcolumn: true
  335. },
  336. {
  337. prop: "dischargeTotal",
  338. label: "总",
  339. ifcolumn: true
  340. }
  341. ]
  342. },
  343. {
  344. prop: "overallEfficiency",
  345. label: "应收益(元)",
  346. ifcolumn: true,
  347. children: null
  348. }
  349. ]);
  350. // 单站报表表头
  351. const singlecolumnList = ref([
  352. {
  353. prop: "year",
  354. label: "日期",
  355. ifcolumn: true,
  356. children: null
  357. },
  358. {
  359. prop: "",
  360. label: "充电量(元kWh)",
  361. ifcolumn: true,
  362. children: [
  363. {
  364. prop: "chargeSharp",
  365. label: "尖",
  366. ifcolumn: true
  367. },
  368. {
  369. prop: "chargePeak",
  370. label: "峰",
  371. ifcolumn: true
  372. },
  373. {
  374. prop: "chargeShoulder",
  375. label: "平",
  376. ifcolumn: true
  377. },
  378. {
  379. prop: "chargeValley",
  380. label: "谷",
  381. ifcolumn: true
  382. },
  383. {
  384. prop: "chargeTotal",
  385. label: "总",
  386. ifcolumn: true
  387. }
  388. ]
  389. },
  390. {
  391. prop: "",
  392. label: "放电量(kWh)",
  393. ifcolumn: true,
  394. children: [
  395. {
  396. prop: "dischargeSharp",
  397. label: "尖",
  398. ifcolumn: true
  399. },
  400. {
  401. prop: "dischargePeak",
  402. label: "峰",
  403. ifcolumn: true
  404. },
  405. {
  406. prop: "dischargeShoulder",
  407. label: "平",
  408. ifcolumn: true
  409. },
  410. {
  411. prop: "dischargeValley",
  412. label: "谷",
  413. ifcolumn: true
  414. },
  415. {
  416. prop: "dischargeTotal",
  417. label: "总(元)",
  418. ifcolumn: true
  419. }
  420. ]
  421. },
  422. // ,
  423. // {
  424. // prop: "overallEfficiency",
  425. // label: "综合效率(%)",
  426. // ifcolumn: true,
  427. // children: null
  428. // }
  429. {
  430. prop: "overallEfficiency",
  431. label: "应收益(元)",
  432. ifcolumn: true,
  433. children: null
  434. }
  435. ]);
  436. //
  437. const currentDate = ref();
  438. const activeName = ref("站点汇总");
  439. const handleClick = async (val: any) => {
  440. activeName.value = val.props.name;
  441. if (val.props.name == "站点汇总") {
  442. getdaymonthyear(1);
  443. gatSummary();
  444. } else {
  445. await poststationstationName();
  446. await onreportforms(2);
  447. }
  448. };
  449. const timepicker: Ref<any> = ref([]);
  450. // 禁用日期
  451. const pickerOptions = (time: { getTime: (arg0: Date) => number }) => {
  452. return time.getTime(new Date()) > Date.now();
  453. };
  454. // 选择时间
  455. // const datepicker = (val: any) => {
  456. // timepicker.value = [formatDate(val[0]), formatDate(val[1])];
  457. // };
  458. // 选择日期
  459. const daymonthyearvalue = ref(1);
  460. const shortcuts = ref([
  461. {
  462. text: "过去7天",
  463. value: () => {
  464. const end = new Date();
  465. const start = new Date();
  466. start.setDate(start.getDate() - 7);
  467. return [start, end];
  468. }
  469. },
  470. {
  471. text: "过去1个月",
  472. value: () => {
  473. const end = new Date();
  474. const start = new Date();
  475. start.setMonth(start.getMonth() - 1);
  476. return [start, end];
  477. }
  478. },
  479. {
  480. text: "过去3个月",
  481. value: () => {
  482. const end = new Date();
  483. const start = new Date();
  484. start.setMonth(start.getMonth() - 3);
  485. return [start, end];
  486. }
  487. }
  488. ]);
  489. const daymonthyear = ref([
  490. {
  491. value: 1,
  492. label: "按日"
  493. },
  494. {
  495. value: 2,
  496. label: "按月"
  497. },
  498. {
  499. value: 3,
  500. label: "按年"
  501. }
  502. ]);
  503. const timetype: Ref<any> = ref("daterange");
  504. const format = ref("YYYY-MM-DD");
  505. const getdaymonthyear = async (value: any) => {
  506. daymonthyearvalue.value = value;
  507. if (value == 1) {
  508. timetype.value = "daterange";
  509. format.value = "YYYY-MM-DD";
  510. shortcuts.value = [
  511. {
  512. text: "过去7天",
  513. value: () => {
  514. const end = new Date();
  515. const start = new Date();
  516. start.setDate(start.getDate() - 7);
  517. return [start, end];
  518. }
  519. },
  520. {
  521. text: "过去1个月",
  522. value: () => {
  523. const end = new Date();
  524. const start = new Date();
  525. start.setMonth(start.getMonth() - 1);
  526. return [start, end];
  527. }
  528. },
  529. {
  530. text: "过去3个月",
  531. value: () => {
  532. const end = new Date();
  533. const start = new Date();
  534. start.setMonth(start.getMonth() - 3);
  535. return [start, end];
  536. }
  537. }
  538. ];
  539. const today = new Date();
  540. const currentDate = today.toISOString().split("T")[0];
  541. timepicker.value = [currentDate, currentDate];
  542. // getreportpowerday();
  543. } else if (value == 2) {
  544. const today = new Date();
  545. const currentDate = today.toISOString().split("T")[0];
  546. const currentYearMonth = currentDate.slice(0, 7);
  547. timepicker.value = [currentYearMonth, currentYearMonth];
  548. // getreportpoweryearMonth();
  549. timetype.value = "monthrange";
  550. format.value = "YYYY-MM";
  551. shortcuts.value = [
  552. {
  553. text: "本月",
  554. value: () => {
  555. return [new Date(), new Date()];
  556. }
  557. },
  558. {
  559. text: "过去6个月",
  560. value: () => {
  561. const end = new Date();
  562. const start = new Date();
  563. start.setMonth(start.getMonth() - 6);
  564. return [start, end];
  565. }
  566. },
  567. {
  568. text: "今年",
  569. value: () => {
  570. const end = new Date();
  571. const start = new Date(new Date().getFullYear(), 0);
  572. return [start, end];
  573. }
  574. }
  575. ];
  576. } else {
  577. const today = new Date();
  578. const currentDate = today.toISOString().split("T")[0];
  579. // 获取去年同月的日期
  580. timepicker.value = [currentDate.substring(0, 4), currentDate.substring(0, 4)];
  581. console.log(timepicker.value);
  582. timetype.value = "yearrange";
  583. format.value = "YYYY";
  584. shortcuts.value = [
  585. {
  586. text: "今年",
  587. value: () => {
  588. return [new Date(), new Date()];
  589. }
  590. },
  591. {
  592. text: "过去1年",
  593. value: () => {
  594. const end = new Date();
  595. const start = new Date(new Date().setFullYear(new Date().getFullYear() - 1));
  596. return [start, end];
  597. }
  598. },
  599. {
  600. text: "过去2年",
  601. value: () => {
  602. const start = new Date();
  603. const end = new Date(new Date().setFullYear(new Date().getFullYear() - 2));
  604. return [start, end];
  605. }
  606. }
  607. ];
  608. // getreportpoweryear();
  609. }
  610. };
  611. // 查询
  612. const gatSummary = () => {
  613. if (daymonthyearvalue.value == 1) {
  614. getreportpowerday();
  615. } else if (daymonthyearvalue.value == 2) {
  616. getreportpoweryearMonth();
  617. } else if (daymonthyearvalue.value == 3) {
  618. getreportpoweryear();
  619. }
  620. };
  621. // 重置
  622. const onreset = () => {
  623. getdaymonthyear(1);
  624. };
  625. const onclose = (val: boolean) => {
  626. console.log(val);
  627. setTimeout(() => {
  628. if (!val) {
  629. for (const column of columnList.value) {
  630. column.ifcolumn = true;
  631. if (column.children) {
  632. for (const child of column.children) {
  633. child.ifcolumn = true;
  634. }
  635. }
  636. }
  637. }
  638. }, 500); // 延迟 0.5毫秒
  639. };
  640. const onsingleclose = (val: boolean) => {
  641. console.log(val);
  642. setTimeout(() => {
  643. if (!val) {
  644. for (const column of singlecolumnList.value) {
  645. column.ifcolumn = true;
  646. if (column.children) {
  647. for (const child of column.children) {
  648. child.ifcolumn = true;
  649. }
  650. }
  651. }
  652. }
  653. }, 500); // 延迟 0.5毫秒
  654. };
  655. // 点击父元素
  656. const oncheck = () => {
  657. if (columnList.value) {
  658. for (let index = 0; index < columnList.value.length; index++) {
  659. const column = columnList.value[index];
  660. if (column.children && column.prop == "") {
  661. for (let i = 0; i < column.children.length; i++) {
  662. const child = column.children[i];
  663. if (child && !column.ifcolumn) {
  664. child.ifcolumn = false;
  665. } else {
  666. child.ifcolumn = true;
  667. }
  668. if (child && child.ifcolumn) {
  669. column.ifcolumn = true;
  670. }
  671. }
  672. }
  673. }
  674. }
  675. };
  676. // 点击子元素
  677. const onchildren = () => {
  678. if (columnList.value) {
  679. for (let index = 0; index < columnList.value.length; index++) {
  680. const column = columnList.value[index];
  681. if (column.children && column.prop == "") {
  682. for (let i = 0; i < column.children.length; i++) {
  683. const child = column.children[i];
  684. console.log(child);
  685. if (child && !child.ifcolumn) {
  686. column.ifcolumn = false;
  687. } else {
  688. column.ifcolumn = true;
  689. return;
  690. }
  691. }
  692. }
  693. }
  694. }
  695. };
  696. // 点击单站父元素多选
  697. const onsingle = () => {
  698. if (singlecolumnList.value) {
  699. for (let index = 0; index < singlecolumnList.value.length; index++) {
  700. const column = singlecolumnList.value[index];
  701. if (column && !column.ifcolumn) {
  702. if (column.children && column.prop == "") {
  703. for (let i = 0; i < column.children.length; i++) {
  704. const child = column.children[i];
  705. child.ifcolumn = false;
  706. }
  707. }
  708. } else {
  709. if (column.children && column.prop == "") {
  710. for (let i = 0; i < column.children.length; i++) {
  711. const child = column.children[i];
  712. child.ifcolumn = true;
  713. }
  714. }
  715. }
  716. }
  717. }
  718. };
  719. // 点击单站子元素
  720. const onsinglechildren = () => {
  721. if (singlecolumnList.value) {
  722. for (let index = 0; index < singlecolumnList.value.length; index++) {
  723. const column = singlecolumnList.value[index];
  724. if (column.children && column.prop == "") {
  725. for (let i = 0; i < column.children.length; i++) {
  726. const child = column.children[i];
  727. console.log(child);
  728. if (child && !child.ifcolumn) {
  729. column.ifcolumn = false;
  730. } else {
  731. column.ifcolumn = true;
  732. return;
  733. }
  734. }
  735. }
  736. }
  737. }
  738. };
  739. // 导出
  740. const onexport = async () => {
  741. let obj: string[] = []; // 假设 prop 是 string 类型,如果不是,请根据实际类型修改
  742. if (columnList.value) {
  743. for (const column of columnList.value) {
  744. if (column?.ifcolumn) {
  745. if (column.prop) {
  746. obj.push(column.prop);
  747. }
  748. if (column.children) {
  749. for (const child of column.children) {
  750. if (child?.ifcolumn && child.prop) {
  751. obj.push(child.prop);
  752. }
  753. }
  754. }
  755. }
  756. }
  757. }
  758. const jsonString = obj.join(",");
  759. if (daymonthyearvalue.value == 1) {
  760. let obj = {
  761. excel: jsonString,
  762. startDate: timepicker.value[0],
  763. endDate: timepicker.value[1]
  764. };
  765. const { data } = await reportsummarymonthEXcel(obj);
  766. downloadxlsx(timepicker.value[0], data);
  767. } else if (daymonthyearvalue.value == 2) {
  768. let obj = {
  769. excel: jsonString,
  770. startYearMonth: timepicker.value[0],
  771. endYearMonth: timepicker.value[1]
  772. };
  773. const { data } = await summaryearmonthEXcel(obj);
  774. downloadxlsx(timepicker.value[0], data);
  775. } else if (daymonthyearvalue.value == 3) {
  776. let obj = {
  777. excel: jsonString,
  778. startYear: timepicker.value[0],
  779. endYear: timepicker.value[1]
  780. };
  781. const { data } = await reportsummaryyearEXcel(obj);
  782. downloadxlsx(timepicker.value[0] + "-" + timepicker.value[1], data);
  783. }
  784. };
  785. const downloadxlsx = (item: string, data: other.Data) => {
  786. console.log(item, data);
  787. let fileUrl = `download/${data.msg}`;
  788. const date = new Date();
  789. const hours = formatTime(date.getHours());
  790. const minutes = formatTime(date.getMinutes());
  791. const seconds = formatTime(date.getSeconds());
  792. let fileName = `${item} ${hours}:${minutes}:${seconds}电量报表.xlsx`;
  793. fetch(fileUrl)
  794. .then(response => response.blob())
  795. .then(blob => {
  796. // 创建一个临时的URL对象
  797. const url = URL.createObjectURL(blob);
  798. // 创建一个隐藏的<a>标签,并设置其href属性为临时URL
  799. const a = document.createElement("a");
  800. a.href = url;
  801. a.download = fileName; // 设置下载的文件名
  802. a.style.display = "none";
  803. // 将<a>标签添加到文档中,并模拟点击下载
  804. document.body.appendChild(a);
  805. a.click();
  806. // 下载完成后,移除<a>标签和临时URL对象
  807. document.body.removeChild(a);
  808. URL.revokeObjectURL(url);
  809. })
  810. .catch(error => {
  811. console.error("下载文件时出错:", error);
  812. });
  813. };
  814. const formatTime = (time: number) => {
  815. return time < 10 ? `0${time}` : time; // 如果时间小于 10,在前面加上 0
  816. };
  817. // const formatDate = (dateString: string | number | Date) => {
  818. // const date = new Date(dateString);
  819. // // 提取年、月、日、时、分信息
  820. // const year = date.getFullYear();
  821. // const month = String(date.getMonth() + 1).padStart(2, "0"); // 月份从0开始,需要加1,并确保是两位数
  822. // const day = String(date.getDate()).padStart(2, "0"); // 确保是两位数
  823. // const hours = String(date.getHours()).padStart(2, "0"); // 确保是两位数
  824. // const minutes = String(date.getMinutes()).padStart(2, "0"); // 确保是两位数
  825. // // 拼接成 "YYYY-MM-DD HH:MM" 格式
  826. // const formattedDate = `${year}-${month}-${day} ${hours}:${minutes}`;
  827. // return formattedDate;
  828. // };
  829. const tableData = ref();
  830. // 日
  831. const getreportpowerday = async () => {
  832. let obj = {
  833. startDate: timepicker.value[0],
  834. endDate: timepicker.value[1]
  835. };
  836. const { data } = await incomeday(obj);
  837. data.total.ymdHour = "总计";
  838. data.list.push(data.total);
  839. tableData.value = data;
  840. };
  841. // 月份
  842. const getreportpoweryearMonth = async () => {
  843. let obj = {
  844. startYearMonth: timepicker.value[0],
  845. endYearMonth: timepicker.value[1]
  846. };
  847. const { data } = await incomeyearMonth(obj);
  848. data.total.ymdHour = "总计";
  849. data.list.push(data.total);
  850. tableData.value = data;
  851. };
  852. // 年份
  853. const getreportpoweryear = async () => {
  854. let obj = {
  855. startYear: timepicker.value[0],
  856. endYear: timepicker.value[1]
  857. };
  858. const { data } = await incomeyear(obj);
  859. data.total.ymdHour = "总计";
  860. data.list.push(data.total);
  861. tableData.value = data;
  862. };
  863. const reportformsindex = ref(2);
  864. const pickertype: Ref<any> = ref("daterange");
  865. const onreportforms = (val: any) => {
  866. reportformsindex.value = val;
  867. if (val == 1) {
  868. pickertype.value = "date";
  869. starttime.value = currentDate.value;
  870. } else if (val == 2) {
  871. shortcuts.value = [
  872. {
  873. text: "过去7天",
  874. value: () => {
  875. const end = new Date();
  876. const start = new Date();
  877. start.setDate(start.getDate() - 7);
  878. return [start, end];
  879. }
  880. },
  881. {
  882. text: "过去1个月",
  883. value: () => {
  884. const end = new Date();
  885. const start = new Date();
  886. start.setMonth(start.getMonth() - 1);
  887. return [start, end];
  888. }
  889. },
  890. {
  891. text: "过去3个月",
  892. value: () => {
  893. const end = new Date();
  894. const start = new Date();
  895. start.setMonth(start.getMonth() - 3);
  896. return [start, end];
  897. }
  898. }
  899. ];
  900. pickertype.value = "daterange";
  901. format.value = "YYYY-MM-DD";
  902. const today = new Date();
  903. const currentDate = today.toISOString().split("T")[0];
  904. starttime.value = [currentDate, currentDate];
  905. } else if (val == 3) {
  906. const today = new Date();
  907. const currentDate = today.toISOString().split("T")[0];
  908. const currentYearMonth = currentDate.slice(0, 7);
  909. starttime.value = [currentYearMonth, currentYearMonth];
  910. format.value = "YYYY-MM";
  911. pickertype.value = "monthrange";
  912. shortcuts.value = [
  913. {
  914. text: "本月",
  915. value: () => {
  916. return [new Date(), new Date()];
  917. }
  918. },
  919. {
  920. text: "过去6个月",
  921. value: () => {
  922. const end = new Date();
  923. const start = new Date();
  924. start.setMonth(start.getMonth() - 6);
  925. return [start, end];
  926. }
  927. },
  928. {
  929. text: "今年",
  930. value: () => {
  931. const end = new Date();
  932. const start = new Date(new Date().getFullYear(), 0);
  933. return [start, end];
  934. }
  935. }
  936. ];
  937. } else if (val == 4) {
  938. const today = new Date();
  939. const currentDate = today.toISOString().split("T")[0];
  940. // 获取去年同月的日期
  941. starttime.value = [currentDate.substring(0, 4), currentDate.substring(0, 4)];
  942. pickertype.value = "yearrange";
  943. format.value = "YYYY";
  944. shortcuts.value = [
  945. {
  946. text: "今年",
  947. value: () => {
  948. return [new Date(), new Date()];
  949. }
  950. },
  951. {
  952. text: "过去1年",
  953. value: () => {
  954. const end = new Date();
  955. const start = new Date(new Date().setFullYear(new Date().getFullYear() - 1));
  956. return [start, end];
  957. }
  958. },
  959. {
  960. text: "过去2年",
  961. value: () => {
  962. const start = new Date();
  963. const end = new Date(new Date().setFullYear(new Date().getFullYear() - 2));
  964. return [start, end];
  965. }
  966. }
  967. ];
  968. }
  969. onselectsite();
  970. };
  971. // 选择站点
  972. const Singlevalue = ref("");
  973. const cities: Ref<Station.todo[]> = ref([]);
  974. const poststationstationName = async () => {
  975. const { data } = await stationstationName({});
  976. Singlevalue.value = data[0].id;
  977. cities.value = data;
  978. // getsingleincomeday();
  979. };
  980. const postemsDevice = async (value: any) => {
  981. console.log(value);
  982. };
  983. // 选择日期
  984. const starttime: Ref<any> = ref("");
  985. // 开始时间
  986. // const yearstarttime = async (val: any) => {
  987. // if (reportformsindex.value == 1) {
  988. // } else if (reportformsindex.value == 2) {
  989. // starttime.value = [formatDate(val[0]), formatDate(val[1])];
  990. // } else if (reportformsindex.value == 3) {
  991. // starttime.value = [formatDate(val[0]), formatDate(val[1])];
  992. // } else if (reportformsindex.value == 4) {
  993. // for (let index = 0; index < val.length; index++) {
  994. // val[index] = formatDate(val[index]);
  995. // }
  996. // starttime.value = val;
  997. // }
  998. // };
  999. // 查询
  1000. const onselectsite = async () => {
  1001. if (reportformsindex.value == 2) {
  1002. getsingleincomeday();
  1003. } else if (reportformsindex.value == 3) {
  1004. getsingleincomeyearMonth();
  1005. } else if (reportformsindex.value == 4) {
  1006. getsingleincomeyear();
  1007. }
  1008. // onreportforms(reportformsindex.value);
  1009. };
  1010. // 重置
  1011. const onselectreset = async () => {
  1012. onreportforms(2);
  1013. };
  1014. // 导出
  1015. const singleexport = async () => {
  1016. let obj: string[] = []; // 假设 prop 是 string 类型,如果不是,请根据实际类型修改
  1017. if (singlecolumnList.value) {
  1018. for (const column of singlecolumnList.value) {
  1019. if (column?.ifcolumn) {
  1020. if (column.prop) {
  1021. obj.push(column.prop);
  1022. }
  1023. if (column.children) {
  1024. for (const child of column.children) {
  1025. if (child?.ifcolumn && child.prop) {
  1026. obj.push(child.prop);
  1027. }
  1028. }
  1029. }
  1030. }
  1031. }
  1032. }
  1033. const jsonString = obj.join(",");
  1034. if (reportformsindex.value == 2) {
  1035. let obj = {
  1036. excel: jsonString,
  1037. startTime: starttime.value[0],
  1038. endTime: starttime.value[1]
  1039. };
  1040. const { data } = await reportsingleExcel(obj, Singlevalue.value);
  1041. downloadxlsx(starttime.value[0], data);
  1042. } else if (reportformsindex.value == 3) {
  1043. let obj = {
  1044. excel: jsonString,
  1045. startYearMonth: starttime.value[0],
  1046. endYearMonth: starttime.value[1]
  1047. };
  1048. const { data } = await singlemonthExcel(obj, Singlevalue.value);
  1049. downloadxlsx(starttime.value[0], data);
  1050. } else if (reportformsindex.value == 4) {
  1051. let obj = {
  1052. excel: jsonString,
  1053. startYear: starttime.value[0],
  1054. endYear: starttime.value[1]
  1055. };
  1056. const { data } = await singleyeaeExcel(obj, Singlevalue.value);
  1057. downloadxlsx(starttime.value[0] + "-" + starttime.value[1], data);
  1058. }
  1059. };
  1060. // 电量报表-单站_日月年报表
  1061. const betweenyear = ref();
  1062. const getsingleincomeday = async () => {
  1063. let obj = {
  1064. startDate: starttime.value[0],
  1065. endDate: starttime.value[1]
  1066. };
  1067. const { data } = await singleincomeday(obj, Singlevalue.value);
  1068. betweenyear.value = data;
  1069. data.total.ymd = "合计";
  1070. betweenyear.value.list.push(data.total);
  1071. };
  1072. const getsingleincomeyearMonth = async () => {
  1073. let obj = {
  1074. startYearMonth: starttime.value[0],
  1075. endYearMonth: starttime.value[1]
  1076. };
  1077. const { data } = await singleincomeyearMonth(obj, Singlevalue.value);
  1078. betweenyear.value = data;
  1079. data.total.ym = "合计";
  1080. betweenyear.value.list.push(data.total);
  1081. };
  1082. const getsingleincomeyear = async () => {
  1083. let obj = {
  1084. startYear: starttime.value[0],
  1085. endYear: starttime.value[1]
  1086. };
  1087. const { data } = await singleincomeyear(obj, Singlevalue.value);
  1088. betweenyear.value = data;
  1089. data.total.year = "合计";
  1090. betweenyear.value.list.push(data.total);
  1091. };
  1092. onMounted(() => {
  1093. const current = localStorage.getItem("currentDate");
  1094. if (current) {
  1095. currentDate.value = current;
  1096. starttime.value = [currentDate.value, currentDate.value];
  1097. }
  1098. timepicker.value = [currentDate.value, currentDate.value];
  1099. getreportpowerday();
  1100. });
  1101. </script>
  1102. <style scoped lang="scss">
  1103. @import "./index.scss";
  1104. </style>
  1105. <!--
  1106. -->