<!-- 可编辑table -->
|
<template>
|
<div class="edit_table_main">
|
<el-form :rules="model.tableRules"
|
:model="model"
|
ref="form">
|
<el-table :data="model.tableData"
|
style="width: 100%"
|
min-height="200"
|
header-cell-class-name="header_cell"
|
cell-class-name="table_cell">
|
<!-- 序号 -->
|
<el-table-column label=" "
|
type="index"
|
v-if="isAutoIndex"></el-table-column>
|
<el-table-column v-for="(colItem, colIndex) in columns"
|
:key="colIndex"
|
:align="colItem.align || 'left'"
|
:label="colItem.label"
|
:type="colItem.colunmType"
|
:prop="colItem.name"
|
:fixed="colItem.fixed"
|
:width="colItem.defWidth"
|
:render-header="renderHeader">
|
<template slot-scope="scope">
|
<el-form-item :prop="'tableData.' + scope.$index + '.' + colItem.name"
|
:rules='model.tableRules[colItem.name]'
|
v-if="colItem.type === 'input' && model.tableData[scope.$index].isEidt">
|
<el-input :placeholder="colItem.placeholder"
|
size="small"
|
validate-event
|
v-model="model.tableData[scope.$index][colItem.name]"
|
:style="{ minWidth: colItem.minWidth, width: '100%' }"
|
:disabled="!model.tableData[scope.$index].isEidt">
|
</el-input>
|
</el-form-item>
|
<p v-if="colItem.type === 'input' && !model.tableData[scope.$index].isEidt"
|
:class="{'changeCol': model.tableData[scope.$index].changeflag && !noHistory}">
|
{{ model.tableData[scope.$index][colItem.name] || '--'}}
|
</p>
|
<p v-if="colItem.type === 'text'"
|
:style="{textAlign: colItem.align || 'left'}"
|
:class="{'changeCol':model.tableData[scope.$index].changeflag} && !noHistory">
|
{{ model.tableData[scope.$index][colItem.name] || '--' }}
|
</p>
|
<el-form-item :prop="'tableData.' + scope.$index + '.' + colItem.name"
|
:rules='model.tableRules[colItem.name]'
|
v-if="colItem.type === 'select' && model.tableData[scope.$index].isEidt">
|
<el-select size="small"
|
v-model="tableData[scope.$index][colItem.name]"
|
:filterable="colItem.filterable || true"
|
:placeholder="colItem.placeholder"
|
:disabled="!model.tableData[scope.$index].isEidt"
|
:style="{ minWidth: colItem.minWidth, width: '100%' }">
|
<el-option v-for="(optionsItem, optionsIndex) in colItem.options"
|
:key="optionsIndex"
|
:label="optionsItem.label || optionsItem[colItem.labelKey]"
|
:value="optionsItem.value || optionsItem[colItem.valueKey]"></el-option>
|
</el-select>
|
</el-form-item>
|
<p v-if="colItem.type === 'select' && !model.tableData[scope.$index].isEidt"
|
:class="{'changeCol': model.tableData[scope.$index].changeflag && !noHistory}">
|
{{ model.tableData[scope.$index].isdeleteValue }}
|
</p>
|
<el-form-item :prop="'tableData.'+ scope.$index + '.' + colItem.name"
|
:rules='model.tableRules[colItem.name]'
|
v-if="colItem.type === 'multipleSelect'">
|
<el-select v-if="colItem.type === 'multipleSelect'"
|
:filterable="colItem.filterable || true"
|
:placeholder="colItem.placeholder"
|
v-model="model.tableData[scope.$index][colItem.name]"
|
:style="{ minWidth: colItem.minWidth, width: '100%' }"
|
multiple
|
collapse-tags>
|
<el-option v-for="(optionsItem, optionsIndex) in colItem.options"
|
:key="optionsIndex"
|
:label="optionsItem.label || optionsItem[colItem.labelKey]"
|
:value="optionsItem.value || optionsItem[colItem.valueKey]"></el-option>
|
</el-select>
|
</el-form-item>
|
<el-date-picker v-model="model.tableData[scope.$index][colItem.name]"
|
v-if="colItem.type === 'date'"
|
:placeholder="colItem.placeholder"
|
:style="{ minWidth: colItem.minWidth, width: '100%' }"
|
type="date"
|
format="yyyy/MM/dd"></el-date-picker>
|
|
<el-date-picker v-if="colItem.type === 'rangeDate'"
|
v-model="scope.row[scope.$index][colItem.name]"
|
:placeholder="colItem.placeholder"
|
:style="{ minWidth: colItem.minWidth, width: '100%' }"
|
type="daterange"
|
range-separator="-"
|
format="yyyy/MM/dd"
|
start-placeholder="开始日期"
|
end-placeholder="结束日期">
|
</el-date-picker>
|
<div v-if="colItem.type === 'operate'">
|
<el-button v-for="(operateItem, i) in model.tableData[scope.$index][colItem.name]"
|
v-show="operateItem.isShow"
|
@click="
|
$emit(
|
'handleOperateClick',
|
operateItem.type,
|
scope.row,
|
scope.$index
|
)
|
"
|
type="text"
|
:key="i"
|
size="small">
|
{{ operateItem.label }}
|
</el-button>
|
</div>
|
</template>
|
</el-table-column>
|
</el-table>
|
<div v-if="isShowPages && pageInfo.total > 0"
|
class="pagination">
|
<el-pagination background
|
@size-change="handleSizeChange"
|
@current-change="handleCurrentChange"
|
:current-page="pageInfo.currentPage"
|
:page-sizes="[10, 20, 50, 100]"
|
:page-size="pageInfo.size"
|
layout="prev, pager, next, jumper, total, sizes"
|
:total="pageInfo.total"></el-pagination>
|
</div>
|
</el-form>
|
</div>
|
</template>
|
<script>
|
export default {
|
mounted () {
|
},
|
props: {
|
tableData: {
|
type: Array,
|
default: () => {
|
return []
|
}
|
},
|
columns: {
|
type: Array,
|
default: () => {
|
return []
|
}
|
},
|
rules: {
|
type: Object,
|
default: () => {
|
return {}
|
}
|
},
|
operateLabel: {
|
type: String,
|
default: '操作'
|
},
|
isAutoIndex: {
|
type: Boolean,
|
default: false
|
},
|
noHistory: {
|
type: Boolean,
|
default: false
|
},
|
pageInfo: {
|
type: Object,
|
default: () => {
|
return {
|
currentPage: 1,
|
pageSize: 10,
|
total: 0
|
}
|
}
|
},
|
isShowPages: {
|
type: Boolean,
|
default: true
|
},
|
},
|
watch: {
|
tableData: {
|
handler (data, olddata) {
|
this.model.tableData = data
|
},
|
deep: true
|
},
|
},
|
data () {
|
return {
|
model: {
|
tableRules: { ...this.rules },
|
tableData: [...this.tableData],
|
},
|
|
}
|
},
|
methods: {
|
handleSizeChange (val) {
|
this.$emit('handleSizeChange', val)
|
},
|
handleCurrentChange (val) {
|
this.$emit('handleCurrentChange', val)
|
},
|
renderHeader (h, { column, $index }) {
|
return h('div', {
|
attrs: {
|
class: 'cell'
|
},
|
domProps: {
|
innerHTML:
|
(column.type === 'required'
|
? '<span class="head_red_slot">* </span>'
|
: '') + column.label
|
}
|
})
|
}
|
}
|
}
|
</script>
|
<style lang="postcss" scoped>
|
.edit_table_main {
|
padding-top: 10px;
|
& .table_cell {
|
height: 48px;
|
padding: 0;
|
& .cell {
|
line-height: 18px;
|
& .changeCol {
|
color: #f56c6c;
|
}
|
}
|
}
|
& .header_cell {
|
height: 47px;
|
padding: 0;
|
background-color: #fafafa;
|
& .cell {
|
line-height: 20px;
|
color: #222222;
|
}
|
}
|
& >>> .head_red_slot {
|
color: #f56c6c;
|
}
|
& >>> .el-table th {
|
background: #fafafa;
|
color: #222222;
|
padding: 0;
|
border-color: #eee;
|
}
|
& >>> .el-table tr {
|
height: 48px;
|
line-height: 48px;
|
}
|
& >>> .el-table tr th {
|
line-height: 44px;
|
}
|
& >>> .el-table td {
|
color: #666666;
|
border-color: #eee;
|
padding: 0;
|
height: 48px;
|
/* & .el-button {
|
margin-right: 20px;
|
} */
|
}
|
& a {
|
color: #0081f0;
|
cursor: pointer;
|
}
|
& >>> .item-inner p {
|
padding: 0;
|
margin: 0;
|
}
|
& >>> .item-inner p .el-button + .el-button {
|
padding-left: 10px;
|
}
|
& >>> .el-table__body-wrapper {
|
&::-webkit-scrollbar {
|
height: 10px;
|
width: 10px;
|
}
|
&::-webkit-scrollbar-track-piece {
|
}
|
&::-webkit-scrollbar-track-piece {
|
}
|
&::-webkit-scrollbar-track {
|
border-radius: 1em;
|
/* background-color: rgba(50, 50, 50, 0.1); */
|
background-color: #ffffff;
|
}
|
&::-webkit-scrollbar-thumb {
|
border-radius: 1em;
|
/* background-color: rgba(50, 50, 50, 0.2); */
|
background-color: rgba(0, 0, 0, 0.5);
|
}
|
}
|
& .pagination {
|
padding: 20px 0;
|
color: #666666;
|
& >>> .el-pagination__total {
|
margin-left: 20px;
|
font-size: 14px;
|
color: #666666;
|
}
|
& >>> .el-pager li {
|
width: auto;
|
min-width: 32px;
|
height: 32px;
|
background: rgba(255, 255, 255, 1);
|
border-radius: 4px;
|
border: 1px solid rgba(238, 238, 238, 1);
|
font-size: 14px;
|
color: #666666;
|
font-weight: normal;
|
/* min-width: 34px; */
|
}
|
& >>> .el-pagination__jump {
|
font-size: 14px;
|
color: #666666;
|
}
|
& >>> .btn-next,
|
& >>> .btn-prev {
|
width: 32px;
|
height: 32px;
|
background: rgba(255, 255, 255, 1);
|
border-radius: 4px;
|
border: 1px solid rgba(238, 238, 238, 1);
|
font-size: 14px;
|
color: #666666;
|
}
|
& >>> .btn-next:disabled,
|
& >>> .btn-prev:disabled {
|
opacity: 0.6;
|
}
|
}
|
& .buttons-links >>> .el-link {
|
margin-right: 20px;
|
&:last-child {
|
margin: 0;
|
}
|
}
|
& .button-select {
|
cursor: pointer;
|
color: #0081f0;
|
& >>> .el-icon--right {
|
margin: 0;
|
}
|
}
|
& .button-select-disabled {
|
color: #c5c5c5;
|
padding-right: 2em;
|
}
|
& p.buttons-wraper {
|
display: flex;
|
justify-content: space-between;
|
align-items: center;
|
padding-right: 10px;
|
}
|
}
|
</style>
|