Commit 44632f2d authored by 周远喜's avatar 周远喜

ok

parent 576f0669
<template> <template>
<div class="table-content"> <div class="table-content1">
<div class="table-tools"> <div class="table-tools">
<div class="table-search"> <div class="table-search">
<slot name="easySearch"></slot> <slot name="easySearch"></slot>
...@@ -46,11 +46,6 @@ ...@@ -46,11 +46,6 @@
</th> </th>
</tr> </tr>
</thead> </thead>
</table>
</div>
<div class="table-body">
<table>
<tbody> <tbody>
<tr <tr
v-for="(item, index) in trs" v-for="(item, index) in trs"
...@@ -784,7 +779,7 @@ export default { ...@@ -784,7 +779,7 @@ export default {
@table_line_height: 50px; @table_line_height: 50px;
@table_hover: #f2f8fe; @table_hover: #f2f8fe;
@table_border: #accef7; @table_border: #accef7;
.table-content { .table-content1 {
position: relative; position: relative;
height: 100%; height: 100%;
display: flex; display: flex;
......
<template>
<div class="table-content">
<div class="table-tools" v-if="tool">
<div class="table-search">
<slot name="easySearch" v-if="easy">
<Form inline>
<FormItem>
<Input search enter-button :placeholder="placeholder" @on-search="easySearch" v-width="300" v-model="keys" />
</FormItem>
<FormItem>
<Button v-if="high" @click="modalSearch = true" type="text">
<Icon type="md-search" />高级
</Button>
</FormItem>
</Form>
</slot>
</div>
<div class="searchBack">
<slot name="searchBack"></slot>
</div>
<div class="btns">
<slot name="buttons"></slot>
<Button @click="export2Excel" v-if="exportTitle.length > 0">导出</Button>
<Button v-if="set && type == 'table'" @click="config = !config">
<Icon type="md-build" title="列设置" />
</Button>
</div>
</div>
<div class="table-main" ref="main">
<Row v-if="type == 'card'" :gutter="40">
<Col :span="span" v-for="(row, i) in list" :key="i">
<slot name="card" :row="row">
<span>{{ row.id }}</span>
</slot>
</Col>
<Col v-if="list.length == 0" span="24" class="zan-wu">
<h4>暂无数据</h4>
</Col>
</Row>
<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" @on-sort-change="sortChange" :row-key="rowKey" stripe></Table>
</div>
<div class="table-footer">
<slot name="footer"></slot>
<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" />
</div>
<Modal v-if="high" v-model="modalSearch" title="高级搜索" draggable width="800" ref="search">
<slot name="searchForm"></slot>
<div slot="footer">
<Button @click="modalSearch = false" style="margin-left: 20px">取消</Button>
<Button @click="complexSearch" type="primary" style="margin-left: 10px">查询</Button>
</div>
</Modal>
<Drawer title="列设置" v-if="set" v-model="config" :scrollable="true" placement="left" :mask="false">
<div slot="header">
列设置
<a @click="undoConfig" class="ml50">
<Icon type="md-refresh" title="恢复初始设置" />
</a>
</div>
<ul class="table-columns">
<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 }">
<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>
<FooterToolbar v-if="batch" v-show="footerToolbar" class="ftball">
<div class="tip">已选{{ selectItems.length }}</div>
<slot name="batch"></slot>
<Button @click="cancelBatch">取消</Button>
</FooterToolbar>
</div>
</template>
<script>
import ColumnSlot from "./treeGrid/columnSolt";
export default {
name: "DataGrid",
components: {
ColumnSlot
},
data() {
return {
keys: "",
selectItems: [],
footerToolbar: false,
modalSearch: false,
search: {
pageIndex: 1,
pageSize: 20,
sortBy: this.conditions.sortBy ? this.conditions.sortBy : 'id',
isDesc: true,
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
};
},
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 {
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: "",
},
},
provide() {
return {
tableRoot: this.slots,
};
},
created() {
this.initColumns();
},
mounted() {
if (this.data && this.data.length > 0) {
this.list = this.data;
return;
}
this.keys = "";
this.intY();
if (this.lazy == true) {
return;
}
if (this.userId > 0 && this.set) {
this.loadUserConfig();
} else {
this.easySearch();
}
if (this.height === 0) {
this.$nextTick(() => {
this.tableHeight = this.$refs.main.offsetHeight;
if (this.tableHeight < 300) {
this.tableHeight =
window.screen.availHeight - this.$refs.main.offsetTop - 200;
}
window.onresize = () => {
///浏览器窗口大小变化
return (() => {
if (this.$refs.main && this.$refs.main.offsetHeight) {
this.tableHeight = this.$refs.main.offsetHeight;
if (this.tableHeight < 300) {
this.tableHeight =
window.screen.availHeight - this.$refs.main.offsetTop - 150;
}
}
})();
};
});
} else {
this.tableHeight = this.height;
}
//注册拖拽事件。
this.$dragging.$on("dragend", (e) => {
this.saveUserconfig();
});
//物料加载类型数据
this.getTreeData();
this.getcodeRuleData();
this.getRoutingHeaderData();
this.getAllUser(); //获取所有用户
},
methods: {
//列初始化 slot 支持;
slots() {
return this.$scopedSlots;
},
initColumns() {
this.columns.forEach((u) => {
if (!u.hide) {
u.hide = false;
}
});
var items = this.$u.clone(this.columns);
// var soct=this.$scopedSlots;
// // console.warn("that.$scopedSlots()",soct["action"]());
// items.forEach((u) => {
// if (u.slot) {
// u.render = (h, params) => {
// return h(
// "span",
// // soct[u.slot]({
// // row: params.row,
// // column: params.column,
// // index: params.index,
// // })
// params.row.id
// );
// };
// delete u.slot;
// }
// });
this.columnsCur = items;
// console.log("cur", items,this.columnsCur);
},
//数据加载
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;
});
}
},
columnInit() {
if (this.userConfig) {
var curColumns = [];
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 = {
conditions: [{
fieldName: "creatorUserId",
fieldValue: this.userId,
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.configLoad = true;
}
});
},
sortChange(column, key, order) {
this.search.sortBy = key;
this.search.isDesc = order == "desc";
this.search.pageIndex = 1;
this.load();
},
saveUserconfig() {
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);
}
},
//展开
expand(row, status) {
this.$emit("on-expand", row, status);
},
//拖拽
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() {
//列设置恢复初始化
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));
}
});
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,
});
}
}
});
}
this.search.pageIndex = 1;
this.search.conditions = where;
this.load();
},
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: 100000,
})
.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);
});
}
});
},
getUserName(id) {
let name = "";
this.allUser.forEach((ele) => {
if (id == ele.userId) {
name = ele.name;
}
});
return name;
},
//批量取消
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)) {
v = v.join(",");
}
if (!this.$u.isNull(v)) {
where.push({
fieldName: u,
fieldValue: v,
conditionalType: op,
});
}
}
});
}
let searchs = {
pageIndex: 1,
conditions: where,
pageSize: 1000,
};
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
getTreeData() {
let data = {
conditions: [],
};
this.$api.post(`${material}/category/list`, data).then((r) => {
this.treeData = r.result;
});
},
getType1(val) {
let tempTreeList = this.$u.clone(this.treeData);
let rootName = "";
tempTreeList.forEach((ele) => {
if (ele.upId == 0 && ele.id == val) {
rootName = ele.name;
}
});
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", {
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>
<style lang="less">
@import "../../assets/css/custom.less";
.table-content {
position: relative;
height: 100%;
display: flex;
flex-direction: column;
.tip {
display: inline;
}
form {
display: inline-block;
.ivu-form-item {
margin: 0;
vertical-align: middle;
}
}
.table-main {
width: 100%;
text-align: left;
padding: 0;
display: block;
overflow-y: auto;
flex-grow: 1;
tr td .ivu-table-cell {
padding: 0 5px;
}
overflow-x: hidden;
.zan-wu {
height: 600px;
line-height: 600px;
text-align: center;
}
}
.table-tools {
display: flex;
line-height: 50px;
background: @right-header-bg;
.table-search {
flex-grow: 1;
}
.btns {
min-width: 200px;
text-align: right;
}
}
.table-footer {
line-height: 45px;
}
.ivu-footer-toolbar {
text-align: left;
background: rgba(0, 0, 0, 0.7);
color: #fff;
}
}
.table-columns {
max-height: calc(100% - 50px);
overflow: auto;
li {
list-style: none;
line-height: 40px;
cursor: move;
border-bottom: 1px dotted #249e91;
color: #249e91;
span {
cursor: pointer;
}
.mr10 {
cursor: pointer;
}
.move {
float: right;
margin: 10px 10px 0 0;
cursor: move;
}
.dis {
color: #aaa;
}
}
}
.searchBack {
display: inline;
margin-left: 20px;
button {
margin-left: 10px;
}
a {
margin-left: 20px;
color: #2680eb;
}
a:hover {
color: #249e91;
}
}
</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