<template>
	<view class="head">
		<!-- 资料附件 -->
		<view class="business">
			营业资质或医疗机构许可证<span style="color: red;">*</span>
		</view>
		<view class="upload">
			请上传营业执照
		</view>
		<view class="Business df fdc aic" @click="license">
			<view class="" v-if="licen ||licensea">
				<image v-if="licen.length>0" style="width: 718rpx;height: 332rpx;margin-top: 0;" :src="$util.img(licen)"
					mode=""></image>
				<image v-else style="width: 718rpx;height: 332rpx;margin-top: 0;" :src="$util.img(licensea)" mode="">
				</image>
			</view>
			<view class="df fdc aic" v-else>
				<image :src="$util.img(`/upload/weapp/pageSalesman/search.png`)" mode=""></image>
				<div class="Upload-pictures">上传图片</div>
				<div class="ask">文件大小不超过10M，支持JPG\PNG\JPEG格式</div>
			</view>
		</view>
		<view class="business-two">
			药品经营许可证<span style="color: red;">*</span>
		</view>
		<view class="upload">
			请上传药品经营许可证
		</view>
		<view class="Business df fdc aic" @click="drug">
			<view class="" v-if="dru || drugs_license">
				<image v-if="dru.length>0" style="width: 718rpx;height: 332rpx;margin-top: 0;" :src="$util.img(dru)"
					mode=""></image>
				<image v-else style="width: 718rpx;height: 332rpx;margin-top: 0;" :src="$util.img(drugs_license)"
					mode=""></image>
			</view>
			<view class="df fdc aic" v-else>
				<image :src="$util.img(`/upload/weapp/pageSalesman/search.png`)" mode=""></image>
				<div class="Upload-pictures">上传图片</div>
				<div class="ask">文件大小不超过10M，支持JPG\PNG\JPEG格式</div>
			</view>
		</view>
		<view class="business-two">
			法人身份证<span style="color: red;">*</span>
		</view>
		<view class="upload">
			请上传法人身份证
		</view>
		<view class="Business df fdc aic" @click="status">
			<view class="" v-if="stat ||card_images">
				<!-- <view class="" style="font-size: 24rpx;width: 300rpx;">
					{{stat}}
				</view> -->
				<image v-if="stat.length>0" style="width: 718rpx;height: 332rpx;margin-top: 0;" :src="$util.img(stat)"
					mode=""></image>
				<view v-else v-for="(v,i) in card_images" :key="i">
					<image style="width: 718rpx;height: 332rpx;margin-top: 0;" :src="$util.img(v)" mode="">
					</image>
				</view>
			</view>
			<view class="df fdc aic" v-else>
				<image :src="$util.img(`/upload/weapp/pageSalesman/search.png`)" mode=""></image>
				<div class="Upload-pictures">上传图片</div>
				<div class="ask">文件大小不超过10M，支持JPG\PNG\JPEG格式</div>
			</view>

		</view>
		<view class="business-two">
			法人委托书
		</view>
		<view class="upload">
			请上传法人委托书
		</view>
		<view class="Business df fdc aic" @click="attorney">
			<!-- <view class="" v-if="attorn ||trust_book_images">
				<image v-if="attorn.length>0" style="width: 718rpx;height: 332rpx;margin-top: 0;"
					:src="$util.img(attorn)" mode=""></image>
				<image v-else style="width: 718rpx;height: 332rpx;margin-top: 0;" :src="$util.img(trust_book_images)"
					mode="">
				</image>
			</view> -->

			<image v-if="attorn.length>0" style="width: 718rpx;height: 332rpx;margin-top: 0;" :src="$util.img(attorn)"
				mode=""></image>
			<view v-else v-for="(v,i) in trust_book_images" :key="i">
				<image style="width: 718rpx;height: 332rpx;margin-top: 0;" :src="$util.img(v)" mode="">
				</image>
			</view>

			<view class="df fdc aic" v-if="attorn.length==0 && trust_book_images.length==0">
				<image :src="$util.img(`/upload/weapp/pageSalesman/search.png`)" mode=""></image>
				<div class="Upload-pictures">上传图片</div>
				<div class="ask">文件大小不超过10M，支持JPG\PNG\JPEG格式</div>
			</view>
		</view>
		<view class="business-two">
			发票信息
		</view>
		<view class="upload">
			请上传发票信息
		</view>
		<view class="Business df fdc aic" @click="bill">
			<view class="" v-if="bil||invoice_images">
				<image v-if="bil.length" style="width: 718rpx;height: 332rpx;margin-top: 0;" :src="$util.img(bil)"
					mode=""></image>
				<image v-else-if="invoice_images.length" style="width: 718rpx;height: 332rpx;margin-top: 0;"
					:src="$util.img(invoice_images)" mode=""></image>
			</view>
			<view class="df fdc aic" v-if="bil.length==0 && invoice_images.length==0">
				<image :src="$util.img(`/upload/weapp/pageSalesman/search.png`)" mode=""></image>
				<div class="Upload-pictures">上传图片</div>
				<div class="ask">文件大小不超过10M，支持JPG\PNG\JPEG格式</div>
			</view>
		</view>
		<view class="business-two">
			店铺logo
		</view>
		<view class="upload">
			请上传店铺logo
		</view>
		<view class="Business df fdc aic" @click="logoBtn">
			<view class="" v-if="logoimg||logo">
				<image v-if="logoimg.lengt" style="width: 718rpx;height: 332rpx;margin-top: 0;"
					:src="$util.img(logoimg)" mode=""></image>
				<image v-else-if="logo.length" style="width: 718rpx;height: 332rpx;margin-top: 0;" :src="$util.img(logo)" mode="">
				</image>
			</view>
			<view class="df fdc aic" v-if="logoimg.length==0 && logo.length==0">
				<image :src="$util.img(`/upload/weapp/pageSalesman/search.png`)" mode=""></image>
				<div class="Upload-pictures">上传图片</div>
				<div class="ask">文件大小不超过10M，支持JPG\PNG\JPEG格式</div>
			</view>
		</view>
		<view class="df aic jcsa accomplish" @click="btn">
			完成
		</view>
	</view>
