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
<template>
<div>
<a-row>
<a-col :span="24">
<div class="tb-title">
<span>项目合作单位</span>
</div>
</a-col>
</a-row>
<a-row type="flex" class="row_center">
<a-col :span="2" class="bg-gray">
<div class="special-middle">
<div>序号</div>
</div>
</a-col>
<a-col :span="18" class="bg-gray">
<div class="special-middle">
<div class="required">单位名称</div>
</div>
</a-col>
<a-col :span="4" class="bg-gray">
<div class="special-middle">
<div>操作</div>
</div>
</a-col>
</a-row>
<a-row v-for="(item, index) in cooperativeUnits" :key="'cooperativeUnits'+index" type="flex" class="row_center">
<a-col :span="2">
<div class="special-middle">
<div>
{{ index + 1 }}
</div>
</div>
</a-col>
<a-col :span="18">
<div class="special-middle">
<div>
<a-form-model-item :prop="'cooperativeUnits.' + index + '.unitName'" :rules="{ required: true,message: '*',trigger: 'blur',}">
<a-input v-model="item.unitName" :maxLength="20" placeholder="单位名称" style="width: 80%" />
</a-form-model-item>
</div>
</div>
</a-col>
<a-col :span="4">
<div class="special-middle">
<a-button icon="arrow-up" type="primary" shape="circle" size="small" :disabled="index == 0" @click="moveUp(index)"></a-button>
<a-button icon="arrow-down" type="primary" shape="circle" size="small" style="margin-left:3px" :disabled="cooperativeUnits.length == index + 1" @click="moveDown(index)"></a-button>
<a-popconfirm title="确定要删除吗?" ok-text="确定" cancel-text="取消" @confirm="removeArray(item)">
<a-button type="link" size="small">[删除]</a-button>
</a-popconfirm>
</div>
</a-col>
</a-row>
<a-row type="flex">
<a-col :span="24" style="text-align: center;">
<div class="special-middle">
<a-button type="dashed" style="width: 50%" @click="addArray">
<a-icon type="plus" /> 添加
</a-button>
</div>
</a-col>
</a-row>
</div>
</template>
<script>
//用法 <cooperative-units :cooperativeUnits.sync="formData.cooperativeUnits" />
const Model = { id: null, unitName: null }
export default {
name: 'cooperativeUnits',
data () {
return {
list: []
}
},
props: {
cooperativeUnits: {
type: Array,
default: () => {
return [{ ...Model }]
}
},
},
components: {
},
created () {
},
methods: {
moveToTop (item) {//成员置顶
let index = this.cooperativeUnits.indexOf(item)
if (index !== -1) {
this.cooperativeUnits.splice(index, 1)
this.cooperativeUnits.unshift({ ...item })
}
},
moveUp (index) {
let arr = this.cooperativeUnits
arr.splice(index - 1, 1, ...arr.splice(index, 1, arr[index - 1]))
},
moveDown (index) {
let arr = this.cooperativeUnits
arr.splice(index, 1, ...arr.splice(index + 1, 1, arr[index]))
},
addArray () {//添加成员
this.cooperativeUnits.push({ ...Model })
},
removeArray (item) {//移除成员
let index = this.cooperativeUnits.indexOf(item)
if (index !== -1) {
this.cooperativeUnits.splice(index, 1)
}
},
},
}
</script>