PvStationLogicCheck.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <template>
  2. <div class="pv-station-logic-check-page">
  3. <a-card :bordered="false">
  4. <a-row :gutter="[12, 12]" align="middle">
  5. <a-col :xs="24" :md="6">
  6. <StationSelector v-model:value="query.stationCode" :options="stationOptions" :multiple="false" />
  7. </a-col>
  8. <a-col :xs="24" :md="6">
  9. <a-radio-group v-model:value="query.dataType" button-style="solid">
  10. <a-radio value="sampleMachine">样板法</a-radio>
  11. <a-radio value="photometricMethod">测光法</a-radio>
  12. </a-radio-group>
  13. </a-col>
  14. <a-col :xs="24" :md="5">
  15. <a-date-picker
  16. v-model:value="query.day"
  17. format="YYYY-MM-DD"
  18. value-format="YYYY-MM-DD"
  19. placeholder="选择日期"
  20. class="full-control"
  21. />
  22. </a-col>
  23. <a-col :xs="24" :md="7">
  24. <a-space>
  25. <a-button type="primary" :loading="loading" @click="handleQuery">确认</a-button>
  26. <a-button :loading="exporting" @click="handleExport">导出</a-button>
  27. </a-space>
  28. </a-col>
  29. </a-row>
  30. </a-card>
  31. <a-card title="数据详情" :bordered="false" style="margin-top: 16px">
  32. <BusinessDataTable
  33. row-key="time"
  34. :columns="tableColumns"
  35. :data-source="tableRows"
  36. :pagination="{ pageSize: 20 }"
  37. :scroll-x="'max-content'"
  38. />
  39. </a-card>
  40. </div>
  41. </template>
  42. <script setup name="PvStationLogicCheck">
  43. import { h, onMounted, reactive, ref } from 'vue'
  44. import { message } from 'ant-design-vue'
  45. import dayjs from 'dayjs'
  46. import { saveAs } from 'file-saver'
  47. import { blobValidate } from '@/utils/bearjia'
  48. import { listStation } from '@/api/config/station'
  49. import { logicCheckList, exportLogicCheck } from '@/api/theoretical/power'
  50. import BusinessDataTable from '../electricity/components/BusinessDataTable.vue'
  51. import StationSelector from '../electricity/components/StationSelector.vue'
  52. import { normalizeRows } from '../electricity/components/dataAdapter.js'
  53. const loading = ref(false)
  54. const exporting = ref(false)
  55. const stationOptions = ref([])
  56. const tableRows = ref([])
  57. const query = reactive({
  58. stationCode: undefined,
  59. dataType: 'sampleMachine',
  60. day: dayjs().format('YYYY-MM-DD')
  61. })
  62. const renderRatioCell = (value, desc) => {
  63. const bad = desc === '不合格'
  64. return h('span', {}, [
  65. h('span', {}, `${Number(value || 0).toFixed(2)} `),
  66. h('span', { style: bad ? { color: '#f5222d' } : {} }, desc || '')
  67. ])
  68. }
  69. const tableColumns = [
  70. { title: '时间', dataIndex: 'time', width: 100 },
  71. {
  72. title: '装机比理论',
  73. dataIndex: 'installed2TheoreticalPercent',
  74. width: 180,
  75. customRender: ({ record }) => renderRatioCell(record.installed2TheoreticalPercent, record.installed2TheoreticalDesc)
  76. },
  77. {
  78. title: '理论比可用',
  79. dataIndex: 'theoretical2AvailablePercent',
  80. width: 180,
  81. customRender: ({ record }) => renderRatioCell(record.theoretical2AvailablePercent, record.theoretical2AvailableDesc)
  82. },
  83. {
  84. title: '可用比实际',
  85. dataIndex: 'available2ActualPercent',
  86. width: 180,
  87. customRender: ({ record }) => renderRatioCell(record.available2ActualPercent, record.available2ActualDesc)
  88. }
  89. ]
  90. const checkStation = () => {
  91. if (!query.stationCode) {
  92. message.warning('请先选择电厂')
  93. return false
  94. }
  95. return true
  96. }
  97. const buildParams = () => ({
  98. stationCode: query.stationCode,
  99. dataType: query.dataType,
  100. day: query.day
  101. })
  102. const loadStationOptions = async () => {
  103. const res = await listStation({ pageNum: 1, pageSize: 500 })
  104. const rows = normalizeRows(res)
  105. stationOptions.value = rows.map((item, index) => ({
  106. label: item.stationName || `站点${index + 1}`,
  107. value: item.stationCode
  108. }))
  109. if (!query.stationCode && stationOptions.value.length) {
  110. query.stationCode = stationOptions.value[0].value
  111. }
  112. }
  113. const handleQuery = async () => {
  114. if (!checkStation()) return
  115. loading.value = true
  116. try {
  117. const res = await logicCheckList(buildParams())
  118. tableRows.value = normalizeRows(res)
  119. } finally {
  120. loading.value = false
  121. }
  122. }
  123. const handleExport = async () => {
  124. if (!checkStation()) return
  125. exporting.value = true
  126. try {
  127. const res = await exportLogicCheck(buildParams())
  128. const isFile = await blobValidate(res)
  129. if (isFile) {
  130. saveAs(new Blob([res]), `光伏场站逻辑校核_${dayjs(query.day).format('YYYYMMDD')}.xlsx`)
  131. message.success('导出成功')
  132. } else {
  133. const text = await res.text()
  134. let msg = '导出失败'
  135. try { msg = JSON.parse(text)?.msg || msg } catch (e) { /* ignore */ }
  136. message.error(msg)
  137. }
  138. } finally {
  139. exporting.value = false
  140. }
  141. }
  142. onMounted(async () => {
  143. await loadStationOptions()
  144. await handleQuery()
  145. })
  146. </script>
  147. <style lang="less" scoped>
  148. .pv-station-logic-check-page {
  149. padding: 16px;
  150. }
  151. .full-control {
  152. width: 100%;
  153. }
  154. </style>