MrShi
2024-03-05 84b74d64ecc519882b89278f1011f7ac7525d190
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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
<template>
    <GlobalWindow
        :title="title"
        width="100%"
        :visible.sync="visible"
        :confirm-working="isWorking"
        @confirm="confirm"
    >
        <el-form :model="form" ref="form" :rules="rules">
            <el-form-item label="方案名称" prop="name">
                <el-input v-model="form.name" placeholder="请输入" v-trim/>
            </el-form-item>
            <el-form-item label="保险公司" prop="insuranceId">
                <el-select v-model="form.insuranceId" @change="getAllWorktype1" placeholder="请选择">
                    <el-option
                        v-for="item in company"
                        :key="item.id"
                        :label="item.name"
                        :value="item.id">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="承保公司" prop="companyName">
                <el-input v-model="form.companyName" placeholder="请输入" v-trim/>
            </el-form-item>
            <el-form-item label="投保年龄" prop="minAge">
                <div style="display: flex; align-items: center;">
                    <el-select v-model="form.minAge" style="flex: 1;" placeholder="请选择">
                        <el-option
                            v-for="item in 80"
                            :key="item"
                            :label="item"
                            :value="item">
                        </el-option>
                    </el-select>
                    <span style="margin: 0 30px;">至</span>
                    <el-select v-model="form.maxAge" style="flex: 1;" placeholder="请选择">
                        <el-option
                            v-for="item in 80"
                            :key="item"
                            :label="item"
                            :value="item">
                        </el-option>
                    </el-select>
                </div>
            </el-form-item>
            <el-form-item label="保险费用" prop="price">
                <div style="display: flex; align-items: center;">
                    <el-input v-model="form.price" style="flex: 1;" placeholder="请输入" v-trim/>
                    <span style="margin: 0 30px;">元/人</span>
                    <el-select v-model="form.timeUnit" style="flex: 1;" placeholder="请选择">
                        <el-option label="天" :value="0"></el-option>
<!--                        <el-option label="半月" :value="1"></el-option>-->
                        <el-option label="月" :value="2"></el-option>
                        <el-option label="年" :value="3"></el-option>
                    </el-select>
                </div>
            </el-form-item>
            <el-form-item label="投保周期" prop="insureCycle">
                <div style="display: flex; align-items: center;">
                    <el-input v-model="form.insureCycle" style="flex: 1;" placeholder="请输入" v-trim/>
                    <span style="margin: 0 30px;"></span>
                    <el-select v-model="form.insureCycleUnit" style="flex: 1;" placeholder="请选择">
                        <el-option label="天" :value="0"></el-option>
<!--                        <el-option label="半月" :value="1"></el-option>-->
                        <el-option label="月" :value="2"></el-option>
                        <el-option label="年" :value="3"></el-option>
                    </el-select>
                </div>
            </el-form-item>
            <el-form-item label="生效时间" prop="validTypeNum">
                <div style="width: 100%; display: flex; align-items: center;">
                    <div style="flex-shrink: 0;">
                        <el-radio-group v-model="form.validType" @change="form.validTypeNum = ''">
                            <el-radio :label="0">日后生效</el-radio>
                            <el-radio :label="1">次月生效</el-radio>
                        </el-radio-group>
                    </div>
                    <el-input style="margin-left: 20px;" type="number" v-model="form.validTypeNum" placeholder="请输入延迟天数" v-if="form.validType === 0"></el-input>
                </div>
            </el-form-item>
            <el-form-item label="投保类型" prop="type">
                <el-radio-group v-model="form.type">
                    <el-radio :label="0">直保</el-radio>
                    <el-radio :label="1">委托投保</el-radio>
                </el-radio-group>
            </el-form-item>
            <el-form-item label="接收文件邮箱" prop="email">
                <el-input v-model="form.email" placeholder="请输入" v-trim/>
            </el-form-item>
<!--            <el-form-item label="投保单签章关键字(如有多个关键字,请使用英文分号 ; 隔开)" prop="signKeyword">
                <el-input v-model="form.signKeyword" placeholder="多个英文分号 ; 隔开" v-trim/>
            </el-form-item>-->
            <el-button type="primary" @click="add">添加工种</el-button>
            <el-table
                :data="form.worktypeIdList"
                border
                style="width: 100%; margin-bottom: 20px;">
                <el-table-column
                    label="序号"
                    align="center"
                    width="80">
                    <template slot-scope="scope">
                        <span>{{scope.$index + 1}}</span>
                    </template>
                </el-table-column>
                <el-table-column
                    align="center"
                    label="所属工种">
                    <template slot-scope="{row}">
                        <el-select filterable v-model="row.worktypeId" placeholder="请选择">
                            <el-option
                                v-for="item in typeWork"
                                :key="item.id"
                                :label="item.name"
                                :value="item.id">
                            </el-option>
                        </el-select>
                    </template>
                </el-table-column>
                <el-table-column
                    label="操作"
                    align="center"
                    width="100">
                    <template slot-scope="scope">
                        <el-button type="text" size="small" style="color: red;" @click="dele(scope.$index)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <el-form-item label="特别约定" prop="specialAgreement">
                <el-input type="textarea" v-model="form.specialAgreement" placeholder="请输入特别约定" v-trim/>
            </el-form-item>
            <el-form-item label="特别说明" prop="specialInfo">
                <el-input type="textarea" v-model="form.specialInfo" placeholder="请输入特别说明" v-trim/>
            </el-form-item>
            <el-form-item label="其他说明" prop="ortherInfo">
                <el-input type="textarea" v-model="form.ortherInfo" placeholder="请输入其他说明" v-trim/>
            </el-form-item>
        </el-form>
    </GlobalWindow>
