123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425 |
- <template>
- <!-- 本组件用于table台账的显示 -->
- <div class="tableDiv">
- <el-table
- ref="table1"
- class="tableCom"
- :cell-class-name="this.startCellClass ? setCellClass : ''"
- :row-class-name="tableRowClassName"
- :data="dataList"
- style="width: 100%"
- height="calc(100% - 66px)"
- stripe
- highlight-current-row
- @row-dblclick="rowDblclick"
- @row-click="rowClick"
- @select="selectRow"
- @select-all="selectRow"
- >
- <template slot="empty">
- <img src="@/assets/icon/null.png" alt="" />
- <p class="empty-p">暂无数据</p>
- </template>
- <el-table-column v-if="config.check" align="center" type="selection" width="55" />
- <el-table-column v-if="config.index" align="center" type="index" width="50" label="序号" />
- <template v-for="(item, index) in config.fieldList">
- <el-table-column
- :key="currentDate + 'header_' + index"
- align="center"
- :prop="item.field"
- :width="item.width ? item.width : ''"
- :min-width="item.minWidth"
- :formatter="formatter"
- sortable
- :label="item.label"
- show-overflow-tooltip
- >
- <template slot-scope="scope">
- <span>{{ formatter(scope.row[item.field]) }}</span>
- </template>
- </el-table-column>
- </template>
- <el-table-column v-if="config.actionList" fixed="right" align="center" label="操作" width="150">
- <template slot-scope="scope">
- <template v-for="(item, index) in config.actionList">
- <el-button
- :key="currentDate + 'scope_' + index"
- type="text"
- :class="item.class"
- size="small"
- @click="item.method(scope.row)"
- >{{ item.label }}</el-button
- >
- </template>
- </template>
- </el-table-column>
- </el-table>
- <el-row class="paginationDiv">
- <el-pagination
- small
- background
- layout="total, sizes, prev, pager, next, jumper"
- :page-sizes="[10, 20, 30, 50, 100, 1000]"
- :page-size="size"
- :current-page="current"
- :total="total"
- @size-change="changeSize"
- @current-change="changecurrent"
- />
- </el-row>
- </div>
- </template>
- <script>
- import commonMe from '@/utils/common.js'
- export default {
- props: {
- config: {
- type: Object,
- default: () => ({
- check: true,
- index: true,
-
- testData: false,
- fieldList: [
- {
- label: '公司',
- field: 'company',
- setCellClassMethod: (e) => {},
- actionMethod: (e) => {}
- },
- {
- label: '部门',
- field: 'department',
- setCellClassMethod: (e) => {},
- actionMethod: (e) => {}
- },
- {
- label: '姓名',
- field: 'user',
- setCellClassMethod: (e) => {},
- actionMethod: (e) => {}
- }
- ],
- actionList: [
- {
- label: '处理',
- method: (e) => {}
- }
- ],
- searchDate: {},
- method: (e) => {},
- click: (e) => {},
- dbClick: (e) => {},
- selectClick: (e) => {}
- })
- }
- },
- data() {
- return {
- testDataList: [],
- dataList: [],
- total: 0,
- currentDate: '',
- current: 1,
- size: 30,
- formatter: commonMe.formatter,
- checkRow: [],
- currentRow: null,
- startCellClass: false,
- cellClassList: []
- }
- },
- created() {
- this.currentDate = commonMe.getCurrentDateToMS() + ''
- },
- mounted() {
- this.startCellClassMethod()
- if (this.config.testData) {
- this.getTestData()
- } else {
- this.getTableData()
- }
- this.setTableInfo()
- },
- methods: {
-
- changecurrent(data) {
- this.current = data
- if (this.config.testData) {
- this.getCurrentTestData()
- } else {
- this.getTableData()
- }
- },
-
- changeSize(data) {
- this.size = data
- if (this.config.testData) {
- this.getCurrentTestData()
- } else {
- this.getTableDataByOne()
- }
- },
-
- getTableDataByOne() {
- if (this.config) this.getTableData(true)
- },
-
- getTableData(data) {
- console.log('更新数据')
- if (data) {
- this.current = 1
- }
- if (this.config.method) {
- const searchData = {
- size: this.size,
- current: this.current
- }
- this.config
- .method(commonMe.notJsonCopy(searchData))
- .then((res) => {
- this.dataList = res.records || []
- this.total = Number(res.total) || 0
- this.reSetTableInfo()
- })
- .catch((err) => {
- this.dataList = []
- this.total = 0
- this.reSetTableInfo()
- console.log(err)
- })
- }
- },
-
- update(params = {}) {
- if (this.config.method) {
- const pageAndSize = { size: this.size, current: 1 }
- this.config
- .method(commonMe.notJsonCopy({ ...params, ...pageAndSize }))
- .then((res) => {
- this.dataList = res.records || []
- this.total = Number(res.total) || 0
- this.reSetTableInfo()
- })
- .catch((err) => {
- this.dataList = []
- this.total = 0
- this.reSetTableInfo()
- console.log(err)
- })
- }
- },
-
- selectRow(data) {
- console.log('选择的信息')
- this.checkRow = data
- this.setTableInfo()
- this.$nextTick((e) => {
- if (this.config.selectClick) {
- this.config.selectClick(data)
- }
- })
- },
-
- rowClick(data) {
- this.currentRow = data
- this.setTableInfo()
- this.$nextTick((e) => {
- if (this.config.click) {
- this.config.click(data)
- }
- })
- },
-
- rowDblclick(data) {
- this.currentRow = data
- this.setTableInfo()
- this.$nextTick((e) => {
- if (this.config.dbClick) {
- this.config.dbClick(data)
- }
- })
- },
-
- reSetTableInfo() {
- this.currentRow = []
- this.checkRow = null
- this.setTableInfo()
- this.$refs['table1'].doLayout()
- },
-
- setTableInfo() {
- const tableData = commonMe.notJsonCopy(this.dataList)
- const config = {
- currentRow: commonMe.notJsonCopy(this.currentRow),
- checkRow: commonMe.notJsonCopy(this.checkRow),
- size: commonMe.notJsonCopy(this.size),
- current: commonMe.notJsonCopy(this.current),
- tableData
- }
- this.$emit('input', config)
- },
-
- startCellClassMethod() {
- this.cellClassList = []
- this.config.fieldList.forEach((item) => {
- if (item.setCellClassMethod) {
- this.startCellClass = true
- this.cellClassList[item.field] = item.setCellClassMethod
- }
- })
- },
-
- setCellClass(data) {
- const field = data.column.property || ''
- if (this.cellClassList[field]) {
- return this.cellClassList[field](data)
- }
- },
-
- tableRowClassName({ row, rowIndex }) {
- if (rowIndex % 2 == 0) {
- return 'rowEven'
- } else {
- return 'rowOdd'
- }
- },
-
- getTestData() {
- const testData = []
- for (let i = 0; i < 100; i++) {
- const testItem = {}
- this.config.fieldLit.forEach((item) => {
- testItem[item.field] = item.label + '' + i
- })
- ;('')
- tetData.push(testItem)
- }
- this.testDataList = testData
- this.total = this.testDataLit.length
- this.getCurrentTestData()
- },
-
- getCurrentTestData() {
- this.dataList = this.testDataList.slice((this.current - 1) * this.size, this.size)
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- @import './src/assets/default';
- /deep/.tableCom {
- @include queryTableRowStyle;
- .rowEven {
- background: $queryTableRowEvenBckgroundColor;
- }
- .rowOdd {
- background: $queryTableRowOddBckgroundColor;
- }
- .current-row {
- background: $queryTableRowSelectBckgroundColor !important;
- td {
- background: rgba(0, 0, 0, 0) !important;
- }
- }
- .el-table__body tr.current-row > td.el-table__cell {
- background-color: #ecf5ff !important;
- transform: none;
- }
- }
- .tableDiv {
- position: relative;
- float: left;
- width: 100%;
- height: 100%;
- }
- .paginationDiv {
- margin-top: 20px;
- width: 100%;
- text-align: right;
- }
- .overtime span {
-
- color: #fa541c !important;
- }
- .notOvertime span {
-
- color: #67c23a !important;
- }
- .notCom span {
-
- color: #fa541c !important;
- border: 1px solid #ffbb96;
- background: #fff2e8;
- }
- .wait span {
-
- color: #f65252 !important;
- border: 1px solid #ffa39e;
- background: #fef0ef;
- }
- .inHand span {
-
- color: #2d74e7 !important;
- border: 1px solid #91d5ff;
- background: #e6f7ff;
- }
- .finished span {
-
- color: #67c23a !important;
- border: 1px solid #b7eb8f;
- background: #f6ffed;
- }
- /deep/.deleteInfo,
- /deep/.updateInfo,
- /deep/.lookInfo {
- span {
- color: #2d74e7 !important;
- }
- }
- </style>
|