export function objToUrl(obj) {
  let uri = '';
  let keys = Object.keys(obj);
  keys.forEach(item => {
    uri += '&' + item + '=' + obj[item];
  });

  uri = uri.substr(1);

  return uri;
}

export function parseQueryString(url) {
    var obj = {};
    var keyvalue = [];
    var key = "",
        value = "";
    var paraString = url.substring(url.indexOf("?") + 1, url.length).split("&");
    for (var i in paraString) {
        keyvalue = paraString[i].split("=");
        key = keyvalue[0];
        value = keyvalue[1];
        obj[key] = value;
    }
    return obj;
}
// 保存图片到阿里云
export const saveImgToAliOss = function(src,callback){
	console.log(src,getApp().globalData.baseUrl,'getApp().globalData.baseUrl')
	const authorization = getApp().globalData.token
	uni.uploadFile({
		url: getApp().globalData.baseUrl + 'upload/', //自行修改各自的对应的接口 
		filePath: src,
		name: 'file',
		header: {'X-AUTH-TOKEN':authorization},
		success: (uploadFileRes) => {
			if (uploadFileRes) {
				let res = JSON.parse(uploadFileRes.data);
				callback(res)
			}
			uni.showToast({
				icon: 'none',
				title: uploadFileRes ? '保存图片成功' : '保存图片失败'
			})
		},
		fail:(error) => {
			console.log(error)
		}
	});
}
// 小数点后两位
export const numberToFixed = function (val, num, max) {
  let maxNums = max || 100000000
  let _value = val + ''
  _value = _value.replace(/[^\d.]/g, '')// 清楚数字和.以外的字数
  _value = _value.replace(/^\./g, '')
  _value = _value.replace(/\.{2,}/g, '')// 保留第一个，清楚多余的

  if (num == 1)_value = _value.replace(/^(\-)*(\d+)\.(\d).*$/, '$1$2.$3')
  else if (num == 3)_value = _value.replace(/^(\-)*(\d+)\.(\d\d\d).*$/, '$1$2.$3')
  else if (num == 4)_value = _value.replace(/^(\-)*(\d+)\.(\d\d\d\d).*$/, '$1$2.$3')
  else if (num == 5)_value = _value.replace(/^(\-)*(\d+)\.(\d\d\d\d\d).*$/, '$1$2.$3')
  else if (num == 0)_value = _value.indexOf('.') >= 0 ? _value.split('.')[0] : _value
  else _value = _value.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3')
  // console.log(_value,maxNums,Number(_value)>Number(maxNums),'_value')
  return Number(_value)>Number(maxNums) ? maxNums : _value
}


  