</template>
 
<script>
    import BaseOpera from '@/components/base/BaseOpera'
    import GlobalWindow from '@/components/common/GlobalWindow'
    import { all } from '@/api/business/insurance'
    import { all as allWorktype } from '@/api/business/worktype'
    import { solutionsId } from '@/api/business/solutions'
    export default {
        name: 'OperaSolutionsWindow',
        extends: BaseOpera,
        components: { GlobalWindow },
        data () {
            var validType = (rule, value, callback) => {
                if (this.form.validType === 0 && !value) {
                    return callback(new Error('延迟天数不能为空'));
                } else if (this.form.validType === 0 && !/^[0-9]*[1-9][0-9]*$/.test(value)) {
                    return callback(new Error('延迟天数只能为正整数'));
                }
                callback();
            }
            return {
                // 表单数据
                form: {
                    id: null,
                    name: '',
                    companyName: '',
                    insuranceId: '',
                    validType: 0,
                    type: 0,
                    minAge: '',
                    maxAge: '',
                    price: '',
                    timeUnit: '',
                    insureCycle: '',
                    insureCycleUnit: '',
                    email: '',
                    specialAgreement: '',
                    specialInfo: '',
                    ortherInfo: '',
                    signKeyword: '',
                    validTypeNum: '',
                    worktypeIdList: [{ worktypeId: '' }]
                },
                // 验证规则
                rules: {
                    name: [
                        { required: true, message: '请输入方案名称' }
                    ],
                    insuranceId: [
                        { required: true, message: '请选择保险公司' }
                    ],
                    companyName: [
                        { required: true, message: '请输入承保公司' }
                    ],
                    minAge: [
                        { required: true, message: '请选择投保年龄' }
                    ],
                    price: [
                        { required: true, message: '请输入保险费用' }
                    ],
                    insureCycle: [
                        { required: true, message: '请输入投保周期' }
                    ],
                    validTypeNum: [
                        { required: true, validator: validType }
                    ],
                    type: [
                        { required: true, message: '请选择投保类型' }
                    ],
                    // signKeyword: [
                    //     { required: false, message: '请输入投保单签章关键字' }
                    // ]
                },
                company: [],
                typeWork: []
            }
        },
        created () {
            this.config({
                api: '/business/solutions',
                'field.id': 'id'
            })
        },
        methods: {
            // 切换公司
            getAllWorktype1() {
                this.form.worktypeIdList = [{ worktypeId: '' }]
                this.getAllWorktype()
            },
            // 确认新建/修改
            confirm () {
                let data = JSON.parse(JSON.stringify(this.form))
                data.worktypeIdList = data.worktypeIdList.map(item => item.worktypeId)
                this.$refs.form.validate((valid) => {
                    if (!valid) {
                        return
                    }
                    // 调用新建接口
                    this.isWorking = true
                    if (data.id == null || data.id === '') {
                        this.api.create(data)
                            .then(() => {
                                this.visible = false
                                this.$tip.apiSuccess('新建成功')
                                this.$emit('success')
                            })
                            .catch(e => {
                                this.$tip.apiFailed(e)
                            })
                            .finally(() => {
                                this.isWorking = false
                            })
                    } else {
                        this.api.updateById(data)
                            .then(() => {
                                this.visible = false
                                this.$tip.apiSuccess('修改成功')
                                this.$emit('success')
                            })
                            .catch(e => {
                                this.$tip.apiFailed(e)
                            })
                            .finally(() => {
                                this.isWorking = false
                            })
                    }
                })
            },
            open (title, target) {
                this.title = title
                this.form.maxAge = ''
                this.form.timeUnit = ''
                this.form.insureCycleUnit = ''
                this.form.validTypeNum = ''
                this.visible = true
                this.form.worktypeIdList = [{ worktypeId: '' }]
                this.allCompany()
                // 新建
                if (target == null) {
                    this.$nextTick(() => {
                        this.$refs.form.resetFields()
                        this.form[this.configData['field.id']] = null
                    })
                    return
                }
                // 编辑
                this.$nextTick(() => {
                    solutionsId(target.id)
                        .then(res => {
                            for (const key in this.form) {
                                this.form[key] = res[key]
                            }
                            this.form.worktypeIdList = res.worktypeList.map(item => {
                                return {
                                    worktypeId: item.worktypeId
                                }
                            })
                            this.getAllWorktype()
                        })
                })
            },
            // 查询保险公司下全部工种
            getAllWorktype() {
                allWorktype({
                    insuranceId: this.form.insuranceId
                }).then(res => {
                    this.typeWork = res
                })
            },
            // 查询全部保险公司
            allCompany() {
                all({ dataType: 2, status: 0 })
                    .then(res => {
                        console.log(res)
                        this.company = res
                    })
            },
            add() {
                this.form.worktypeIdList.push({ worktypeId: '' })
            },
            dele(index) {
                if (this.form.worktypeIdList.length === 1) {
                    this.$message.warning('至少要保留一项')
                    return
                }
                this.form.worktypeIdList.splice(index, 1)
            }
        }
    }
</script>