qx
6 小时以前 ad54cf427ee94e01e8c72a01f738615eb2b6569d
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
<template>
  <div>
    <el-table class="form-table" :row-key="(record) => record.key" :data="model">
      <template>
        <el-table-column label="序号" align="center" type="index" width="50" />
        <template v-for="(option, index) in fields">
          <el-table-column :key="index" :label="getTableColumnLabel(option)" align="center">
            <template #default="scope">
              {{ showText(scope.row, option.vModel) }}
            </template>
          </el-table-column>
        </template>
        <el-table-column label="操作" align="center" width="300">
          <template #default="scope">
            <el-button type="primary" size="mini" @click="handleViewData(scope.$index, scope.row)">
              <i class="el-icon-view" />查看
            </el-button>
          </template>
        </el-table-column>
      </template>
    </el-table>
    <el-dialog title="详情" :visible.sync="dialogVisible" width="40%" append-to-body>
      <ViewData :fields="viewFields" :page-form-model="pageFormModel" />
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
 
<script>
import { removeHtmlTag } from '@/utils/index'
import _ from 'lodash'
 
export default {
  name: 'SubFormView',
  components: {},
  props: {
    model: {
      type: Array,
      default: () => []
    },
    fields: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      dialogVisible: false,
      pageFormModel: {}
    }
  },
  computed: {
    viewFields() {
      return this.fields.map((item) => {
        const isLabel = this.isLabelTag(item.vModel)
        // 特殊处理单选多选等组件 不然会直接显示选中的id
        return {
          label: removeHtmlTag(item.config.label),
          value: isLabel ? `${item.vModel}label` : item.vModel,
          type: item.typeId,
          scheme: item
        }
      })
    }
  },
  beforeCreate() {
    this.$options.components.ViewData = require('../ViewData').default
  },
  methods: {
    getTableColumnLabel(option) {
      return removeHtmlTag(option.config.label)
    },
    showText(row, key) {
      if (this.isLabelTag(key)) {
        return row[`${key}label`]
      }
      return row[key]
    },
    handleViewData(index, row) {
      this.dialogVisible = true
      this.pageFormModel = row
    },
    isLabelTag(key) {
      if (
        _.startsWith(key, 'radio') ||
        _.startsWith(key, 'checkbox') ||
        _.startsWith(key, 'select') ||
        _.startsWith(key, 'image_select') ||
        _.startsWith(key, 'cascader')
      ) {
        return true
      }
      return false
    }
  }
}
</script>
 
<style lang="scss" scoped>
.matrix-table {
  font-family: verdana, arial, sans-serif;
  font-size: 11px;
  color: #303133;
  border-width: 1px;
  border-color: #dcdfe6;
  border-collapse: collapse;
  width: 90%;
  overflow: auto;
}
 
.matrix-table {
  display: block;
  overflow-y: scroll;
}
 
.matrix-table th {
  border-width: 1px;
  padding: 8px;
  border-style: solid;
  border-color: #dcdfe6;
  background-color: #dedede;
}
 
.matrix-table td {
  border-width: 1px;
  padding: 8px;
  border-style: solid;
  border-color: #dcdfe6;
  background-color: #ffffff;
  word-break: break-all;
  text-align: center;
}
</style>