wh 1 vuosi sitten
vanhempi
commit
e092945752
1 muutettua tiedostoa jossa 40 lisäystä ja 119 poistoa
  1. 40 119
      pages/index/Onlinewarranty/Onlinewarranty.vue

+ 40 - 119
pages/index/Onlinewarranty/Onlinewarranty.vue

@@ -41,13 +41,10 @@
 				:required=true>
 					<u--input v-model="model1.userInfo.faultDes" border="none"></u--input>
 				</u-form-item>
-
 				<u-form-item labelWidth='180' label="上传照片:" prop="userInfo.faultPics" borderBottom ref="item1">
-					<view class="">
-						<u-upload :fileList="fileList1" @afterRead="afterRead" @delete="deletePic" 	name="1"
-							multiple :maxCount="10">
-							<image :src="xiangji" mode="widthFix" style="width: 90rpx;height: 90rpx;"></image>
-						</u-upload>
+					<view class="uploadPart">
+						<image :src="img" mode="widthFix" style="width: 90rpx;height: 90rpx;" v-for="img in fileList1"></image>
+						<span @click="uploadImg" class="uploadBox"  v-if="fileList1.length<4"><u-icon name="plus"></u-icon></span>
 					</view>
 				</u-form-item>
 
@@ -89,6 +86,7 @@
 		components: {},
 		data() {
 			return {
+				uploadUrl:BaseApi.BaseApi + '/uploadFile',
 				loading: false,
 				fileList1: [],
 				xiangji: require('@/static/index/xj.png'),
@@ -223,120 +221,32 @@
 						},
 
 			// 新增图片
-			async afterRead(event) {
-
-				// 当设置 mutiple 为 true 时, file 为数组格式,否则为对象格式
-				let lists = [].concat(event.file)
-				let fileListLen = this.fileList1.length
-				lists.map((item) => {
-					this.fileList1.push({
-						...item,
-						status: 'uploading',
-						message: '上传中'
-					})
-				})
-				//console.log(this.fileList1)
-				for (let i = 0; i < lists.length; i++) {
-					const result = await this.uploadFilePromise(lists[i].url)
-					let item = this.fileList1[fileListLen]
-					this.fileList1.splice(fileListLen, 1, Object.assign(item, {
-						status: 'success',
-						message: '',
-						rl: result
-					}))
-					fileListLen++
-				}
-
-				console.log(this.fileList1);
-				//this.problemPhotos=this.fileList1;
-			},
-			uploadFilePromise(url) {
-				console.log('111111111111111111',url)
-				let _self=this;
-				return new Promise((resolve, reject) => {
-					let a = uni.uploadFile({
-						url:  BaseApi.BaseApi + '/uploadFile',
-						header: {
-							'content-type': 'application/json',
-							"token": uni.getStorageSync('tokendata'),
-						},
-						filePath: url,
-						name: 'file',
-						success: (res) => {
-							let result = JSON.parse(res.data)
-							//	console.log(result.fileName);
-							setTimeout(() => {
-								resolve(JSON.parse(res.data).fileName)
-							}, 1000)
+			uploadImg() {
+				uni.chooseImage({
+					count:4,
+					success: (chooseImageRes) => {
+						const tempFilePaths = chooseImageRes.tempFilePaths;
+						for(let i=0;i<tempFilePaths.length;i++) {
+							uni.uploadFile({
+									url:  BaseApi.BaseApi + '/uploadFile',
+								filePath: tempFilePaths[i],
+								name: 'file',
+								formData: {
+									'user': 'test'
+								},
+								success: (uploadFileRes) => {
+									console.log(uploadFileRes);
+									this.fileList1.push(JSON.parse(uploadFileRes.data).data)
+									console.log(this.fileList1);
+								}
+							});
 						}
-					});
-				})
-			},
-
-
-
-
-						// 新增图片
-						// async afterRead(event) {
-						// 	// 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
-						// 	let lists = [].concat(event.file)
-						// 	let fileListLen =this.fileList1.length
-						// 	lists.map((item) => {
-						// 		this.fileList1.push({
-						// 			...item,
-						// 			status: 'uploading',
-						// 			message: '上传中'
-						// 		})
-						// 	})
-						//
-						// 	//  console.log('111111111111111111',this.fileList1)
-						// 	for (let i = 0; i < lists.length; i++) {
-						// 		const result = await this.uploadFilePromise(lists[i])
-						//
-						// 		let item = this.fileList1[fileListLen]
-						// 		this.fileList1.splice(fileListLen, 1, Object.assign(item, {
-						// 			status: 'success',
-						// 			message: '',
-						// 			url: result
-						// 		}))
-						// 		fileListLen++
-						// 	}
-						// },
-						// uploadFilePromise(url) {
-						// 	  console.log('999',url)
-						//
-						// 	//  这时候我们创建一个formData对象实例
-						// 	const formData = new FormData();
-						// 	formData.append("file", url);
-						// 	console.log('222222',formData)
-						//
-						// 	//
-						// 	// this.$api.post('/uploadFile',{file:url})
-						// 	// .then(res=>{
-						// 	//   console.log('111111111111111111',res)
-						// 	// })
-						//
-						//
-						//
-						//
-						// 	// return new Promise((resolve, reject) => {
-						// 	// 	let a = uni.uploadFile({
-						// 	// 		url: BaseApi.BaseApi + '/uploadFile',
-						// 	// 		filePath: url,
-						// 	// 		name: 'file',
-						// 	// 		formData: {
-						// 	// 			user: 'test'
-						// 	// 		},
-						// 	// 		success: (res) => {
-						// 	// 			setTimeout(() => {
-						// 	// 				resolve(res.data.data)
-						// 	// 			}, 1000)
-						// 	// 		}
-						// 	// 	});
-						// 	// })
-						// },
-
+						
+					}
+				});
 
+			
+			},
 			changeHandler(e) {
 				const {
 					columnIndex,
@@ -494,5 +404,16 @@
 		margin: 20rpx;
 		margin-top: 0px;
 	}
-
+.uploadBox{
+	    width: 50px;
+	    height: 50px;
+	    line-height: 50px;
+	    text-align: center;
+	    border: 1px solid #ddd;
+	    display: flex;
+	    justify-content: center;
+	    align-items: center;
+	    border-radius: 3px;
+}
+.uploadPart{display: flex;align-items: center;}
 </style>