<template>
	<view>
		<view class="single_Phone">
			<span style="color:red;margin-right:5rpx;" v-show="CompData.IsRequire">*</span>{{CompData.Name}}
		</view>
		 <imgupload ref="uUpload" :action="action" :show-tips="false" @on-remove="onRemove"
		 @on-oversize="onversize"
		 @on-exceed="onexceed"
		  :max-size="CompData.FileSizeLimit==0?99999* 1024 * 1024:CompData.FileSizeLimit * 1024 * 1024"
		  :max-count="CompData.FileCount==0?'999999':CompData.FileCount"
		  :file-list="fileList"
		  @on-success="uploadSuccessHandler"
		  ></imgupload>
		  <view style="width: 100%;height: 1px;background: #e2e2e2;"></view>
		<view class="single_Remark" v-if="CompData.Remark">{{CompData.Remark}}</view>
	</view>
</template>

<script>
	import imgupload from '../components/img-upload.vue'
	export default {
		props: ["CompData",'index'],
		components: { imgupload},
		data(){
			return{
				action: '',
				fileList:[],
			}
		},
		created() {
			let MallBaseId = uni.getStorageSync("mall_UserInfo").MallBaseId ? uni.getStorageSync("mall_UserInfo").MallBaseId : 1;
			var newPath = "/korea/Test/Upload/";
			this.action  = this.UploadConfig().UploadUrl + "?fileSavePath=" + newPath;
			if(this.CompData.FileList.length>0){
				this.fileList=[]
				this.CompData.FileList.forEach(x=>{
					let obj={
						url:x
					}
					this.fileList.push(obj)
					
				})
				 
			}
		},
		methods:{
			uploadSuccessHandler(data, index, lists) {
				let r = JSON.parse(data);
				var url= this.UploadConfig().ImageUrl+ r.FilePath;
				console.log(url)
				this.CompData.FileList.push(url);
				this.$emit('success', this.CompData, this.index)
				
			},
			onRemove(index) {
				this.CompData.FileList.splice(index, 1);
			},
			onversize(){
				uni.showToast({
					title: '超出允许的文件大小',
					icon: "none"
				});
			},
			onexceed(){
				uni.showToast({
					title: '超出最大允许的文件个数',
					icon: "none"
				});
				
			}
		}
	}
</script>

<style>
</style>