</template>

<script>
	import eventBus from '@/common/js/bus.js'
	export default {
		data() {
			return {
				licen: [],
				dru: [],
				stat: [],
				attorn: [],
				bil: [],
				logoimg: [],
				licensea: '',
				drugs_license: '',
				card_images: [],
				trust_book_images: [],
				invoice_images: '',
				logo: "",
				kpi: '',
				objectt: {}
			};
		},
		onLoad(e) {
			if (e.kpi) {
				this.kpi = e.kpi
			}
			eventBus.$on('measn', (data) => {
				console.log(data, '现在的图片');
				this.objectt = data.card_images
				//营业执照
				this.licensea = data.card_images.license
				//药品经营许可证
				this.drugs_license = data.card_images.drugs_license
				//身份证
				this.card_images = data.card_images.card_images
				//委托书
				this.trust_book_images = data.card_images.trust_book_images
				//发票信息
				this.invoice_images = data.card_images.invoice_images
				//店铺logo
				this.logo = data.card_images.logo
				eventBus.$off('measn')
			})
		},
		methods: {
			//营业执照
			license(type, size = 1) {
				this.$util.upload(size, {
					path: 'otherImage'
				}, res => {
					console.log(res);
					this.licen = res[0]
				})
			},
			//药品许可证
			drug(type, size = 1) {
				this.$util.upload(size, {
					path: 'otherImage'
				}, res => {
					console.log(res);
					this.dru = res[0]
				})
			},
			//法人身份证
			status(type, size = 1) {
				this.$util.upload(size, {
					path: 'otherImage'
				}, res => {
					console.log(res);
					this.stat = res[0]
					console.log(this.stat);
				})
			},
			//法人委托书
			attorney(type, size = 1) {
				this.$util.upload(size, {
					path: 'otherImage'
				}, res => {
					console.log(res);
					this.attorn = res[0]
				})
			},
			//发票信息
			bill(type, size = 1) {
				this.$util.upload(size, {
					path: 'otherImage'
				}, res => {
					console.log(res);
					this.bil = res[0]
				})
			},
			logoBtn(type, size = 1) {
				this.$util.upload(size, {
					path: 'otherImage'
				}, res => {
					console.log(res);
					this.logoimg = res[0]
				})
			},
			btn() {
				console.log(this.kpi);
				if (this.kpi == 1) {
					this.btn1()
					return
				}
				if (this.licen.length == 0) {
					this.$util.showToast({
						title: '请上传营业执照'
					});
					return
				}
				if (this.dru.length == 0) {
					this.$util.showToast({
						title: '请上传药品经营许可证'
					});
					return
				}
				if (this.stat.length == 0) {
					this.$util.showToast({
						title: '请上传法人身份证'
					});
					return
				}

				eventBus.$emit('picture', {
					licen: this.licen,
					dru: this.dru,
					stat: this.stat,
					attorn: this.attorn,
					bil: this.bil,
					logoimg: this.logoimg
				});
				history.back()
			},
			//编辑
			btn1() {
				console.log(this.attorn, 'attorn');
				console.log(this.stat, 'stat');
				// return	
				if (this.stat.length > 0) {
					if (this.stat.length == 0) {
						this.$util.showToast({
							title: '请上传法人身份证'
						});
						return
					}

				}
				this.$api.sendRequest({
					url: `/api/salasman/editStore`,
					header: {
						'Content-Type': 'application/json' //自定义请求头信息
					},
					data: {
						member_id: this.objectt.member_id, //客户id
						id: this.objectt.id, //店铺id
						title: this.objectt.title, //店铺名称
						province_id: this.objectt.province_id, //省id
						city_id: this.objectt.city_id, // 市id
						district_id: this.objectt.district_id, // 区县id
						license: this.licen.length > 0 ? this.licen : this.objectt.license, //营业执照
						drugs_license: this.dru.length > 0 ? this.dru : this.objectt.drugs_license, //药品经营许可证
						card_images: this.stat.length > 0 ? this.stat : this.objectt.card_images, //	身份证正反面照片 多图
						trust_book_images: this.attorn.length > 0 ? this.attorn : this.objectt
							.trust_book_images, //法人委托书 多图
						invoice_images: this.bil.length > 0 ? this.bil : this.objectt.invoice_images, //发票信息
						logo: this.logoimg.length > 0 ? this.logoimg : this.objectt.logo,
						store_type: this.objectt.store_type, //店铺类型
						store_code: this.objectt.store_code, //编号
						contacts: this.objectt.contacts, //联系人姓名
						phone: this.objectt.phone, //联系人电话
						address: this.objectt.address, //地址
						email: this.objectt.email, //邮箱
					},
					success: res => {
						this.$util.showToast({
							title: '保存成功'
						});
						setTimeout(() => {
							// this.$router.go(-1)
							// uni.navigateBack({
							// 	delta: 1
							// });
							uni.redirectTo({
								url: `/page_salesman_customer/Customer_details/Customer_details?id=${this.objectt.id}&st=${this.objectt.member_id}`,
							})
						}, 500)
					},

				})
			}

		}
	}
