| | |
| | | <div> |
| | | <el-button type="primary" @click="openForm('add')">新增</el-button> |
| | | <el-button type="info" plain icon="Upload" @click="handleImport">导入</el-button> |
| | | <el-button @click="handleOut">导出</el-button> |
| | | <el-button type="danger" plain @click="handleDelete">删除</el-button> |
| | | </div> |
| | | </div> |
| | |
| | | v-model="upload.open" |
| | | width="400px" |
| | | append-to-body |
| | | @close="handleDialogClose" |
| | | > |
| | | <el-upload |
| | | ref="uploadRef" |
| | | :limit="1" |
| | | accept=".xlsx, .xls" |
| | | :headers="upload.headers" |
| | | :action="upload.url + '?updateSupport=' + upload.updateSupport" |
| | | :action="upload.url" |
| | | :disabled="upload.isUploading" |
| | | :before-upload="upload.beforeUpload" |
| | | :on-progress="upload.onProgress" |
| | |
| | | <template #tip> |
| | | <div class="el-upload__tip text-center"> |
| | | <span>仅允许导入xls、xlsx格式文件。</span> |
| | | <!-- <el-link--> |
| | | <!-- type="primary"--> |
| | | <!-- :underline="false"--> |
| | | <!-- style="font-size: 12px; vertical-align: baseline"--> |
| | | <!-- @click="importTemplate"--> |
| | | <!-- >下载模板</el-link--> |
| | | <!-- >--> |
| | | <el-link |
| | | type="primary" |
| | | :underline="false" |
| | | style="font-size: 12px; vertical-align: baseline" |
| | | @click="importTemplate" |
| | | >下载模板</el-link |
| | | > |
| | | </div> |
| | | </template> |
| | | </el-upload> |
| | |
| | | |
| | | <script setup> |
| | | import {Search} from "@element-plus/icons-vue"; |
| | | import {onMounted, ref} from "vue"; |
| | | import {onMounted, ref, getCurrentInstance} from "vue"; |
| | | import FormDia from "@/views/energyManagement/energyPower/components/formDia.vue"; |
| | | import {ElMessageBox} from "element-plus"; |
| | | import {getToken} from "@/utils/auth.js"; |
| | |
| | | }); |
| | | const { searchForm } = toRefs(data); |
| | | |
| | | const selectedRows = ref([]); |
| | | const tableColumn = ref([ |
| | | { |
| | | label: "设备名称", |
| | |
| | | prop: "dayNum", |
| | | width: 150, |
| | | }, |
| | | { |
| | | label: "累计用电量", |
| | | prop: "sumNum", |
| | | width: 150, |
| | | }, |
| | | // { |
| | | // label: "累计用电量", |
| | | // prop: "sumNum", |
| | | // width: 150, |
| | | // }, |
| | | { |
| | | label: "每日限制电量", |
| | | prop: "everyNum", |
| | |
| | | // 设置上传的请求头部 |
| | | headers: { Authorization: "Bearer " + getToken() }, |
| | | // 上传的地址 |
| | | url: import.meta.env.VITE_APP_BASE_API + "/basic/customer/importData", |
| | | url: import.meta.env.VITE_APP_BASE_API + "/equipmentEnergyConsumption/importData", |
| | | // 文件上传前的回调 |
| | | beforeUpload: (file) => { |
| | | console.log('文件即将上传', file); |
| | |
| | | function handleImport() { |
| | | upload.title = "设备能耗"; |
| | | upload.open = true; |
| | | // 清空上次上传的文件列表 |
| | | nextTick(() => { |
| | | proxy.$refs["uploadRef"]?.clearFiles(); |
| | | }); |
| | | } |
| | | function importTemplate() { |
| | | proxy.download( |
| | | "/equipmentEnergyConsumption/export", |
| | | {}, |
| | | '设备能耗导入模版.xlsx' |
| | | ); |
| | | } |
| | | /** 提交上传文件 */ |
| | | function submitFileForm() { |
| | | proxy.$refs["uploadRef"].submit(); |
| | | } |
| | | |
| | | /** 弹框关闭时清空文件列表 */ |
| | | function handleDialogClose() { |
| | | nextTick(() => { |
| | | proxy.$refs["uploadRef"]?.clearFiles(); |
| | | }); |
| | | } |
| | | |
| | | const handleDelete = () => { |
| | | let ids = []; |
| | | if (selectedRows.value.length > 0) { |
| | | // 检查是否有他人维护的数据 |
| | | const unauthorizedData = selectedRows.value.filter(item => item.maintainer !== userStore.nickName); |
| | | if (unauthorizedData.length > 0) { |
| | | proxy.$modal.msgWarning("不可删除他人维护的数据"); |
| | | return; |
| | | } |
| | | ids = selectedRows.value.map((item) => item.id); |
| | | } else { |
| | | proxy.$modal.msgWarning("请选择数据"); |
| | |
| | | proxy.$modal.msg("已取消"); |
| | | }); |
| | | }; |
| | | |
| | | // 导出 |
| | | const handleOut = () => { |
| | | ElMessageBox.confirm("选中的内容将被导出,是否确认导出?", "导出", { |
| | | confirmButtonText: "确认", |
| | | cancelButtonText: "取消", |
| | | type: "warning", |
| | | }) |
| | | .then(() => { |
| | | proxy.download("/equipmentEnergyConsumption/export", {}, "能源功率.xlsx"); |
| | | }) |
| | | .catch(() => { |
| | | proxy.$modal.msg("已取消"); |
| | | }); |
| | | }; |
| | | |
| | | onMounted(() => { |
| | | getList(); |
| | | }); |