<template>
	<!-- 相关资质页面 -->
	<!-- 
	 设计思路 没有上传过的直接上传提交
	 之前上传过的可以 展示出来 可以删除和修改
	 -->
	<view class="Qualifications">
		<view class="pic">
			<view class="biao_05">
				请上传相关资质图片：
			</view>
			<robby-image-upload fileKeyName="img" :value="c_pics" :server-url="uploadurl1+'/merchant.php/FileUpload/uploadify'" :form-data="c_formData" :server-url-delete-image="uploadurl1"
			 @delete="c_delImage" @add="c_onImg" @move="onMove_c" :limit="3"></robby-image-upload>
		</view> 
		
		<!-- 提交按钮 -->
		<view class="formsubmitsbtn">
			<button type="primary" @tap="storeCertificateFun">保存</button>
		</view>
		
	</view>
</template>

<script>
	import robbyImageUpload from '@/components/plan-image-upload/up_img';//上传资质图片组件
	import {storeCertificate,shopDetail} from "@/utils/api/api.js";//提交资质接口
	
	export default {
		components:{
			robbyImageUpload
		},
		data(){
			return {
				ff:"",
				c_pics: [],
				serverUrl:  'up_img',
				DelServelUrl: 'del_img',
				c_photos: [],
				c_formData: {
					// use: 'pro_img',
					// back: 'idurl'
					model:"shopphoto",
					user_token:"",
				},
				icp:"",//上传的图片 原来的
			}
		},
		computed: {
			uploadurl1(){
				return this.$store.state.uploadurl1;
			},
			
		},
		onLoad() {
			this.c_formData.user_token = this.$store.state.token;
			
			this.getshopDetail();//获取之前提交的信息
		},
		methods:{
			async getshopDetail(){
				let res = await shopDetail({
					
				});
				if(res.code==0){
					this.icp = res.data.icp.split(";");
					
					this.icp.forEach((item,index)=>{
						this.c_pics.push({data:item})
					});
					
				}else{
					this.$api.msg(res.msg);
				}
			},
			//图片上传
			c_delImage(e) {
				let arr = []
				for (let k in e.allImages) {
					arr[k] = e.allImages[k].id
				}
				this.c_photos = arr
			},
			c_onImg(e) {
				this.c_pics = e.allImages
				const obj = e.allImages
				for (let index in obj) {
					let id = obj[index].data
					this.c_photos[index] = id
				}
			},
			onMove_c(e) {
				this.c_pics = e
				const obj = e
				for (let index in obj) {
					let id = obj[index].data
					this.c_photos[index] = id
				} 
			},
			//提交店铺资质接口
			async storeCertificateFun(){
				let isipc = this.c_pics.map((item,index)=>{
					return item.data;
				})
				isipc = isipc.join(";");
				console.info(isipc,"111");
				
				
				let res = await storeCertificate({
					icp:isipc,
					//估计就是 ， ；隔开
				});
				if(res.code==0){
					this.$api.msg(res.msg);
				}else{
					this.$api.msg(res.msg);
				}
			}
		},
		watch:{
			
		}
	}
</script>

<style lang="scss">
	.pic {
		padding: 20upx 10upx;background-color: #fff;
	}
	.formsubmitsbtn{
		height: 88upx;
		padding: 0 20upx;
		button{
			height: 88upx;
			line-height: 88upx;
			color:#FFFFFF;
			background-color: $base_color;
		}
	}
</style>
