把这两个页面使用Composition API重构要求用vue2并完整重构文件中的每一个方法
时间: 2024-11-09 12:20:05 浏览: 8
将 `ProjectMaterialStatistics.vue` 和 `ProjectMaterialDetails.vue` 使用 Composition API 进行重构,并保持 Vue 2 的兼容性,可以借助 `vue-composition-api` 插件。以下是两个页面的重构代码:
### ProjectMaterialStatistics.vue
```vue
<template>
<a-spin :spinning="state.spinning" tip="报表同步中,请稍等">
<a-card :bordered="false">
<!-- 查询区域 -->
<div class="table-page-search-wrapper">
<a-form layout="inline" @keyup.enter.native="searchQuery">
<a-row :gutter="24">
<a-col>
<my-fast-date-picker
:radioList="[{ value: 2, text: '月' }, { value: 3, text: '年' }]"
:radioVal="2"
:currName="'近半年'"
:showRadioGroup="true"
:fastTime="state.fastTime"
@change="handleChange"
>
<template v-slot:text>时间:</template>
</my-fast-date-picker>
</a-col>
<template v-if="state.toggleSearchStatus">
<a-col :xl="6" :lg="7" :md="8" :sm="24">
<a-form-item label="项目编号:">
<a-input placeholder="请输入项目编号" allowClear v-model="state.queryParam.projectCode"></a-input>
</a-form-item>
</a-col>
<a-col :xl="6" :lg="7" :md="8" :sm="24">
<a-form-item label="项目名称">
<a-select
allowClear
show-search
v-model="state.queryParam.projectName_Code"
placeholder="请输入项目名称"
style="width: 100%"
:show-arrow="false"
:filter-option="false"
:not-found-content="null"
@search="projectCodeSearch"
@change="projectCodeChange"
>
<a-select-option v-for="d in state.projectNameList" :key="d.id">{{ d.text }}</a-select-option>
</a-select>
</a-form-item>
</a-col>
<a-col :xl="6" :lg="7" :md="8" :sm="24">
<a-form-item label="物资">
<a-input placeholder="请输入物资编号/名称" allowClear v-model="state.queryParam.keyWord"></a-input>
</a-form-item>
</a-col>
<a-col :xl="6" :lg="7" :md="8" :sm="24">
<a-form-item label="厂商">
<j-search-select-tag
placeholder="请选择厂商"
v-model="state.queryParam.producerId"
dict="biz_product_vendor,abbreviation,id,del_flag = 0 and status = 1"
/>
</a-form-item>
</a-col>
<a-col :xl="6" :lg="7" :md="8" :sm="24">
<a-form-item label="规格型号">
<a-input placeholder="请输入规格型号" allowClear v-model="state.queryParam.specification"></a-input>
</a-form-item>
</a-col>
</template>
<a-col :xl="6" :lg="7" :md="8" :sm="24">
<span style="float: left; overflow: hidden;" class="table-page-search-submitButtons">
<a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
<a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
<a @click="handleToggleSearch" style="margin-left: 8px">
{{ state.toggleSearchStatus ? '收起' : '展开' }}
<a-icon :type="state.toggleSearchStatus ? 'up' : 'down'" />
</a>
</span>
</a-col>
</a-row>
</a-form>
</div>
<!-- 查询区域-END -->
<!-- 操作按钮区域 -->
<div class="table-operator">
<div>
<a-button type="primary" icon="download" @click="handleExportXlsx()">导出</a-button>
</div>
</div>
<!-- table区域-begin -->
<div>
<a-table
ref="table"
size="middle"
:scroll="{ x: true }"
bordered
rowKey="uniqueId"
:columns="state.columns"
:dataSource="state.dataSource"
:pagination="state.ipagination"
:loading="state.loading"
class="j-table-force-nowrap"
@change="handleTableChange"
>
<span slot="receivingFreezeAmount">
领用冻结
<a-tooltip>
<template slot="title">项目领用申请审核通过后,待出库的数量。</template>
<a-icon type="info-circle" />
</a-tooltip>
</span>
<span slot="receivingFreezeAmount_title">
预算余量
<a-tooltip>
<template slot="title">预算余量=预算总数-领用冻结-领用总数+领用归还</template>
<a-icon type="info-circle" />
</a-tooltip>
</span>
<span slot="requisitionAmount_title">
领用总数
<a-tooltip>
<template slot="title">项目盘盈更新领用余料时,会自动产生领用增补单(不受预算限制),可能导致领用总数超过预算总数。</template>
<a-icon type="info-circle" />
</a-tooltip>
</span>
<span slot="budgetTotalAmount" slot-scope="text, record">
<a-tooltip>
<template slot="title">
<div class="tipItem">
<div>预算编号</div>
<div>预算数</div>
</div>
<div v-for="(value, key) in record.budgetDetail" class="tipItem" v-show="key !== '小计'">
<div>{{ key }}</div>
<div>{{ value }}</div>
</div>
<div class="tipItem">
<div>小记</div>
<div>{{ text }}</div>
</div>
</template>
<span style="color: blue">{{ text }}</span>
</a-tooltip>
</span>
<span slot="budgetSurplusAmount" slot-scope="text, record">
<span :style="{ color: record.budgetSurplusAmount <= state.projectBudgetMarginWarning ? 'red' : 'black' }">
{{ text }}
</span>
</span>
<span slot="inventoryAmount" slot-scope="text, record">
<span :style="{ color: record.inventoryAmount <= record.budgetSurplusAmount ? 'red' : 'black' }">
{{ text }}
</span>
</span>
</a-table>
</div>
</a-card>
</a-spin>
</template>
<script>
import Vue from 'vue';
import { reactive, computed, onMounted } from '@vue/composition-api';
import { PRINT_DOM } from '@/store/mutation-types';
import MyFastDatePicker from '@/components/date/MyFastDatePicker';
import '@/assets/less/TableExpand.less';
import { mixinDevice } from '@/utils/mixin';
import { JeecgListMixin } from '@/mixins/JeecgListMixin';
import { getAction, postAction } from '@/api/manage';
const renderMergedCells = (value, row, index, dataSource) => {
const obj = { children: value, attrs: {} };
if (index === 0 || row.projectName !== dataSource[index - 1].projectName) {
let rowSpan = 1;
for (let i = index + 1; i < dataSource.length; i++) {
if (dataSource[i].projectName === row.projectName) {
rowSpan++;
} else {
break;
}
}
obj.attrs.rowSpan = rowSpan;
} else {
obj.attrs.rowSpan = 0;
}
return obj;
};
export default {
name: 'ProjectMaterialStatistics',
mixins: [JeecgListMixin, mixinDevice],
components: { MyFastDatePicker },
setup() {
const state = reactive({
projectNameList: [],
projectName_Code: '',
projectBudgetMarginWarning: 0,
expandedRowKeys: [],
workorderProjectList: [],
description: '营业报表管理页面',
fastTime: ['本月', '上月', '近半年'],
noCreate: true,
hasUpdateTime: true,
configOrderSubTypeList: [],
configOrderSubTypeTemp: undefined,
allDepartList: [],
hallCodeDataList: [],
spinning: false,
checkFlag: true,
updateTime: '',
url: {
list: '/web/projectUseMaterial/list',
exportXlsxUrl: '/web/projectUseMaterial/export',
exportPdfUrl: '/web/bizBusinessRecord/exportpdf',
exportDetailUrl: '/web/bizBusinessRecord/exportDetailExcel',
},
keyList: ['saleNum', 'saleName', 'terminalTypeName', 'userTypeName', 'configOrderMainTypeName', 'configOrderSubTypeName'],
ipagination: {
current: 1,
pageSize: 20,
pageSizeOptions: ['20', '50', '80'],
showTotal: (total, range) => `${range[0]}-${range[1]} 共${total}条`,
showQuickJumper: true,
showSizeChanger: true,
total: 0,
},
columns: [
{ title: '项目编号', align: 'center', dataIndex: 'projectCode', customRender: (text, row, index) => renderMergedCells(text, row, index, state.dataSource) },
{ title: '项目名称', align: 'center', dataIndex: 'projectName', customRender: (text, row, index) => renderMergedCells(text, row, index, state.dataSource) },
{ title: '物资编号', align: 'center', dataIndex: 'materialCode' },
{ title: '物资名称', align: 'center', dataIndex: 'materialName' },
{ title: '厂商', align: 'center', dataIndex: 'producerId_dictText' },
{ title: '规格型号', align: 'center', dataIndex: 'specification' },
{ title: '单位', align: 'center', dataIndex: 'unit' },
{ title: '预算总数', align: 'center', dataIndex: 'budgetTotalAmount', scopedSlots: { customRender: 'budgetTotalAmount' } },
{ align: 'center', slots: { title: 'receivingFreezeAmount' }, dataIndex: 'receivingFreezeAmount' },
{ align: 'center', slots: { title: 'requisitionAmount_title' }, dataIndex: 'receivingTotalAmount' },
{ title: '领用余料', align: 'center', dataIndex: 'receivingSurplusAmount' },
{ title: '领料使用', align: 'center', dataIndex: 'receivingUseAmount' },
{ align: 'center', dataIndex: 'budgetSurplusAmount', slots: { title: 'receivingFreezeAmount_title' }, scopedSlots: { customRender: 'budgetSurplusAmount' } },
{ title: '库存可用数', align: 'center', dataIndex: 'inventoryAmount', scopedSlots: { customRender: 'inventoryAmount' } },
],
queryParam: {
projectCode: '',
keyWord: '',
producerId: '',
specification: '',
projectName_Code: '',
projectName: '',
},
toggleSearchStatus: false,
});
const handleChange = (val1, val2, val3) => {
state.exportParams.dateTpye = val3 === 2 ? 1 : 2;
state.queryParam.beginDate = val1;
state.queryParam.endDate = val2;
state.queryParam.hiddenZeroTotalAmountFlag = state.checkFlag ? 1 : 0;
};
const projectCodeSearch = (value) => {
getAction('/web/projectRecord/searchMainProject', { order: 'desc', pageNo: 1, pageSize: 100, keyword: value }).then((res) => {
const data = [];
res.result.forEach((item) => {
data.push({ id: item.id, value: item.projectCode, text: item.projectName });
});
state.projectNameList = data;
});
};
const projectCodeChange = (value) => {
state.queryParam.projectName_Code = value;
const obj = state.projectNameList.filter((item) => item.id === value);
if (obj.length > 0) {
state.exportParams.projectName = obj[0].text;
state.queryParam.projectName = obj[0].text;
} else {
state.exportParams.projectName = '';
state.queryParam.projectName = '';
}
};
const searchQuery = () => {
let val = state.configOrderSubTypeTemp;
if (val) {
if (state.queryParam.configOrderMainType == 1) {
if (val.key.length == 2) {
state.queryParam.configOrderSubType = val.key.substr(0, 1);
} else {
state.queryParam.configOrderSubType = val.key.substr(0, 2);
}
} else {
state.queryParam.configOrderSubType = val.key;
}
}
loadData(1);
};
const searchReset = () => {
state.queryParam.projectCode = '';
state.queryParam.keyWord = '';
state.queryParam.producerId = '';
state.queryParam.specification = '';
state.queryParam.projectName_Code = '';
state.queryParam.projectName = '';
loadData(1);
};
const handleToggleSearch = () => {
state.toggleSearchStatus = !state.toggleSearchStatus;
};
const handleExportXlsx = () => {
// 实现导出功能
};
const handleTableChange = (pagination, filters,
阅读全文