// import $http from "@/common/requestConfig.js"
import request from "./request";
// import {baseURL,apiURL,cffpURL} from "../environments/environment";
// 上传的事件
	export function CommonUpload() {

		// @ts-ignore
		return new Promise((resolve, rej) => {
			uni.chooseImage({
				count: 1, //默认9
				sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
				sourceType: ['album'], //从相册选择
				success: function(res) {
					var urlList = []
					// res.tempFiles 数组
					for (var i = 0; i < res.tempFiles.length; i++) {
						uni.showLoading({
							title: '加载中',
							mask: true
						});
						uni.uploadFile({
							url: $http.baseUrl + '/route/appUser/updateImgUrl', // 后端api接口
							filePath: res.tempFilePaths[0], // uni.chooseImage函数调用后获取的本地文件路劲
							name: 'file', //后端通过'file'获取上传的文件对象
							// formData: this.sendDate,
							// header:{"third-session": uni.getStorageSync('thirdSession')},
							header: {
								// "third-session": uni.getStorageSync('thirdSession')
								'Authorization': 'Bearer' + uni.getStorageSync('access_token')
							},
							success: (res) => {
								//  let data = JSON.parse(res.data)
								// that.headUrl = data.data.link
								let data = JSON.parse(res.data)

								urlList.push({
									url: data.data.link,
									recordId: data.data.recordId
								})
								// 抛出
								resolve(urlList)
								uni.hideLoading();
							}
						});
					}
				}
			});
		})
	}


// 上传文件
export function uploadFilepdf (){
	return new Promise((resolve, reject) => {
	uni.showLoading({
		title: '加载中',
		mask: true
	});
	 uni.uploadFile({
			url: baseURL + '/common/upload', //仅为示例，非真实的接口地址
			filePath: tempFilePaths,
			name: 'file',
			formData: {...data,token:uni.getStorageSync('token') || ''},
			success: (res) => {
				uni.showLoading({
					title: '加载中',
					mask: true
				});
				console.log(res);
				if(res.statusCode==200){
					resolve(JSON.parse(res.data).data)
				}
			},
			fail:(err)=>{
				uni.showLoading({
					title: '加载中',
					mask: true
				});
				console.log(err,'上传报错');
				// return 
				reject(err)
			}
		})
	})
}
