bom导入 料品导入
This commit is contained in:
parent
25e1359d19
commit
9d50a1aca7
|
|
@ -148,6 +148,8 @@ export default {
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
let details = JSON.parse(JSON.stringify(this.$refs.xGrid.getTableData().fullData));
|
||||
|
||||
|
||||
|
|
@ -157,7 +159,10 @@ export default {
|
|||
for (let i = 0; i < this.options.exportColumns.length; i++) {
|
||||
let item = this.options.exportColumns[i];
|
||||
var v = "";
|
||||
if(item.dataField){
|
||||
if (item.valueGetter) {
|
||||
v = item.valueGetter({ row: row,column:item });
|
||||
}
|
||||
else if (item.dataField) {
|
||||
v = row[item.dataField];
|
||||
if (item.textField && v) {
|
||||
v = v[item.textField]
|
||||
|
|
@ -498,6 +503,10 @@ export default {
|
|||
this.bindSearchData = arg;
|
||||
this.$refs.xGrid.commitProxy('query') // 提交搜索
|
||||
},
|
||||
|
||||
gridReload(){
|
||||
this.$refs.xGrid.commitProxy('query')
|
||||
}
|
||||
},
|
||||
// 监听属性
|
||||
watch: {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
<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>
|
||||
|
||||
<script>
|
||||
|
|
@ -32,6 +32,238 @@ export default {
|
|||
// 动作
|
||||
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() {
|
||||
// 页面数据
|
||||
var pageData = { // 页面数据变量
|
||||
|
|
@ -49,6 +281,21 @@ export default {
|
|||
start_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: {
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@
|
|||
</div>
|
||||
<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>
|
||||
|
|
@ -73,12 +73,13 @@ export default {
|
|||
pageOptions: {},
|
||||
|
||||
modelName: "",
|
||||
|
||||
attributes: [],
|
||||
typeData: [],
|
||||
actions: {
|
||||
treedata: `${BASE_URL.BASE_URL}/MesMaterials/v1/mes/materials/sort/list`,
|
||||
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,
|
||||
detailsData: [
|
||||
|
|
@ -102,6 +103,7 @@ export default {
|
|||
},
|
||||
created() {
|
||||
|
||||
this.attributeDataInit();
|
||||
this.optionsInit();
|
||||
this.$nextTick(() => {
|
||||
|
||||
|
|
@ -116,6 +118,143 @@ export default {
|
|||
// 函数
|
||||
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() {
|
||||
// 页面数据
|
||||
var pageData = { // 页面数据变量
|
||||
|
|
@ -126,6 +265,20 @@ export default {
|
|||
addPageUrl: "/MesMaterials/MesMaterialsAdd",
|
||||
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 接口地址
|
||||
// =============================== 接口地址 自动生成 Start ===============================
|
||||
|
|
@ -239,6 +392,7 @@ export default {
|
|||
title: "料品分类",
|
||||
key: "root"
|
||||
};
|
||||
this.typeData = r.data.MesMaterialsSort;
|
||||
let at = toArrayTree(r.data.MesMaterialsSort, { parentKey: "parent_id" });
|
||||
console.log(at);
|
||||
treedata[childrenFieldName] = at;
|
||||
|
|
@ -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() {
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in New Issue