yangfeng
2023-09-21 1ed83e98d5bc89f4e87b8ae6692eb31888e55579
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
<!-- eslint-disable vue/no-use-v-if-with-v-for -->
<template>
  <div class="table-view" v-loading="loading">
    <el-table
      ref="table"
      border
      :data="tableList.tableInfomation"
      tooltip-effect="dark"
      style="width: 100%"
      :height="'calc(100% - 0px)'"
      :max-height="tableList.maxHeight"
      :lazy="tableList.lazy"
      @selection-change="handleSelectionChange"
      :header-cell-style="{ background: '#f1f3f8', color: '#000009' }"
      :highlight-current-row="tableList.highlight"
      :row-class-name="tableRowClassName"
      @row-click="tableRowClick"
      :row-key="tableList.key"
      :default-expand-all="tableList.isDefaultExpandAll"
      :tree-props="{ children: 'child', hasChildren: 'hasChildren' }"
      :span-method="objectSpanMethod"
    >
      <el-table-column v-if="tableList.selectBox" type="selection" width="40"> </el-table-column>
      <el-table-column v-if="tableList.selectIndex" type="index" label="序号" width="50"> </el-table-column>
      <el-table-column
        v-for="(item, i) in tableList.tableColumn"
        :key="i"
        :prop="item.prop"
        :label="item.label"
        :width="item.width"
        :min-width="item.min"
        show-overflow-tooltip
        :sortable="item.sortable"
        v-if="item.isShowColumn"
      >
        <template slot-scope="scope">
          <span v-if="item.price">{{ "¥" + number_format(scope.row[item.prop], 2, ".", ",") }}</span>
          <!-- 状态显示 -->
          <div v-else-if="item.status">
            <span
              class="Badge"
              :class="{
                greenSlot: scope.row.status == '4',
                redSlot: scope.row.status == '5',
                blueSlot: scope.row.status == '3',
                graySlot: scope.row.status == '1'
              }"
              >{{
                item.isCallMethod ? item.getCallMethod(scope.row[item.prop], scope.row) : scope.row[item.prop]
              }}</span
            >
          </div>
          <!-- 调用方法显示文字 -->
          <div v-else-if="item.isCallMethod">
            <span>{{ item.getCallMethod(scope.row[item.prop], scope.row) }}</span>
          </div>
          <!-- 小于当前时间显示不同颜色 -->
          <span
            v-else-if="item.date"
            :style="{ color: new Date().getTime() > new Date(scope.row[item.prop]).getTime() ? '#D23F3A' : '#606266' }"
            >{{ timeAgo(scope.row[item.prop]) }}</span
          >
          <span
            v-else-if="item.isClick && scope.row[item.prop]"
            :class="item.className ? item.className : 'sel-name'"
            @click="selCommonClick(scope.row)"
            >{{ scope.row[item.prop] }}</span
          >
          <span v-else-if="item.propType == 'mulitple'">
            {{ scope.row[item.prop][item.propTwo] ? scope.row[item.prop][item.propTwo] : "--" }}
          </span>
          <span :class="item.className ? item.className : ''" v-else>{{
            scope.row[item.prop] ? scope.row[item.prop] : scope.row[item.prop] === 0 ? scope.row[item.prop] : "--"
          }}</span>
        </template>
      </el-table-column>
      <slot name="tableButton" />
      <div slot="empty">
        <el-empty description="暂无数据"></el-empty>
      </div>
    </el-table>
    <div class="overSpread1" v-show="iscolopen" @click="onMaskClick"></div>
    <div v-if="showCheckcol" class="styleBtn">
      <i @click="checkcol()" class="label">...</i>
      <el-checkbox-group v-model="showcolList" v-show="iscolopen" class="checkbox-group" @change="selCeckBoxList">
        <el-checkbox v-for="item in tableList.allcol" :label="item" :key="item">{{ item }} </el-checkbox>
      </el-checkbox-group>
    </div>
  </div>
</template>
 
