2016-11-23 16:27:17 +08:00
|
|
|
<template>
|
2016-11-26 08:57:09 +08:00
|
|
|
<table cellspacing="0" cellpadding="0" border="0" :style="style">
|
|
|
|
<colgroup>
|
|
|
|
<col v-for="column in columns" :width="setCellWidth(column, $index)">
|
|
|
|
</colgroup>
|
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<th v-for="column in columns" :class="alignCls(column)">
|
2016-11-27 01:42:39 +08:00
|
|
|
<div :class="cellClasses(column)">
|
2016-11-26 08:57:09 +08:00
|
|
|
<template v-if="column.type === 'selection'"><Checkbox :checked="isSelectAll" @on-change="selectAll"></Checkbox></template>
|
2016-11-27 22:56:05 +08:00
|
|
|
<template v-else>
|
|
|
|
{{{ renderHeader(column, $index) }}}
|
|
|
|
<span :class="[prefixCls + '-sort']" v-if="column.sortable">
|
2016-11-28 16:53:19 +08:00
|
|
|
<i class="ivu-icon ivu-icon-arrow-up-b" :class="{on: column._sortType === 'asc'}" @click="handleSort($index, 'asc')"></i>
|
|
|
|
<i class="ivu-icon ivu-icon-arrow-down-b" :class="{on: column._sortType === 'desc'}" @click="handleSort($index, 'desc')"></i>
|
2016-11-27 22:56:05 +08:00
|
|
|
</span>
|
2016-11-29 11:04:48 +08:00
|
|
|
<Poptip
|
|
|
|
v-if="column.filters && (fixed || (!fixed && !column.fixed))"
|
|
|
|
:visible.sync="column._filterVisible"
|
|
|
|
placement="bottom"
|
|
|
|
@on-popper-hide="handleFilterHide($index)">
|
2016-11-28 21:30:59 +08:00
|
|
|
<span :class="[prefixCls + '-filter']">
|
2016-11-29 08:43:47 +08:00
|
|
|
<i class="ivu-icon ivu-icon-funnel" :class="{on: column._isFiltered}"></i>
|
2016-11-28 21:30:59 +08:00
|
|
|
</span>
|
2016-11-29 11:04:48 +08:00
|
|
|
<div slot="content" :class="[prefixCls + '-filter-list']" v-if="column._filterMultiple">
|
2016-11-29 08:43:47 +08:00
|
|
|
<div :class="[prefixCls + '-filter-list-item']">
|
|
|
|
<checkbox-group :model.sync="column._filterChecked">
|
|
|
|
<checkbox v-for="item in column.filters" :value="item.value">{{ item.label }}</checkbox>
|
|
|
|
</checkbox-group>
|
|
|
|
</div>
|
|
|
|
<div :class="[prefixCls + '-filter-footer']">
|
2016-11-29 11:04:48 +08:00
|
|
|
<i-button type="text" size="small" :disabled="!column._filterChecked.length" @click="handleFilter($index)">筛选</i-button>
|
2016-11-29 08:43:47 +08:00
|
|
|
<i-button type="text" size="small" @click="handleReset($index)">重置</i-button>
|
|
|
|
</div>
|
2016-11-28 21:30:59 +08:00
|
|
|
</div>
|
2016-11-29 11:04:48 +08:00
|
|
|
<div slot="content" :class="[prefixCls + '-filter-list']" v-else>
|
|
|
|
<ul>
|
|
|
|
<li :class="[prefixCls + '-filter-select-item', {[prefixCls + '-filter-select-item-selected']: !column._filterChecked.lengtg}]">全部</li>
|
|
|
|
<li :class="[prefixCls + '-filter-select-item', {[prefixCls + '-filter-select-item-selected']: column._filterChecked[0] === item.value}]" v-for="item in column.filters">{{ item.label }}</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
2016-11-28 21:30:59 +08:00
|
|
|
</Poptip>
|
2016-11-27 22:56:05 +08:00
|
|
|
</template>
|
2016-11-26 08:57:09 +08:00
|
|
|
</div>
|
|
|
|
</th>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
</table>
|
2016-11-23 16:27:17 +08:00
|
|
|
</template>
|
|
|
|
<script>
|
2016-11-29 08:43:47 +08:00
|
|
|
import CheckboxGroup from '../checkbox/checkbox-group.vue';
|
2016-11-24 15:27:46 +08:00
|
|
|
import Checkbox from '../checkbox/checkbox.vue';
|
2016-11-28 21:30:59 +08:00
|
|
|
import Poptip from '../poptip/poptip.vue';
|
2016-11-29 08:43:47 +08:00
|
|
|
import iButton from '../button/button.vue';
|
2016-11-24 15:27:46 +08:00
|
|
|
import Mixin from './mixin';
|
|
|
|
import { deepCopy } from '../../utils/assist';
|
|
|
|
|
2016-11-23 16:27:17 +08:00
|
|
|
export default {
|
2016-11-24 15:27:46 +08:00
|
|
|
mixins: [ Mixin ],
|
2016-11-29 08:43:47 +08:00
|
|
|
components: { CheckboxGroup, Checkbox, Poptip, iButton },
|
2016-11-23 16:27:17 +08:00
|
|
|
props: {
|
|
|
|
prefixCls: String,
|
2016-11-26 08:57:09 +08:00
|
|
|
style: Object,
|
2016-11-24 15:27:46 +08:00
|
|
|
columns: Array,
|
2016-11-28 15:43:19 +08:00
|
|
|
objData: Object,
|
2016-11-26 08:57:09 +08:00
|
|
|
fixed: Boolean
|
2016-11-23 16:27:17 +08:00
|
|
|
},
|
|
|
|
computed: {
|
2016-11-24 15:27:46 +08:00
|
|
|
isSelectAll () {
|
2016-11-28 15:43:19 +08:00
|
|
|
let isSelectAll = true;
|
|
|
|
for (let i in this.objData) {
|
|
|
|
if (!this.objData[i]._isChecked) isSelectAll = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return isSelectAll;
|
2016-11-24 15:27:46 +08:00
|
|
|
}
|
2016-11-23 16:27:17 +08:00
|
|
|
},
|
|
|
|
methods: {
|
2016-11-27 01:42:39 +08:00
|
|
|
cellClasses (column) {
|
|
|
|
return [
|
|
|
|
`${this.prefixCls}-cell`,
|
|
|
|
{
|
|
|
|
[`${this.prefixCls}-hidden`]: !this.fixed && column.fixed && (column.fixed === 'left' || column.fixed === 'right')
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
2016-11-26 08:57:09 +08:00
|
|
|
setCellWidth (column, index) {
|
|
|
|
return this.$parent.setCellWidth(column, index);
|
|
|
|
},
|
2016-11-23 16:27:17 +08:00
|
|
|
renderHeader (column, $index) {
|
|
|
|
if ('renderHeader' in this.columns[$index]) {
|
|
|
|
return this.columns[$index].renderHeader(column, $index);
|
|
|
|
} else {
|
|
|
|
return column.title || '#';
|
|
|
|
}
|
2016-11-23 18:38:39 +08:00
|
|
|
},
|
2016-11-24 15:27:46 +08:00
|
|
|
selectAll () {
|
|
|
|
const status = !this.isSelectAll;
|
2016-11-26 10:50:24 +08:00
|
|
|
this.$parent.selectAll(status);
|
2016-11-27 22:56:05 +08:00
|
|
|
},
|
2016-11-28 16:53:19 +08:00
|
|
|
handleSort (index, type) {
|
|
|
|
if (this.columns[index]._sortType === type) {
|
|
|
|
type = 'normal';
|
2016-11-28 14:23:49 +08:00
|
|
|
}
|
2016-11-28 16:53:19 +08:00
|
|
|
this.$parent.handleSort(index, type);
|
2016-11-28 21:30:59 +08:00
|
|
|
},
|
|
|
|
handleFilter (index) {
|
2016-11-29 11:04:48 +08:00
|
|
|
this.$parent.handleFilter(index);
|
2016-11-29 08:43:47 +08:00
|
|
|
},
|
|
|
|
handleReset (index) {
|
2016-11-29 11:04:48 +08:00
|
|
|
this.$parent.handleFilterReset(index);
|
2016-11-29 08:43:47 +08:00
|
|
|
},
|
2016-11-29 11:04:48 +08:00
|
|
|
handleFilterHide (index) {
|
|
|
|
this.$parent.handleFilterHide(index);
|
2016-11-23 16:27:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-11-27 01:42:39 +08:00
|
|
|
</script>
|