modal-upload-card-comp.js
2.72 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
import api from '@/api/api'
import {
httpGet,
httpPost
} from '@/api/fetch-api.js'
import { read } from 'fs';
export default {
props: {
// 是否显示组件
visible: {
type: Boolean,
default: true,
},
// 标题名称 需要再 assets/images/common/ 目录下添加图标
icon: {
type: String,
default: "succ",
},
// 标题,不建议使用
title: {
type: String,
default: "",
},
// 文案
content: {
type: String,
default: "",
},
// 确认文案
confirmText: {
type: String,
default: "確認",
},
// 取消文案
cancelText: {
type: String,
default: "取消",
},
// 是否显示确认按钮
showConfirm: {
type: Boolean,
default: true,
},
// 是否显示取消按钮
showCancel: {
type: Boolean,
default: false,
},
// 是否显示遮罩层
overlayShow: {
type: Boolean,
default: true,
},
// 确定按钮回调方法
confirm: {
type: Function,
default: null
},
// 取消按钮回调方法
cancel: {
type: Function,
default: null
},
// 点击关闭回调方法
close: {
type: Function,
default: null
},
// 点击蒙层回调方法
overlay: {
type: Function,
default: null
}
},
data() {
return {
key: 'value',
frontPicSrc: null,
backPicSrc: null,
frontPicFile: null,
backPicFile: null
}
},
components: {},
computed: {
submitBtnDisabled() {
let b1 = this.frontPicFile ? false : true;
let b2 = this.backPicFile ? false : true;
return b1 || b2;
}
},
methods: {
// 点击确认
onConfirmHandler() {
if (this.submitBtnDisabled) {
return;
}
this.$emit("onSubmit", { front: this.frontPicFile, back: this.backPicFile });
},
handlePicSelect(type) {
let _this = this;
let input = document.createElement("input");
input.setAttribute("type", "file");
input.setAttribute("accept", "image/*");
input.onchange = function (val) {
var reader = new FileReader();
reader.onload = function (e) {
if (type == 'front') {
_this.$set(_this, 'frontPicSrc', reader.result);
} else {
_this.$set(_this, 'backPicSrc', reader.result);
}
}
let file = input.files[0];
if (type == 'front') {
_this.$set(_this, 'frontPicFile', file);
} else {
_this.$set(_this, 'backPicFile', file);
}
reader.readAsDataURL(file);
};
input.click();
},
// 点击取消
onCancelHandler() {
this.$emit("close");
},
// 点击关闭
onCloseHandler() {
this.$emit("close");
},
// 点击蒙层
onOverLayHandler() {
this.$emit("close");
},
init() {
this.frontPicFile = null;
this.backPicFile = null;
this.frontPicSrc = null;
this.backPicSrc = null;
}
},
mounted() { },
created() { }
}