农村饮用水
This commit is contained in:
214
src/views/water/drinking-water-village/collect/index.vue
Normal file
214
src/views/water/drinking-water-village/collect/index.vue
Normal file
@@ -0,0 +1,214 @@
|
||||
<template>
|
||||
<div class="ele-body">
|
||||
<a-card style="width: 100%" :bordered="false">
|
||||
<template #title>
|
||||
<a-space>
|
||||
<a-upload
|
||||
:before-upload="importFileTop"
|
||||
:showUploadList="false"
|
||||
accept=".xls,.xlsx,.csv"
|
||||
>
|
||||
<a-button>农村地表水导入</a-button>
|
||||
</a-upload>
|
||||
<a-upload
|
||||
:before-upload="importFileBottom"
|
||||
:showUploadList="false"
|
||||
accept=".xls,.xlsx,.csv"
|
||||
>
|
||||
<a-button>农村地下水导入</a-button>
|
||||
</a-upload>
|
||||
</a-space>
|
||||
</template>
|
||||
<a-tabs v-model:activeKey="activeKey">
|
||||
<a-tab-pane tab="噪声信息" key="water">
|
||||
<water-bill ref="water"></water-bill>
|
||||
</a-tab-pane>
|
||||
</a-tabs>
|
||||
</a-card>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import XLSX from "xlsx";
|
||||
import utils from "./utils";
|
||||
import { Modal } from "ant-design-vue";
|
||||
import WaterBill from "./water-bill.vue";
|
||||
import { saveDrinkingWaterVillageBill } from "@/api/ecology/drinking-water-village";
|
||||
export default {
|
||||
name: "DrinkWaterVillageCollectIndex",
|
||||
components: {
|
||||
WaterBill,
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
activeKey: "water",
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
/* 导入本地excel文件 */
|
||||
importFileTop(file) {
|
||||
const hide = this.$message.loading("导入中..", 0);
|
||||
let reader = new FileReader();
|
||||
reader.onload = (e) => {
|
||||
try {
|
||||
let data = new Uint8Array(e.target.result);
|
||||
let workbook = XLSX.read(data, {
|
||||
type: "array",
|
||||
});
|
||||
//0.昼间数据 1.夜间数据 2.其他信息
|
||||
let sheetNames = workbook.SheetNames;
|
||||
// 解析成二维数组
|
||||
let aoa1 = XLSX.utils.sheet_to_json(workbook.Sheets[sheetNames[0]], {
|
||||
header: 1,
|
||||
});
|
||||
|
||||
const drinkingWaterVillageList = aoa1.filter((item) => {
|
||||
return item.length >= 40 && typeof item[0] == "number";
|
||||
});
|
||||
|
||||
// 解析成对象数组
|
||||
console.log(file);
|
||||
const billName1 = file.name;
|
||||
const billData1 = utils.toVillageTop(drinkingWaterVillageList);
|
||||
|
||||
if (!billData1 || billData1.length == 0) {
|
||||
hide();
|
||||
Modal.error({
|
||||
title: "导入失败",
|
||||
content: "找不到可用数据",
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (billData1.length > 0) {
|
||||
// 上传到服务器
|
||||
saveDrinkingWaterVillageBill({
|
||||
billName: billName1,
|
||||
regionLevel: "农村",
|
||||
waterSourceType: 1,
|
||||
drinkingWaterType: 1,
|
||||
drinkingWaterVillageList: billData1,
|
||||
})
|
||||
.then((res) => {
|
||||
if (res.data.code == 0) {
|
||||
Modal.success({
|
||||
title: "导入成功",
|
||||
content: `成功导入${billData1.length}条数据`,
|
||||
});
|
||||
this.$refs.water && this.$refs.water.reload();
|
||||
} else {
|
||||
Modal.error({
|
||||
title: "导入失败",
|
||||
content: "数据上传出错",
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
Modal.error({
|
||||
title: "导入失败",
|
||||
content: "数据上传出错",
|
||||
});
|
||||
})
|
||||
.finally(() => {
|
||||
hide();
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
hide();
|
||||
Modal.error({
|
||||
title: "导入失败",
|
||||
content: error.message,
|
||||
});
|
||||
console.log(error);
|
||||
}
|
||||
};
|
||||
reader.readAsArrayBuffer(file);
|
||||
return false;
|
||||
},
|
||||
importFileBottom(file) {
|
||||
const hide = this.$message.loading("导入中..", 0);
|
||||
let reader = new FileReader();
|
||||
reader.onload = (e) => {
|
||||
try {
|
||||
let data = new Uint8Array(e.target.result);
|
||||
let workbook = XLSX.read(data, {
|
||||
type: "array",
|
||||
});
|
||||
//0.昼间数据 1.夜间数据 2.其他信息
|
||||
let sheetNames = workbook.SheetNames;
|
||||
// 解析成二维数组
|
||||
let aoa1 = XLSX.utils.sheet_to_json(workbook.Sheets[sheetNames[0]], {
|
||||
header: 1,
|
||||
});
|
||||
|
||||
const drinkingWaterVillageList = aoa1.filter((item) => {
|
||||
return item.length >= 40 && typeof item[0] == "number";
|
||||
});
|
||||
|
||||
// 解析成对象数组
|
||||
console.log(file);
|
||||
const billName1 = file.name;
|
||||
const billData1 = utils.toVillageBottom(drinkingWaterVillageList);
|
||||
|
||||
if (!billData1 || billData1.length == 0) {
|
||||
hide();
|
||||
Modal.error({
|
||||
title: "导入失败",
|
||||
content: "找不到可用数据",
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (billData1.length > 0) {
|
||||
// 上传到服务器
|
||||
saveDrinkingWaterVillageBill({
|
||||
billName: billName1,
|
||||
regionLevel: "农村",
|
||||
waterSourceType: 2,
|
||||
drinkingWaterType: 1,
|
||||
drinkingWaterVillageList: billData1,
|
||||
})
|
||||
.then((res) => {
|
||||
if (res.data.code == 0) {
|
||||
Modal.success({
|
||||
title: "导入成功",
|
||||
content: `成功导入${billData1.length}条数据`,
|
||||
});
|
||||
this.$refs.water && this.$refs.water.reload();
|
||||
} else {
|
||||
Modal.error({
|
||||
title: "导入失败",
|
||||
content: "数据上传出错",
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
Modal.error({
|
||||
title: "导入失败",
|
||||
content: "数据上传出错",
|
||||
});
|
||||
})
|
||||
.finally(() => {
|
||||
hide();
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
hide();
|
||||
Modal.error({
|
||||
title: "导入失败",
|
||||
content: error.message,
|
||||
});
|
||||
console.log(error);
|
||||
}
|
||||
};
|
||||
reader.readAsArrayBuffer(file);
|
||||
return false;
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
</style>
|
||||
Reference in New Issue
Block a user