Blame view

src/components/modal-upload-card-comp/modal-upload-card-comp.js 3.9 KB
simon committed
1 2 3 4
/**
 * 组件描述:证件上传组件
 */

simon committed
5 6 7 8 9
import api from '@/api/api'
import {
	httpGet,
	httpPost
} from '@/api/fetch-api.js'
joe committed
10
import { read } from 'fs';
simon committed
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


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
1  
joe committed
80 81 82 83
		},
		showType: {
			type: String,
			default: "owner"
simon committed
84 85 86 87
		}
	},
	data() {
		return {
joe committed
88
			key: 'value',
1  
joe committed
89 90 91 92 93 94 95 96 97
			ownerFrontPicSrc: null,
			ownerBackPicSrc: null,
			ownerFrontPicFile: null,
			ownerBackPicFile: null,

			insuredFrontPicSrc: null,
			insuredBackPicSrc: null,
			insuredFrontPicFile: null,
			insuredBackPicFile: null
simon committed
98 99 100
		}
	},
	components: {},
joe committed
101 102
	computed: {
		submitBtnDisabled() {
1  
joe committed
103 104 105 106 107 108 109 110 111 112 113 114 115 116
			let b = false;
			if (this.showType == "owner" || this.showType == "both") {
				let b1 = this.ownerFrontPicSrc ? false : true;
				let b2 = this.ownerBackPicSrc ? false : true;
				b = b1 || b2;
			}

			if (this.showType == "insured" || this.showType == "both") {
				let b3 = this.insuredFrontPicSrc ? false : true;
				let b4 = this.insuredBackPicSrc ? false : true;

				b = b || b3 || b4;
			}
			return b;
joe committed
117 118
		}
	},
simon committed
119 120 121
	methods: {
		// 点击确认
		onConfirmHandler() {
joe committed
122 123
			if (this.submitBtnDisabled) {
				return;
simon committed
124
			}
1  
joe committed
125 126 127 128 129 130 131

			this.$emit("onSubmit", {
				ownerFrontPicFile: this.ownerFrontPicFile,
				ownerBackPicFile: this.ownerBackPicFile,
				insuredFrontPicFile: this.insuredFrontPicFile,
				insuredBackPicFile: this.insuredBackPicFile
			});
joe committed
132 133 134 135 136 137 138 139 140
		},
		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) {
1  
joe committed
141 142 143 144 145 146 147 148 149 150 151 152 153
					switch (type) {
						case "ownerFront":
							_this.$set(_this, 'ownerFrontPicSrc', reader.result);
							break;
						case "ownerBack":
							_this.$set(_this, 'ownerBackPicSrc', reader.result);
							break;
						case "insuredFront":
							_this.$set(_this, 'insuredFrontPicSrc', reader.result);
							break;
						case "insuredBack":
							_this.$set(_this, 'insuredBackPicSrc', reader.result);
							break;
joe committed
154 155 156
					}
				}
				let file = input.files[0];
1  
joe committed
157 158 159 160 161 162 163 164 165 166 167 168 169
				switch (type) {
					case "ownerFront":
						_this.$set(_this, 'ownerFrontPicFile', file);
						break;
					case "ownerBack":
						_this.$set(_this, 'ownerBackPicFile', file);
						break;
					case "insuredFront":
						_this.$set(_this, 'insuredFrontPicFile', file);
						break;
					case "insuredBack":
						_this.$set(_this, 'insuredBackPicFile', file);
						break;
joe committed
170 171 172 173
				}
				reader.readAsDataURL(file);
			};
			input.click();
simon committed
174 175 176
		},
		// 点击取消
		onCancelHandler() {
joe committed
177
			this.$emit("close");
simon committed
178 179 180
		},
		// 点击关闭
		onCloseHandler() {
joe committed
181
			this.$emit("close");
simon committed
182 183 184
		},
		// 点击蒙层
		onOverLayHandler() {
joe committed
185
			this.$emit("close");
simon committed
186
		},
joe committed
187 188 189 190 191 192
		init() {
			this.frontPicFile = null;
			this.backPicFile = null;
			this.frontPicSrc = null;
			this.backPicSrc = null;
		}
simon committed
193
	},
joe committed
194
	mounted() { },
1  
joe committed
195 196
	created() {
	 }
simon committed
197
}