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
| <template>
| <el-dialog v-model="params.visible" title="新增候选人" width="60%" destroy-on-close>
| <div class="table-box">
| <avue-crud v-model="form" :option="option" :data="data" @row-save="rowSave">
| <template #menu="{ row }">
| <el-popconfirm title="是否确认删除当前候选人?" @confirm="rowDel(row)">
| <template #reference>
| <el-button text plan type="primary" icon="el-icon-delete">删除</el-button>
| </template>
| </el-popconfirm>
| </template>
| </avue-crud>
| </div>
| </el-dialog>
| </template>
|
| <script setup>
| import { getCurrentInstance, reactive, ref, watch } from 'vue';
| import _ from 'lodash'
| import { ElMessage } from 'element-plus'
| import {
| getList
| } from '@/api/system/user';
| import { update } from '@/api/evaluate/evaluateTask';
|
| const config = getCurrentInstance().appContext.config.globalProperties
|
| const $props = defineProps({
| params: {
| type: Object,
| default: () => ({
| visible: false,
| type: 0,
| data: {},
| }),
| }
| })
|
| const $emit = defineEmits(['refreshTable'])
|
| const data = ref([])
| const form = ref({})
|
| const option = reactive({
| height: '300',
| tip: false,
| searchShow: true,
| searchMenuSpan: 6,
| border: true,
| index: true,
| viewBtn: false,
| addBtn: true,
| editBtn: false,
| delBtn: false,
| selection: true,
| refreshBtn: false,
| dialogClickModal: false,
| menuFixed: 'right',
| column: [
| {
| label: '候选人姓名',
| prop: 'name',
| type: 'select',
| dicData: [],
| props: {
| label: 'name',
| value: 'id'
| },
| control: (val, row) => {
| const { findObject } = config
| const { dicData } = findObject(option.column, 'name')
| const data = dicData.find(item => item.id === val)
| row.deptName = data.deptName || ''
| row.deptId = data.deptId || ''
| form.value = row
| }
| },
| {
| label: '部门',
| prop: 'deptName',
| type: 'select',
| disabled: true,
| }
| ]
| })
|
|
| const initData = () => {
| const { candidateNum } = _.cloneDeep($props.params.data)
| const userList = []
| candidateNum.forEach(item => {
| const { deptName, deptId, users } = item
| users.forEach(user => {
| user.deptName = deptName
| user.deptId = deptId
| userList.push(user)
| })
| })
| data.value = userList
|
| const { findObject } = config
| const column = findObject(option.column, 'name');
| getList(1, 999999, {}).then(res => {
| column.dicData = res.data.data.records
| })
| }
|
| const rowSave = (row, done) => {
| const { findObject } = config
| const column = findObject(option.column, 'name');
| const params = $props.params.data
| const info = params.candidateNum.find(item => item.deptId === row.deptId)
| const { name } = column.dicData.find(item => item.id === row.name)
| const is = data.value.find(item => item.id === row.name)
| if (is) {
| ElMessage.warning('当前候选人已存在')
| done()
| } else {
| const user = {
| id: row.name,
| name
| }
| info.users.push(user)
| update(params).then(
| () => {
| ElMessage({
| type: 'success',
| message: '操作成功!',
| });
| initData()
| $emit('refreshTable', '')
| done()
| },
| error => {
| ElMessage({
| type: 'error',
| message: error,
| });
| }
| );
|
| }
| }
|
| const rowDel = (row) => {
| const { $index, id, deptId } = row
| const params = $props.params.data
| const info = params.candidateNum.find(item => item.deptId === deptId)
| const index = info.users.findIndex(item => item.id === id)
| info.users.splice(index, 1)
| // if (info.val === 0) {
|
| // }
| // if (info.val > info.users.length) {
| // info.val = info.users.length
| // }
| // update(params).then(
| // () => {
| // ElMessage({
| // type: 'success',
| // message: '操作成功!',
| // });
| // initData()
| // $emit('refreshTable', '')
| // },
| // error => {
| // ElMessage({
| // type: 'error',
| // message: error,
| // });
| // }
| // );
| }
|
| watch(() => $props.params.visible, (val) => {
| val && initData();
| }, {
| deep: true,
| immediate: true
| })
| </script>
|
| <style lang="scss" scoped>
| .table-box {
| height: 400px;
| overflow-x: auto;
| }
| </style>
|
|