antd 表格识别data中的"\n"style="white-space:pre-line;"
总条数
:show-total="total => `总条数 ${ipagination.total} `"
表格某列悬停弹窗
<span slot="action1"
slot-scope="text, record">
<a @mouseover="fastView(record)">
<a-popover title="详情"
placement="left">
<template slot="content">
<div style="width:1100px">
<ReportTable :id="recorderNO"></ReportTable>
</div>
</template>
<span>子项目概况</span>
</a-popover>
</a>
</span>
编辑表格
<template v-for="col in ['proportion', 'projectProgress', 'nodeRequirements','reply','bigEvents','startMeet','coordination','reviewMeetTime','reviewMeetIdea','reviewMeet']"
:slot="col"
slot-scope="text, record, index">
<div :key="col">
<div v-if="record.editable">
<a-tooltip>
<template slot="title">
{{text}}
</template>
<a-textarea v-if="record.editable&&(col!='proportion')"
style="margin: -5px 0"
:value="text"
@change="e => handleChange(e.target.value, record.key, col)" />
<a-input v-if="record.editable&&(col=='proportion')"
style="margin: -5px 0"
max='100'
min='0'
type="number"
oninput="if(!/^[0-9]+$/.test(value)) value=value.replace(/\D/g,'');if(value>100)value=100;if(value<0)value=null"
:value="text"
@change="e => handleChange(e.target.value, record.key, col)" />
</a-tooltip>
</div>
<template v-else>
{{ text }}
</template>
</div>
</template>
表格多列悬停
<template v-for="col in ['totalContractAmout', 'totalPayAmout', 'totalSettleAmout','totalArrearAmout']"
:slot="col"
slot-scope="text, record, index">
<div :key="col">
<span @mouseover="fastView(record)">
<a-popover title="详情"
placement="left">
<template slot="content">
<div style="width:100px">
<ReportTable></ReportTable>
</div>
</template>
<span>{{text}}</span>
</a-popover>
</span>
</div>
</template>
表格编辑
<template>
<a-card>
<div class="table-page-search-wrapper">
<a-form layout="inline"
@keyup.enter.native="searchQuery">
<a-row :gutter="24">
<a-col :xl="6"
:lg="7"
:md="8"
:sm="24">
<a-form-item label="项目名称">
<a-input placeholder="请输入项目名称"
v-model="queryParam.subProjectName"></a-input>
</a-form-item>
</a-col>
<a-col :xl="6"
:lg="7"
:md="8"
:sm="24">
<a-form-item label="项目编号">
<a-input placeholder="请输入项目编号"
v-model="queryParam.subProjectNo"></a-input>
</a-form-item>
</a-col>
<a-col :xl="6"
:lg="7"
:md="8"
:sm="24">
<span style="float: left;overflow: hidden;"
class="table-page-search-submitButtons">
<a-button type="primary"
@click="searchQuery"
icon="search">查询</a-button>
<a-button type="primary"
@click="searchReset"
icon="reload"
style="margin-left: 8px">重置</a-button>
</span>
</a-col>
</a-row>
</a-form>
</div>
<a-table :show-total="total => `总条数 ${ipagination.total} `"
:pagination="ipagination"
:columns="columns"
:data-source="data"
@change="handleTableChange"
:scroll="{ x: 2000 }"
bordered>
<template v-for="col in ['plan', 'finish', 'problem','help','nextPlan','bigEvents','proportion','projectProgress']"
:slot="col"
slot-scope="text, record, index">
<div :key="col">
<div v-if="record.editable">
<a-tooltip>
<template slot="title">
{{text}}
</template>
<a-textarea v-if="record.editable&&(col!='proportion')"
style="margin: -5px 0"
:value="text"
@change="e => handleChange(e.target.value, record.key, col)" />
<a-input v-if="record.editable&&(col=='proportion')"
style="margin: -5px 0"
type="number"
max='100'
min='0'
oninput="if(!/^[0-9]+$/.test(value)) value=value.replace(/\D/g,'');if(value>100)value=100;if(value<0)value=null"
:value="text"
@change="e => handleChange(e.target.value, record.key, col)" />
</a-tooltip>
</div>
<template v-else>
{{ text }}
</template>
</div>
</template>
<template slot="action"
slot-scope="text, record, index">
<div class="editable-row-operations">
<span v-if="record.editable">
<a @click="() => save(record.key)">保存</a>
<a-popconfirm title="确定取消?"
@confirm="() => cancel(record.key)">
<a>取消</a>
</a-popconfirm>
</span>
<span v-else>
<a :disabled="editingKey !== ''"
@click="() => edit(record.key)">编辑</a>
</span>
</div>
</template>
</a-table>
</a-card>
</template>
<script>
import { getAction, postAction } from '@/api/manage'
import { filterObj } from '@/utils/util'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
const columns = [
{
title: '#',
dataIndex: '',
key: 'rowIndex',
width: 50,
align: "center",
customRender: function (t, r, index) {
return parseInt(index) + 1;
}
},
{
title: '项目名称',
align: "center",
width: 100,
dataIndex: 'projectName'
},
{
title: '项目编号',
align: "center",
width: 100,
dataIndex: 'zsxmProjectNo'
},
{
title: '负责人',
align: "center",
width: 100,
dataIndex: 'personName'
},
{
title: '本月生产计划',
align: "center",
width: 100,
dataIndex: 'plan',
scopedSlots: { customRender: 'plan' },
},
{
title: '本月计划完成情况',
align: "center",
width: 100,
dataIndex: 'finish',
scopedSlots: { customRender: 'finish' },
},
{
title: '本月存在的问题及原因',
align: "center",
width: 100,
dataIndex: 'problem',
scopedSlots: { customRender: 'problem' },
},
{
title: '本月需要公司层面协调解决的问题',
align: "center",
width: 100,
dataIndex: 'help',
scopedSlots: { customRender: 'help' },
},
{
title: '下月生产计划',
align: "center",
width: 100,
dataIndex: 'nextPlan',
scopedSlots: { customRender: 'nextPlan' },
},
{
title: '项目进度',
align: "center",
children: [
{
title: "完成总任务的占比(%)",
align: "center",
width: 100,
dataIndex: 'proportion',
scopedSlots: { customRender: 'proportion' },
},
{
title: "进度说明",
align: "center",
width: 100,
dataIndex: 'projectProgress',
scopedSlots: { customRender: 'projectProgress' },
},
]
},
{
title: '项目大事记',
align: "center",
width: 100,
dataIndex: 'bigEvents',
scopedSlots: { customRender: 'bigEvents' },
},
{
title: '操作',
key: 'action',
align: "center",
width: 100,
scopedSlots: { customRender: 'action' },
},
];
const data = [];
export default {
mixins: [JeecgListMixin],
data () {
return {
data,
columns,
editingKey: '',
ipagination: {
current: 1,
pageSize: 10,
pageSizeOptions: ['10', '20', '30'],
showTotal: (total, range) => {
return range[0] + "-" + range[1] + " 共" + total + "条"
},
showQuickJumper: true,
showSizeChanger: true,
total: 0
},
isorter: {
column: 'createTime',
order: 'desc',
},
url: {
list: "/pomel/person/userMouthPerson",
},
mounth: "",
cacheData: "",
queryParam: {}
};
},
created () {
this.loadData();
},
methods: {
getQueryParams () {
var param = Object.assign({}, this.queryParam, this.isorter);
param.field = this.getQueryField();
param.pageNo = this.ipagination.current;
param.pageSize = this.ipagination.pageSize;
param.zsx91110xmzt014 = "进行中"
return filterObj(param);
},
getQueryField () {
//TODO 字段权限控制
},
loadData (arg) {
//加载数据 若传入参数1则加载第一页的内容
if (arg === 1) {
this.ipagination.current = 1;
}
debugger
var param = this.getQueryParams();//查询条件
postAction(this.url.list, param).then((res) => {
debugger
if (res.success) {
this.mounth = res.result[0].mounth;
debugger
for (let i = 0; i < res.result.length; i++) {
res.result[i].key = i
}
this.data = res.result;
this.ipagination.total = res.result.length;
}
}).catch((err) => {
console.log(err)
})
},
handleChange (value, key, column) {
const newData = [...this.data];
const target = newData.find(item => key === item.key);
if (target) {
target[column] = value;
this.data = newData;
}
},
handleTableChange (pagination, filters, sorter) {
//分页、排序、筛选变化时触发
console.log(sorter);
//TODO 筛选
if (Object.keys(sorter).length > 0) {
this.isorter.column = sorter.field;
this.isorter.order = "ascend" == sorter.order ? "asc" : "desc"
}
this.ipagination = pagination;
this.loadData();
},
edit (key) {
const newData = [...this.data];
const target = newData.find(item => key === item.key);
this.editingKey = key;
if (target) {
target.editable = true;
this.data = newData;
}
},
save (key) {
debugger
const newData = [...this.data];
this.cacheData = this.data.map(item => ({ ...item }));
const newCacheData = [...this.cacheData];
const target = newData.find(item => key === item.key);
const targetCache = newCacheData.find(item => key === item.key);
if (target && targetCache) {
delete target.editable;
this.data = newData;
Object.assign(targetCache, target);
this.cacheData = newCacheData;
}
this.editingKey = '';
this.data.map(item => {
if (item.key == key) {
debugger
postAction("/pomel/person/updatePerson", item).then((res) => {
debugger
})
return
}
})
},
cancel (key) {
debugger
const newData = [...this.data];
const target = newData.find(item => key === item.key);
this.cacheData = this.data.map(item => ({ ...item }));
this.editingKey = '';
if (target) {
Object.assign(target, this.cacheData.find(item => key === item.key));
delete target.editable;
this.data = newData;
}
},
},
};
</script>
<style scoped>
.editable-row-operations a {
margin-right: 8px;
}
</style>