Commit 47b9c631 authored by renjintao's avatar renjintao

dataGrid

parent 7e16e1e1
<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: [], //工艺规程
}; };
},
},
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();
}, },
//展开 methods: {
expand(row, status) { //数据加载
this.$emit("on-expand", row, status); load() {
}, if (this.action) {
//拖拽 //条件初始化处理。
onDragDrop(a, b) { if (this.initsearch) {
this.$emit("on-drag-drop", a, b); 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);
},
//批量取消
cancelBatch() {
this.footerToolbar = false;
this.$refs.table.selectAll(false);
},
tHeader.push(el.title); //导出excel
filterVal.push(el.key); export2Excel() {
} //当前显示数据
}); var where = [];
list.forEach((e) => { var conditions = this.searchConditions;
//给导出数据增加数据字典对应的name if (conditions) {
tempCol.forEach((ele) => { Object.keys(conditions).forEach((u) => {
e[ele.key] = this.$u.dirName( let v = conditions[u].value;
this.$store.getters.dictionaryByKey(ele.code), let op = conditions[u].op;
e[ele.key] if (!this.$u.isNull(v)) {
); if (op == "Range") {
}); let times = [];
//导出数据增加对应的物料管理信息 code: 1【rootCategoryId 大类】 2【categoryId 大类】 3【codeRuleId 编码名称】 v.map((u) => {
tempCol1.forEach((elcol1) => { if (!this.$u.isNull(u)) {
if (elcol1.code == 1) { times.push(this.$u.toTime(u));
e[elcol1.key] = this.getType1(e[elcol1.key]); }
} else if (elcol1.code == 2) { });
e[elcol1.key] = this.getType2(e[elcol1.key]); v = times.join(",");
} else if (elcol1.code == 3) { } else if (op.indexOf("In") > -1 && Array.isArray(v)) {
e[elcol1.key] = this.getType3(e[elcol1.key]); v = v.join(",");
}
if (!this.$u.isNull(v)) {
where.push({
fieldName: u,
fieldValue: v,
conditionalType: op,
});
}
}
});
} }
}); let searchs = {
//导出工艺规程相关转换表头信息 pageIndex: 1,
tempCol2.forEach((elcol2) => { conditions: where,
if (elcol2.code == 1) { pageSize: 1000,
e[elcol2.key] = this.getRoutingHeaderName(e[elcol2.key]); };
} 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 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,
}); //临时存放工艺规程相关转换
}
let nowDate = this.$u.getNowTime(); //年月日时分秒yyyyMMddhhmmss tHeader.push(el.title);
//获取导出数据结束 filterVal.push(el.key);
this.$u.outExcel( }
this.exportTitle + "(" + nowDate + ")", });
tHeader, list.forEach((e) => {
filterVal, //给导出数据增加数据字典对应的name
list // tempCol.forEach((ele) => {
); // e[ele.key] = this.$u.dirName(
}); // this.$store.getters.dictionaryByKey(ele.code),
}, // e[ele.key]
//物料大类和子类的解析start // );
getTreeData() { // });
let data = { tempCol.forEach((elem) => {
conditions: [], if (
}; e[elem.key] &&
this.$api.post(`${material}/category/list`, data).then((r) => { e[elem.key] != "" &&
this.treeData = r.result; e[elem.key] != null
}); ) {
}, //如果数据字典项对应的DirName字段存在,通过name查询到对应的code,然后赋值。
getType1(val) { let codeArr = []
let tempTreeList = this.$u.clone(this.treeData); let keyValue = e[elem.key]
let rootName = ""; if (keyValue.length > 0 && (keyValue.indexOf(',') > -1 || keyValue.indexOf(',') > -1)) { //如果对应的数据包含多个数据字典项,比如包含“,”或“,”
tempTreeList.forEach((ele) => { if (keyValue.indexOf(',') > -1) {
if (ele.upId == 0 && ele.id == val) { codeArr = keyValue.split(',')
rootName = ele.name; }
} if (keyValue.indexOf > -1) {
}); codeArr = keyValue.split(',')
return rootName; }
}, }
getType2(val) { if (codeArr.length <= 1) { //对应的数据包含一个数据字典项
let tempTreeList = this.$u.clone(this.treeData); e[elem.key] = this.$u.dirName(
let childrenName = ""; this.$store.getters.dictionaryByKey(elem.code),
tempTreeList.forEach((ele) => { e[elem.key]
if (ele.upId > 0 && ele.id == val) { );
childrenName = ele.name; } else { //对应的数据包含多个数据字典项
} let codeInfo = ''
}); codeArr.forEach(el => {
return childrenName; codeInfo = codeInfo + this.$u.dirName(this.$store.getters.dictionaryByKey(elem.code), el) + ",";
}, })
//获取编码名称 e[elem.key] = codeInfo.substr(0, codeInfo.length - 1)
getcodeRuleData() { }
let data = { }
conditions: [], });
}; //导出数据增加对应的物料管理信息 code: 1【rootCategoryId 大类】 2【categoryId 大类】 3【codeRuleId 编码名称】
this.$api.post(`${material}/coderule/paged`, data).then((r) => { tempCol1.forEach((elcol1) => {
if (r.success) { if (elcol1.code == 1) {
this.codeRuleData = r.result.items || []; 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) {
getType3(val) { e[elcol1.key] = this.getType3(e[elcol1.key]);
let codeRuleDataList = this.$u.clone(this.codeRuleData); }
let codeRuleName = ""; });
codeRuleDataList.forEach((ele) => { //导出工艺规程相关转换表头信息
if (ele.id == val) { tempCol2.forEach((elcol2) => {
codeRuleName = ele.name; if (elcol2.code == 1) {
} e[elcol2.key] = this.getRoutingHeaderName(e[elcol2.key]);
}); }
return codeRuleName; });
}, });
//物料大类和子类的解析end
//工艺规程的解析start let nowDate = this.$u.getNowTime(); //年月日时分秒yyyyMMddhhmmss
//获取工艺规程名称 //获取导出数据结束
getRoutingHeaderData() { this.$u.outExcel(
let data = { this.exportTitle + "(" + nowDate + ")",
conditions: [], tHeader,
}; filterVal,
this.$api.post(`${technologyUrl}routingheader/list`, data).then((r) => { list
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] + "",
},
}); });
}; },
} //物料大类和子类的解析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>
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