2024-05-20 19:51:23 +08:00

282 lines
8.9 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<div class="warning-page">
<LeftMenu
v-model="active"
:tabs="['项目名称', '工程名称']"
:records="records"
@change-page="onCurChange"
@search="onSearchInput"
:pageable="pages"
class="leftMenu"
>
<template #default="{ data }">
<div class="leftProject" @click="onSearch(data)">
<span class="projectName">{{ data.projectName || data.engineeringName }}</span>
<div class="leftMenu_item">
<div class="leftMenu_item flx-justify-between">
<div style="margin-top: 5px" class="flx-justify-between">
<img
style="margin-right: 5px; width: 25px; height: 25px"
src="@/assets/images/AIwaring/dustMapWhite.png"
alt=""
/>
<span class="middleSize">{{ data.projectAddress || data.address }}</span>
</div>
</div>
</div>
</div>
</template>
</LeftMenu>
<div class="table-box">
<div class="table">
<ProTable
ref="proTable"
title="工程量清单列表"
:columns="columns"
:requestApi="getTableList"
:dataCallback="dataCallback"
:tool-button="false"
:pagination="true"
background
:isShowSearch="false"
>
<template #formButton="scope">
<el-upload
v-auth="'quantity_import'"
accept=".xlsx"
:headers="headers"
:action="`${baseUrl}` + '/gov/projectQuantity/importExcel'"
:on-success="uploadFileSuccess"
:before-upload="uploadFileBefore"
:data="otherParams"
style="margin-left: 20px"
:show-file-list="false"
>
<el-button class="hzStyle" type="primary">导入</el-button>
</el-upload>
<el-upload
v-auth="'quantity_cover'"
accept=".xlsx"
:headers="headers"
:action="`${baseUrl}` + '/gov/projectQuantity/importExcel'"
:on-success="uploadFileSuccess"
:data="otherParams"
style="margin-left: 20px"
:show-file-list="false"
>
<el-button class="hzStyle" type="primary">导入覆盖</el-button>
</el-upload>
<el-button class="hzStyle" type="primary" style="margin-left: 20px" @click="modelDocumentDownload"
>模板下载</el-button
>
<el-button class="hzStyle" type="primary" style="margin-left: 20px" @click="openDialog">历史记录</el-button>
</template>
<!-- 表格操作 -->
<!-- <template #operation="{ row }">
<el-button class="btnStyle" type="primary" @click="handleItemDetail(2, row)">
<img src="@/assets/images/tableIcon/configureIcon.png" alt="" class="configureIcon" />
<span>查看</span>
</el-button>
</template> -->
</ProTable>
</div>
</div>
<!-- 历史记录 -->
<historyDialog v-model:historyListDialog="historyListDialog" :snValue="searchSn" :active="active"></historyDialog>
</div>
</template>
<script lang="tsx" setup name="engineerInventory">
import { ref, onMounted, onBeforeMount, watch } from "vue";
import { ElMessage } from "element-plus";
import { useRoute } from "vue-router";
import { GlobalStore } from "@/stores";
import LeftMenu from "@/components/LeftMenu/LeftMenu.vue";
import ProTable from "@/components/ProTable/index.vue";
import { ColumnProps } from "@/components/ProTable/interface";
import { payGovermentEngList, payGovermentProList, engineerInfoPage, downModel } from "@/api/modules/huizhou";
import { sendIframeMessage } from "@/utils/util";
import historyDialog from "./components/historyDialog.vue";
const route = useRoute();
const otherParams = ref({});
const historyListDialog = ref(false);
const relativeId = ref("");
const pages = ref({
pageNo: 1,
pageSize: 7,
total: 0
});
const records = ref([]);
const active = ref(1);
const store = GlobalStore();
const headers = ref({ Authorization: "Bearer " + store.token });
const baseUrl = window.location.protocol + "//" + window.location.host;
// const baseUrl = import.meta.env.VITE_API_URL;
// 表格配置项
const columns: ColumnProps[] = [
{ prop: "projectCode", label: "子目号", width: 150 },
{
prop: "projectName",
label: "子目名称",
search: { el: "input" }
},
// 多级 prop
{ prop: "unit", label: "单位" },
{ prop: "number", label: "数量" },
{ prop: "unitPrice", label: "单价(元)" },
{ prop: "totalPrice", label: "合价(元)" }
// { prop: "operation", label: "操作", fixed: "right", width: 120 }
];
// 获取 ProTable 元素,调用其获取刷新数据方法(还能获取到当前查询参数,方便导出携带参数)
const proTable = ref();
// 搜索用的项目sn或者工程sn
const searchSn = ref("");
// 模板下载
const modelDocumentDownload = async () => {
const { result } = await downModel({ id: 1 });
if (result && result.value) {
window.open(result.value);
} else {
ElMessage.error("当前没有文件,请先上传文件");
}
};
// 导入之前
const uploadFileBefore = () => {
if (proTable.value.tableData.length) {
ElMessage.error("导入之后无法更改,如有变更需调整请联系建设单位");
return false;
}
};
// 导入文件
const uploadFileSuccess = (response: any) => {
console.log(response);
proTable.value.getTableList();
};
const openDialog = () => {
historyListDialog.value = true;
};
// 项目或者工程名字
const searchName = ref<string>("");
// dataCallback 是对于返回的表格数据做处理,如果你后台返回的数据不是 list && total && pageNum && pageSize 这些字段,那么你可以在这里进行处理成这些字段
// 或者直接去 hooks/useTable.ts 文件中把字段改为你后端对应的就行
const dataCallback = (data: any) => {
// console.log(data);
return {
list: data.records,
total: Number(data.total),
pageNo: Number(data.current),
pageSize: Number(data.size)
};
};
// 如果你想在请求之前对当前请求参数做一些操作可以自定义如下函数params 为当前所有的请求参数(包括分页),最后返回请求列表接口
// 默认不做操作就直接在 ProTable 组件上绑定 :requestApi="getUserList"
const getTableList = (params: any) => {
let newParams = JSON.parse(JSON.stringify(params));
if (newParams.contractTime) {
newParams.contractTime_begin = newParams.contractTime[0];
newParams.contractTime_end = newParams.contractTime[1];
delete newParams.contractTime;
}
if (active.value === 0) {
newParams.projectSn = searchSn.value;
} else {
newParams.engineeringSn = searchSn.value;
}
if (!(newParams.projectSn || newParams.engineeringSn)) {
return;
}
return engineerInfoPage(newParams);
};
// 页面的项目名称和工程名称的div点击事件
const onSearch = async (params: any) => {
otherParams.value = {};
console.log(params);
if (active.value === 0) {
searchSn.value = params.projectSn;
searchName.value = params.projectName;
otherParams.value.projectSn = params.projectSn;
} else {
searchSn.value = params.engineeringSn;
searchName.value = params.engineeringName;
otherParams.value.engineeringSn = params.engineeringSn;
}
proTable.value.getTableList();
};
// leftMenu页面的搜索按钮
const onSearchInput = async (params: string) => {
console.log(params);
if (active.value === 0) {
const { result } = await payGovermentProList({ projectName: params, ...pages.value });
records.value = result.records;
} else {
const { result } = await payGovermentEngList({ engineeringName: params, ...pages.value });
records.value = result.records;
}
};
// leftMenu页面的分页
const onCurChange = async (params: number) => {
if (active.value === 0) {
const { result } = await payGovermentProList({ ...pages.value, pageNo: params });
records.value = result.records;
} else {
const { result } = await payGovermentEngList({ ...pages.value, pageNo: params });
records.value = result.records;
pages.value.total = +result.total;
}
pages.value.total = +res.result.total;
};
// 获取项目名称分页
const getProPage = async () => {
const { result } = await payGovermentProList(pages.value);
records.value = result.records;
records.value.map(item => {
let showGif = false;
item.showGif = showGif;
});
pages.value.total = Number(result.total);
};
// 获取工程名称分页
const getEngPage = async () => {
const { result } = await payGovermentEngList(pages.value);
records.value = result.records;
records.value.map(item => {
let showGif = false;
item.showGif = showGif;
});
pages.value.total = +result.total;
};
watch(
() => active.value,
async (value: number) => {
pages.value.pageNo = 1;
pages.value.total = 0;
console.log(66666666666666666);
if (value === 0) {
await getProPage();
onSearch(records.value[0]);
} else {
await getEngPage();
onSearch(records.value[0]);
}
},
{
deep: true
}
);
onMounted(async () => {
await getEngPage();
searchSn.value = records.value[0].engineeringSn;
searchName.value = records.value[0].engineeringName;
otherParams.value = {
engineeringSn: records.value[0].engineeringSn
};
onSearch(records.value[0]);
await sendIframeMessage({ obj: { path: route.path } }, 2, undefined);
});
</script>
<style lang="scss" scoped>
@import "./index.scss";
</style>