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

<script>
	export default {
		props: ["CompData",'index'],
		
		data(){
			return{
				action: this.host2 + "/api/File/UploadTencent",
				fileList:[],
			}
		},
		created() {
			let MallBaseId = uni.getStorageSync("mall_UserInfo").MallBaseId ? uni.getStorageSync("mall_UserInfo").MallBaseId : 1;
			this.action = this.host2 + '/api/File/UploadTencent?MallBaseId=' + MallBaseId
			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);
				this.CompData.FileList.push(r.data);
				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>