<script>
import { timeago } from "@/common/config/index"
export default {
  name: "TableCommonView",
  props: {
    tableList: {
      type: Object,
      default: () => {
        return {
          selectBox: false,
          selectIndex: false,
          showStyle: true,
          tableInfomation: [], // 接口返回数据
          showcol: [],
          allcol: [],
          highlight: false,
          tableColumn: [
            // table表单
            { label: "", prop: "", min: 200, tooltip: true }
          ]
        }
      },
      showcol: {
        typeof: Array,
        default: () => []
      }
    },
    // 合并单元格
    rowData: {
      type: Array,
      default: () => {
        return []
      }
    },
    // 加载的loading
    loading: {
      type: Boolean,
      default: false
    },
    // 选中的样式
    selectClassRow: {
      type: Object,
      default: () => {
        return {}
      }
    },
    showCheckcol: {
      type: Boolean,
      default: true
    }
  },
  data() {
    return {
      iscolopen: false,
      showcolList: this.tableList.showcol
    }
  },
  watch: {},
  computed: {},
  beforeUpdate() {},
  methods: {
    onMaskClick() {
      this.iscolopen = false
    },
    // 合并单元格
    objectSpanMethod({ row, column, rowIndex, columnIndex }) {
      row
      column
      if (this.rowData && this.rowData.length > 0) {
        // 产品BOM 表格特殊处理 合并单元格
        if (columnIndex < 5 || columnIndex == 9) {
          const _row = this.rowData[rowIndex]
          const _col = _row > 0 ? 1 : 0
          return {
            rowspan: _row,
            colspan: _col
          }
        }
      }
    },
    tableRowClick(row) {
      this.$emit("tableRowClick", row)
    },
    handleReserve(row) {
      return row._id ? row._id : row.id
    },
    handleSelectionChange(val) {
      this.$emit("getSelectArray", val)
    },
    // 公共详情
    selCommonClick(row) {
      this.$emit("selCommonClick", row)
    },
    // 选择列
    checkcol() {
      this.iscolopen = !this.iscolopen
    },
    closeCheckbox() {
      let label = document.querySelector(".label")
      if (label) {
        this.iscolopen = false
      }
    },
    selCeckBoxList(val) {
      this.$emit("selTableCol", val)
    },
    // 单选行相关
    tableRowClassName({ row }) {
      if (Object.keys(this.selectClassRow).length > 0) {
        if (row.id == this.selectClassRow.id) {
          return "onSelect"
        }
      }
      this.$emit("tableRowClassName", row)
    },
    timeAgo(val) {
      return timeago(val)
    }
  }
}
</script>
 
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="scss" scoped>
.table-view {
  position: relative;
  height: 100%;
  .blue {
    width: 70px;
    text-align: center;
    color: #fff;
    background-color: $color-primary;
    border-radius: 4px;
  }
  .sel-name {
    color: $color-primary;
    cursor: pointer;
  }
  .greenSlot {
    background: #28a745;
  }
  .redSlot {
    background: #dc3545;
  }
  .blueSlot {
    background: #1771bb;
  }
  .graySlot {
    color: #444b5a;
    background: #d3d3d3;
  }
  .yellowSlot {
    background: #e6a23c;
  }
  .styleBtn {
    position: absolute;
    width: 30px;
    height: 48px;
    // line-height: 26px;
    background: #f1f3f8;
    border-top-right-radius: 8px;
    top: 0px;
    right: 2px;
    // z-index: 9999;
    .label {
      position: absolute;
      top: 12px;
      font-size: 20px;
      cursor: pointer;
      color: #000;
      transform: rotate(-90deg);
      -moz-transform: rotate(-90deg);
      -webkit-transform: rotate(-90deg);
    }
    .checkbox-group {
      width: 160px;
      height: 330px;
      overflow: auto;
      display: flex;
      flex-direction: column;
      line-height: 35px;
      background: #ffffff;
      border-radius: 16px;
      padding: 12px;
      position: absolute;
      right: 0;
      top: 30px;
      z-index: 99;
      box-shadow: 0 0 2px 2px #f8f8f8;
    }
  }
}
::v-deep {
  .el-table__footer-wrapper {
    tbody td.el-table__cell {
      background-color: #fff;
      font-weight: bold;
    }
  }
  .el-table {
    border-top-left-radius: 12px;
    border-top-right-radius: 12px;
    overflow: auto;
  }
}
</style>