certification.vue
4.1 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
<template>
<div>
<group>
<cell>
<p slot="title">车牌号码:{{ $route.query.carNum }}</p>
<p slot class="carColor" :class="carBgFilter($route.query.carNumberColor)"></p>
</cell>
</group>
<div style="padding: 15px;position: relative">
<img :src="carPic" width="100%" height="180px">
<div class="camera"></div>
<input type="file" class="upload" @change="addImg" ref="inputer"
accept="image/png,image/jpeg,image/gif,image/jpg"/>
</div>
<div class="tipWrap">
<span>照片须符合如下条件:</span>
<p>
1、行驶证正面。
</p>
<p>
2、信息清晰显示真实有效。
</p>
</div>
<div style="padding: 20px 15px">
<x-button type="primary" @click.native="cerHandle">提交认证</x-button>
</div>
</div>
</template>
<script>
import { userCarsInfoEdit, uploadPic } from "@/api/myCars/myCars";
export default {
name: "certification",
data() {
return {
carPic: require("../../assets/images/myCars/carPic.png"),
formData: new FormData(),
fil: ""
};
},
methods: {
addImg(e) {
// this.formData = new window.FormData();
// 获取待上传的文件对象
this.fil = e.target.files[0];
console.log(this.fil);
let file = e.target.files[0];
// 声明一个读取文件对象
let reader = new FileReader();
// 开始读取文件内容
reader.readAsDataURL(file);
// 读取操作结束时触发
reader.onloadend = (ev) => {
// 赋值给vue对象属性
this.carPic = ev.target.result;
};
},
cerHandle() {
if (this.fil) {
console.log(this.fil);
let params = new FormData();
params.append("picFile", this.fil);
params.append("fileType", 7);
params.append("token", sessionStorage.getItem("wx_Token")); // sessionStorage.getItem("wx_Token")
uploadPic(params).then(data => {
console.log(data);
if (data.code == 0) {
let res = data.data;
this.rez(res);
} else {
this.$vux.toast.text(data.message, "top");
}
});
} else {
this.$vux.toast.text("请先上传图片再认证", "top");
}
},
rez(res) {
let arr = [];
let carlist = {
carNumber: this.$route.query.carNum,
cerPicturePath: res,
carNumberColor: this.$route.query.carNumberColor,
id: this.$route.query.id
};
let jsondata = this.$utils.commonParams();
arr.push(carlist);
// 状态;1-已使用,0-未使用, 2-已使用+未使用
jsondata.optType = "02";
jsondata.carNumbers = JSON.stringify(arr);
jsondata.sign = this.$utils.signObject(jsondata);
userCarsInfoEdit(jsondata).then(data => {
console.log(data);
if (data.code == 0) {
this.$router.push({
path: "myCars"
});
} else {
this.$vux.toast.text(data.message, "top");
}
});
},
carBgFilter: function(val) {
console.log(val);
// 车牌颜色:0:蓝牌;1:黄牌;2:白牌;3:黑牌;4:绿色
if (val == 0) {
return "blueBg";
}
if (val == 1) {
return "yellowBg";
}
if (val == 2) {
return "whiteBg";
}
if (val == 3) {
return "blackBg";
}
if (val == 4) {
return "greenBg";
}
}
}
};
</script>
<style scoped lang="scss">
> > > .weui-cells {
margin-top: 0;
}
.carPic {
width: 100%;
height: 160px;
background: url("../../assets/images/myCars/carPic.png");
background-size: 100% 100%;
}
.camera {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 70px;
height: 70px;
background: url("../../assets/images/myCars/camera.png");
background-size: 100% 100%;
}
.upload {
width: 100%;
height: 100%;
opacity: 0;
position: absolute;
top: 0;
left: 0;
z-index: 100;
}
.tipWrap {
padding: 15px;
p {
text-indent: 15px;
}
}
</style>