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
<template>
<div>
<el-form-item
label=" "
:prop="'expTree.'+index+'.value'"
:rules="[
{ required: true, message: '必输项'},
{ validator: validTable, trigger: 'change' },
]"
>
<el-table :data="tableList"
style="width: 100%"
class="eContainer-table"
max-height="350px"
highlight-current-row
:row-class-name="rowClassName"
@row-click="handleRowClick"
>
<el-table-column
prop="docnam"
label="Document"
min-width="200px"
sortable
>
<template slot-scope="scope">
<c-select
v-model="scope.row.docnam"
clearable
v-limitLength="57"
allow-create
@change="handleChange"
>
<el-option :key="item.value" :label="item.label" :value="item.value" v-for="item in docgrdList"></el-option>
</c-select>
</template>
</el-table-column>
<el-table-column
prop="cmail1"
label="1st"
min-width="69px"
sortable
>
<template slot-scope="scope">
<c-input v-model="scope.row.cmail1" maxlength="12" @blur="handleChange"></c-input>
</template>
</el-table-column>
<el-table-column
prop="cmail2"
label="2nd"
min-width="69px"
sortable
>
<template slot-scope="scope">
<c-input v-model="scope.row.cmail2" maxlength="12" @blur="handleChange"></c-input>
</template>
</el-table-column>
<el-table-column label="" prop="det" min-width="95px" fixed="right">
<template slot-scope="scope" slot="header">
<c-button circle class="el-icon-plus" size="mini" @click="addLeftRow(scope)">
</c-button>
<c-button circle class="el-icon-minus" size="mini" @click="removeLeftRow(scope)">
</c-button>
</template>
</el-table-column>
</el-table>
</el-form-item>
</div>
</template>
<script>
import commonDepend from '~/mixin/commonDepend.js'
import { callbackify } from 'util';
export default {
inject: ["root"],
mixins: [commonDepend],
props:['node','index'],
data(){
return{
docgrdList:[
{label:"增值税发票",value:"增值税发票"},
{label:"发票",value:"发票"},
{label:"装箱单",value:"装箱单"},
{label: "空运单", value: "空运单"},
{label: "海运提单", value: "海运提单"},
{label: "铁路运单", value: "铁路运单"},
{label: "货物收据", value: "货物收据"},
{label: "邮政收据", value: "邮政收据"},
{label:"出库单",value:"出库单"},
{label:"保险单",value:"保险单"},
{label:"质检证",value:"质检证"},
{label:"受益人证明",value:"受益人证明"},
],
curIndex: 0,
tableList: []
}
},
mounted(){
},
//自定义下拉框输入长度
directives: {
limitLength: {
bind:function (el,binding,vnode){
const input = el.getElementsByTagName('input')[0]
if(input){
input.setAttribute('maxlength',binding.value)
}
}
}
},
methods:{
addLeftRow(row) {
let newRow = {
docnam:'',
cmail1:'',
cmail2:'',
};
let start = 0;
if (this.tableList) {
start = this.tableList.length;
}
this.tableList.splice(start, 0, newRow);
},
removeLeftRow() {
if (this.curIndex === -1) {
this.$notify.error({
title: "错误",
message: "请选择一条数据删除!"
});
return;
}
this.tableList.splice(this.curIndex, 1);
this.curIndex = -1;
},
handleRowClick(row){
this.curIndex = row.index
},
rowClassName({ row, rowIndex }) {
row.index = rowIndex;
},
handleChange() {
let str = ''
let lineList = []
this.node.value = ''
if (this.tableList.length > 0) {
this.tableList.forEach((item) => {
let itemConList = []
itemConList.push(item.docnam || '')
itemConList.push(item.cmail1 || '')
itemConList.push(item.cmail2 || '')
let itemConStr = itemConList.join(' ')
lineList.push(itemConStr)
})
str = lineList.join('\n')
console.log('tableDoc:', str)
this.node.value = str
}
},
validTable(rule, value, callback) {
let flag = this.tableList.some((item) => {
return item.docnam && item.cmail1
})
if (!flag) {
callback(new Error('必输项'))
} else {
callback()
}
}
}
}
</script>
<style scoped>
.el-table .warning-row {
background: oldlace;
}
.el-table .success-row {
background: #f0f9eb;
}
.selectColumnClass .el-checkbox__label {
width: 67px;
font-size: 13px;
}
</style>