</script>

<style lang="scss">
	.head {
		padding: 20rpx 32rpx;

		.business {
			font-size: 28rpx;
			font-family: PingFangSC-Regular, PingFang SC;
			font-weight: 400;
			color: #222222;
			line-height: 40rpx;
		}

		.upload {
			font-size: 24rpx;
			font-family: PingFangSC-Regular, PingFang SC;
			font-weight: 400;
			color: #999999;
			line-height: 34rpx;
			margin-top: 8rpx;
		}

		.Business {
			width: 686rpx;
			height: 320rpx;
			background: #F6F6F6;
			border-radius: 16rpx;
			margin-top: 24rpx;

			image {
				width: 48rpx;
				height: 48rpx;
				margin-top: 88rpx;
			}

			.Upload-pictures {
				font-size: 28rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #BFBFBF;
				line-height: 40rpx;
				margin-top: 16rpx;
			}

			.ask {
				font-size: 24rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #BFBFBF;
				line-height: 34rpx;
				margin-top: 8rpx;
			}
		}

		.business-two {
			font-size: 28rpx;
			font-family: PingFangSC-Regular, PingFang SC;
			font-weight: 400;
			color: #222222;
			line-height: 40rpx;
			margin-top: 48rpx;
		}

		.accomplish {
			width: 690rpx;
			height: 80rpx;
			background: #21BBF3;
			border-radius: 40rpx;
			margin-top: 32rpx;
			font-size: 28rpx;
			font-family: PingFangSC-Medium, PingFang SC;
			font-weight: 500;
			color: #FFFFFF;
			line-height: 40rpx;
		}
	}
</style>