zouyu
2023-11-10 69be1e17629ee50cbc2f63aec9627360535d61f0
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
<template>
  <div>
        <avue-crud
        ref="crud"
        class="l-mes"
        rowKey="oneId"
        :data="tableData"
        :option="option"
        :span-method="spanMethod" 
        :page="page" 
        :table-loading="loading" 
        >
        <template slot="code" slot-scope="scope">
            <avue-text-ellipsis use-tooltip :text="scope.row.code" :height="40" :width="100">
                <small slot="more">...</small>
            </avue-text-ellipsis>
        </template>
            <template slot="paramValue" slot-scope="scope">
                <el-input @blur="checkType(scope.row)" :disabled="routingTemplateId!=null" :placeholder="'请输入'+scope.row.paramType" v-model="scope.row.paramValue"/>
            </template>
        </avue-crud>
  </div>
</template>
 
<script>
export default {
    props:{
       option:{
         type: Object,
         default: ()=>{
            return {
            height: 600,
            loadingText: "加载中...",
            columnBtn: false,
            index: true,
            indexLabel: '序号',
            menu: false,
            menuAlign: 'center',
            editBtn: false,
            delBtn: false,
            addBtn: false,
            border: true,
            size: 'small',
            refreshBtn: false,
            align: 'center',
            column: [
            {
                label: '参数编号',
                prop: 'code',
                slot: true
            },
            {
                label: '参数项',
                prop: 'paramItem',
            },
            {
                label: '二级参数',
                prop: 'paramItemTwo',
            },
            {
                label: '三级参数',
                prop: 'paramItemThree',
            },
            {
                label: '参数类型',
                prop: 'paramType',
                formslot: true,
                rules: [{
                required: true,
                message: "请选择参数类型",
                trigger: "change"
                }]
            },
            {
                label: '值',
                prop: 'paramValue',
                slot: true,
                formslot: true,
                labelslot: true
            }, {
                label: '单位',
                prop: 'unit',
                rules: [{
                required: true,
                message: "单位不能为空",
                trigger: "blur"
                }]
            },]
         }
         }
       },
       tableData:{
         type: Array,
         default: () => {
            return []
         },
         required: true
       },
       loading:{
        type: Boolean,
        default: false
       },
       page:{
         type: Object,
         default:()=>{
            return {
                total: 10,
                currentPage: 1,
                pageSize: 10
            }
         }
       },
       spanArr:{
         type: Array,
         default: ()=>{
            return [{
                prop: 'code',
                span: []
            }, {
                prop: 'paramItem',
                span: []
            }, {
                prop: 'paramItemTwo',
                span: []
            }]
         }
       },
       routingTemplateId:{
         type: String,
         default: ()=>{
            return ''
         }
       }
    },
    created(){
        this.rowSort()
        this.rowCalc()
    },
    beforeDestroy(){
        console.log("销毁前");
    },
    data(){
        return {
            
        }
    },
    methods:{
        checkType(row){
            if(row.paramType == '数值格式'){
                let val = row.paramValue
                const reg = /^[0-9]*$/
                if(!reg.test(val)){
                    row.paramValue = ''
                    this.$message.warning("请输入数值格式的数据!")
                }
            }
        },
        //动态合并方法
        rowCalc() {
            this.spanArr.forEach((ele, index) => {
                let parent
                if (index !== 0) parent = this.spanArr[ele.parent || index - 1].span
                ele.span = this.rowSpan(ele.prop, parent)
            })
        },
        rowSort(list) {
            let propList = this.spanArr.map(ele => ele.prop)
            this.spanArr.forEach((ele, index) => {
                let key = ele.prop
                this.tableData = this.tableData.sort((a, b) => {
                let flag = true;
                for (let i = 0; i < index; i++) {
                    let prop = this.spanArr[i].prop
                    flag = flag && a[prop] == b[prop]
                }
                if (flag) {
                    if (a[key] < b[key]) { return 1; }
                    else if (a[key] > b[key]) { return -1; }
                    return 0;
                }
                return 0;
                })
            })
        },
        rowSpan(key, parent) {
            let list = [];
            let position = 0;
            this.tableData.forEach((item, index) => {
                if (index === 0) {
                list.push(1)
                let position = 0;
                } else {
                if (this.tableData[index][key] === this.tableData[index - 1][key]) {
                    if (parent && parent[index] !== 0) {
                    list.push(1)
                    position = index
                    } else {
                    list[position] += 1;
                    list.push(0)
                    }
                } else {
                    list.push(1)
                    position = index
                }
                }
            })
            return list
        },
        spanMethod({ row, column, rowIndex, columnIndex }) {
            for (let i = 0; i < this.spanArr.length; i++) {
                const ele = this.spanArr[i]
                if (column.property == ele.prop) {
                const _row = ele.span[rowIndex];
                const _col = _row > 0 ? 1 : 0;
                return {
                    rowspan: _row,
                    colspan: _col
                }
                }
            }
        }
    },
}
</script>
 
<style>
 .avue-crud__menu{
    display: none;
 }
</style>