ming %!s(int64=3) %!d(string=hai) anos
pai
achega
d76c24bd0e
Modificáronse 1 ficheiros con 81 adicións e 30 borrados
  1. 81 30
      pages/repair/repairDetail/repairDetail.vue

+ 81 - 30
pages/repair/repairDetail/repairDetail.vue

@@ -57,10 +57,14 @@
 						<text class="necessary">*</text>
 						上传图片:
 					</view>
-					<view style="width:500rpx">
-						<view ref="input" class="input">
-						</view>
+					<view class="unload-box" @tap="goCamera()">
+						<image v-if="this.imgUrl" mode="aspectFit" style="width:70rpx;height:70rpx" :src="this.imgUrl"
+							:data-src="this.imgUrl"></image>
+						<view v-else
+							style="background:rgb(223 215 215 / 63%);font-size:22rpx;line-height:40rpx;margin-top:20rpx;padding:0 20px;display:inline-block;border-radius:10rpx">
+							请上传 + </view>
 					</view>
+					
 				</view>
 				<view class="form-item margin-top" style="padding-bottom: 200rpx;">
 					<view class="title">
@@ -77,11 +81,18 @@
 			</view>
 			
 		</form>
+		
+		<helang-compress ref="helangCompress"></helang-compress>
+		
 	</view>
 </template>
 
 <script>
+	import helangCompress from '../../../components/helang-compress/helang-compress';
 	export default {
+		components: {
+			helangCompress
+		},
 		data() {
 			return {
 				getData:{},
@@ -95,6 +106,18 @@
 				zb_id: 0,
 				cl_type:'',
 				
+				imgUrl: '',
+				// reportName: '',
+				// radioOne: 0,
+				// zb_id: 0,
+					
+				params: {
+					maxSize: 800,
+					fileType: 'png',
+					quality: 0.85,
+					minSize: 640
+				},
+				
 				showDetail:true,
 			}
 		},
@@ -116,14 +139,7 @@
 		},
 
 		mounted() {
-			// 创建附件上传
-			var _self = this;
-			var input = document.createElement('input'); //创建元素
-			input.type = 'file' //添加file类型
-			input.onchange = (event) => {
-				_self.upFile(input, event)
-			}
-			this.$refs.input.$el.appendChild(input)
+	
 
 		},
 		methods: {
@@ -136,25 +152,6 @@
 				console.log('type:' + e.detail.value);
 				this.radioOne = e.detail.value;
 			},
-
-			upFile(input, event) {
-				var _self = this;
-				uni.uploadFile({
-					url: this.$BASE_URL+'/Inspection/setUpload',
-					files: [{
-						file: input.files[0],
-						uri: event.srcElement.value
-					}],
-					success: (uploadFileRes) => {
-						var data = JSON.parse(uploadFileRes.data)
-						this.img = data.img_url;
-						console.log(this.img)
-					},
-					fail: (err) => {
-						console.log(err)
-					}
-				});
-			},
 			
 			//回显请求
 			async getRepairDetail(params = {}) {
@@ -178,6 +175,60 @@
 			console.log('this.getData2')
 				console.log(this.getData2)
 			},
+			
+			
+			goCamera() {
+				const that = this;
+				uni.chooseImage({
+					count: 1, // 最多可以选择的图片张数
+					sizeType: ['original', 'compressed'], //original 原图,compressed 压缩图,默认二者都有
+					sourceType: ['camera', 'album'],
+					success: function(res) {
+						console.log(res);
+						that.imgUrl = res.tempFilePaths[0];
+						var tempFilePaths = res.tempFilePaths[0];
+			
+						that.$refs.helangCompress.compress({
+							src: tempFilePaths,
+							maxSize: that.params.maxSize,
+							fileType: that.params.fileType,
+							quality: that.params.quality,
+							minSize: that.params.minSize
+						}).then((res) => {
+							uni.hideLoading();
+							// uni.showToast({
+							// 	title: "压缩成功",
+							// 	icon: "success"
+							// })							
+							tempFilePaths = [res][0];
+							
+							uni.uploadFile({
+								url: that.$BASE_URL + 'Inspection/setUpload',
+								filePath: tempFilePaths,
+								name: 'file',
+								success: (uploadFileRes) => {
+									
+									uni.showToast({
+										title: "上传成功",
+										icon: "success"
+									})	
+									that.img = JSON.parse(uploadFileRes.data).img_url;
+								}
+							});
+						}).catch((err) => {
+							uni.hideLoading();
+							uni.showToast({
+								title: "压缩失败",
+								icon: "none"
+							})
+						})
+					}
+				})
+			
+			},
+			
+			
+			
 
 			addSubmit() {
 				if (!this.img) {