bom导入 料品导入

This commit is contained in:
xielue 2023-06-07 16:30:40 +08:00
parent 25e1359d19
commit 9d50a1aca7
3 changed files with 445 additions and 87 deletions

View File

@ -148,6 +148,8 @@ export default {
} }
let details = JSON.parse(JSON.stringify(this.$refs.xGrid.getTableData().fullData)); let details = JSON.parse(JSON.stringify(this.$refs.xGrid.getTableData().fullData));
@ -157,12 +159,15 @@ export default {
for (let i = 0; i < this.options.exportColumns.length; i++) { for (let i = 0; i < this.options.exportColumns.length; i++) {
let item = this.options.exportColumns[i]; let item = this.options.exportColumns[i];
var v = ""; var v = "";
if(item.dataField){ if (item.valueGetter) {
v = item.valueGetter({ row: row,column:item });
}
else if (item.dataField) {
v = row[item.dataField]; v = row[item.dataField];
if(item.textField && v){ if (item.textField && v) {
v = v[item.textField] v = v[item.textField]
} }
}else{ } else {
v = row[item.field] || ''; v = row[item.field] || '';
} }
@ -178,7 +183,7 @@ export default {
/* get binary string as output */ /* get binary string as output */
var wbout = XLSX.write(workbook, { bookType: 'xlsx', bookSST: true, type: 'array' }) var wbout = XLSX.write(workbook, { bookType: 'xlsx', bookSST: true, type: 'array' })
try { try {
FileSaver.saveAs(new Blob([wbout], { type: 'application/octet-stream' }), (this.options.exportFileTitle || '导出数据' )+ '.xlsx') FileSaver.saveAs(new Blob([wbout], { type: 'application/octet-stream' }), (this.options.exportFileTitle || '导出数据') + '.xlsx')
} catch (e) { } catch (e) {
if (typeof console !== 'undefined') { if (typeof console !== 'undefined') {
console.log(e, wbout) console.log(e, wbout)
@ -289,7 +294,7 @@ export default {
if (mode == "like") { // if (mode == "like") { //
value = "%" + value + "%"; // % value = "%" + value + "%"; // %
} }
if(typeof(value) == "object" && value.id){ if (typeof (value) == "object" && value.id) {
value = value.id; value = value.id;
} }
rules.push({ // rules.push({ //
@ -498,6 +503,10 @@ export default {
this.bindSearchData = arg; this.bindSearchData = arg;
this.$refs.xGrid.commitProxy('query') // this.$refs.xGrid.commitProxy('query') //
}, },
gridReload(){
this.$refs.xGrid.commitProxy('query')
}
}, },
// //
watch: { watch: {

View File

@ -1,5 +1,5 @@
<template> <template>
<basic-page-list :desc="desc" :options="pageOptions"></basic-page-list> <basic-page-list ref="listPage" :desc="desc" @importData="pageImport" :options="pageOptions"></basic-page-list>
</template> </template>
<script> <script>
@ -32,6 +32,238 @@ export default {
// //
methods: { methods: {
loadMaterials({ materials_names }) {
return this.$mk.post({
url: `${BASE_URL.BASE_URL}/MesMaterials/v1/mes/materials/list`,
data: {
"page": 1,
"limit": 100000,
"end_time": 0,
"start_time": 0,
"order_bys": [
],
"search_rules": [
{ "column": "name", "mode": "in", "value": materials_names.join(",") }
]
},
useBigInt: true
});
},
loadWarehouses({ warehouse_names }) {
return this.$mk.post({
url: `${BASE_URL.BASE_URL}/MesWarehouse/v1/mes/warehouse/list`,
data: {
"page": 1,
"limit": 100000,
"end_time": 0,
"start_time": 0,
"order_bys": [
],
"search_rules": [
{ "column": "warehouse_name", "mode": "in", "value": warehouse_names.join(",") }
]
},
useBigInt: true
});
},
pageImport({ data }) {
let dataRows = [];
var materials_names = [];
var warehouse_names = [];
var materials_list = [];
var warehouse_list = [];
data.forEach(item => {
let dataRow = {};
this.pageOptions.exportColumns.forEach(col => {
if (col.title in item) {
let v = item[col.title];
dataRow[col.field] = v;
}
})
dataRows.push(dataRow);
});
dataRows.forEach(item => {
if (item.parent_material_name) {
let v = item.parent_material_name;
if (!materials_names.filter(a => a == v).length) {
materials_names.push(v);
}
}
if (item.child_material_name) {
let v = item.child_material_name;
if (!materials_names.filter(a => a == v).length) {
materials_names.push(v);
}
}
if (item.parent_warehouse_name) {
let v = item.parent_warehouse_name;
if (!warehouse_names.filter(a => a == v).length) {
warehouse_names.push(v);
}
}
if (item.child_warehouse_name) {
let v = item.child_warehouse_name;
if (!warehouse_names.filter(a => a == v).length) {
warehouse_names.push(v);
}
}
});
console.log(dataRows,materials_names,warehouse_names);
let getMaterialId = ({ name }) => {
if (!name) return 0;
for (let i = 0; i < materials_list.length; i++) {
if (materials_list[i].name == name) {
return materials_list[i].id;
}
}
return 0;
}
let getWarehouseId = ({ name }) => {
if (!name) return 0;
for (let i = 0; i < warehouse_list.length; i++) {
if (warehouse_list[i].warehouse_name == name) {
return warehouse_list[i].id;
}
}
return 0;
}
let getParents = () => {
let rows = [];
dataRows.forEach(item => {
let material_id = getMaterialId({ name: item.parent_material_name });
if (material_id && rows.filter(a => a.material_id == material_id && a.version == item.parent_version).length == 0) {
let warehouse_id = getWarehouseId({ name: item.parent_warehouse_name });
rows.push({
material_id: material_id,
warehouse_id: warehouse_id,
version: (item.parent_version || "").toString(),
is_default: item.is_default == "1" ? 1 : 0
})
}
});
return rows;
}
let getChidlren = ({ parent }) => {
let rows = [];
dataRows.forEach(item => {
let material_id = getMaterialId({ name: item.parent_material_name });
let child_material_id = getMaterialId({ name: item.child_material_name });
if (material_id &&
parent.material_id == material_id &&
parent.version == item.parent_version &&
child_material_id &&
rows.filter(a => a.material_id == child_material_id).length == 0) {
let warehouse_id = getWarehouseId({ name: item.child_warehouse_name });
rows.push({
material_id: child_material_id,
warehouse_id: warehouse_id,
loss_rate: parseFloat(item.loss_rate),
sub_qty: parseFloat(item.sub_qty)
})
}
});
return rows;
}
let getImportData = () => {
let parentData = getParents();
let data = [];
parentData.forEach(item => {
let children = getChidlren({ parent: item });
if (children.length) {
data.push({
parent: item,
child: children
})
}
})
return data;
}
let startImport = () => {
let data = getImportData();
if (!data.length) {
this.$mk.error("无可导入数据");
return;
}
console.log(data)
this.$mk.post({
url: `${BASE_URL.BASE_URL}/MesBom/v1/mes/bom/batchCreateParentAndChild`,
loading: "导入中...",
data: {
"bom": data
},
useBigInt: true
}).then((a) => { //
this.$mk.success(a.data.msg || "导入成功"); //
this.$refs.listPage.gridReload();
}).catch((a) => { //
this.$mk.error(a.data.msg); //
});
}
if(!materials_names.length){
this.$mk.error("没有可导入数据"); //
return;
}
this.loadMaterials({ materials_names }).then((a) => {
materials_list = a.data.MesMaterials;
if(warehouse_names.length){
this.loadWarehouses({ warehouse_names }).then((b) => {
warehouse_list = b.data.MesWarehouse;
startImport();
})
}else{
startImport();
}
})
},
optionsInit() { optionsInit() {
// //
var pageData = { // var pageData = { //
@ -49,6 +281,21 @@ export default {
start_time: 0, // start_time: 0, //
end_time: 0, // end_time: 0, //
exportFileTitle: "物料清单",
enabledExport: false,
enabledImport: true,
enabledImportTemplate: true,
exportColumns: [
{ title: '父件', field: "parent_material_name" },
{ title: '版本号', field: "parent_version" },
{ title: '默认仓库', field: "parent_warehouse_name" },
{ title: '是否默认', field: "parent_is_default" },
{ title: '子件', field: "child_material_name" },
{ title: '预出仓库', field: "child_warehouse_name" },
{ title: '需用数量', field: "sub_qty" },
{ title: '损耗率', field: "loss_rate" },
],
// //
searchFormData: { searchFormData: {

View File

@ -27,7 +27,7 @@
</div> </div>
<div class="right"> <div class="right">
<basic-page-list ref="listPage" :options="pageOptions"></basic-page-list> <basic-page-list ref="listPage" @importData="pageImport" :options="pageOptions"></basic-page-list>
</div> </div>
</div> </div>
@ -73,12 +73,13 @@ export default {
pageOptions: {}, pageOptions: {},
modelName: "", modelName: "",
attributes: [],
typeData: [],
actions: { actions: {
treedata: `${BASE_URL.BASE_URL}/MesMaterials/v1/mes/materials/sort/list`, treedata: `${BASE_URL.BASE_URL}/MesMaterials/v1/mes/materials/sort/list`,
delete: `${BASE_URL.BASE_URL}/MesMaterials/v1/mes/materials/sort/batchDelete`, delete: `${BASE_URL.BASE_URL}/MesMaterials/v1/mes/materials/sort/batchDelete`,
listdata: `${BASE_URL.BASE_URL}/MesEnum/v1/mes/enum/value/list`,
save: `${BASE_URL.BASE_URL}/MesEnum/v1/mes/enum/value/batchHandle`, productAttribute: `${BASE_URL.BASE_URL}/MesProductCustomAttribute/v1/get/productAttribute`
}, },
tipTimes: 0, tipTimes: 0,
detailsData: [ detailsData: [
@ -102,6 +103,7 @@ export default {
}, },
created() { created() {
this.attributeDataInit();
this.optionsInit(); this.optionsInit();
this.$nextTick(() => { this.$nextTick(() => {
@ -116,6 +118,143 @@ export default {
// //
methods: { methods: {
attributeDataInit() {
this.$mk.post({
url: this.actions.productAttribute,
loading: "加载中..."
}).then(a => {
this.attributes = a.data.attribute;
this.attributes.forEach(item => {
this.pageOptions.exportColumns.push(
{
title: item.name, type: "attribute", valueGetter: this.getExportAttributeValue
});
})
}).catch((a) => {
this.$mk.error(a.data.msg);
});
},
getAttribute(name) {
for (let i = 0; this.attributes && i < this.attributes.length; i++) {
if (this.attributes[i].name == name) {
return this.attributes[i];
}
}
return null;
},
getAttributeId(name) {
for (let i = 0; this.attributes && i < this.attributes.length; i++) {
if (this.attributes[i].name == name) {
return this.attributes[i].id;
}
}
return null;
},
getAttributeValue({ row, attribute_id }) {
for (let i = 0; row.custom_attribute_value && i < row.custom_attribute_value.length; i++) {
if (row.custom_attribute_value[i].attribute_id.toString() == attribute_id.toString()) {
return row.custom_attribute_value[i].value;
}
}
return '';
},
getExportAttributeValue({ row, column }) {
console.log(row, column, this.attributes)
let attrid = this.getAttributeId(column.title);
if (!attrid) return '';
return this.getAttributeValue({ row: row, attribute_id: attrid })
},
getTypeId(name) {
for (let i = 0; i < this.typeData.length; i++) {
if (this.typeData[i].name == name) {
return this.typeData[i].id;
}
}
return 0;
},
getOptionValue({ label, options }) {
for (let i = 0; i < options.length; i++) {
if (options[i].label == label) {
return options[i].value;
}
}
return '';
},
pageImport({ data }) {
let rows = [];
console.log(data)
data.forEach(item => {
let row = {
custom_attribute_value: []
};
this.pageOptions.exportColumns.forEach(col => {
if (col.title in item) {
let v = item[col.title];
if (col.options) {
v = this.getOptionValue({ options: col.options, label: v });
} else if (col.field == "sort_id") {
v = this.getTypeId(v);
}
else if (col.type == "attribute") {
let attrid = this.getAttributeId(col.title);
if (!attrid) return;
let attr = this.getAttribute(col.title);
v = v || ""
if (attr.typeName == '7') {
v = (v == "1" || v == "TRUE" || v == "true" || v == "True") ? "true" : "false";
}
if (attr.typeName == "3" || attr.typeName == "4" || attr.typeName == "5") {
//
let date = new Date((v - 1) * 24 * 60 * 60 * 1000 + 1);
v = date.getFullYear() + '-' + (date.getMonth() + 1).toString().padStart(2, '0') + '-' + date.getDate().toString().padStart(2, '0');
}
row.custom_attribute_value.push({
attribute_id: attrid,
"value": v.toString(),
"e_value": v.toString()
})
return;
}
row[col.field] = v;
}
})
if(row.code && row.name){
rows.push(row);
}
});
this.$mk.post({
url: `${BASE_URL.BASE_URL}/MesProcesses/v1/mes/processes/batchCreate`,
loading: "导入中...",
data: {
"list": rows
},
useBigInt: true
}).then((a) => { //
this.$mk.success(a.data.msg || "导入成功"); //
this.$refs.listPage.gridReload();
}).catch((a) => { //
this.$mk.error(a.data.msg); //
});
},
optionsInit() { optionsInit() {
// //
var pageData = { // var pageData = { //
@ -126,6 +265,20 @@ export default {
addPageUrl: "/MesMaterials/MesMaterialsAdd", addPageUrl: "/MesMaterials/MesMaterialsAdd",
editPageUrl: "/MesMaterials/MesMaterialsUpdate/", editPageUrl: "/MesMaterials/MesMaterialsUpdate/",
enabledExport: true,
enabledImport: true,
enabledImportTemplate: true,
exportColumns: [
{ title: '编码', field: "code" },
{ title: '料品', field: "name" },
{ title: '规格型号', field: "spec" },
{ title: '分类', field: "sort_id", dataField: 'mes_materials_sort', textField: "name" },
],
// //
actions: { // Api actions: { // Api
// =============================== Start =============================== // =============================== Start ===============================
@ -189,16 +342,16 @@ export default {
{ field: 'spec', title: '规格型号' , width: 150 }, { field: 'spec', title: '规格型号', width: 150 },
{ field: 'size', title: '尺寸' , width: 150}, { field: 'size', title: '尺寸', width: 150 },
{ field: 'color', title: '颜色' , width: 150}, { field: 'color', title: '颜色', width: 150 },
{ field: 'face', title: '花面' , width: 150 }, { field: 'face', title: '花面', width: 150 },
{ field: 'molding', title: '成型方式' , width: 150 }, { field: 'molding', title: '成型方式', width: 150 },
{ field: 'production_type', title: '布产方式' , width: 150 }, { field: 'production_type', title: '布产方式', width: 150 },
{ field: 'theoretical_load', title: '理论装车量' , width: 150 }, { field: 'theoretical_load', title: '理论装车量', width: 150 },
{ field: 'soil', title: '土质' , width: 150 }, { field: 'soil', title: '土质', width: 150 },
{ field: 'unit', title: '单位' , width: 150 }, { field: 'unit', title: '单位', width: 150 },
{ field: 'create_time', formatter: 'formatDate', width: 160, sortable: true, title: '创建时间', showHeaderOverflow: true }, // { field: 'create_time', formatter: 'formatDate', width: 160, sortable: true, title: '创建时间', showHeaderOverflow: true }, //
{ field: 'update_time', formatter: 'formatDate', width: 160, sortable: true, title: '更新时间', showHeaderOverflow: true }, // { field: 'update_time', formatter: 'formatDate', width: 160, sortable: true, title: '更新时间', showHeaderOverflow: true }, //
@ -239,6 +392,7 @@ export default {
title: "料品分类", title: "料品分类",
key: "root" key: "root"
}; };
this.typeData = r.data.MesMaterialsSort;
let at = toArrayTree(r.data.MesMaterialsSort, { parentKey: "parent_id" }); let at = toArrayTree(r.data.MesMaterialsSort, { parentKey: "parent_id" });
console.log(at); console.log(at);
treedata[childrenFieldName] = at; treedata[childrenFieldName] = at;
@ -395,7 +549,7 @@ export default {
} }
}else{ } else {
this.$refs.listPage.onSearch(null); this.$refs.listPage.onSearch(null);
} }
@ -412,59 +566,7 @@ export default {
} }
} }
}, },
ok() {
let save = () => {
if (!this.selectedKey || this.selectedKey == "root") {
this.$mk.error("请先选择料品分类");
return;
}
let node = this.findTreeNode(this.selectedKey);
let ds = JSON.parse(JSON.stringify(this.detailsData));
var postdata = {
insertList: [],
updateList: [],
deleteList: this.deletedDetailsData
};
ds.forEach(item => {
delete item._X_ROW_KEY;
item.enum_id = node.id;
if (item.id && item.id != "0") {
let source = this.findSourceInfo(item.id);
item.id = source.id;
postdata.updateList.push(item);
} else {
postdata.insertList.push(item);
}
})
this.$mk.post({
url: this.actions.save,
loading: "保存中...",
data: postdata,
useBigInt: true
}).then(a => {
if (a.code == "200") {
this.$mk.success("保存成功");
this.reloadData();
} else {
this.$mk.error(a.message);
}
}).catch((a) => {
this.$mk.error(a.data.msg);
});
};
save();
},
back() { back() {
}, },