GuLiMmo
2023-12-25 36cf6c5a265d3300a286e2aff6058b82bca8227e
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
<template>
    <el-dialog v-model="params.visible" title="新增候选人" width="60%" destroy-on-close>
        <avue-crud v-model="form" :option="option" :data="data" v-model:page="table.page" :table-loading="table.loading"
            @row-save="rowSave" @selection-change="selectionChange" @on-load="onLoad">
            <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>
    </el-dialog>
</template>
 
<script setup>
import { computed, getCurrentInstance, reactive, ref, watch } from 'vue';
import _ from 'lodash'
import { ElMessage } from 'element-plus'
import {
    getList
} from '@/api/system/user';
import {
    getCandidateList,
    addCandidate,
    removeCandidate
} from '@/api/evaluate/evaluateTask'
 
const dataSourceStatus = {
    0: '系统分配',
    1: '手动添加'
}
 
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 table = reactive({
    loading: false,
    page: {
        pageSize: 10,
        currentPage: 1,
        total: 0,
    },
    selectionList: [],
})
 
const option = reactive({
    height: '300',
    tip: false,
    searchShow: true,
    searchMenuSpan: 6,
    border: true,
    index: true,
    viewBtn: false,
    addBtn: true,
    editBtn: false,
    delBtn: false,
    selection: false,
    refreshBtn: false,
    dialogClickModal: false,
    menuFixed: 'right',
    labelWidth: 100,
    column: [
        {
            label: '候选人姓名',
            prop: 'userId',
            type: 'select',
            dicData: [],
            props: {
                label: 'name',
                value: 'id'
            },
            control: (val, row) => {
                const { findObject } = config
                const column = findObject(option.column, 'userId') || []
                const params = column.dicData.find(item => item.id === val)
                if (!params) return
                row.deptName = params.deptName
                row.postName = params.postName
                row.userName = params.name
            },
            rules: [
                {
                    required: true,
                    message: '请选择候选人',
                    trigger: 'blur',
                },
            ]
        },
        {
            label: '部门',
            prop: 'deptName',
            type: 'input',
            disabled: true,
        },
        {
            label: '部门',
            prop: 'postName',
            type: 'input',
            disabled: true,
        },
        {
            label: '数据来源',
            prop: 'dataSource',
            type: 'input',
            display: false,
            formatter: (row) => {
                return dataSourceStatus[row.dataSource] || '系统分配'
            },
        }
    ]
})
 
 
const initData = () => {
    const { findObject } = config
    const column = findObject(option.column, 'userId');
    getList(1, 999999, { userType: 2 }).then(res => {
        column.dicData = res.data.data.records
    })
}
 
const rowSave = (row, done, loading) => {
    const { data: { id, taskName } } = $props.params
    addCandidate({
        evaluateTaskId: id,
        evaluateTaskName: taskName,
        ...row,
        dataSource: 1
    }).then(res => {
        ElMessage.success('新增候选人成功');
        onLoad(table.page);
        done();
    }, error => {
        loading();
        console.log(error);
    })
}
 
const rowDel = ({ id }) => {
    removeCandidate(id).then(res => {
        ElMessage.success('删除当前候选人成功');
        onLoad(table.page);
    }, error => {
        ElMessage.error(error);
        console.log(error);
    })
}
 
const selectionChange = (list) => {
    table.selectionList = list;
}
 
const onLoad = (page, params = {}) => {
    table.loading = true;
 
    let values = {
        evaluateTaskId: $props.params.data.id,
        ...params
    };
    getCandidateList(page.currentPage, page.pageSize, values).then(res => {
        const candidateRes = res.data.data;
        table.page.total = candidateRes.total;
        data.value = candidateRes.records;
        table.loading = false;
    });
}
 
watch(() => $props.params.visible, (val) => {
    val && initData();
}, {
    deep: true,
    immediate: true
})
 
const ids = computed(() => {
    let ids = [];
    table.selectionList.forEach(ele => {
        ids.push(ele.id);
    });
    return ids.join(',');
})
</script>
 
<style lang="scss" scoped></style>