add.vue
6.25 KB
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
<template>
<el-dialog :title="title" :visible.sync="open" v-if="open" width="1000px" append-to-body>
<el-row :span="24">
<el-form ref="form" :model="form" :rules="rules" label-width="100px">
<el-col :span="12">
<el-form-item label="客户名称" prop="applyUserName">
<el-input v-model="form.applyUserName" placeholder="请输入客户名称" />
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="手机号码" prop="phone">
<el-input v-model="form.phone" placeholder="请输入编码名称" />
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="身份证号码" prop="idCard">
<el-input v-model="form.idCard" placeholder="请输入身份证号码" />
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="产品名称" prop="applyProductCode">
<el-select v-model="form.applyProductCode" placeholder="产品名称" clearable size="small">
<el-option v-for="(item, index) in product" :key="index" :label="item.name" :value="item.businessCode" />
</el-select>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="风控类型" prop="applyCreditType">
<el-select v-model="form.applyCreditType" placeholder="风控类型" clearable size="small">
<el-option v-for="dict in dict.type.file_risk_type" :key="dict.value" :label="dict.label"
:value="dict.value" />
</el-select>
</el-form-item>
</el-col>
<div class="box1">
<el-form-item label="身份证正面照" prop="status">
<el-upload class="avatar-uploader" action :show-file-list="false" :on-success="handleAvatarSuccess"
:before-upload="beforeAvatarUpload" :http-request="uploadSectionFile">
<img v-if="imageUrl" :src="imageUrl" class="avatar">
<i v-else class="el-icon-plus avatar-uploader-icon"></i>
</el-upload>
</el-form-item>
<el-form-item label="身份证反面照" prop="status">
<el-upload class="avatar-uploader" action="https://jsonplaceholder.typicode.com/posts/"
:show-file-list="false" :on-success="handleAvatarSuccess" :before-upload="beforeAvatarUpload">
<img v-if="imageUrl" :src="imageUrl" class="avatar">
<i v-else class="el-icon-plus avatar-uploader-icon"></i>
</el-upload>
</el-form-item>
</div>
</el-form>
</el-row>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitForm">确 定</el-button>
<el-button @click="cancel">取 消</el-button>
</div>
</el-dialog>
</template>
<script>
import { applyInfoSave, ossUploadFile, ossDownloadFile, selectAll } from "@/api/postList/list";
export default {
name: 'addMobile',
dicts: ['file_risk_type'],
data() {
return {
imageUrl: '',
open: false,
// 弹出层标题
title: "",
// 表单参数
form: {},
// 表单校验
product: [],
rules: {
applyUserName: [
{ required: true, message: "客户名称不能为空", trigger: "blur" }
],
phone: [
{ required: true, message: "手机号码不能为空", trigger: "blur" }
],
idCard: [
{ required: true, message: "身份证号码不能为空", trigger: "blur" }
],
applyProductCode: [
{ required: true, message: "产品名称不能为空", trigger: "blur" }
],
applyCreditType: [
{ required: true, message: "风控类型不能为空", trigger: "blur" }
]
}
}
},
methods: {
// 取消按钮
cancel() {
this.open = false;
this.form = {}
},
add() {
this.open = true;
this.title = "添加风控申请";
this.form = {}
var lis = {
pageNum: 1,
pageSize: 10000,
}
selectAll(lis).then(response => {
this.product = response.data;
});
},
edit(res) {
this.form = res
this.open = true;
this.title = "修改风控申请";
},
uploadSectionFile(params) {
const file = params.file,
fileType = file.type,
isImage = fileType.indexOf("image") != -1,
isLt2M = file.size / 1024 / 1024 < 5;
if (!isImage) {
this.$message.error("只能上传图片格式png、jpg");
return;
}
if (!isLt2M) {
this.$message.error("只能上传图片大小小于5M");
return;
}
const form = new FormData();
form.append("file", file);
ossUploadFile(form)
.then(res => {
const code = res && parseInt(res.code, 10);
if (code === 200) {
// xxx
} else {
// xxx
}
})
.catch(() => {
// xxx
});
},
handleAvatarSuccess(res, file) {
this.imageUrl = URL.createObjectURL(file.raw);
},
beforeAvatarUpload(file) {
const isJPG = file.type === 'image/jpeg';
const isLt2M = file.size / 1024 / 1024 < 5;
if (!isJPG) {
this.$message.error('上传头像图片只能是 JPG 格式!');
}
if (!isLt2M) {
this.$message.error('上传头像图片大小不能超过 5MB!');
}
return isJPG && isLt2M;
},
/** 提交按钮 */
submitForm: function () {
this.$refs["form"].validate(valid => {
if (valid) {
applyInfoSave(this.form).then(response => {
this.$modal.msgSuccess("新增成功");
this.open = false;
this.$emit('getList')
});
}
});
},
}
}
</script>
<style>
.box1 {
display: flex;
justify-content: space-around;
width: 100%;
}
.avatar-uploader .el-upload {
border: 1px dashed #d9d9d9;
border-radius: 6px;
cursor: pointer;
position: relative;
overflow: hidden;
}
.avatar-uploader .el-upload:hover {
border-color: #409EFF;
}
.avatar-uploader-icon {
font-size: 28px;
color: #8c939d;
width: 178px;
height: 178px;
line-height: 178px;
text-align: center;
}
.avatar {
width: 178px;
height: 178px;
display: block;
}
</style>