<template>
	<view class="upBox">
		<uni-file-picker
			limit="3" 
			fileMediatype="image" 
			file-extname="jpg,jpeg,png" 
			@select="picSelect" 
			@success="picSuccess"  
			@fail="picFail" 
			@delete="picDelete"
			title="最多选择3张图片">
		</uni-file-picker>
	</view>
</template>

<script>
	export default {
		name:"uploadFile",
		props: {
		    module: {
				type: String,
				default: "",
		    }
		},
		data() {
			return {
				attaments:[]
			};
		},
		methods: {
			//选择图片,上传
			picSelect(e){
				let that = this;
				const tempFilePaths = e.tempFilePaths;
				console.log(tempFilePaths);
				uni.showLoading({
					title: "图片上传中"
				});
			   uni.uploadFile({
				url: that.apiWebUrl + '/data/doc/add',
				filePath: tempFilePaths[0],
				name: 'file',
				formData: {
					module:  this.module
				},
				success: (res) => {
                    let info = JSON.parse(res.data);
					uni.hideLoading();
					console.log(info);
					that.attaments.push(info.data);
					that.$emit("getUpFlie",that.attaments);
				},
				fail: () => {
					uni.hideLoading();
					uni.showToast("图片上传失败!");
				},
			   });
						
			},			
			//上传成功
			picSuccess(){
				uni.showToast({
					icon:'none',
					title: '上传成功',
					duration: 2000
				});
			},	
			//上传失败
			picFail(){
				uni.showToast({
					icon:'none',
					title: '上传失败，请重新上传!',
					duration: 2000
				});
			},			
			//删除图片
			picDelete(e){
				console.log(e);
			},
			
		},	
	}
</script>

<style lang="scss" scoped>
  .upBox{
	  width: 100%;
	  display: block;
  }
</style>
