Commit 590fddf4 authored by 仇晓婷's avatar 仇晓婷

Merge branch 'product' of http://git.mes123.com/zhouyx/mes-ui into product

parents 596e79e2 146db3e9
<template> <template>
<div class="table-content"> <div class="table-content">
<div class="table-tools" v-if="tool"> <div class="table-tools" v-if="tool">
<div class="table-search"> <div class="table-search">
<slot name="easySearch" v-if="easy"> <slot name="easySearch" v-if="easy">
<Form inline> <Form inline>
<FormItem> <FormItem>
<Input <Input search enter-button :placeholder="placeholder" @on-search="easySearch" v-width="300" v-model="keys" />
search </FormItem>
enter-button <FormItem>
:placeholder="placeholder" <Button v-if="high" @click="modalSearch=true" type="text">
@on-search="easySearch" <Icon type="md-search" />高级
v-width="300" </Button>
v-model="keys" </FormItem>
/> </Form>
</FormItem> </slot>
<FormItem> </div>
<Button v-if="high" @click="modalSearch=true" type="text">
<Icon type="md-search" />高级
</Button>
</FormItem>
</Form>
</slot>
</div>
<div class="searchBack"> <div class="searchBack">
<slot name="searchBack"></slot> <slot name="searchBack"></slot>
</div> </div>
<div class="btns"> <div class="btns">
<slot name="buttons"></slot> <slot name="buttons"></slot>
<Button @click="export2Excel" v-if="exportTitle.length>0">导出</Button> <Button @click="export2Excel" v-if="exportTitle.length>0">导出</Button>
<Button v-if="set&&type=='table'" @click="config=!config"> <Button v-if="set&&type=='table'" @click="config=!config">
<Icon type="md-build" title="列设置" /> <Icon type="md-build" title="列设置" />
</Button> </Button>
</div> </div>
</div> </div>
<div class="table-main" ref="main"> <div class="table-main" ref="main">
<Row v-if="type=='card'" :gutter="40"> <Row v-if="type=='card'" :gutter="40">
<Col :span="span" v-for="(row,i) in list" :key="i"> <Col :span="span" v-for="(row,i) in list" :key="i">
<slot name="card" :row="row"> <slot name="card" :row="row">
<span>{{row.id}}</span> <span>{{row.id}}</span>
</slot> </slot>
</Col> </Col>
</Row> </Row>
<Table <Table v-else :border="border" :columns="columnsNow" :data="list" :height="tableHeight" :draggable="draggable" ref="table" class="tableCommon" @on-expand="expand" @on-drag-drop="onDragDrop" @on-selection-change="selectionChange" @on-select="onSelect" @on-select-all="allChange" :row-key="rowKey" stripe></Table>
v-else
:border="border"
:columns="columnsNow"
:data="list"
:height="tableHeight"
:draggable="draggable"
ref="table"
class="tableCommon"
@on-expand="expand"
@on-drag-drop="onDragDrop"
@on-selection-change="selectionChange"
@on-select="onSelect"
@on-select-all="allChange"
:row-key="rowKey"
stripe
></Table>
</div> </div>
<div class="table-footer"> <div class="table-footer">
<slot name="footer"></slot> <slot name="footer"></slot>
<Page <Page v-if="page" :total="search.total" :current="search.page" class="fr" show-total size="small" show-elevator show-sizer :page-size="search.pageSize" :page-size-opts="pageSizeOpts" @on-change="pageChange" @on-page-size-change="pageSizeChange" />
v-if="page"
:total="search.total"
:current="search.page"
class="fr"
show-total
size="small"
show-elevator
show-sizer
:page-size="search.pageSize"
:page-size-opts="pageSizeOpts"
@on-change="pageChange"
@on-page-size-change="pageSizeChange"
/>
</div> </div>
<Modal v-if="high" v-model="modalSearch" title="高级搜索" draggable width="800" ref="search"> <Modal v-if="high" v-model="modalSearch" title="高级搜索" draggable width="800" ref="search">
<slot name="searchForm"></slot> <slot name="searchForm"></slot>
<div slot="footer"> <div slot="footer">
<Button @click="modalSearch=false" style="margin-left:20px;">取消</Button> <Button @click="modalSearch=false" style="margin-left:20px;">取消</Button>
<Button @click="complexSearch" type="primary" style="margin-left:10px;">查询</Button> <Button @click="complexSearch" type="primary" style="margin-left:10px;">查询</Button>
</div> </div>
</Modal> </Modal>
<Drawer <Drawer title="列设置" v-if="set" v-model="config" :scrollable="true" placement="left" :mask="false">
title="列设置" <div slot="header">
v-if="set" 列设置
v-model="config" <a @click="undoConfig" class="ml50">
:scrollable="true" <Icon type="md-refresh" title="恢复初始设置" />
placement="left" </a>
:mask="false" </div>
> <ul class="table-columns">
<div slot="header"> <li v-for="(li,index) in columnsCur" :key="index" v-dragging="{ item: li, list: columnsCur, group: 'li' }">
列设置 <label @click="columnChange(li,index)" :class="{dis:li.hide}">
<a @click="undoConfig" class="ml50"> <Icon :type="li.hide?'md-eye-off':'md-eye'" size="16" class="mr10" />
<Icon type="md-refresh" title="恢复初始设置" /> <span>{{li.title}}</span>
</a> </label>
</div> <Icon type="ios-move" class="move" size="18" />
<ul class="table-columns"> </li>
<li </ul>
v-for="(li,index) in columnsCur"
:key="index"
v-dragging="{ item: li, list: columnsCur, group: 'li' }"
>
<label @click="columnChange(li,index)" :class="{dis:li.hide}">
<Icon :type="li.hide?'md-eye-off':'md-eye'" size="16" class="mr10" />
<span>{{li.title}}</span>
</label>
<Icon type="ios-move" class="move" size="18" />
</li>
</ul>
</Drawer> </Drawer>
<FooterToolbar v-if="batch" v-show="footerToolbar" class="ftball"> <FooterToolbar v-if="batch" v-show="footerToolbar" class="ftball">
<div class="tip">已选{{selectItems.length}}</div> <div class="tip">已选{{selectItems.length}}</div>
<slot name="batch"></slot> <slot name="batch"></slot>
<Button @click="cancelBatch">取消</Button> <Button @click="cancelBatch">取消</Button>
</FooterToolbar> </FooterToolbar>
</div> </div>
</template> </template>
<script> <script>
export default { export default {
name: "DataGrid", name: "DataGrid",
data() { data() {
return {
keys: "",
selectItems: [],
footerToolbar: false,
modalSearch: false,
search: {
pageIndex: 1,
pageSize: 20,
conditions: [],
},
searchConditions: this.search,
pageSizeOpts: [20, 50, 100],
tableHeight: 0,
firstY: 0,
config: false,
list: [],
columnsCur: [],
configLoad: false,
userConfig: null, //用户页面配置信息。,
// userId: 1
userId: this.$store.state.userInfo.userId,
treeData: [], //物料数据
codeRuleData: [], //物料编码
routingHeaderData: [], //工艺规程
};
},
props: {
border: {
//是否显示边框
type: Boolean,
default: true,
},
batch: {
//是否批量操作
type: Boolean,
default: true,
},
format: {
type: Function,
default: null,
},
initsearch: {
type: Function,
default: null,
},
lazy: {
//懒加载设置,设置为真时候,默认不加载数据。
type: Boolean,
default: false,
},
placeholder: {
type: String,
default: "请输入关键字",
},
height: {
type: Number,
default: 0,
},
tool: {
//是否显示工具栏
type: Boolean,
default: true,
},
easy: {
//是否显示简单搜索
type: Boolean,
default: true,
},
high: {
//是否显示高级搜索
type: Boolean,
default: true,
},
draggable: {
//是否可以拖拽
type: Boolean,
default: false,
},
set: {
//是否显示列设置
type: Boolean,
default: true,
},
page: {
//是否分页
type: Boolean,
default: true,
},
data: {
// 当作table使用,直接显示数据
type: Array,
default: function () {
return [];
},
},
columns: {
//要显示的字段
type: Array,
default: [],
},
action: {
//接口地址
type: String,
default: "",
},
conditions: {
//查询条件
type: Object,
default: function () {
return { return {
keys: { keys: "",
op: "name", selectItems: [],
value: "", footerToolbar: false,
default: true, modalSearch: false,
}, search: {
pageIndex: 1,
pageSize: 20,
conditions: [],
},
searchConditions: this.search,
pageSizeOpts: [20, 50, 100],
tableHeight: 0,
firstY: 0,
config: false,
list: [],
columnsCur: [],
configLoad: false,
userConfig: null, //用户页面配置信息。,
// userId: 1
userId: this.$store.state.userInfo.userId,
treeData: [], //物料数据
codeRuleData: [], //物料编码
routingHeaderData: [], //工艺规程
allUser: [] //所有user
}; };
},
},
type: {
type: String,
default: "table",
validator: function (value) {
// 这个值必须匹配下列字符串中的一个
return ["table", "card", "list"].indexOf(value) !== -1;
},
}, },
span: { props: {
//栅格数 border: {
type: Number, //是否显示边框
default: 24, type: Boolean,
}, default: true,
//table控件children子数据控制功能 },
rowKey: { batch: {
type: [String, Number], //是否批量操作
}, type: Boolean,
gutter: { default: true,
//间距 },
type: Number, format: {
default: 40, type: Function,
}, default: null,
exportTitle: { },
type: String, initsearch: {
default: "", type: Function,
}, default: null,
}, },
created() { lazy: {
this.columns.forEach((u) => { //懒加载设置,设置为真时候,默认不加载数据。
if (!u.hide) { type: Boolean,
u.hide = false; default: false,
} },
}); placeholder: {
this.columnsCur = this.$u.clone(this.columns); type: String,
}, default: "请输入关键字",
mounted() { },
if (this.data && this.data.length > 0) { height: {
this.list = this.data; type: Number,
return; default: 0,
} },
this.keys = ""; tool: {
this.intY(); //是否显示工具栏
if (this.lazy == true) { type: Boolean,
return; default: true,
} },
if (this.userId > 0 && this.set) { easy: {
this.loadUserConfig(); //是否显示简单搜索
} else { type: Boolean,
this.easySearch(); default: true,
} },
if (this.height === 0) { high: {
this.$nextTick(() => { //是否显示高级搜索
this.tableHeight = this.$refs.main.offsetHeight; type: Boolean,
if (this.tableHeight < 300) { default: true,
this.tableHeight = },
window.screen.availHeight - this.$refs.main.offsetTop - 200; draggable: {
} //是否可以拖拽
window.onresize = () => { type: Boolean,
///浏览器窗口大小变化 default: false,
return (() => { },
if (this.$refs.main && this.$refs.main.offsetHeight) { set: {
this.tableHeight = this.$refs.main.offsetHeight; //是否显示列设置
if (this.tableHeight < 300) { type: Boolean,
this.tableHeight = default: true,
window.screen.availHeight - this.$refs.main.offsetTop - 150; },
} page: {
//是否分页
type: Boolean,
default: true,
},
data: {
// 当作table使用,直接显示数据
type: Array,
default: function () {
return [];
},
},
columns: {
//要显示的字段
type: Array,
default: [],
},
action: {
//接口地址
type: String,
default: "",
},
conditions: {
//查询条件
type: Object,
default: function () {
return {
keys: {
op: "name",
value: "",
default: true,
},
};
},
},
type: {
type: String,
default: "table",
validator: function (value) {
// 这个值必须匹配下列字符串中的一个
return ["table", "card", "list"].indexOf(value) !== -1;
},
},
span: {
//栅格数
type: Number,
default: 24,
},
//table控件children子数据控制功能
rowKey: {
type: [String, Number],
},
gutter: {
//间距
type: Number,
default: 40,
},
exportTitle: {
type: String,
default: "",
},
},
created() {
this.columns.forEach((u) => {
if (!u.hide) {
u.hide = false;
} }
})();
};
});
} else {
this.tableHeight = this.height;
}
//注册拖拽事件。
this.$dragging.$on("dragend", (e) => {
this.saveUserconfig();
});
//物料加载类型数据
this.getTreeData();
this.getcodeRuleData();
this.getRoutingHeaderData();
},
methods: {
//数据加载
load() {
if (this.action) {
//条件初始化处理。
if (this.initsearch) {
this.initsearch(this.search);
}
this.$api.post(this.action, this.search).then((r) => {
if (this.format) {
this.list = this.format(r.result.items);
} else {
this.list = r.result.items;
}
this.search.total = r.result.totalCount || r.result.count;
}); });
} this.columnsCur = this.$u.clone(this.columns);
}, },
columnInit() { mounted() {
if (this.userConfig) { if (this.data && this.data.length > 0) {
var curColumns = []; this.list = this.data;
var config = JSON.parse(this.userConfig.content); return;
if (config.length == this.columnsCur.length) {
config.map((u) => {
var item = this.columnsCur.filter((c) => {
return c.key == u.key;
});
if (item[0]) {
item[0].hide = u.hide;
curColumns.push(item[0]);
}
});
this.columnsCur = curColumns;
} }
} this.keys = "";
}, this.intY();
loadUserConfig() { if (this.lazy == true) {
var query = { return;
conditions: [ }
{ if (this.userId > 0 && this.set) {
fieldName: "creatorUserId", this.loadUserConfig();
fieldValue: this.userId, } else {
conditionalType: "Equal",
},
{
fieldName: "component",
fieldValue: "Grid",
conditionalType: "Equal",
},
{
fieldName: "page",
fieldValue: window.location.pathname,
conditionalType: "Equal",
},
],
pageSize: 1,
};
this.$api.post(`${window.systemUrl}/config/list`, query).then((r) => {
if (r.success) {
if (r.result.length == 1) {
this.userConfig = r.result[0];
this.columnInit();
}
if (!this.configLoad) {
this.easySearch(); this.easySearch();
}
this.configLoad = true;
} }
}); if (this.height === 0) {
}, this.$nextTick(() => {
saveUserconfig() { this.tableHeight = this.$refs.main.offsetHeight;
let url = `${window.systemUrl}/config/update`; if (this.tableHeight < 300) {
var content = []; this.tableHeight =
this.columnsCur.map((u) => { window.screen.availHeight - this.$refs.main.offsetTop - 200;
content.push({ }
key: u.key, window.onresize = () => {
hide: u.hide, ///浏览器窗口大小变化
}); return (() => {
}); if (this.$refs.main && this.$refs.main.offsetHeight) {
if (!this.userConfig) { this.tableHeight = this.$refs.main.offsetHeight;
url = `${window.systemUrl}/config/create`; if (this.tableHeight < 300) {
var data = { this.tableHeight =
page: window.location.pathname, window.screen.availHeight - this.$refs.main.offsetTop - 150;
component: "Grid", }
key: this.$u.guid(), }
content: JSON.stringify(content), })();
}; };
this.$api.post(url, data).then((r) => { });
this.loadUserConfig(); } else {
this.tableHeight = this.height;
}
//注册拖拽事件。
this.$dragging.$on("dragend", (e) => {
this.saveUserconfig();
}); });
} else { //物料加载类型数据
this.userConfig.content = JSON.stringify(content); this.getTreeData();
this.$api.post(url, this.userConfig); this.getcodeRuleData();
} this.getRoutingHeaderData();
}, this.getAllUser(); //获取所有用户
//展开 },
expand(row, status) { methods: {
this.$emit("on-expand", row, status); //数据加载
}, load() {
//拖拽 if (this.action) {
onDragDrop(a, b) { //条件初始化处理。
this.$emit("on-drag-drop", a, b); if (this.initsearch) {
}, this.initsearch(this.search);
easySearch() {
if (
this.conditions &&
this.conditions.keys &&
this.conditions.keys.default
) {
//判断没有传入条件的用默认的查询
this.conditions.keys.value = this.keys;
}
this.reload(this.conditions);
},
undoConfig() {
//列设置恢复初始化
this.columnsCur = this.$u.clone(this.columns);
this.saveUserconfig();
},
complexSearch() {
var search = this.$refs.search.$children.filter((u) => {
return u.condition;
});
if (search) {
var conditions = search[0].condition;
this.reload(conditions);
}
},
reload(conditions) {
var where = [];
this.searchConditions = conditions;
if (conditions) {
Object.keys(conditions).forEach((u) => {
let v = conditions[u].value;
let op = conditions[u].op;
if (!this.$u.isNull(v)) {
if (op == "Range" && Array.isArray(v)) {
let times = [];
v.map((u) => {
if (!this.$u.isNull(u)) {
times.push(this.$u.toTime(u));
} }
}); this.$api.post(this.action, this.search).then((r) => {
v = times.join(","); if (this.format) {
} else if (op.indexOf("In") > -1 && Array.isArray(v)) { this.list = this.format(r.result.items);
v = v.join(","); } else {
this.list = r.result.items;
}
this.search.total = r.result.totalCount || r.result.count;
});
} }
if (!this.$u.isNull(v)) { },
where.push({ columnInit() {
fieldName: u, if (this.userConfig) {
fieldValue: v, var curColumns = [];
conditionalType: op, var config = JSON.parse(this.userConfig.content);
}); if (config.length == this.columnsCur.length) {
config.map((u) => {
var item = this.columnsCur.filter((c) => {
return c.key == u.key;
});
if (item[0]) {
item[0].hide = u.hide;
curColumns.push(item[0]);
}
});
this.columnsCur = curColumns;
}
} }
} },
}); loadUserConfig() {
} var query = {
this.search.pageIndex = 1; conditions: [{
this.search.conditions = where; fieldName: "creatorUserId",
this.load(); fieldValue: this.userId,
}, conditionalType: "Equal",
pageChange(page) { },
this.search.page = page; {
this.search.pageIndex = page; fieldName: "component",
this.load(); fieldValue: "Grid",
}, conditionalType: "Equal",
pageSizeChange(size) { },
this.search.pageSize = size; {
this.search.pageIndex = 1; fieldName: "page",
this.load(); fieldValue: window.location.pathname,
}, conditionalType: "Equal",
columnChange(item, i) { },
item.hide = !item.hide; ],
this.$set(this.columnsCur, item, i); pageSize: 1,
this.saveUserconfig(); };
}, this.$api.post(`${window.systemUrl}/config/list`, query).then((r) => {
selectionChange(items) { if (r.success) {
this.$emit("on-selection-change", items); if (r.result.length == 1) {
this.selectItems = items; this.userConfig = r.result[0];
this.footerToolbar = items.length > 0; this.columnInit();
}, }
onSelect(rows, row) { if (!this.configLoad) {
this.$emit("on-change", rows, row); this.easySearch();
}, }
allChange(items) { this.configLoad = true;
this.$emit("all-change", items);
},
intY() {
if (this.$refs.table != undefined) {
this.firstY = this.$refs.table.$el.getBoundingClientRect().top;
}
},
selectAll(status) {
this.$refs.table.selectAll(status);
},
//批量取消
cancelBatch() {
this.footerToolbar = false;
this.$refs.table.selectAll(false);
},
//导出excel
export2Excel() {
//当前显示数据
var where = [];
var conditions = this.searchConditions;
if (conditions) {
Object.keys(conditions).forEach((u) => {
let v = conditions[u].value;
let op = conditions[u].op;
if (!this.$u.isNull(v)) {
if (op == "Range") {
let times = [];
v.map((u) => {
if (!this.$u.isNull(u)) {
times.push(this.$u.toTime(u));
} }
}); });
v = times.join(","); },
} else if (op.indexOf("In") > -1 && Array.isArray(v)) { saveUserconfig() {
v = v.join(","); let url = `${window.systemUrl}/config/update`;
var content = [];
this.columnsCur.map((u) => {
content.push({
key: u.key,
hide: u.hide,
});
});
if (!this.userConfig) {
url = `${window.systemUrl}/config/create`;
var data = {
page: window.location.pathname,
component: "Grid",
key: this.$u.guid(),
content: JSON.stringify(content),
};
this.$api.post(url, data).then((r) => {
this.loadUserConfig();
});
} else {
this.userConfig.content = JSON.stringify(content);
this.$api.post(url, this.userConfig);
} }
if (!this.$u.isNull(v)) { },
where.push({ //展开
fieldName: u, expand(row, status) {
fieldValue: v, this.$emit("on-expand", row, status);
conditionalType: op, },
}); //拖拽
onDragDrop(a, b) {
this.$emit("on-drag-drop", a, b);
},
easySearch() {
if (
this.conditions &&
this.conditions.keys &&
this.conditions.keys.default
) {
//判断没有传入条件的用默认的查询
this.conditions.keys.value = this.keys;
} }
} this.reload(this.conditions);
}); },
} undoConfig() {
let searchs = { //列设置恢复初始化
pageIndex: 1, this.columnsCur = this.$u.clone(this.columns);
conditions: where, this.saveUserconfig();
pageSize: 1000, },
}; complexSearch() {
this.$api.post(this.action, searchs).then((r) => { var search = this.$refs.search.$children.filter((u) => {
let list = []; return u.condition;
list = r.result.items; });
const tHeader = []; // 设置Excel的表格第一行的标题 if (search) {
const filterVal = []; //list里对象的属性 var conditions = search[0].condition;
var tempCol = []; this.reload(conditions);
var tempCol1 = []; //存放物料相关表头
var tempCol2 = []; //存放工艺规程相关表头
var columnsCur = this.$u.clone(this.columnsCur); //导出列标题信息griddata this.$refs.grid.columnsCur
columnsCur.forEach((el) => {
if (
(el.hide && el.import) ||
(!el.hide &&
el.key != "action" &&
el.type != "selection" &&
el.key != "ico")
) {
if (el.code) {
tempCol.push({
key: el.key,
code: el.code,
}); //临时存放code数据字典的字段及对应的数据字典code
} }
if (el.materialKey) { },
tempCol1.push({ reload(conditions) {
key: el.key, var where = [];
code: el.materialKey, this.searchConditions = conditions;
}); //临时存放物料管理大类和子类列表 if (conditions) {
Object.keys(conditions).forEach((u) => {
let v = conditions[u].value;
let op = conditions[u].op;
if (!this.$u.isNull(v)) {
if (op == "Range" && Array.isArray(v)) {
let times = [];
v.map((u) => {
if (!this.$u.isNull(u)) {
times.push(this.$u.toTime(u));
}
});
v = times.join(",");
} else if (op.indexOf("In") > -1 && Array.isArray(v)) {
v = v.join(",");
}
if (!this.$u.isNull(v)) {
where.push({
fieldName: u,
fieldValue: v,
conditionalType: op,
});
}
}
});
} }
if (el.techKey) { this.search.pageIndex = 1;
tempCol2.push({ this.search.conditions = where;
key: el.key, this.load();
code: el.techKey, },
}); //临时存放工艺规程相关转换 pageChange(page) {
this.search.page = page;
this.search.pageIndex = page;
this.load();
},
pageSizeChange(size) {
this.search.pageSize = size;
this.search.pageIndex = 1;
this.load();
},
columnChange(item, i) {
item.hide = !item.hide;
this.$set(this.columnsCur, item, i);
this.saveUserconfig();
},
selectionChange(items) {
this.$emit("on-selection-change", items);
this.selectItems = items;
this.footerToolbar = items.length > 0;
},
onSelect(rows, row) {
this.$emit("on-change", rows, row);
},
allChange(items) {
this.$emit("all-change", items);
},
intY() {
if (this.$refs.table != undefined) {
this.firstY = this.$refs.table.$el.getBoundingClientRect().top;
} }
},
selectAll(status) {
this.$refs.table.selectAll(status);
},
//获取所有用户信息
getAllUser() {
this.$api.post(`${systemUrl}/user/paged`, {
conditions: [],
pageIndex: 1,
pageSize: 1000,
})
.then((r) => {
if (r.success) {
let tempUserInfo = r.result.items
tempUserInfo.forEach(ele => {
let temObj = {
userId: ele.id,
name: ele.userName
}
this.allUser.push(temObj)
})
tHeader.push(el.title); }
filterVal.push(el.key); })
} },
}); getUserName(id) {
list.forEach((e) => { let name = ''
//给导出数据增加数据字典对应的name this.allUser.forEach(ele => {
tempCol.forEach((ele) => { if (id == ele.userId) {
e[ele.key] = this.$u.dirName( name = ele.name
this.$store.getters.dictionaryByKey(ele.code), }
e[ele.key] })
); return name
}); },
//导出数据增加对应的物料管理信息 code: 1【rootCategoryId 大类】 2【categoryId 大类】 3【codeRuleId 编码名称】 //批量取消
tempCol1.forEach((elcol1) => { cancelBatch() {
if (elcol1.code == 1) { this.footerToolbar = false;
e[elcol1.key] = this.getType1(e[elcol1.key]); this.$refs.table.selectAll(false);
} else if (elcol1.code == 2) { },
e[elcol1.key] = this.getType2(e[elcol1.key]);
} else if (elcol1.code == 3) {
e[elcol1.key] = this.getType3(e[elcol1.key]);
}
});
//导出工艺规程相关转换表头信息
tempCol2.forEach((elcol2) => {
if (elcol2.code == 1) {
e[elcol2.key] = this.getRoutingHeaderName(e[elcol2.key]);
}
});
});
let nowDate = this.$u.getNowTime(); //年月日时分秒yyyyMMddhhmmss //导出excel
//获取导出数据结束 export2Excel() {
this.$u.outExcel( //当前显示数据
this.exportTitle + "(" + nowDate + ")", var where = [];
tHeader, var conditions = this.searchConditions;
filterVal, if (conditions) {
list Object.keys(conditions).forEach((u) => {
); let v = conditions[u].value;
}); let op = conditions[u].op;
}, if (!this.$u.isNull(v)) {
//物料大类和子类的解析start if (op == "Range") {
getTreeData() { let times = [];
let data = { v.map((u) => {
conditions: [], if (!this.$u.isNull(u)) {
}; times.push(this.$u.toTime(u));
this.$api.post(`${material}/category/list`, data).then((r) => { }
this.treeData = r.result; });
}); v = times.join(",");
}, } else if (op.indexOf("In") > -1 && Array.isArray(v)) {
getType1(val) { v = v.join(",");
let tempTreeList = this.$u.clone(this.treeData); }
let rootName = ""; if (!this.$u.isNull(v)) {
tempTreeList.forEach((ele) => { where.push({
if (ele.upId == 0 && ele.id == val) { fieldName: u,
rootName = ele.name; fieldValue: v,
} conditionalType: op,
}); });
return rootName; }
}, }
getType2(val) { });
let tempTreeList = this.$u.clone(this.treeData);
let childrenName = "";
tempTreeList.forEach((ele) => {
if (ele.upId > 0 && ele.id == val) {
childrenName = ele.name;
}
});
return childrenName;
},
//获取编码名称
getcodeRuleData() {
let data = {
conditions: [],
};
this.$api.post(`${material}/coderule/paged`, data).then((r) => {
if (r.success) {
this.codeRuleData = r.result.items || [];
}
});
},
getType3(val) {
let codeRuleDataList = this.$u.clone(this.codeRuleData);
let codeRuleName = "";
codeRuleDataList.forEach((ele) => {
if (ele.id == val) {
codeRuleName = ele.name;
}
});
return codeRuleName;
},
//物料大类和子类的解析end
//工艺规程的解析start
//获取工艺规程名称
getRoutingHeaderData() {
let data = {
conditions: [],
};
this.$api.post(`${technologyUrl}routingheader/list`, data).then((r) => {
if (r.success) {
this.routingHeaderData = r.result || [];
}
});
},
getRoutingHeaderName(val) {
let routingHeaderDataList = this.$u.clone(this.routingHeaderData);
let routingHeaderName = "";
routingHeaderDataList.forEach((ele) => {
if (ele.id == val) {
routingHeaderName = ele.name;
}
});
return routingHeaderName;
},
//工艺规程的解析end
},
computed: {
columnsNow() {
var cols = this.columnsCur.filter((u) => {
if (u.code) {
u.render = (h, params) => {
let values = u.key;
let type = "text";
if (u.category) {
type = u.category;
} }
return h("state", { let searchs = {
props: { pageIndex: 1,
code: u.code, conditions: where,
type: type, pageSize: 1000,
value: params.row[values] + "", };
}, this.$api.post(this.action, searchs).then((r) => {
let list = [];
list = r.result.items;
const tHeader = []; // 设置Excel的表格第一行的标题
const filterVal = []; //list里对象的属性
var tempCol = [];
var tempCol1 = []; //存放物料相关表头
var tempCol2 = []; //存放工艺规程相关表头
var tempColUser = []; //存放type=user的表头
var columnsCur = this.$u.clone(this.columnsCur); //导出列标题信息griddata this.$refs.grid.columnsCur
columnsCur.forEach((el) => {
if (
(el.hide && el.import) ||
(!el.hide &&
el.key != "action" &&
el.type != "selection" &&
el.key != "ico")
) {
if (el.code) {
tempCol.push({
key: el.key,
code: el.code,
}); //临时存放code数据字典的字段及对应的数据字典code
}
if (el.materialKey) {
tempCol1.push({
key: el.key,
code: el.materialKey,
}); //临时存放物料管理大类和子类列表
}
if (el.techKey) {
tempCol2.push({
key: el.key,
code: el.techKey,
}); //临时存放工艺规程相关转换
}
if (el.type && el.type == "user") {
tempColUser.push({
key: el.key,
code: el.type,
}); //临时存放user列
}
tHeader.push(el.title);
filterVal.push(el.key);
}
});
list.forEach((e) => {
//给导出数据增加数据字典对应的name
// tempCol.forEach((ele) => {
// e[ele.key] = this.$u.dirName(
// this.$store.getters.dictionaryByKey(ele.code),
// e[ele.key]
// );
// });
tempCol.forEach((elem) => {
if (
e[elem.key] &&
e[elem.key] != "" &&
e[elem.key] != null
) {
//如果数据字典项对应的DirName字段存在,通过name查询到对应的code,然后赋值。
let codeArr = []
let keyValue = e[elem.key]
if (keyValue.length > 0 && (keyValue.indexOf(',') > -1 || keyValue.indexOf(',') > -1)) { //如果对应的数据包含多个数据字典项,比如包含“,”或“,”
if (keyValue.indexOf(',') > -1) {
codeArr = keyValue.split(',')
}
if (keyValue.indexOf > -1) {
codeArr = keyValue.split(',')
}
}
if (codeArr.length <= 1) { //对应的数据包含一个数据字典项
e[elem.key] = this.$u.dirName(
this.$store.getters.dictionaryByKey(elem.code),
e[elem.key]
);
} else { //对应的数据包含多个数据字典项
let codeInfo = ''
codeArr.forEach(el => {
codeInfo = codeInfo + this.$u.dirName(this.$store.getters.dictionaryByKey(elem.code), el) + ",";
})
e[elem.key] = codeInfo.substr(0, codeInfo.length - 1)
}
}
});
//导出数据增加对应的物料管理信息 code: 1【rootCategoryId 大类】 2【categoryId 大类】 3【codeRuleId 编码名称】
tempCol1.forEach((elcol1) => {
if (elcol1.code == 1) {
e[elcol1.key] = this.getType1(e[elcol1.key]);
} else if (elcol1.code == 2) {
e[elcol1.key] = this.getType2(e[elcol1.key]);
} else if (elcol1.code == 3) {
e[elcol1.key] = this.getType3(e[elcol1.key]);
}
});
//导出工艺规程相关转换表头信息
tempCol2.forEach((elcol2) => {
if (elcol2.code == 1) {
e[elcol2.key] = this.getRoutingHeaderName(e[elcol2.key]);
}
});
//导出username相关信息
tempColUser.forEach(eluser => {
if (
e[eluser.key] &&
e[eluser.key] != "" &&
e[eluser.key] != null
) {
e[eluser.key] = this.getUserName(e[eluser.key])
}
})
});
let nowDate = this.$u.getNowTime(); //年月日时分秒yyyyMMddhhmmss
//获取导出数据结束
this.$u.outExcel(
this.exportTitle + "(" + nowDate + ")",
tHeader,
filterVal,
list
);
}); });
}; },
} //物料大类和子类的解析start
if (u.type == "user") { getTreeData() {
u.render = (h, params) => { let data = {
let values = u.key; conditions: [],
if (params.row[values]) { };
return h("User", { this.$api.post(`${material}/category/list`, data).then((r) => {
props: { this.treeData = r.result;
value: params.row[values],
},
});
}
};
}
if (u.type == "workShopName") {
u.render = (h, params) => {
let values = u.key;
if (params.row[values]) {
return h("WorkShopName", {
props: {
value: params.row[values],
},
});
}
};
}
if (u.type == "date" || u.type == "dateTime") {
u.render = (h, params) => {
let values = u.key;
return h("DTSpan", {
props: {
type: u.type,
value: params.row[values],
},
}); });
}; },
} getType1(val) {
return !u.hide; let tempTreeList = this.$u.clone(this.treeData);
}); let rootName = "";
return cols; tempTreeList.forEach((ele) => {
}, if (ele.upId == 0 && ele.id == val) {
}, rootName = ele.name;
watch: { }
data() { });
this.list = this.data; return rootName;
}, },
height() { getType2(val) {
this.tableHeight = this.height; let tempTreeList = this.$u.clone(this.treeData);
}, let childrenName = "";
columns() { tempTreeList.forEach((ele) => {
this.columns.forEach((u) => { if (ele.upId > 0 && ele.id == val) {
if (!u.hide) { childrenName = ele.name;
u.hide = false; }
} });
}); return childrenName;
this.columnsCur = this.$u.clone(this.columns); },
//获取编码名称
getcodeRuleData() {
let data = {
conditions: [],
};
this.$api.post(`${material}/coderule/paged`, data).then((r) => {
if (r.success) {
this.codeRuleData = r.result.items || [];
}
});
},
getType3(val) {
let codeRuleDataList = this.$u.clone(this.codeRuleData);
let codeRuleName = "";
codeRuleDataList.forEach((ele) => {
if (ele.id == val) {
codeRuleName = ele.name;
}
});
return codeRuleName;
},
//物料大类和子类的解析end
//工艺规程的解析start
//获取工艺规程名称
getRoutingHeaderData() {
let data = {
conditions: [],
};
this.$api.post(`${technologyUrl}routingheader/list`, data).then((r) => {
if (r.success) {
this.routingHeaderData = r.result || [];
}
});
},
getRoutingHeaderName(val) {
let routingHeaderDataList = this.$u.clone(this.routingHeaderData);
let routingHeaderName = "";
routingHeaderDataList.forEach((ele) => {
if (ele.id == val) {
routingHeaderName = ele.name;
}
});
return routingHeaderName;
},
//工艺规程的解析end
},
computed: {
columnsNow() {
var cols = this.columnsCur.filter((u) => {
if (u.code) {
u.render = (h, params) => {
let values = u.key;
let type = "text";
if (u.category) {
type = u.category;
}
return h("state", {
props: {
code: u.code,
type: type,
value: params.row[values] + "",
},
});
};
}
if (u.type == "user") {
u.render = (h, params) => {
let values = u.key;
if (params.row[values]) {
return h("User", {
props: {
value: params.row[values],
},
});
}
};
}
if (u.type == "workShopName") {
u.render = (h, params) => {
let values = u.key;
if (params.row[values]) {
return h("WorkShopName", {
props: {
value: params.row[values],
},
});
}
};
}
if (u.type == "date" || u.type == "dateTime") {
u.render = (h, params) => {
let values = u.key;
return h("DTSpan", {
props: {
type: u.type,
value: params.row[values],
},
});
};
}
return !u.hide;
});
return cols;
},
},
watch: {
data() {
this.list = this.data;
},
height() {
this.tableHeight = this.height;
},
columns() {
this.columns.forEach((u) => {
if (!u.hide) {
u.hide = false;
}
});
this.columnsCur = this.$u.clone(this.columns);
},
}, },
},
}; };
</script> </script>
<style lang="less"> <style lang="less">
@import "../../assets/css/custom.less"; @import "../../assets/css/custom.less";
.table-content { .table-content {
position: relative; position: relative;
height: 100%; height: 100%;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
.tip { .tip {
display: inline; display: inline;
} }
form { form {
display: inline-block; display: inline-block;
.ivu-form-item { .ivu-form-item {
margin: 0; margin: 0;
vertical-align: middle; vertical-align: middle;
}
} }
}
.table-main { .table-main {
width: 100%; width: 100%;
text-align: left; text-align: left;
padding: 0; padding: 0;
display: block; display: block;
overflow-y: auto; overflow-y: auto;
flex-grow: 1; flex-grow: 1;
tr td .ivu-table-cell {
padding: 0 5px;
}
tr td .ivu-table-cell { overflow-x: hidden;
padding: 0 5px;
} }
overflow-x: hidden; .table-tools {
} display: flex;
line-height: 50px;
background: @right-header-bg;
.table-tools { .table-search {
display: flex; flex-grow: 1;
line-height: 50px; }
background: @right-header-bg;
.table-search {
flex-grow: 1;
}
.btns { .btns {
min-width: 200px; min-width: 200px;
text-align: right; text-align: right;
}
} }
}
.table-footer { .table-footer {
line-height: 45px; line-height: 45px;
} }
.ivu-footer-toolbar { .ivu-footer-toolbar {
text-align: left; text-align: left;
background: rgba(0, 0, 0, 0.7); background: rgba(0, 0, 0, 0.7);
color: #fff; color: #fff;
} }
} }
.table-columns { .table-columns {
max-height: calc(100% - 50px); max-height: calc(100% - 50px);
overflow: auto; overflow: auto;
li { li {
list-style: none; list-style: none;
line-height: 40px; line-height: 40px;
cursor: move; cursor: move;
border-bottom: 1px dotted #249e91; border-bottom: 1px dotted #249e91;
color: #249e91; color: #249e91;
span { span {
cursor: pointer; cursor: pointer;
} }
.mr10 { .mr10 {
cursor: pointer; cursor: pointer;
} }
.move { .move {
float: right; float: right;
margin: 10px 10px 0 0; margin: 10px 10px 0 0;
cursor: move; cursor: move;
} }
.dis { .dis {
color: #aaa; color: #aaa;
}
} }
}
} }
.searchBack { .searchBack {
display: inline; display: inline;
margin-left: 20px; margin-left: 20px;
button { button {
margin-left: 10px; margin-left: 10px;
} }
a { a {
margin-left: 20px; margin-left: 20px;
color: #2680eb; color: #2680eb;
} }
a:hover { a:hover {
color: #249e91; color: #249e91;
} }
} }
</style> </style>
<template> <template>
<Modal v-model="ImportModal" :title="modalTitles" fullscreen footer-hide @on-cancel="cancelModal"> <Modal v-model="ImportModal" :title="modalTitles" fullscreen footer-hide @on-cancel="cancelModal">
<div class="table-content"> <div class="table-content">
<div class="table-tools"> <div class="table-tools">
<div class="table-search"> <div class="table-search">
<Form inline> <Form inline>
<FormItem> <FormItem>
<div style="height:34px;overflow: hidden;padding:0;width:120px"> <div style="height:34px;overflow: hidden;padding:0;width:120px">
<Upload action :before-upload="beforeUpload" ref="uploadfile" :format="formatList"> <Upload action :before-upload="beforeUpload" ref="uploadfile" :format="formatList">
<Button icon="ios-cloud-upload-outline">上传文件</Button> <Button icon="ios-cloud-upload-outline">上传文件</Button>
</Upload> </Upload>
</div> </div>
</FormItem> </FormItem>
<FormItem> <FormItem>
<Button type="primary" @click="openInfoModal" :disabled="btnIm">导入</Button> <Button type="primary" @click="openInfoModal" :disabled="btnIm">导入</Button>
</FormItem> </FormItem>
</Form> </Form>
</div>
<div class="btns">
<Form inline>
<FormItem>
<RadioGroup v-model="excelType" type="button" @on-change="changeExcel" size="small">
<Tooltip content="文件数据">
<Radio label="0">
<Icon type="ios-list-box-outline" />
</Radio>
</Tooltip>
<Tooltip content="粘贴Excel数据">
<Radio label="1">
<Icon type="ios-copy" />
</Radio>
</Tooltip>
</RadioGroup>
</FormItem>
</Form>
</div>
</div> </div>
<div class="btns"> <div class="table-main" ref="main">
<Form inline> <Table :border="true" :columns="columnsImport" :data="excelData" :height="tdHeightExcel" :no-data-text="noDataText" ref="table" class="tableCommon" v-if="tableImport"></Table>
<FormItem> <component :is="detailExcel" ref="comExcel" @on-datalength="datalength" />
<RadioGroup v-model="excelType" type="button" @on-change="changeExcel" size="small">
<Tooltip content="文件数据">
<Radio label="0">
<Icon type="ios-list-box-outline" />
</Radio>
</Tooltip>
<Tooltip content="粘贴Excel数据">
<Radio label="1">
<Icon type="ios-copy" />
</Radio>
</Tooltip>
</RadioGroup>
</FormItem>
</Form>
</div> </div>
</div> <FooterToolbar v-if="sheetNames.length>1&&tableImport">
<div class="table-main" ref="main"> <Form inline>
<Table <FormItem>
:border="true" <Tabs :animated="false" :value="0" @on-click="sheetClick">
:columns="columnsImport" <TabPane :label="item" v-for="(item,index) in sheetNames" :key="index"></TabPane>
:data="excelData" </Tabs>
:height="tdHeightExcel" </FormItem>
:no-data-text="noDataText" </Form>
ref="table" </FooterToolbar>
class="tableCommon" <Modal v-model="infoModal" :title="modalTitles" fullscreen>
v-if="tableImport" <DataGrid :tool="false" :page="false" :columns="colsIm" :data="dataIm" :height="tdHeightExcel+30" ref="dataImport"></DataGrid>
></Table> <div slot="footer">
<component :is="detailExcel" ref="comExcel" @on-datalength="datalength" /> <Button @click="infoModal=false">关闭</Button>
</div> <Button type="primary" @click="importOk" v-show="imBtn">确定导入</Button>
<FooterToolbar v-if="sheetNames.length>1&&tableImport"> </div>
<Form inline> </Modal>
<FormItem>
<Tabs :animated="false" :value="0" @on-click="sheetClick">
<TabPane :label="item" v-for="(item,index) in sheetNames" :key="index"></TabPane>
</Tabs>
</FormItem>
</Form>
</FooterToolbar>
<Modal v-model="infoModal" :title="modalTitles" fullscreen>
<DataGrid
:tool="false"
:page="false"
:columns="colsIm"
:data="dataIm"
:height="tdHeightExcel+30"
ref="dataImport"
></DataGrid>
<div slot="footer">
<Button @click="infoModal=false">关闭</Button>
<Button type="primary" @click="importOk" v-show="imBtn">确定导入</Button>
</div>
</Modal>
</div> </div>
</Modal> </Modal>
</template> </template>
<script> <script>
import XLSX from "xlsx"; import XLSX from "xlsx";
import { Switch } from "view-design"; import {
Switch
} from "view-design";
export default { export default {
name: "Edit", name: "Edit",
data() { data() {
return { return {
tabVal: 0, tabVal: 0,
infoModal: false, infoModal: false,
entity: {}, entity: {},
downUrl: fileUrlDown, downUrl: fileUrlDown,
fileUrlPath: "", fileUrlPath: "",
disabled: false, disabled: false,
detailExcel: null, detailExcel: null,
tableImport: true, tableImport: true,
tdHeightExcel: "", tdHeightExcel: "",
excelData: [], excelData: [],
excelDataBack: [], //临时存储原始数据 excelDataBack: [], //临时存储原始数据
formatList: ["xlsx"], formatList: ["xlsx"],
columnsImport: [], columnsImport: [],
departArr: [], //部门list departArr: [], //部门list
sheetNames: [], //excel的表明 sheetNames: [], //excel的表明
workBook: {}, workBook: {},
openDatas: [], openDatas: [],
dataType: 0, dataType: 0,
//new //new
colsIm: [], colsIm: [],
dataIm: [], dataIm: [],
excelType: "0", excelType: "0",
btnIm: true, btnIm: true,
titleInfo: "", titleInfo: "",
noDataText: "暂无数据", noDataText: "暂无数据",
imBtn: true, imBtn: true,
columnsIm: this.columns, columnsIm: this.columns,
ImportModal: this.open, ImportModal: this.open,
batchImportUrl: "", batchImportUrl: "",
modalTitles: "导入", modalTitles: "导入",
}; };
},
props: {
eid: Number,
data: {
// 当作table使用,直接显示数据
type: Array,
default: function () {
return [];
},
}, },
columns: { props: {
//要显示的字段 eid: Number,
type: Array, data: {
default: [], // 当作table使用,直接显示数据
type: Array,
default: function () {
return [];
},
},
columns: {
//要显示的字段
type: Array,
default: [],
},
open: {
type: Boolean,
default: false,
},
modalTitle: {
type: String,
default: "",
},
}, },
open: { created() {
type: Boolean, this.tdHeightExcel = window.innerHeight - 180;
default: false, //导出对列表头进行预加载start
this.$api.get(`${systemUrl}/Department/GetDepartments`).then((r) => {
this.departArr = r.result.items;
});
//导出对列表头进行预加载end
}, },
modalTitle: { mounted() {
type: String, //if (this.eid > 0) {
default: "", // this.load(this.eid);
//}
this.modalTitles = "导入到【" + this.modalTitle + "】";
window.onresize = () => {
///浏览器窗口大小变化
return (() => {
window.screenHeight = window.innerHeight;
this.tdHeightExcel = window.screenHeight - 180;
})();
};
}, },
}, methods: {
created() { //重新处理colum
this.tdHeightExcel = window.innerHeight - 180; loadColum(columns) {
//导出对列表头进行预加载start let tempCol = this.$u.clone(columns);
this.$api.get(`${systemUrl}/Department/GetDepartments`).then((r) => { tempCol.forEach((ele, index) => {
this.departArr = r.result.items; if (
}); ele.key == "action" ||
ele.type == "selection" ||
ele.key == "ico"
) {
ele.hide = true;
}
});
this.colsIm = tempCol;
this.colsIm.unshift({
type: "index",
width: 80,
align: "right",
title: "序号",
}, {
key: "ico",
title: " ",
align: "center",
width: 60,
render: (h, params) => {
return h(
"div", {
class: "",
},
[
h(params.row.ico ? "op" : "", {
attrs: {
icon: "ios-alert",
type: "icon",
title: "数据不合法",
color: "#ff9900",
},
}),
]
);
},
});
//处理原始数据和表头进行对应
let temCol = this.$u.clone(this.colsIm); //原始数据表头
let temColPage = this.$u.clone(columns); //需要显示的页面的表头
//let temData = this.$u.clone(this.excelDataBack); //原始数据
let temData = []; //原始数据
if (this.excelType == "0") {
temData = this.$u.clone(this.excelDataBack);
} else {
temData = this.$u.clone(this.$refs.comExcel.excelData);
}
let arrTitleUse = []; ////使用数据字典的字段
temColPage.forEach((elCode) => {
if (elCode.code) {
arrTitleUse.push({
key: elCode.key,
code: elCode.code,
});
}
});
let useData = []; //重新组织list列表数据
temData.forEach((elData, index) => {
let objTm = {};
temCol.forEach((elTitle) => {
objTm[elTitle.key] = elData[elTitle.title];
});
useData.push(objTm);
});
//导出对列表头进行预加载end //对列表里的部门及数据字典项进行处理
}, useData.forEach((eles) => {
mounted() { //如果导入文件没有departmentid,但存在departmentTitle的话,通过title获取id
//if (this.eid > 0) { if (
// this.load(this.eid); [
//} (eles.departmentTitle && eles.departmentTitle != "") ||
this.modalTitles = "导入到【" + this.modalTitle + "】"; (eles.departmentName && eles.departmentName != ""),
window.onresize = () => { ] &&
///浏览器窗口大小变化 (!eles.departmentId || eles.departmentId == "")
return (() => { ) {
window.screenHeight = window.innerHeight; this.departArr.forEach((e) => {
this.tdHeightExcel = window.screenHeight - 180; if (
})(); (eles.departmentTitle && eles.departmentTitle == e.name) ||
}; (eles.departmentName && eles.departmentName == e.name)
}, ) {
methods: { eles.departmentId = e.id;
//重新处理colum }
loadColum(columns) { });
let tempCol = this.$u.clone(columns); } else if (
tempCol.forEach((ele, index) => { //如果导入文件没有departmentTitle,但存在departmentid的话,通过id获取departmentTitle
if ( eles.departmentId &&
ele.key == "action" || eles.departmentId + "" != "" &&
ele.type == "selection" || (!eles.departmentTitle || eles.departmentTitle == "") &&
ele.key == "ico" (!eles.departmentName || eles.departmentName == "")
) { ) {
ele.hide = true; this.departArr.forEach((e) => {
} if (eles.departmentId && eles.departmentId == e.id) {
}); eles.departmentTitle = e.name;
this.colsIm = tempCol; eles.departmentName = e.name;
this.colsIm.unshift( }
{ });
type: "index", }
width: 80,
align: "right", arrTitleUse.forEach((elem) => {
title: "序号", if (
eles[elem.key] &&
eles[elem.key] != "" &&
eles[elem.key] != null
) {
//如果数据字典项对应的DirName字段存在,通过name查询到对应的code,然后赋值
let codeArr = []
let keyValue = eles[elem.key]
if (keyValue.length > 0 && (keyValue.indexOf(',') > -1 || keyValue.indexOf(',') > -1)) { //如果对应的数据包含多个数据字典项,比如包含“,”或“,”
if (keyValue.indexOf(',') > -1) {
codeArr = keyValue.split(',')
}
if (keyValue.indexOf > -1) {
codeArr = keyValue.split(',')
}
}
if (codeArr.length <= 1) { //对应的数据包含一个数据字典项
eles[elem.key] = this.$u.dirCode(
this.$store.getters.dictionaryByKey(elem.code),
eles[elem.key]
);
} else { //对应的数据包含多个数据字典项
let codeInfo = ''
codeArr.forEach(el => {
codeInfo = codeInfo + this.$u.dirCode(this.$store.getters.dictionaryByKey(elem.code), el) + ",";
})
eles[elem.key] = codeInfo.substr(0, codeInfo.length - 1)
}
}
});
});
this.dataIm = useData;
let tempData = this.$u.clone(this.dataIm);
this.$emit("on-get-data", tempData);
}, },
{
key: "ico", //导入excel文件
title: " ",
align: "center", async beforeUpload(file) {
width: 60, //初始化
render: (h, params) => { this.sheetNames = [];
return h( this.workBook = {};
"div", this.$refs.uploadfile.clearFiles(); //清除上一次上传文件列表
{ //上传成功后的读取到excel信息
class: "", this.workBook = await this.$u.readXLSX(file);
}, this.sheetNames = this.workBook.SheetNames; //execel里的表明
[ this.btnIm = false;
h(params.row.ico ? "op" : "", { this.dealSheet(0); //默认显示第一个表
attrs: { return false;
icon: "ios-alert", },
type: "icon", //对上传的excel表信息进行处理,不对表头进行处理
title: "数据不合法", dealSheet(index) {
color: "#ff9900", this.dataType = 1;
}, this.columnsImport = [];
}), this.excelData = [];
] this.excelDataBack = [];
const sheet2JSONOpts = {
defval: "", //给defval赋值为空的字符串
};
var csv = XLSX.utils.sheet_to_csv(
this.workBook.Sheets[this.workBook.SheetNames[index]],
sheet2JSONOpts
); );
},
}
);
//处理原始数据和表头进行对应
let temCol = this.$u.clone(this.colsIm); //原始数据表头
let temColPage = this.$u.clone(columns); //需要显示的页面的表头
//let temData = this.$u.clone(this.excelDataBack); //原始数据
let temData = []; //原始数据
if (this.excelType == "0") {
temData = this.$u.clone(this.excelDataBack);
} else {
temData = this.$u.clone(this.$refs.comExcel.excelData);
}
let arrTitleUse = []; ////使用数据字典的字段
temColPage.forEach((elCode) => {
if (elCode.code) {
arrTitleUse.push({
key: elCode.key,
code: elCode.code,
});
}
});
let useData = []; //重新组织list列表数据
temData.forEach((elData, index) => {
let objTm = {};
temCol.forEach((elTitle) => {
objTm[elTitle.key] = elData[elTitle.title];
});
useData.push(objTm);
});
//对列表里的部门及数据字典项进行处理 var lines = csv.split("\n"); //第一行标题
useData.forEach((eles) => { var headers = lines[0].split(",");
//如果导入文件没有departmentid,但存在departmentTitle的话,通过title获取id var headersNow = [];
if ( headersNow.push({
[ type: "index",
(eles.departmentTitle && eles.departmentTitle != "") || width: 80,
(eles.departmentName && eles.departmentName != ""), align: "right",
] && title: "序号",
(!eles.departmentId || eles.departmentId == "") });
) { headers.forEach((elHead) => {
this.departArr.forEach((e) => { let headObj = {};
headObj.title = elHead;
headObj.key = elHead;
headersNow.push(headObj);
});
this.columnsImport = headersNow;
var result = [];
for (var i = 1; i < lines.length - 1; i++) {
var obj = {};
var currentline = lines[i].split(",");
for (var j = 0; j < headers.length; j++) {
obj[headers[j]] = currentline[j];
}
result.push(obj);
}
this.excelData = result;
this.excelDataBack = result;
this.changeExcel(0);
},
//切换sheet表重新加载
sheetClick(val) {
this.tabVal = val;
this.dealSheet(val);
},
handleClose() {
this.$emit("on-close");
},
cancelExcel() {
this.excelData = [];
this.excelDataBack = [];
this.$refs.uploadfile.clearFiles();
let parms = {
status: 1,
id: this.eid,
};
//导入中心列表数据状态更新
this.$emit("on-close");
},
//打开导入数据格式化后的窗口
openInfoModal() {
if ( if (
(eles.departmentTitle && eles.departmentTitle == e.name) || (this.excelType == "0" && this.excelData.length > 0) ||
(eles.departmentName && eles.departmentName == e.name) (this.excelType == "1" && this.$refs.comExcel.excelData.length > 0)
) { ) {
eles.departmentId = e.id; this.imBtn = true;
this.loadColum(this.columnsIm);
this.titleInfo = "批量导入";
this.infoModal = true;
} else {
this.imBtn = false;
this.$Message.error("没有可导入的数据!");
} }
}); },
} else if ( //确定导入按钮操作
//如果导入文件没有departmentTitle,但存在departmentid的话,通过id获取departmentTitle importOk() {
eles.departmentId && let imData = [];
eles.departmentId + "" != "" && let imDataError = [];
(!eles.departmentTitle || eles.departmentTitle == "") && this.dataIm.forEach((ele) => {
(!eles.departmentName || eles.departmentName == "") if (!ele.ico) {
) { imData.push(ele);
this.departArr.forEach((e) => { } else {
if (eles.departmentId && eles.departmentId == e.id) { imDataError.push(ele);
eles.departmentTitle = e.name; }
eles.departmentName = e.name; });
this.$api
.post(this.batchImportUrl, {
list: imData,
})
.then((r) => {
if (r.success) {
this.$Message.success("批量导入成功" + imData.length + "条数据");
this.dataIm = imDataError;
this.$emit("on-ok");
} else {
this.$Message.error("批量导入失败");
}
})
.catch((err) => {
this.$Message.error("数据异常!");
});
},
//切换列表和excel按钮
changeExcel(val) {
if (val == 1) {
this.tableImport = false;
this.detailExcel = () => import("./detailExcel");
this.excelType = "1";
this.btnIm = true;
} else {
this.detailExcel = null;
this.tableImport = true;
this.excelType = "0";
if (this.excelData.length > 0) {
this.btnIm = false;
} else {
this.btnIm = true;
}
} }
}); },
} datalength(val) {
if (val > 0) {
arrTitleUse.forEach((elem) => { this.btnIm = false;
if ( }
eles[elem.key] && },
eles[elem.key] != "" && cancelModal() {
eles[elem.key] != null this.$emit("on-cancel");
) { },
//如果数据字典项对应的DirName字段存在,通过name查询到对应的code,然后赋值 //主页面里第二次处理数据
eles[elem.key] = this.$u.dirCode( deelData(url, columns, formatList) {
this.$store.getters.dictionaryByKey(elem.code), this.dataIm = formatList;
eles[elem.key] this.batchImportUrl = url;
); },
} l(key) {
}); key = "user" + "." + key;
}); return this.$t(key);
this.dataIm = useData; },
let tempData = this.$u.clone(this.dataIm);
this.$emit("on-get-data", tempData);
},
//导入excel文件
async beforeUpload(file) {
//初始化
this.sheetNames = [];
this.workBook = {};
this.$refs.uploadfile.clearFiles(); //清除上一次上传文件列表
//上传成功后的读取到excel信息
this.workBook = await this.$u.readXLSX(file);
this.sheetNames = this.workBook.SheetNames; //execel里的表明
this.btnIm = false;
this.dealSheet(0); //默认显示第一个表
return false;
},
//对上传的excel表信息进行处理,不对表头进行处理
dealSheet(index) {
this.dataType = 1;
this.columnsImport = [];
this.excelData = [];
this.excelDataBack = [];
const sheet2JSONOpts = {
defval: "", //给defval赋值为空的字符串
};
var csv = XLSX.utils.sheet_to_csv(
this.workBook.Sheets[this.workBook.SheetNames[index]],
sheet2JSONOpts
);
var lines = csv.split("\n"); //第一行标题
var headers = lines[0].split(",");
var headersNow = [];
headersNow.push({
type: "index",
width: 80,
align: "right",
title: "序号",
});
headers.forEach((elHead) => {
let headObj = {};
headObj.title = elHead;
headObj.key = elHead;
headersNow.push(headObj);
});
this.columnsImport = headersNow;
var result = [];
for (var i = 1; i < lines.length - 1; i++) {
var obj = {};
var currentline = lines[i].split(",");
for (var j = 0; j < headers.length; j++) {
obj[headers[j]] = currentline[j];
}
result.push(obj);
}
this.excelData = result;
this.excelDataBack = result;
this.changeExcel(0);
},
//切换sheet表重新加载
sheetClick(val) {
this.tabVal = val;
this.dealSheet(val);
},
handleClose() {
this.$emit("on-close");
},
cancelExcel() {
this.excelData = [];
this.excelDataBack = [];
this.$refs.uploadfile.clearFiles();
let parms = {
status: 1,
id: this.eid,
};
//导入中心列表数据状态更新
this.$emit("on-close");
},
//打开导入数据格式化后的窗口
openInfoModal() {
if (
(this.excelType == "0" && this.excelData.length > 0) ||
(this.excelType == "1" && this.$refs.comExcel.excelData.length > 0)
) {
this.imBtn = true;
this.loadColum(this.columnsIm);
this.titleInfo = "批量导入";
this.infoModal = true;
} else {
this.imBtn = false;
this.$Message.error("没有可导入的数据!");
}
},
//确定导入按钮操作
importOk() {
let imData = [];
let imDataError = [];
this.dataIm.forEach((ele) => {
if (!ele.ico) {
imData.push(ele);
} else {
imDataError.push(ele);
}
});
this.$api
.post(this.batchImportUrl, {
list: imData,
})
.then((r) => {
if (r.success) {
this.$Message.success("批量导入成功" + imData.length + "条数据");
this.dataIm = imDataError;
this.$emit("on-ok");
} else {
this.$Message.error("批量导入失败");
}
})
.catch((err) => {
this.$Message.error("数据异常!");
});
},
//切换列表和excel按钮
changeExcel(val) {
if (val == 1) {
this.tableImport = false;
this.detailExcel = () => import("./detailExcel");
this.excelType = "1";
this.btnIm = true;
} else {
this.detailExcel = null;
this.tableImport = true;
this.excelType = "0";
if (this.excelData.length > 0) {
this.btnIm = false;
} else {
this.btnIm = true;
}
}
},
datalength(val) {
if (val > 0) {
this.btnIm = false;
}
},
cancelModal() {
this.$emit("on-cancel");
},
//主页面里第二次处理数据
deelData(url, columns, formatList) {
this.dataIm = formatList;
this.batchImportUrl = url;
},
l(key) {
key = "user" + "." + key;
return this.$t(key);
},
},
watch: {
columns() {
this.columns.forEach((u) => {
if (!u.hide) {
u.hide = false;
}
});
this.colsIm = this.$u.clone(this.columns);
this.columnsIm = this.$u.clone(this.columns);
},
open(v) {
this.ImportModal = v;
}, },
modalTitle(v) { watch: {
this.modalTitles = "导入到【" + v + "】"; columns() {
this.columns.forEach((u) => {
if (!u.hide) {
u.hide = false;
}
});
this.colsIm = this.$u.clone(this.columns);
this.columnsIm = this.$u.clone(this.columns);
},
open(v) {
this.ImportModal = v;
},
modalTitle(v) {
this.modalTitles = "导入到【" + v + "】";
},
}, },
},
}; };
</script> </script>
<style lang="less"> <style lang="less">
@import "../../../assets/css/custom.less"; @import "../../../assets/css/custom.less";
.table-content { .table-content {
position: relative; position: relative;
height: 100%; height: 100%;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
.tip { .tip {
display: inline; display: inline;
} }
form { form {
display: inline-block; display: inline-block;
.ivu-form-item { .ivu-form-item {
margin: 0; margin: 0;
vertical-align: middle; vertical-align: middle;
}
} }
}
.table-main { .table-main {
width: 100%; width: 100%;
text-align: left; text-align: left;
padding: 0; padding: 0;
display: block; display: block;
overflow-y: auto; overflow-y: auto;
flex-grow: 1; flex-grow: 1;
tr td .ivu-table-cell {
padding: 0 5px;
}
tr td .ivu-table-cell { overflow-x: hidden;
padding: 0 5px;
} }
overflow-x: hidden; .table-tools {
} display: flex;
line-height: 50px;
background: @right-header-bg;
.table-tools { .table-search {
display: flex; flex-grow: 1;
line-height: 50px; }
background: @right-header-bg;
.table-search {
flex-grow: 1;
}
.btns { .btns {
min-width: 200px; min-width: 200px;
text-align: right; text-align: right;
}
} }
}
} }
</style> </style>
...@@ -428,12 +428,18 @@ export default { ...@@ -428,12 +428,18 @@ export default {
DipartLocation: { DipartLocation: {
name: "部门", name: "部门",
organizationType: "组织类型", organizationType: "组织类型",
status: '是否生产班组', // status: '是否生产班组',
status: '属性',
departcode: '部门编号', departcode: '部门编号',
department: '部门名称', department: '部门名称',
cityName: '省市县', cityName: '省市县',
creationTime: '创建时间', creationTime: '创建时间',
upMent: '上级部门', upMent: '上级部门',
code:'部门编号',
location:'省市县',
parent_Id:'上级部门',
property:'属性',
parentTitle:'上级部门'
}, },
instance: { instance: {
id: '主键', id: '主键',
......
...@@ -166,6 +166,42 @@ henq.findRoots = (arr1, id) => { ...@@ -166,6 +166,42 @@ henq.findRoots = (arr1, id) => {
forFn(arr1, id) forFn(arr1, id)
return temp return temp
} }
//省市县pacc转为list
henq.treeToList1 = (tree) => {
let list = [];
function treeToList1(data) {
data.map(u => {
if (u.children&&u.level!=1) {
treeToList1(u.children, u)
}
else if(u.children&&u.level==1)
{
list=list.concat(u.children);
}
})
}
treeToList1(tree, null)
return list;
}
//根据departId返出上级所有name
henq.getDepartAllName = (list,id) => {
let names = '';
function getDepartAllName(list,id) {
list.map(u => {
if(id==u.id)
{
names=u.name+"/"+names
if (u.parent_Id>0) {
getDepartAllName(list, u.parent_Id)
}
}
})
}
getDepartAllName(list,id)
return names.slice(0,names.length-1);
}
//导出pdf //导出pdf
henq.outPdf = (ele, fileName) => { henq.outPdf = (ele, fileName) => {
// document.head.innerHTML = // document.head.innerHTML =
......
...@@ -1744,7 +1744,7 @@ ...@@ -1744,7 +1744,7 @@
"dependencies": { "dependencies": {
"ajv": { "ajv": {
"version": "5.5.2", "version": "5.5.2",
"resolved": "https://registry.npmjs.org/ajv/-/ajv-5.5.2.tgz", "resolved": "https://registry.npm.taobao.org/ajv/download/ajv-5.5.2.tgz?cache=0&sync_timestamp=1597480760804&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fajv%2Fdownload%2Fajv-5.5.2.tgz",
"integrity": "sha1-c7Xuyj+rZT49P5Qis0GtQiBdyWU=", "integrity": "sha1-c7Xuyj+rZT49P5Qis0GtQiBdyWU=",
"dev": true, "dev": true,
"optional": true, "optional": true,
...@@ -1776,7 +1776,7 @@ ...@@ -1776,7 +1776,7 @@
}, },
"cross-spawn": { "cross-spawn": {
"version": "5.1.0", "version": "5.1.0",
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-5.1.0.tgz", "resolved": "https://registry.npm.taobao.org/cross-spawn/download/cross-spawn-5.1.0.tgz?cache=0&sync_timestamp=1590421014780&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fcross-spawn%2Fdownload%2Fcross-spawn-5.1.0.tgz",
"integrity": "sha1-6L0O/uWPz/b4+UUQoKVUu/ojVEk=", "integrity": "sha1-6L0O/uWPz/b4+UUQoKVUu/ojVEk=",
"dev": true, "dev": true,
"optional": true, "optional": true,
...@@ -1856,7 +1856,7 @@ ...@@ -1856,7 +1856,7 @@
}, },
"fast-deep-equal": { "fast-deep-equal": {
"version": "1.1.0", "version": "1.1.0",
"resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-1.1.0.tgz", "resolved": "https://registry.npm.taobao.org/fast-deep-equal/download/fast-deep-equal-1.1.0.tgz",
"integrity": "sha1-wFNHeBfIa1HaqFPIHgWbcz0CNhQ=", "integrity": "sha1-wFNHeBfIa1HaqFPIHgWbcz0CNhQ=",
"dev": true, "dev": true,
"optional": true "optional": true
...@@ -1894,7 +1894,7 @@ ...@@ -1894,7 +1894,7 @@
}, },
"json-schema-traverse": { "json-schema-traverse": {
"version": "0.3.1", "version": "0.3.1",
"resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.3.1.tgz", "resolved": "https://registry.npm.taobao.org/json-schema-traverse/download/json-schema-traverse-0.3.1.tgz",
"integrity": "sha1-NJptRMU6Ud6JtAgFxdXlm0F9M0A=", "integrity": "sha1-NJptRMU6Ud6JtAgFxdXlm0F9M0A=",
"dev": true, "dev": true,
"optional": true "optional": true
...@@ -1964,7 +1964,7 @@ ...@@ -1964,7 +1964,7 @@
}, },
"yallist": { "yallist": {
"version": "2.1.2", "version": "2.1.2",
"resolved": "https://registry.npmjs.org/yallist/-/yallist-2.1.2.tgz", "resolved": "https://registry.npm.taobao.org/yallist/download/yallist-2.1.2.tgz",
"integrity": "sha1-HBH5IY8HYImkfdUS+TxmmaaoHVI=", "integrity": "sha1-HBH5IY8HYImkfdUS+TxmmaaoHVI=",
"dev": true, "dev": true,
"optional": true "optional": true
......
...@@ -135,16 +135,39 @@ export default { ...@@ -135,16 +135,39 @@ export default {
}, },
columns1() { columns1() {
let col1 = [{ let col1 = [{
key: "userName", key: "name",
title: this.l("userName"), title: this.l1("name"),
align: "left", align: "left",
}, },
{ {
key: "status", key: "parent_Id",
title: this.l("status"), title: this.l1("parent_Id"),
align: "center", align: "left",
code: "User.base.status", parentDepart: true,
import: true,
},
{
key: "code",
title: this.l1("code"),
align: "left",
},
{
key: "location",
title: this.l1("location"),
align: "left",
location: true,
import: true,
},
{
key: "property",
title: this.l1("property"),
align: "left",
code: "department.property",
},
{
key: "creationTime",
title: this.l1("creationTime"),
align: "left",
}, },
] ]
return col1 return col1
...@@ -629,6 +652,10 @@ export default { ...@@ -629,6 +652,10 @@ export default {
key = "user" + "." + key; key = "user" + "." + key;
return i18n.t(key); return i18n.t(key);
}, },
l1(key) {
key = "DipartLocation" + "." + key;
return i18n.t(key);
},
l2(key) { l2(key) {
key = "resource" + "." + key; key = "resource" + "." + key;
return i18n.t(key); return i18n.t(key);
...@@ -645,8 +672,7 @@ export default { ...@@ -645,8 +672,7 @@ export default {
key = "product_info" + "." + key; key = "product_info" + "." + key;
return i18n.t(key); return i18n.t(key);
}, },
test() test() {
{ ViewUI.Message.error("terterer")
ViewUI.Message.error("terterer")
} }
} }
\ No newline at end of file
<template> <template>
<div class="table-contentProcess"> <div class="table-contentProcess">
<div class="table-tools"> <div class="table-tools">
<div class="table-search"> <div class="table-search">
<Form inline> <Form inline>
<FormItem> <FormItem>
<span>导入到</span> <span>导入到</span>
</FormItem> </FormItem>
<FormItem> <FormItem>
<dictionary <dictionary code="import.im.page" style="width:160px" @on-change="pageChange" v-model="pageType"></dictionary>
code="import.im.page" </FormItem>
style="width:160px" <FormItem>
@on-change="pageChange" <Button type="primary" @click="openInfoModal" :disabled="btnIm">导入</Button>
v-model="pageType" </FormItem>
></dictionary> <FormItem>
</FormItem> <div style="height:34px;overflow: hidden;padding:0">
<FormItem> <Upload action :before-upload="beforeUpload" ref="uploadfile" :format="formatList">
<Button type="primary" @click="openInfoModal" :disabled="btnIm">导入</Button> <Button icon="ios-cloud-upload-outline" @click="resetParms">重新上传</Button>
</FormItem> </Upload>
<FormItem> <Cascader :data="citys" v-show="false"></Cascader>
<div style="height:34px;overflow: hidden;padding:0"> </div>
<Upload action :before-upload="beforeUpload" ref="uploadfile" :format="formatList"> </FormItem>
<Button icon="ios-cloud-upload-outline" @click="resetParms">重新上传</Button> </Form>
</Upload> </div>
</div> <div class="btns">
</FormItem> <Form inline>
</Form> <FormItem>
</div> <Tooltip content="下载文件">
<div class="btns"> <a @click="downFile" tooltip="1111">
<Form inline> <Icon type="md-download" />
<FormItem> {{entity.file}}
<Tooltip content="下载文件"> </a>
<a @click="downFile" tooltip="1111"> </Tooltip>
<Icon type="md-download" /> </FormItem>
{{entity.file}} <FormItem>
</a> <Tooltip content="预览文件">
</Tooltip> <a class="ml10 mr10" @click="resetTable">
</FormItem> <Icon type="md-eye" />预览
<FormItem> </a>
<Tooltip content="预览文件"> </Tooltip>
<a class="ml10 mr10" @click="resetTable"> </FormItem>
<Icon type="md-eye" />预览 <FormItem>
</a> <RadioGroup v-model="excelType" type="button" @on-change="changeExcel" size="small">
</Tooltip> <Tooltip content="文件数据">
</FormItem> <Radio label="0">
<FormItem> <Icon type="ios-list-box-outline" />
<RadioGroup v-model="excelType" type="button" @on-change="changeExcel" size="small"> </Radio>
<Tooltip content="文件数据"> </Tooltip>
<Radio label="0"> <Tooltip content="粘贴Excel数据">
<Icon type="ios-list-box-outline" /> <Radio label="1">
</Radio> <Icon type="ios-copy" />
</Tooltip> </Radio>
<Tooltip content="粘贴Excel数据"> </Tooltip>
<Radio label="1"> </RadioGroup>
<Icon type="ios-copy" /> </FormItem>
</Radio> </Form>
</Tooltip> </div>
</RadioGroup>
</FormItem>
</Form>
</div>
</div> </div>
<div class="table-main" ref="main"> <div class="table-main" ref="main">
<Table <Table :border="true" :columns="columnsImport" :data="excelData" :height="tdHeightExcel" :no-data-text="noDataText" ref="table" class="tableCommon" v-if="tableImport"></Table>
:border="true" <component :is="detailExcel" ref="comExcel" @on-datalength="datalength" />
:columns="columnsImport"
:data="excelData"
:height="tdHeightExcel"
:no-data-text="noDataText"
ref="table"
class="tableCommon"
v-if="tableImport"
></Table>
<component :is="detailExcel" ref="comExcel" @on-datalength="datalength" />
</div> </div>
<FooterToolbar v-if="sheetNames.length>1&&tableImport"> <FooterToolbar v-if="sheetNames.length>1&&tableImport">
<Form inline> <Form inline>
<FormItem> <FormItem>
<Tabs :animated="false" :value="0" @on-click="sheetClick"> <Tabs :animated="false" :value="0" @on-click="sheetClick">
<TabPane :label="item" v-for="(item,index) in sheetNames" :key="index"></TabPane> <TabPane :label="item" v-for="(item,index) in sheetNames" :key="index"></TabPane>
</Tabs> </Tabs>
</FormItem> </FormItem>
</Form> </Form>
</FooterToolbar> </FooterToolbar>
<Modal v-model="infoModal" :title="titleInfo" fullscreen> <Modal v-model="infoModal" :title="titleInfo" fullscreen>
<DataGrid <DataGrid :tool="false" :page="false" :columns="colsIm" :data="dataIm" :height="tdHeightExcel+30" ref="dataImport"></DataGrid>
:tool="false" <div slot="footer">
:page="false" <Button @click="infoModal=false">关闭</Button>
:columns="colsIm" <Button type="primary" @click="importOk" v-show="imBtn">确定导入</Button>
:data="dataIm" </div>
:height="tdHeightExcel+30"
ref="dataImport"
></DataGrid>
<div slot="footer">
<Button @click="infoModal=false">关闭</Button>
<Button type="primary" @click="importOk" v-show="imBtn">确定导入</Button>
</div>
</Modal> </Modal>
</div> </div>
</template> </template>
<script> <script>
import Api from "./api"; import Api from "./api";
import BaseColums from "./baseColums"; import BaseColums from "./baseColums";
import citys from "@/libs/citys";
import XLSX from "xlsx"; import XLSX from "xlsx";
import { Switch } from "view-design"; import {
Switch
} from "view-design";
export default { export default {
name: "Edit", name: "Edit",
data() { data() {
return { return {
pageType: undefined, pageType: undefined,
tabVal: 0, tabVal: 0,
infoModal: false, infoModal: false,
entity: {}, entity: {},
downUrl: fileUrlDown, downUrl: fileUrlDown,
fileUrlPath: "", fileUrlPath: "",
disabled: false, disabled: false,
detailExcel: null, detailExcel: null,
tableImport: true, tableImport: true,
tdHeightExcel: "", tdHeightExcel: "",
excelData: [], excelData: [],
excelDataBack: [], //临时存储原始数据 excelDataBack: [], //临时存储原始数据
formatList: ["xlsx"], formatList: ["xlsx"],
columnsImport: [], columnsImport: [],
departArr: [], //部门list departArr: [], //部门list
sheetNames: [], //excel的表明 sheetNames: [], //excel的表明
workBook: {}, workBook: {},
openDatas: [], openDatas: [],
dataType: 0, dataType: 0,
//new //new
colsIm: [], colsIm: [],
dataIm: [], dataIm: [],
excelType: "0", excelType: "0",
btnIm: true, btnIm: true,
listLength: 0, listLength: 0,
titleInfo: "", titleInfo: "",
noDataText: "暂无数据", noDataText: "暂无数据",
imBtn: true, imBtn: true,
//物料管理 //物料管理
treeData: [], //物料管理左侧类别树 treeData: [], //物料管理左侧类别树
codeRuleData: [], //物料编码等信息 codeRuleData: [], //物料编码等信息
routingHeaderData: [], //工艺规程列表信息 routingHeaderData: [], //工艺规程列表信息
}; //部门管理
}, treeList: [],
props: { citys: citys(),
eid: Number, cityDatas: [], //省市县在一起
}, };
created() {
this.tdHeightExcel = window.innerHeight - 180;
//导出对列表头进行预加载start
this.$api.get(`${systemUrl}/Department/GetDepartments`).then((r) => {
this.departArr = r.result.items;
});
//导出对列表头进行预加载end
},
mounted() {
if (this.eid > 0) {
this.load(this.eid);
}
//物料加载类型数据
this.getTreeData();
this.getcodeRuleData();
//获取工艺规程信息
this.getRoutingHeaderData();
window.onresize = () => {
///浏览器窗口大小变化
return (() => {
window.screenHeight = window.innerHeight;
this.tdHeightExcel = window.screenHeight - 180;
})();
};
},
methods: {
load(v) {
Api.get({
id: v,
}).then((r) => {
this.entity = r.result || {};
});
this.dataType = 0;
this.sheetNames = [];
this.excelData = [];
this.excelDataBack = [];
Api.openExcel({
id: v,
})
.then((res) => {
if (res.success) {
this.openDatas = res.result || [];
this.dealOpenTable(0);
//获取excel sheetname
if (res.result.length > 0) {
res.result.forEach((el) => {
this.sheetNames.push(el.title);
});
}
}
})
.catch((e) => {
this.noDataText =
"文件无法解析,建议下载原文件后转换为Excel文件格式重新上传!";
});
}, },
//加载原文件列表 props: {
dealOpenTable(val) { eid: Number,
this.excelData = this.openDatas[val].dataTable;
this.excelDataBack = this.openDatas[val].dataTable;
this.listLength = this.excelData.length;
var tempCos = Object.keys(this.openDatas[val].dataTable[0]); //获取列表标题
this.columnsImport = [];
var headersNow = [];
headersNow.push({
type: "index",
width: 80,
align: "right",
title: "序号",
});
tempCos.forEach((el) => {
let headObj = {};
headObj.title = el;
headObj.key = el;
headersNow.push(headObj);
});
this.columnsImport = headersNow;
}, },
//重新处理colum created() {
loadColum(columns) { this.tdHeightExcel = window.innerHeight - 180;
let tempCol = this.$u.clone(columns); //导出对列表头进行预加载start
tempCol.unshift({ this.$api.get(`${systemUrl}/Department/GetDepartments`).then((r) => {
type: "index", this.departArr = r.result.items;
width: 80,
align: "right",
title: "序号",
});
tempCol.forEach((ele, index) => {
if (ele.key == "action") {
ele.hide = true;
}
});
this.colsIm = tempCol;
//处理原始数据和表头进行对应
let temCol = this.$u.clone(this.colsIm); //原始数据表头
let temColPage = this.$u.clone(columns); //需要显示的页面的表头
//let temData = this.$u.clone(this.excelDataBack); //原始数据
let temData = []; //原始数据
if (this.excelType == "0") {
temData = this.$u.clone(this.excelDataBack);
} else {
temData = this.$u.clone(this.$refs.comExcel.excelData);
}
let arrTitleUse = []; //使用数据字典的字段
let arrTitleUse1 = []; //使用物料编码的字段
temColPage.forEach((elCode) => {
if (elCode.code) {
arrTitleUse.push({
key: elCode.key,
code: elCode.code,
});
}
if (elCode.materialKey) {
//临时存放物料管理大类和子类列表
arrTitleUse1.push({
key: elCode.key,
code: elCode.materialKey,
});
}
});
let useData = []; //重新组织list列表数据
temData.forEach((elData, index) => {
let objTm = {};
temCol.forEach((elTitle) => {
objTm[elTitle.key] = elData[elTitle.title];
}); });
useData.push(objTm);
});
//对列表里的部门及数据字典项进行处理 //导出对列表头进行预加载end
useData.forEach((eles) => {
//如果导入文件没有departmentid,但存在departmentTitle的话,通过title获取id
if (
[
(eles.departmentTitle && eles.departmentTitle != "") ||
(eles.departmentName && eles.departmentName != ""),
] &&
(!eles.departmentId || eles.departmentId == "")
) {
this.departArr.forEach((e) => {
if (
(eles.departmentTitle && eles.departmentTitle == e.name) ||
(eles.departmentName && eles.departmentName == e.name)
) {
eles.departmentId = e.id;
}
});
} else if (
//如果导入文件没有departmentTitle,但存在departmentid的话,通过id获取departmentTitle
eles.departmentId &&
eles.departmentId + "" != "" &&
(!eles.departmentTitle || eles.departmentTitle == "") &&
(!eles.departmentName || eles.departmentName == "")
) {
this.departArr.forEach((e) => {
if (eles.departmentId && eles.departmentId == e.id) {
eles.departmentTitle = e.name;
eles.departmentName = e.name;
}
});
}
arrTitleUse.forEach((elem) => {
if (
eles[elem.key] &&
eles[elem.key] != "" &&
eles[elem.key] != null
) {
//如果数据字典项对应的DirName字段存在,通过name查询到对应的code,然后赋值
eles[elem.key] = this.$u.dirCode(
this.$store.getters.dictionaryByKey(elem.code),
eles[elem.key]
);
}
});
});
this.dataIm = useData;
}, },
//下载原excel文件 mounted() {
downFile() { if (this.eid > 0) {
let truePath = this.entity.path; this.load(this.eid);
if (truePath.length > 2) {
if (
truePath.substring(0, 7).toLowerCase() == "http://" ||
truePath.substring(0, 8).toLowerCase() == "https://"
) {
window.open(truePath, "_blank");
} else {
this.fileUrlPath = this.downUrl + this.entity.path;
window.open(this.fileUrlPath, "_blank");
} }
} //物料加载类型数据
}, this.getTreeData();
//导入excel文件 this.getcodeRuleData();
//打开传时初始化 //获取工艺规程信息
resetParms() { this.getRoutingHeaderData();
this.pageType = undefined; this.formatCity();
this.tdHeightExcel = window.innerHeight - 180; window.onresize = () => {
}, ///浏览器窗口大小变化
async beforeUpload(file) { return (() => {
//初始化 window.screenHeight = window.innerHeight;
this.sheetNames = []; this.tdHeightExcel = window.screenHeight - 180;
this.workBook = {}; })();
this.$refs.uploadfile.clearFiles(); //清除上一次上传文件列表 };
//上传成功后的读取到excel信息
this.workBook = await this.$u.readXLSX(file);
this.sheetNames = this.workBook.SheetNames; //execel里的表明
this.dealSheet(0); //默认显示第一个表
return false;
}, },
//对上传的excel表信息进行处理,不对表头进行处理 methods: {
dealSheet(index) { load(v) {
this.dataType = 1; Api.get({
this.columnsImport = []; id: v,
this.excelData = []; }).then((r) => {
this.excelDataBack = []; this.entity = r.result || {};
const sheet2JSONOpts = { });
defval: "", //给defval赋值为空的字符串 this.dataType = 0;
}; this.sheetNames = [];
var csv = XLSX.utils.sheet_to_csv( this.excelData = [];
this.workBook.Sheets[this.workBook.SheetNames[index]], this.excelDataBack = [];
sheet2JSONOpts
);
var lines = csv.split("\n"); //第一行标题 Api.openExcel({
var headers = lines[0].split(","); id: v,
var headersNow = []; })
headersNow.push({ .then((res) => {
type: "index", if (res.success) {
width: 80, this.openDatas = res.result || [];
align: "right", this.dealOpenTable(0);
title: "序号", //获取excel sheetname
}); if (res.result.length > 0) {
headers.forEach((elHead) => { res.result.forEach((el) => {
let headObj = {}; this.sheetNames.push(el.title);
headObj.title = elHead; });
headObj.key = elHead; }
headersNow.push(headObj); }
}); })
this.columnsImport = headersNow; .catch((e) => {
var result = []; this.noDataText =
for (var i = 1; i < lines.length - 1; i++) { "文件无法解析,建议下载原文件后转换为Excel文件格式重新上传!";
var obj = {}; });
var currentline = lines[i].split(","); },
for (var j = 0; j < headers.length; j++) { //加载原文件列表
obj[headers[j]] = currentline[j]; dealOpenTable(val) {
} this.excelData = this.openDatas[val].dataTable;
result.push(obj); this.excelDataBack = this.openDatas[val].dataTable;
} this.listLength = this.excelData.length;
this.excelData = result; var tempCos = Object.keys(this.openDatas[val].dataTable[0]); //获取列表标题
this.excelDataBack = result; this.columnsImport = [];
this.changeExcel(0); var headersNow = [];
}, headersNow.push({
//切换sheet表重新加载 type: "index",
sheetClick(val) { width: 80,
this.tabVal = val; align: "right",
if (this.dataType == 0) { title: "序号",
this.dealOpenTable(val); });
} else { tempCos.forEach((el) => {
this.dealSheet(val); let headObj = {};
} headObj.title = el;
if (this.pageType != undefined) { headObj.key = el;
this.pageChange(this.pageType); headersNow.push(headObj);
} });
}, this.columnsImport = headersNow;
//选择导入的模块 0:用户管理 },
pageChange(val) { //重新处理colum
this.btnIm = false; loadColum(columns) {
if (val == undefined) { let tempCol = this.$u.clone(columns);
this.btnIm = true; tempCol.unshift({
} else { type: "index",
this.btnIm = false; width: 80,
} align: "right",
}, title: "序号",
handleClose() { });
this.$emit("on-close"); tempCol.forEach((ele, index) => {
}, if (ele.key == "action") {
cancelExcel() { ele.hide = true;
this.excelData = []; }
this.excelDataBack = []; });
this.$refs.uploadfile.clearFiles(); this.colsIm = tempCol;
let parms = {
status: 1,
id: this.eid,
};
//导入中心列表数据状态更新
Api.updateimportstatus(parms).then((res) => {
if (res.success) {
this.$emit("on-ok");
}
});
this.$emit("on-close");
},
//重新加载excel //处理原始数据和表头进行对应
resetTable() { let temCol = this.$u.clone(this.colsIm); //原始数据表头
this.pageType = undefined; let temColPage = this.$u.clone(columns); //需要显示的页面的表头
this.load(this.eid); //let temData = this.$u.clone(this.excelDataBack); //原始数据
this.tdHeightExcel = window.innerHeight - 180; let temData = []; //原始数据
if (this.excelType == 1) { if (this.excelType == "0") {
this.changeExcel(0); temData = this.$u.clone(this.excelDataBack);
} } else {
}, temData = this.$u.clone(this.$refs.comExcel.excelData);
//打开导入数据格式化后的窗口 }
openInfoModal() { let arrTitleUse = []; //使用数据字典的字段
if (this.excelData.length > 0 && this.pageType != undefined) { let arrTitleUse1 = []; //使用物料编码的字段
this.imBtn = true; temColPage.forEach((elCode) => {
switch (this.pageType) { if (elCode.code) {
case 0: arrTitleUse.push({
this.loadColum(BaseColums.columns0()); key: elCode.key,
break; code: elCode.code,
case 1: });
this.loadColum(BaseColums.columns1()); }
break; if (elCode.materialKey) {
case 2: //临时存放物料管理大类和子类列表
this.loadColum(BaseColums.columns2()); arrTitleUse1.push({
break; key: elCode.key,
case 3: code: elCode.materialKey,
this.loadColum(BaseColums.columns3()); });
break; }
case 4: });
this.loadColum(BaseColums.columns4()); let useData = []; //重新组织list列表数据
break; temData.forEach((elData, index) => {
case 5: let objTm = {};
this.loadColum(BaseColums.columns5()); temCol.forEach((elTitle) => {
break; objTm[elTitle.key] = elData[elTitle.title];
case 6: });
this.loadColum(BaseColums.columns6()); useData.push(objTm);
break; });
default:
this.loadColum(BaseColums.columns0()); //对列表里的部门及数据字典项进行处理
} useData.forEach((eles) => {
this.titleInfo = //如果导入文件没有departmentid,但存在departmentTitle的话,通过title获取id
"批量导入到 【" + if (
this.$u.dirName( [
this.$store.getters.dictionaryByKey("import.im.page"), (eles.departmentTitle && eles.departmentTitle != "") ||
this.pageType (eles.departmentName && eles.departmentName != ""),
) + ] &&
"】 模块"; (!eles.departmentId || eles.departmentId == "")
this.infoModal = true; ) {
} else { this.departArr.forEach((e) => {
this.imBtn = true; if (
if (this.excelData.length == 0) { (eles.departmentTitle && eles.departmentTitle == e.name) ||
this.$Message.error( (eles.departmentName && eles.departmentName == e.name)
"表【" + this.sheetNames[this.tabVal] + "】没有可导入的数据!" ) {
); eles.departmentId = e.id;
} else if (this.pageType == undefined) { }
this.$Message.error("请选择需要批量导入到的模块!"); });
} } else if (
} //如果导入文件没有departmentTitle,但存在departmentid的话,通过id获取departmentTitle
}, eles.departmentId &&
//导入按钮操作 eles.departmentId + "" != "" &&
importOk() { (!eles.departmentTitle || eles.departmentTitle == "") &&
switch (this.pageType) { (!eles.departmentName || eles.departmentName == "")
case 0: ) {
this.importUser(); this.departArr.forEach((e) => {
break; if (eles.departmentId && eles.departmentId == e.id) {
case 2: eles.departmentTitle = e.name;
this.importResource(); eles.departmentName = e.name;
break; }
case 3: });
this.importMateriel(); }
break;
case 4: arrTitleUse.forEach((elem) => {
this.importRountingHeader(); if (
break; eles[elem.key] &&
case 5: eles[elem.key] != "" &&
this.importRountingBom(); eles[elem.key] != null
break; ) {
case 6: //如果数据字典项对应的DirName字段存在,通过name查询到对应的code,然后赋值。
this.importProductMix(); let codeArr = []
break; let keyValue = eles[elem.key]
default: if (keyValue.length > 0 && (keyValue.indexOf(',') > -1 || keyValue.indexOf(',') > -1)) { //如果对应的数据包含多个数据字典项,比如包含“,”或“,”
//this.loadColum(this.columns1); if (keyValue.indexOf(',') > -1) {
} codeArr = keyValue.split(',')
}, }
//批量导入用户 if (keyValue.indexOf > -1) {
importUser() { codeArr = keyValue.split(',')
let tempData = this.$u.clone(this.dataIm); }
let tempList = []; }
tempData.forEach((ele) => { if (codeArr.length <= 1) { //对应的数据包含一个数据字典项
let obj = { eles[elem.key] = this.$u.dirCode(
userName: ele.userName, this.$store.getters.dictionaryByKey(elem.code),
cardNo: ele.cardNo, eles[elem.key]
gender: ele.gender, );
birthday: ele.birthday, } else { //对应的数据包含多个数据字典项
degreeId: ele.degreeId, let codeInfo = ''
departmentId: ele.departmentId, codeArr.forEach(el => {
status: ele.status, codeInfo = codeInfo + this.$u.dirCode(this.$store.getters.dictionaryByKey(elem.code), el) + ",";
phone: ele.phone, })
email: ele.email, eles[elem.key] = codeInfo.substr(0, codeInfo.length - 1)
licensedToWork: ele.licensedToWork, }
positionId: ele.positionId, }
titleId: ele.titleId, });
departmentTitle: ele.departmentTitle, });
}; this.dataIm = useData;
if ( },
ele.userName && //下载原excel文件
ele.userName != "" && downFile() {
ele.cardNo && let truePath = this.entity.path;
ele.cardNo != "" && if (truePath.length > 2) {
ele.departmentId && if (
ele.departmentId != "" && truePath.substring(0, 7).toLowerCase() == "http://" ||
ele.phone && truePath.substring(0, 8).toLowerCase() == "https://"
ele.phone != "" ) {
) { window.open(truePath, "_blank");
tempList.push(obj); } else {
} this.fileUrlPath = this.downUrl + this.entity.path;
}); window.open(this.fileUrlPath, "_blank");
if (tempList.length == 0) { }
this.$Message.error("所有导入的数据均不合法!"); }
} else { },
let parms = { //导入excel文件
list: tempList, //打开传时初始化
}; resetParms() {
let url = `${systemUrl}/userimportservice/import`; this.pageType = undefined;
this.$api.post(url, parms).then((res) => { this.tdHeightExcel = window.innerHeight - 180;
if (res.success) { },
this.$Message.success( async beforeUpload(file) {
"成功批量导入用户管理成功模块 " + tempList.length + " 条数据" //初始化
this.sheetNames = [];
this.workBook = {};
this.$refs.uploadfile.clearFiles(); //清除上一次上传文件列表
//上传成功后的读取到excel信息
this.workBook = await this.$u.readXLSX(file);
this.sheetNames = this.workBook.SheetNames; //execel里的表明
this.dealSheet(0); //默认显示第一个表
return false;
},
//对上传的excel表信息进行处理,不对表头进行处理
dealSheet(index) {
this.dataType = 1;
this.columnsImport = [];
this.excelData = [];
this.excelDataBack = [];
const sheet2JSONOpts = {
defval: "", //给defval赋值为空的字符串
};
var csv = XLSX.utils.sheet_to_csv(
this.workBook.Sheets[this.workBook.SheetNames[index]],
sheet2JSONOpts
); );
this.imBtn = false;
this.cancelExcel(); var lines = csv.split("\n"); //第一行标题
} else { var headers = lines[0].split(",");
this.$Message.error("批量导入用户管理失败!"); var headersNow = [];
} headersNow.push({
}); type: "index",
} width: 80,
}, align: "right",
//批量插入制造资源 title: "序号",
importResource() { });
let tempData = this.$u.clone(this.dataIm); headers.forEach((elHead) => {
let tempList = []; let headObj = {};
tempData.forEach((ele) => { headObj.title = elHead;
let obj = { headObj.key = elHead;
nameOfResource: ele.nameOfResource ? ele.nameOfResource : "", headersNow.push(headObj);
resourceCode: ele.resourceCode ? ele.resourceCode : "", });
code: ele.code ? ele.code : "", this.columnsImport = headersNow;
totalNum: ele.totalNum ? ele.totalNum : 0, var result = [];
storeTitle: ele.storeTitle ? ele.storeTitle : "", for (var i = 1; i < lines.length - 1; i++) {
storeId: ele.storeId ? ele.storeId : null, var obj = {};
state: 1, var currentline = lines[i].split(",");
numberAvailable: ele.numberAvailable ? ele.numberAvailable : 0, for (var j = 0; j < headers.length; j++) {
json: {}, obj[headers[j]] = currentline[j];
}; }
if ( result.push(obj);
ele.nameOfResource && }
ele.nameOfResource != "" && this.excelData = result;
ele.code && this.excelDataBack = result;
ele.code != "" && this.changeExcel(0);
ele.resourceCode && },
ele.resourceCode != "" //切换sheet表重新加载
) { sheetClick(val) {
tempList.push(obj); this.tabVal = val;
} if (this.dataType == 0) {
}); this.dealOpenTable(val);
if (tempList.length == 0) {
this.$Message.error("所有导入的数据均不合法!");
} else {
let parms = {
list: tempList,
};
let url = `${resourceUrl}/resourceimportservice/import`;
this.$api
.post(url, parms)
.then((r) => {
if (r.success) {
this.$Message.success(
"成功批量导入制造资源成功模块 " + tempList.length + " 条数据"
);
this.imBtn = false;
this.cancelExcel();
} else { } else {
this.$Message.error("批量导入失败"); this.dealSheet(val);
} }
}) if (this.pageType != undefined) {
.catch((err) => { this.pageChange(this.pageType);
this.$Message.error("数据异常!"); }
}); },
} //选择导入的模块 0:用户管理
}, pageChange(val) {
//插入物料管理start this.btnIm = false;
importMateriel() { if (val == undefined) {
let tempData = this.$u.clone(this.dataIm); this.btnIm = true;
let tempList = [];
tempData.forEach((ele) => {
let obj = {
name: ele.name ? ele.name : "",
version: ele.version ? Number(ele.version) : "",
drawing: ele.drawing ? ele.drawing : "",
description: ele.description ? ele.description : "",
code: 0,
status: ele.status ? Number(ele.status) : "",
customProperties: {},
categoryId: this.getType2(ele.categoryId)
? this.getType2(ele.categoryId)
: 1, //左侧树点击的id
rootCategoryId: this.getType1(ele.rootCategoryId)
? this.getType1(ele.rootCategoryId)
: 1, //左侧树点击的数据的最顶层id
codeRuleId: this.getType3(ele.codeRuleId)
? this.getType3(ele.codeRuleId)
: 1, //类别编码名称
codeRuleType: ele.codeRuleType ? Number(ele.codeRuleType) : 1, //类别codeType
};
if (
ele.codeRuleId &&
this.getType3(ele.codeRuleId) != "" &&
ele.codeRuleType &&
ele.codeRuleType != "" &&
ele.codeRuleType != null &&
ele.rootCategoryId &&
this.getType1(ele.rootCategoryId) != "" &&
ele.name &&
ele.name != ""
) {
tempList.push(obj);
}
});
if (tempList.length == 0) {
this.$Message.error("所有导入的数据均不合法!");
} else {
let parms = {
list: tempList,
};
let url = `${material}/materialimportservice/import`;
this.$api
.post(url, parms)
.then((r) => {
if (r.success) {
this.$Message.success(
"成功批量导入物料管理模块 " + tempList.length + " 条数据"
);
this.imBtn = false;
this.cancelExcel();
} else { } else {
this.$Message.error("批量导入失败"); this.btnIm = false;
} }
}) },
.catch((err) => { handleClose() {
this.$Message.error("数据异常!"); this.$emit("on-close");
}); },
} cancelExcel() {
}, this.excelData = [];
//物料大类和子类的解析start this.excelDataBack = [];
getTreeData() { this.$refs.uploadfile.clearFiles();
let data = { let parms = {
conditions: [], status: 1,
}; id: this.eid,
this.$api.post(`${material}/category/list`, data).then((r) => { };
if (r.success) { //导入中心列表数据状态更新
this.treeData = r.result || []; Api.updateimportstatus(parms).then((res) => {
} if (res.success) {
}); this.$emit("on-ok");
}, }
getType1(val) { });
let tempTreeList = this.$u.clone(this.treeData); this.$emit("on-close");
let rootId = ""; },
if (val && val != "" && val != null) {
tempTreeList.forEach((ele) => { //重新加载excel
if (ele.upId == 0 && ele.name == val) { resetTable() {
rootId = ele.id; this.pageType = undefined;
} this.load(this.eid);
}); this.tdHeightExcel = window.innerHeight - 180;
} if (this.excelType == 1) {
return rootId; this.changeExcel(0);
}, }
getType2(val) { },
let tempTreeList = this.$u.clone(this.treeData); //打开导入数据格式化后的窗口
let childrenId = ""; openInfoModal() {
if (val && val != "" && val != null) { if (this.excelData.length > 0 && this.pageType != undefined) {
tempTreeList.forEach((ele) => { this.imBtn = true;
if (ele.upId > 0 && ele.name == val) { switch (this.pageType) {
childrenId = ele.id; case 0:
} this.loadColum(BaseColums.columns0());
}); break;
} case 1:
return childrenId; this.loadColum(BaseColums.columns1());
}, break;
//物料大类和子类的解析end case 2:
//获取编码名称等start this.loadColum(BaseColums.columns2());
getcodeRuleData() { break;
let data = { case 3:
conditions: [], this.loadColum(BaseColums.columns3());
}; break;
this.$api.post(`${material}/coderule/paged`, data).then((r) => { case 4:
if (r.success) { this.loadColum(BaseColums.columns4());
this.codeRuleData = r.result.items || []; break;
} case 5:
}); this.loadColum(BaseColums.columns5());
}, break;
getType3(val) { case 6:
let codeRuleDataList = this.$u.clone(this.codeRuleData); this.loadColum(BaseColums.columns6());
let codeRuleId = ""; break;
if (val && val != "" && val != null) { default:
codeRuleDataList.forEach((ele) => { this.loadColum(BaseColums.columns0());
if (ele.name == val) { }
codeRuleId = ele.id; this.titleInfo =
} "批量导入到 【" +
}); this.$u.dirName(
} this.$store.getters.dictionaryByKey("import.im.page"),
return codeRuleId; this.pageType
}, ) +
//获取编码名称等end "】 模块";
//插入物料管理end this.infoModal = true;
//插入工艺规程 及工艺相关start
importRountingHeader() {
let tempData = this.$u.clone(this.dataIm);
let tempList = [];
tempData.forEach((ele) => {
let obj = {
classId: null,
unicode: "",
name: ele.name ? ele.name : "",
code: ele.code ? ele.code : "",
productId: ele.productId ? ele.productId : "", //?
productName: ele.productName ? ele.productName : "", //?
productBomId: ele.productBomId ? ele.productBomId : "", //?
drawingNo: ele.drawingNo ? ele.drawingNo : "", //?
version: "",
versionid: ele.versionid ? ele.versionid : "",
author: null,
departmentId: ele.departmentId ? ele.departmentId : null, //?
departmentName: ele.departmentName ? ele.departmentName : "", //?
isMain: 1,
upId: null,
upDetailId: null,
routingType: ele.routingType ? ele.routingType : null,
status: 0,
approvalStatus: 4, //?
remark: "",
approvalStatusRemark: "",
auditUserId1: "",
auditUserId2: "",
platesnum: null,
versionnotes: "",
isSendPpm: 1,
fileId: "",
phase: ele.phase ? ele.phase : null,
isEffect: ele.isEffect ? ele.isEffect : 1,
};
if (ele.name && ele.name != "") {
tempList.push(obj);
}
});
if (tempList.length == 0) {
this.$Message.error("所有导入的数据均不合法!");
} else {
let parms = {
list: tempList,
};
let url = `${technologyUrl}routingheaderimportservice/import`;
this.$api
.post(url, parms)
.then((r) => {
if (r.success) {
this.$Message.success(
"成功批量导入工艺规程模块 " + tempList.length + " 条数据"
);
this.imBtn = false;
this.cancelExcel();
} else { } else {
this.$Message.error("批量导入失败"); this.imBtn = true;
if (this.excelData.length == 0) {
this.$Message.error(
"表【" + this.sheetNames[this.tabVal] + "】没有可导入的数据!"
);
} else if (this.pageType == undefined) {
this.$Message.error("请选择需要批量导入到的模块!");
}
} }
}) },
.catch((err) => { //导入按钮操作
this.$Message.error("数据异常!"); importOk() {
}); switch (this.pageType) {
} case 0:
}, this.importUser();
//导入工艺bom break;
importRountingBom() { case 1:
let tempData = this.$u.clone(this.dataIm); this.importDepart();
let tempList = []; break;
tempData.forEach((ele) => { case 2:
let obj = { this.importResource();
routingHeaderId: Number(this.getRoutingHeaderId(ele.routingHeaderId)), break;
routingDetailId: ele.routingDetailId case 3:
? Number(ele.routingDetailId) this.importMateriel();
: null, break;
routingDetailNo: ele.routingDetailNo case 4:
? Number(ele.routingDetailNo) this.importRountingHeader();
: null, break;
routingDetailName: ele.routingDetailName ? ele.routingDetailName : "", case 5:
routingStepId: 0, this.importRountingBom();
quantity: ele.quantity ? Number(ele.quantity) : 0, break;
materialId: ele.materialId ? ele.materialId : "", case 6:
materialType: ele.materialType ? Number(ele.materialType) : "", this.importProductMix();
materialNumber: ele.materialNumber ? ele.materialNumber : "", break;
nameMaterial: ele.nameMaterial ? ele.nameMaterial : "", default:
brand: ele.brand ? ele.brand : "", //this.loadColum(this.columns1);
specifications: ele.specifications ? ele.specifications : "", }
xhgg: ele.xhgg ? ele.xhgg : "", },
texture: ele.texture ? ele.texture : "", //批量导入用户
procurementStandards: ele.procurementStandards importUser() {
? ele.procurementStandards let tempData = this.$u.clone(this.dataIm);
: "", let tempList = [];
qualityGrade: ele.qualityGrade ? ele.qualityGrade : "", tempData.forEach((ele) => {
state: null, let obj = {
extend: "", userName: ele.userName,
remark: "", cardNo: ele.cardNo,
drawNum: ele.drawNum ? ele.drawNum : "", gender: ele.gender,
}; birthday: ele.birthday,
if (ele.routingDetailId && ele.routingDetailId != null) { degreeId: ele.degreeId,
tempList.push(obj); departmentId: ele.departmentId,
} status: ele.status,
}); phone: ele.phone,
if (tempList.length == 0) { email: ele.email,
this.$Message.error("所有导入的数据均不合法!"); licensedToWork: ele.licensedToWork,
} else { positionId: ele.positionId,
let parms = { titleId: ele.titleId,
list: tempList, departmentTitle: ele.departmentTitle,
}; };
let url = `${technologyUrl}productinfoimportservice/import`; if (
this.$api ele.userName &&
.post(url, parms) ele.userName != "" &&
.then((r) => { ele.cardNo &&
if (r.success) { ele.cardNo != "" &&
this.$Message.success( ele.departmentId &&
"成功批量导入工艺Bom模块 " + tempList.length + " 条数据" ele.departmentId != "" &&
); ele.phone &&
this.imBtn = false; ele.phone != ""
this.cancelExcel(); ) {
tempList.push(obj);
}
});
if (tempList.length == 0) {
this.$Message.error("所有导入的数据均不合法!");
} else { } else {
this.$Message.error("批量导入失败"); let parms = {
list: tempList,
};
let url = `${systemUrl}/userimportservice/import`;
this.$api.post(url, parms).then((res) => {
if (res.success) {
this.$Message.success(
"成功批量导入用户管理成功模块 " + tempList.length + " 条数据"
);
this.imBtn = false;
this.cancelExcel();
} else {
this.$Message.error("批量导入用户管理失败!");
}
});
} }
}) },
.catch((err) => { //批量插入部门
this.$Message.error("数据异常!"); importDepart() {
}); let tempData = this.$u.clone(this.dataIm);
} let tempList = [];
}, tempData.forEach((ele) => {
//获取工艺规程列表 let obj = {
getRoutingHeaderData() { parentTitle: ele.parent_Id ? ele.parent_Id : '',
let url = `${technologyUrl}routingheader/list`; name: ele.name ? ele.name : '', //部门名称
let data = { parent_Id: ele.parent_Id ? ele.parent_Id : '', //上级部门 [id]
conditions: [], code: ele.code ? ele.code : '', //部门编号
}; location: ele.location ? this.getCityValue(ele.location) : '', //省市县
isProduction: ele.property.indexOf('1') > -1 && ele.property.indexOf('2') > -1 && ele.property.indexOf('3') > -1 ? 1 : 0, //是否生产班组:1是,0否. 属性值为三个值,则是生产班组
property: ele.property ? ele.property : '' //属性
};
if (
ele.name &&
ele.name != ""
) {
tempList.push(obj);
}
});
if (tempList.length == 0) {
this.$Message.error("所有导入的数据均不合法!");
} else {
let parms = {
list: tempList,
};
let url = `${systemUrl}/departmentimport/import`;
this.$api.post(url, parms).then((res) => {
if (res.success) {
this.$Message.success(
"成功批量导入部门管理成功模块 " + tempList.length + " 条数据"
);
this.imBtn = false;
this.cancelExcel();
} else {
this.$Message.error("批量导入部门管理失败!");
}
});
}
},
//获取省市县信息
formatCity() {
let list = this.$u.clone(this.treeList);
let cityData = this.$u.clone(this.citys);
let temp = this.$u.treeToList1(cityData);
this.cityDatas = [];
temp.forEach(ele => {
let objTem = {
label: ele.__label.replace(/\s*/g, ""),
value: ele.__value
}
this.cityDatas.push(objTem)
})
},
//根据value获取当前cityname
getCityName(val) {
let cities = this.$u.clone(this.cityDatas)
let label = "";
cities.forEach(ele => {
if (val == ele.value) {
label = ele.label
}
})
return label
},
getCityValue(val) {
let cities = this.$u.clone(this.cityDatas)
let value = "";
cities.forEach(ele => {
if (val == ele.label) {
value = ele.value
}
})
return value
},
//批量插入制造资源
importResource() {
let tempData = this.$u.clone(this.dataIm);
let tempList = [];
tempData.forEach((ele) => {
let obj = {
nameOfResource: ele.nameOfResource ? ele.nameOfResource : "",
resourceCode: ele.resourceCode ? ele.resourceCode : "",
code: ele.code ? ele.code : "",
totalNum: ele.totalNum ? ele.totalNum : 0,
storeTitle: ele.storeTitle ? ele.storeTitle : "",
storeId: ele.storeId ? ele.storeId : null,
state: 1,
numberAvailable: ele.numberAvailable ? ele.numberAvailable : 0,
json: {},
};
if (
ele.nameOfResource &&
ele.nameOfResource != "" &&
ele.code &&
ele.code != "" &&
ele.resourceCode &&
ele.resourceCode != ""
) {
tempList.push(obj);
}
});
if (tempList.length == 0) {
this.$Message.error("所有导入的数据均不合法!");
} else {
let parms = {
list: tempList,
};
let url = `${resourceUrl}/resourceimportservice/import`;
this.$api
.post(url, parms)
.then((r) => {
if (r.success) {
this.$Message.success(
"成功批量导入制造资源成功模块 " + tempList.length + " 条数据"
);
this.imBtn = false;
this.cancelExcel();
} else {
this.$Message.error("批量导入失败");
}
})
.catch((err) => {
this.$Message.error("数据异常!");
});
}
},
//插入物料管理start
importMateriel() {
let tempData = this.$u.clone(this.dataIm);
let tempList = [];
tempData.forEach((ele) => {
let obj = {
name: ele.name ? ele.name : "",
version: ele.version ? Number(ele.version) : "",
drawing: ele.drawing ? ele.drawing : "",
description: ele.description ? ele.description : "",
code: 0,
status: ele.status ? Number(ele.status) : "",
customProperties: {},
categoryId: this.getType2(ele.categoryId) ?
this.getType2(ele.categoryId) : 1, //左侧树点击的id
rootCategoryId: this.getType1(ele.rootCategoryId) ?
this.getType1(ele.rootCategoryId) : 1, //左侧树点击的数据的最顶层id
codeRuleId: this.getType3(ele.codeRuleId) ?
this.getType3(ele.codeRuleId) : 1, //类别编码名称
codeRuleType: ele.codeRuleType ? Number(ele.codeRuleType) : 1, //类别codeType
};
if (
ele.codeRuleId &&
this.getType3(ele.codeRuleId) != "" &&
ele.codeRuleType &&
ele.codeRuleType != "" &&
ele.codeRuleType != null &&
ele.rootCategoryId &&
this.getType1(ele.rootCategoryId) != "" &&
ele.name &&
ele.name != ""
) {
tempList.push(obj);
}
});
if (tempList.length == 0) {
this.$Message.error("所有导入的数据均不合法!");
} else {
let parms = {
list: tempList,
};
let url = `${material}/materialimportservice/import`;
this.$api
.post(url, parms)
.then((r) => {
if (r.success) {
this.$Message.success(
"成功批量导入物料管理模块 " + tempList.length + " 条数据"
);
this.imBtn = false;
this.cancelExcel();
} else {
this.$Message.error("批量导入失败");
}
})
.catch((err) => {
this.$Message.error("数据异常!");
});
}
},
//物料大类和子类的解析start
getTreeData() {
let data = {
conditions: [],
};
this.$api.post(`${material}/category/list`, data).then((r) => {
if (r.success) {
this.treeData = r.result || [];
}
});
},
getType1(val) {
let tempTreeList = this.$u.clone(this.treeData);
let rootId = "";
if (val && val != "" && val != null) {
tempTreeList.forEach((ele) => {
if (ele.upId == 0 && ele.name == val) {
rootId = ele.id;
}
});
}
return rootId;
},
getType2(val) {
let tempTreeList = this.$u.clone(this.treeData);
let childrenId = "";
if (val && val != "" && val != null) {
tempTreeList.forEach((ele) => {
if (ele.upId > 0 && ele.name == val) {
childrenId = ele.id;
}
});
}
return childrenId;
},
//物料大类和子类的解析end
//获取编码名称等start
getcodeRuleData() {
let data = {
conditions: [],
};
this.$api.post(`${material}/coderule/paged`, data).then((r) => {
if (r.success) {
this.codeRuleData = r.result.items || [];
}
});
},
getType3(val) {
let codeRuleDataList = this.$u.clone(this.codeRuleData);
let codeRuleId = "";
if (val && val != "" && val != null) {
codeRuleDataList.forEach((ele) => {
if (ele.name == val) {
codeRuleId = ele.id;
}
});
}
return codeRuleId;
},
//获取编码名称等end
//插入物料管理end
//插入工艺规程 及工艺相关start
importRountingHeader() {
let tempData = this.$u.clone(this.dataIm);
let tempList = [];
tempData.forEach((ele) => {
let obj = {
classId: null,
unicode: "",
name: ele.name ? ele.name : "",
code: ele.code ? ele.code : "",
productId: ele.productId ? ele.productId : "", //?
productName: ele.productName ? ele.productName : "", //?
productBomId: ele.productBomId ? ele.productBomId : "", //?
drawingNo: ele.drawingNo ? ele.drawingNo : "", //?
version: "",
versionid: ele.versionid ? ele.versionid : "",
author: null,
departmentId: ele.departmentId ? ele.departmentId : null, //?
departmentName: ele.departmentName ? ele.departmentName : "", //?
isMain: 1,
upId: null,
upDetailId: null,
routingType: ele.routingType ? ele.routingType : null,
status: 0,
approvalStatus: 4, //?
remark: "",
approvalStatusRemark: "",
auditUserId1: "",
auditUserId2: "",
platesnum: null,
versionnotes: "",
isSendPpm: 1,
fileId: "",
phase: ele.phase ? ele.phase : null,
isEffect: ele.isEffect ? ele.isEffect : 1,
};
if (ele.name && ele.name != "") {
tempList.push(obj);
}
});
if (tempList.length == 0) {
this.$Message.error("所有导入的数据均不合法!");
} else {
let parms = {
list: tempList,
};
let url = `${technologyUrl}routingheaderimportservice/import`;
this.$api
.post(url, parms)
.then((r) => {
if (r.success) {
this.$Message.success(
"成功批量导入工艺规程模块 " + tempList.length + " 条数据"
);
this.imBtn = false;
this.cancelExcel();
} else {
this.$Message.error("批量导入失败");
}
})
.catch((err) => {
this.$Message.error("数据异常!");
});
}
},
//导入工艺bom
importRountingBom() {
let tempData = this.$u.clone(this.dataIm);
let tempList = [];
tempData.forEach((ele) => {
let obj = {
routingHeaderId: Number(this.getRoutingHeaderId(ele.routingHeaderId)),
routingDetailId: ele.routingDetailId ?
Number(ele.routingDetailId) : null,
routingDetailNo: ele.routingDetailNo ?
Number(ele.routingDetailNo) : null,
routingDetailName: ele.routingDetailName ? ele.routingDetailName : "",
routingStepId: 0,
quantity: ele.quantity ? Number(ele.quantity) : 0,
materialId: ele.materialId ? ele.materialId : "",
materialType: ele.materialType ? Number(ele.materialType) : "",
materialNumber: ele.materialNumber ? ele.materialNumber : "",
nameMaterial: ele.nameMaterial ? ele.nameMaterial : "",
brand: ele.brand ? ele.brand : "",
specifications: ele.specifications ? ele.specifications : "",
xhgg: ele.xhgg ? ele.xhgg : "",
texture: ele.texture ? ele.texture : "",
procurementStandards: ele.procurementStandards ?
ele.procurementStandards : "",
qualityGrade: ele.qualityGrade ? ele.qualityGrade : "",
state: null,
extend: "",
remark: "",
drawNum: ele.drawNum ? ele.drawNum : "",
};
if (ele.routingDetailId && ele.routingDetailId != null) {
tempList.push(obj);
}
});
if (tempList.length == 0) {
this.$Message.error("所有导入的数据均不合法!");
} else {
let parms = {
list: tempList,
};
let url = `${technologyUrl}productinfoimportservice/import`;
this.$api
.post(url, parms)
.then((r) => {
if (r.success) {
this.$Message.success(
"成功批量导入工艺Bom模块 " + tempList.length + " 条数据"
);
this.imBtn = false;
this.cancelExcel();
} else {
this.$Message.error("批量导入失败");
}
})
.catch((err) => {
this.$Message.error("数据异常!");
});
}
},
//获取工艺规程列表
getRoutingHeaderData() {
let url = `${technologyUrl}routingheader/list`;
let data = {
conditions: [],
};
this.$api.post(url, data).then((r) => { this.$api.post(url, data).then((r) => {
if (r.success) { if (r.success) {
this.routingHeaderData = r.result || []; this.routingHeaderData = r.result || [];
} }
}); });
}, },
//根据工艺规程ID获得name //根据工艺规程ID获得name
getRoutingHeaderId(val) { getRoutingHeaderId(val) {
let routingHeaderDataList = this.$u.clone(this.routingHeaderData); let routingHeaderDataList = this.$u.clone(this.routingHeaderData);
let routingHeaderId = 0; let routingHeaderId = 0;
routingHeaderDataList.forEach((ele) => { routingHeaderDataList.forEach((ele) => {
if (ele.name == val) { if (ele.name == val) {
routingHeaderId = ele.id; routingHeaderId = ele.id;
} }
}); });
return routingHeaderId; return routingHeaderId;
}, },
//插入工艺规程 及工艺相关end //插入工艺规程 及工艺相关end
//插入产品管理start //插入产品管理start
importProductMix() { importProductMix() {
let tempData = this.$u.clone(this.dataIm); let tempData = this.$u.clone(this.dataIm);
let tempList = []; let tempList = [];
tempData.forEach((ele) => { tempData.forEach((ele) => {
let obj = { let obj = {
mmcode: ele.mmcode ? ele.mmcode : "", mmcode: ele.mmcode ? ele.mmcode : "",
drawingNo: ele.drawingNo ? ele.drawingNo : "", drawingNo: ele.drawingNo ? ele.drawingNo : "",
name: ele.name ? ele.name : "", name: ele.name ? ele.name : "",
type: ele.type ? ele.type : 1, type: ele.type ? ele.type : 1,
madeCompany: ele.madeCompany ? ele.madeCompany : null, madeCompany: ele.madeCompany ? ele.madeCompany : null,
madeCompanyTitle: ele.madeCompanyTitle ? ele.madeCompanyTitle : "", madeCompanyTitle: ele.madeCompanyTitle ? ele.madeCompanyTitle : "",
version: ele.version ? ele.version : 0, version: ele.version ? ele.version : 0,
productUrl: "", productUrl: "",
productUrlList: "", productUrlList: "",
levelId: ele.levelId ? ele.levelId : null, levelId: ele.levelId ? ele.levelId : null,
levelTitle: ele.levelTitle ? ele.levelTitle : "", levelTitle: ele.levelTitle ? ele.levelTitle : "",
materialId: ele.materialId ? ele.materialId : "", materialId: ele.materialId ? ele.materialId : "",
}; };
if (ele.name && ele.name != "") { if (ele.name && ele.name != "") {
tempList.push(obj); tempList.push(obj);
} }
}); });
if (tempList.length == 0) { if (tempList.length == 0) {
this.$Message.error("所有导入的数据均不合法!"); this.$Message.error("所有导入的数据均不合法!");
} else {
let parms = {
list: tempList,
};
let url = `${technologyUrl}productinfoimportservice/import`;
this.$api
.post(url, parms)
.then((r) => {
if (r.success) {
this.$Message.success(
"成功批量导入产品管理模块 " + tempList.length + " 条数据"
);
this.imBtn = false;
this.cancelExcel();
} else { } else {
this.$Message.error("批量导入失败"); let parms = {
list: tempList,
};
let url = `${technologyUrl}productinfoimportservice/import`;
this.$api
.post(url, parms)
.then((r) => {
if (r.success) {
this.$Message.success(
"成功批量导入产品管理模块 " + tempList.length + " 条数据"
);
this.imBtn = false;
this.cancelExcel();
} else {
this.$Message.error("批量导入失败");
}
})
.catch((err) => {
this.$Message.error("数据异常!");
});
} }
}) },
.catch((err) => { //插入产品管理end
this.$Message.error("数据异常!"); //切换列表和excel按钮
}); changeExcel(val) {
} if (val == 1) {
}, this.tableImport = false;
//插入产品管理end this.detailExcel = () => import("./detailExcel");
//切换列表和excel按钮 this.pageType = undefined;
changeExcel(val) { this.excelType = "1";
if (val == 1) { } else {
this.tableImport = false; this.detailExcel = null;
this.detailExcel = () => import("./detailExcel"); this.tableImport = true;
this.pageType = undefined; this.pageType = undefined;
this.excelType = "1"; this.excelType = "0";
} else { this.listLength = this.excelData.length;
this.detailExcel = null; }
this.tableImport = true; },
this.pageType = undefined; datalength(val) {
this.excelType = "0"; this.listLength = val;
this.listLength = this.excelData.length; },
}
},
datalength(val) {
this.listLength = val;
}, },
}, watch: {
watch: { eid(v) {
eid(v) { if (v != 0) {
if (v != 0) { this.load(v);
this.load(v); }
} },
}, },
},
}; };
</script> </script>
<style lang="less"> <style lang="less">
@import "../../assets/css/custom.less"; @import "../../assets/css/custom.less";
.table-contentProcess { .table-contentProcess {
position: relative; position: relative;
height: 100%; height: 100%;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
.tip { .tip {
display: inline; display: inline;
} }
form { form {
display: inline-block; display: inline-block;
.ivu-form-item { .ivu-form-item {
margin: 0; margin: 0;
vertical-align: middle; vertical-align: middle;
}
} }
}
.table-main { .table-main {
width: 100%; width: 100%;
text-align: left; text-align: left;
padding: 0; padding: 0;
display: block; display: block;
overflow-y: auto; overflow-y: auto;
flex-grow: 1; flex-grow: 1;
tr td .ivu-table-cell {
padding: 0 5px;
}
tr td .ivu-table-cell { overflow-x: hidden;
padding: 0 5px;
} }
overflow-x: hidden; .table-tools {
} display: flex;
line-height: 50px;
background: @right-header-bg;
.table-tools { .table-search {
display: flex; flex-grow: 1;
line-height: 50px; }
background: @right-header-bg;
.table-search {
flex-grow: 1;
}
.btns { .btns {
min-width: 200px; min-width: 200px;
text-align: right; text-align: right;
}
} }
}
.table-footer { .table-footer {
line-height: 45px; line-height: 45px;
background: #f5f5f5; background: #f5f5f5;
} }
.ivu-footer-toolbar { .ivu-footer-toolbar {
text-align: left; text-align: left;
// background: #f5f5f5; // background: #f5f5f5;
.ivu-footer-toolbar-right { .ivu-footer-toolbar-right {
float: left; float: left;
}
} }
}
} }
</style> </style>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment