fix:表格导出完善(枚举情况)

This commit is contained in:
shijing 2025-12-16 08:35:13 +08:00
parent 0d4145551f
commit 0a707478f7
3 changed files with 189 additions and 151 deletions

View File

@ -333,14 +333,21 @@ export default {
dataToExcel(this.hExportCols, this.tableData, this.hExportName?this.hExportName:'表格数据')
}else if (type === 2) {
const extractHeaderKeys = (columns) =>{
const keys = columns.map(item => {
// key
return item.key.split('.')[0];
});
//
return [...new Set(keys)].join(',');
}
const keys = [];
columns.map(item => {
if(item.is_notquery){
let key = item.key.split('.')[0];
if(key.indexOf('mio')>-1){
keys.push('mio');
}
}else{
let key = item.key.split('.')[0];// key
keys.push(key);
}
});
//
return [...new Set(keys)].join(',');
}
var c = Object.assign({}, this.query, this.tableParams, {[this.orderStr]: this.order}, {page: 0},
{query: "{" + extractHeaderKeys(this.hExportCols) + "}"}
)

View File

@ -22,7 +22,7 @@ export const dataToExcel = (columns = [], data = [], name = 'data') => {
const dataList = data.map((item) => {
let obj = {};
columns.forEach(col => {
obj[col.header] = getNestedValue(item, col.key) ?? '';
obj[col.header] = getNestedValue(item, col.key, col.type_dict) ?? '';
});
return obj;
});
@ -54,19 +54,30 @@ export const dataToExcel = (columns = [], data = [], name = 'data') => {
// URL.revokeObjectURL(blobUrl);
};
const getNestedValue = (obj, path, defaultValue = '') => {
const getNestedValue = (obj, path,type_dict, defaultValue = '') => {
if (!obj || !path) return defaultValue;
const keys = path.split('.');
let result = obj;
for (const key of keys) {
if (result === null || result === undefined) {
return defaultValue;
if(type_dict!==undefined){
let dict_key = "";
if(path.indexOf(".")>-1){
let key0 = path.split(".")[0];
let key1 = path.split(".")[1];
let obj1 = result[key0];
let key2 = obj1[key1];
dict_key = key2;
}else{
dict_key = result[path];
}
result = result[key];
result = type_dict[dict_key]
}else{
for (const key of keys) {
if (result === null || result === undefined) {
return defaultValue;
}
result = result[key];
}
}
return result !== undefined ? result : defaultValue;
};
const calculateColumnWidths = (columns, dataList) => {

View File

@ -3,7 +3,7 @@
<el-header>
<div class="right-panel">
<el-date-picker
v-model="query.mio__inout_date__gte"
v-model="params.mio__inout_date__gte"
type="date"
placeholder="开始日期"
format="YYYY-MM-DD"
@ -11,7 +11,7 @@
style="width: 150px;"
/>
<el-date-picker
v-model="query.mio__inout_date__lte"
v-model="params.mio__inout_date__lte"
type="date"
format="YYYY-MM-DD"
value-format="YYYY-MM-DD"
@ -20,7 +20,7 @@
/>
<xtSelect
:apiObj="apiObjm"
v-model="query.material"
v-model="params.material"
v-model:obj="selectObj"
:labelField="'full_name'"
style="width: 150px;"
@ -30,7 +30,7 @@
<el-table-column label="物料" prop="full_name"></el-table-column>
</xtSelect>
<el-input
v-model="query.search"
v-model="params.search"
placeholder="名称"
clearable
style="width: 150px;"
@ -43,15 +43,18 @@
</div>
</el-header>
<el-main style="padding: 0;">
<el-table
<scTable
ref="table"
:data="tableData"
:apiObj="apiObj"
row-key="id"
stripe
border
style="height: 100%;"
:params="params"
:summary-method="getSummaries"
show-summary
:hExportCols = "hExportCols"
:hExportName="'辅料出入库记录'"
style="height: 100%;"
>
<el-table-column type="index" width="50" />
<el-table-column label="类型" width="80">
@ -155,21 +158,8 @@
>撤消</el-button>
</template>
</el-table-column>
</el-table>
</scTable>
</el-main>
<el-footer>
<el-pagination
background
:small="true"
:total="dataTotal"
layout="total, sizes, prev, pager, next, jumper"
:page-size="params.page_size"
:page-sizes="[20, 50, 100, 200]"
:current-page="params.page"
@current-change="getList"
@update:page-size="getList2"
></el-pagination>
</el-footer>
</el-container>
</template>
<script>
@ -177,13 +167,14 @@ export default {
name: "mioitemlist",
data() {
return {
apiObj: null,
params: {
page:1,
page_size:20,
with_mio:'yes',
material__type:40,
mio__state:20
mio__state:20,
mio__inout_date__gte:'',
mio__inout_date__lte:'',
material:'',
search:'',
},
mquery:{
page: 0,
@ -192,7 +183,6 @@ export default {
is_assemb: false,
},
selection: [],
tableData:[],
nameFilters1: [],
nameFilters2: [],
nameFilters3: [],
@ -202,12 +192,6 @@ export default {
nameFilters7: [],
nameFilters8: [],
nameFilters9: [],
query: {
search : "",
material : "",
mio__inout_date__gte : "",
mio__inout_date__lte : "",
},
stateDict: {
10: "创建中",
20: "已提交",
@ -221,110 +205,150 @@ export default {
other_out: "其他出库",
},
selectObj: {},
project_code:'',
dataTotal:0,
apiObj:this.$API.inm.mioitem.list,
apiObjm:this.$API.mtm.material.list,
hExportCols:[{
header: "类型",
key: "mio_.type",
type_dict:{
do_out: "生产领料",
sale_out: "销售发货",
pur_in: "采购入库",
do_in: "生产入库",
other_in: "其他入库",
other_out: "其他出库",
},
is_notquery: true
}, {
header: "日期",
key: "inout_date"
}, {
header: "物料编号",
key: "material_.number"
}, {
header: "名称",
key: "material_.name"
}, {
header: "货位号",
key: "material_.bin_number_main"
}, {
header: "规格",
key: "material_.specification"
}, {
header: "品牌型号",
key: "material_.model"
}, {
header: "单位",
key: "material_.unit"
}, {
header: "入库数量",
key: "count"
}, {
header: "单价",
key: "unit_price"
}, {
header: "总金额",
key: "price",
is_notquery: true,
}, {
header: "入库人",
key: "mio_.submit_user_name",
is_notquery: true,
}, {
header: "入库凭证号",
key: "mio_.number",
is_notquery: true,
}, {
header: "供应商",
key: "supplier_name",
is_notquery: true,
}
]
};
},
mounted() {
this.checkTemplate = this.checkTemplate+"?t=" + new Date().getTime();
this.project_code = this.$TOOL.data.get("BASE_INFO").base.base_code;
this.params.mio = this.mioId;
let that = this;
that.getList();
this.$nextTick(() => {
this.getFilters();
});
},
methods: {
getList(val){
getFilters(){
let that = this;
that.params.page = val?val:1;
that.params.with_mio = 'yes';
that.params.search = that.query.search;
that.params.mio__inout_date__gte = that.query.mio__inout_date__gte;
that.params.mio__inout_date__lte = that.query.mio__inout_date__lte;
if(that.query.material!==''||that.query.material!==undefined||that.query.material!==null){
that.params.material = that.query.material;
let datas = [];
datas = that.$refs.table.tableData;
console.log( datas);
if(datas.length&&datas.length>0){
let numberList=[],nameList = [],batchlist=[],specificationList=[],modelList=[],unitList=[],userList=[],mioNumberList=[],typeList=[];
datas.forEach((ite) => {
if (numberList.indexOf(ite.material_.number) > -1) {} else {
numberList.push(ite.material_.number);
let obj = {};
obj.text = ite.material_.number;
obj.value = ite.material_.number;
that.nameFilters1.push(obj);
}
if (nameList.indexOf(ite.material_.name) > -1) {} else {
nameList.push(ite.material_.name);
let obj = {};
obj.text = ite.material_.name;
obj.value = ite.material_.name;
that.nameFilters2.push(obj);
}
if (batchlist.indexOf(ite.material_.bin_number_main) > -1) {} else {
batchlist.push(ite.material_.bin_number_main);
let obj = {};
obj.text = ite.material_.bin_number_main;
obj.value = ite.material_.bin_number_main;
that.nameFilters3.push(obj);
}
if (specificationList.indexOf(ite.material_.specification) > -1) {} else {
specificationList.push(ite.material_.specification);
let obj = {};
obj.text = ite.material_.specification;
obj.value = ite.material_.specification;
that.nameFilters4.push(obj);
}
if (modelList.indexOf(ite.material_.model) > -1) {} else {
modelList.push(ite.material_.model);
let obj = {};
obj.text = ite.material_.model;
obj.value = ite.material_.model;
that.nameFilters5.push(obj);
}
if (unitList.indexOf(ite.material_.unit) > -1) {} else {
unitList.push(ite.material_.unit);
let obj = {};
obj.text = ite.material_.unit;
obj.value = ite.material_.unit;
that.nameFilters6.push(obj);
}
if (userList.indexOf(ite.mio_.submit_user_name) > -1) {} else {
userList.push(ite.mio_.submit_user_name);
let obj = {};
obj.text = ite.mio_.submit_user_name;
obj.value = ite.mio_.submit_user_name;
that.nameFilters7.push(obj);
}
if (mioNumberList.indexOf(ite.mio_.number) > -1) {} else {
mioNumberList.push(ite.mio_.number);
let obj = {};
obj.text = ite.mio_.number;
obj.value = ite.mio_.number;
that.nameFilters8.push(obj);
}
if (typeList.indexOf(ite.mio_.type) > -1) {} else {
typeList.push(ite.mio_.type);
let obj = {};
obj.text = that.typeDict[ite.mio_.type];
obj.value = that.typeDict[ite.mio_.type];
that.nameFilters9.push(obj);
}
})
}else{
setTimeout(function(){
that.getFilters();
},500);
}
that.$API.inm.mioitem.list.req(that.params).then((res) => {
if (res.count > 0) {
that.tableData = res.results;
that.dataTotal = res.count;
let numberList=[],nameList = [],batchlist=[],specificationList=[],modelList=[],unitList=[],userList=[],mioNumberList=[],typeList=[];
res.results.forEach((ite) => {
if (numberList.indexOf(ite.material_.number) > -1) {} else {
numberList.push(ite.material_.number);
let obj = {};
obj.text = ite.material_.number;
obj.value = ite.material_.number;
that.nameFilters1.push(obj);
}
if (nameList.indexOf(ite.material_.name) > -1) {} else {
nameList.push(ite.material_.name);
let obj = {};
obj.text = ite.material_.name;
obj.value = ite.material_.name;
that.nameFilters2.push(obj);
}
if (batchlist.indexOf(ite.material_.bin_number_main) > -1) {} else {
batchlist.push(ite.material_.bin_number_main);
let obj = {};
obj.text = ite.material_.bin_number_main;
obj.value = ite.material_.bin_number_main;
that.nameFilters3.push(obj);
}
if (specificationList.indexOf(ite.material_.specification) > -1) {} else {
specificationList.push(ite.material_.specification);
let obj = {};
obj.text = ite.material_.specification;
obj.value = ite.material_.specification;
that.nameFilters4.push(obj);
}
if (modelList.indexOf(ite.material_.model) > -1) {} else {
modelList.push(ite.material_.model);
let obj = {};
obj.text = ite.material_.model;
obj.value = ite.material_.model;
that.nameFilters5.push(obj);
}
if (unitList.indexOf(ite.material_.unit) > -1) {} else {
unitList.push(ite.material_.unit);
let obj = {};
obj.text = ite.material_.unit;
obj.value = ite.material_.unit;
that.nameFilters6.push(obj);
}
if (userList.indexOf(ite.mio_.submit_user_name) > -1) {} else {
userList.push(ite.mio_.submit_user_name);
let obj = {};
obj.text = ite.mio_.submit_user_name;
obj.value = ite.mio_.submit_user_name;
that.nameFilters7.push(obj);
}
if (mioNumberList.indexOf(ite.mio_.number) > -1) {} else {
mioNumberList.push(ite.mio_.number);
let obj = {};
obj.text = ite.mio_.number;
obj.value = ite.mio_.number;
that.nameFilters8.push(obj);
}
if (typeList.indexOf(ite.mio_.type) > -1) {} else {
typeList.push(ite.mio_.type);
let obj = {};
obj.text = that.typeDict[ite.mio_.type];
obj.value = that.typeDict[ite.mio_.type];
that.nameFilters9.push(obj);
}
})
}else{
that.tableData = [];
that.dataTotal = 0;
}
});
},
getList2(val){
let that = this;
that.params.page = 1;
that.params.page_size = val;
that.getList(1);
},
handleCheckSuccess() {
this.$refs.table.refresh();
@ -332,15 +356,11 @@ export default {
},
handleQuery() {
let that = this;
that.params.page = 1;
that.getList(1);
},
resetQuery() {
this.query = {};
that.$refs.table.queryData(that.params);
},
selectMaterialChange() {
var that = this;
that.query.material = that.selectObj.id;
that.params.material = that.selectObj.id;
},
//
printMaterial(row,type){