<template>
	<view class="main">
		<view class="padding-lr-sm margin-top-sm">
			<text class="text-black">上传被保人证件照片</text>
		</view>
		<view class="padding-lr-sm text-sm text-gray margin-top-sm margin-bottom-sm">
			办理家医计划业务需上传被保人清晰证件照片(身份证正反面，护照，户口簿选择其中一种即可)
		</view>
		<u-upload ref="uUpload" :action="action" max-count="2"></u-upload>
		<view class="cu-bar bg-white tabbar" style="position: fixed;bottom: 0;width: 100%;">
			<view class="submit" style="background-color: #0B73B9;color: white;" @click="upcard">
				提交审核
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		onLoad(options) {
			if (options.id) {
				this.archivesId = options.id
			}
		},
		onShow() {

		},
		data() {
			return {
				action: "https://t5.9026.com/api/v1/common/uploadFile",
				filesArr: [],
				archivesId: ""
			}
		},
		methods: {
			upcard: async function() {
				let files = [];
				// 通过filter，筛选出上传进度为100的文件(因为某些上传失败的文件，进度值不为100，这个是可选的操作)
				files = this.$refs.uUpload.lists.filter(val => {
					return val.progress == 100;
				})
				files = files.map(item => {
					return item.response.data.url
				})
				// 如果您不需要进行太多的处理，直接如下即可
				// files = this.$refs.uUpload.lists;
				if (files.length != 0) {
					let res = await this.$request.post("/api/v1/patient/submitCardImg", {
						id: this.archivesId,
						card_img_url: files[0],
						card_back_img_url:files[1]
					})
					if (res.status == 0) {
						uni.showToast({
							title: "上传成功",
							icon: "none",
							duration: 1500
						})
						setTimeout(() => {
							uni.navigateBack({
								delta: 1
							})
						}, 1500)
					}
				}
			}
		}
	};
</script>

<style scoped lang="scss">
	.main {}
</style>
