加入图片雅俗

This commit is contained in:
java110 2021-01-21 00:59:51 +08:00
parent 81ca878c6f
commit 3592f2107c
2 changed files with 142 additions and 32 deletions

View File

@ -31,7 +31,8 @@
<view class="block__title">报修信息</view>
<view class="cu-form-group">
<view class="title">报修类型</view>
<picker id="complaintType" bindchange="PickerChange" :value="repairTypeIndex" :range-key="'repairTypeName'" :range="repairTypes" @change="repairTypeChange">
<picker id="complaintType" bindchange="PickerChange" :value="repairTypeIndex" :range-key="'repairTypeName'" :range="repairTypes"
@change="repairTypeChange">
<view class="picker">
{{repairTypes[repairTypeIndex].repairTypeName}}
</view>
@ -103,6 +104,8 @@
<script>
// pages/enterCommunity/enterCommunity.js
import * as TanslateImage from '../../utils/translate-image.js'
s
const context = require("../../context/Java110Context.js");
const constant = context.constant;
const factory = context.factory;
@ -127,7 +130,7 @@
context: '',
bindRepairName: '',
userId: '',
userName:'',
userName: '',
storeId: '',
photos: [],
communityId: "",
@ -152,7 +155,7 @@
}
],
repairTypes: [],
repairTypeIndex:0,
repairTypeIndex: 0,
repairScopeIndex: 0,
repairObjType: '',
repairObjId: '',
@ -161,7 +164,7 @@
floorId: '',
unitNum: '',
unitId: '',
priceScope:'',
priceScope: '',
};
},
@ -173,7 +176,7 @@
context.onLoad(options);
context.getRooms().then(res => {
let arr = res.data.rooms;
let roomCloums = [];
let roomIdArr = [];
arr.map(item => {
@ -187,7 +190,7 @@
that.communityId = res.data.owner.communityId;
that.communityName = res.data.owner.communityName;
});
//
this._loadRepairTypes();
},
@ -269,11 +272,11 @@
"photos": [],
"context": this.context,
"userId": this.userId,
"userName":this.userName,
"userName": this.userName,
"communityId": this.communityId,
"bindDate": this.bindDate,
"bindTime": this.bindTime,
"repairObjType":this.repairObjType
"repairObjType": this.repairObjType
}
if (this.repairObjType == '001') {
@ -281,11 +284,11 @@
obj.repairObjName = this.communityName;
} else if (this.repairObjType == '002') {
obj.repairObjId = this.floorId;
obj.repairObjName = this.floorNum ;
obj.repairObjName = this.floorNum;
} else if (this.repairObjType == '003') {
obj.repairObjId = this.unitId;
obj.repairObjName = this.floorNum + this.unitNum ;
}else{
obj.repairObjName = this.floorNum + this.unitNum;
} else {
obj.repairObjId = this.roomId;
obj.repairObjName = this.roomName;
}
@ -298,7 +301,7 @@
});
let msg = "";
if (obj.repairType == "") {
if (obj.repairType == "") {
msg = "请选择报修类型";
} else if (obj.bindRepairName == "") {
msg = "请填写报修人";
@ -310,7 +313,7 @@
msg = "请选择预约时间";
} else if (obj.context == "") {
msg = "请填写投诉内容";
}else if(obj.repairObjId == ''){
} else if (obj.repairObjId == '') {
msg = "请选择报修位置";
}
@ -378,17 +381,24 @@
let that = this;
wx.chooseImage({
count: 4, //9
sizeType: ['original', 'compressed'], //
sourceType: ['album','camera'], //
sizeType: ['compressed'], //
sourceType: ['album'], //
success: (res) => {
console.log(res);
that.$data.imgList.push(res.tempFilePaths[0]);
let _base64Photo = '';
factory.base64.urlTobase64(res.tempFilePaths[0]).then(function(_res) {
_base64Photo = _res;
console.log('base64', _base64Photo);
that.photos.push(_base64Photo);
var tempFilePaths = res.tempFilePaths[0]
//#ifdef H5
TanslateImage.translate(tempFilePaths, (url) => {
that.photos.push(url);
})
//#endif
//#ifdef MP-WEIXIN
factory.base64.urlTobase64(tempFilePaths).then(function(_res) {
that.photos.push(_res);
});
//#endif
}
});
},
@ -401,24 +411,24 @@
this.repairScopeIndex = e.target.value //
let selected = this.repairScopes[this.repairScopeIndex] //
this.repairObjType = selected.id //id
},
repairChange: function(e) {
this.typeName = this.columns[e.detail.value];
this.typeId = this.repairIdAttr[e.detail.value];
},
repairTypeChange:function(e){
repairTypeChange: function(e) {
this.repairTypeIndex = e.target.value //
let selected = this.repairTypes[this.repairTypeIndex] //
this.repairType = selected.repairType //id
let _payFeeFlag = selected.payFeeFlag;
if(_payFeeFlag == 'T'){
if (_payFeeFlag == 'T') {
this.priceScope = selected.priceScope;
}else{
} else {
this.priceScope = '';
}
},
dateChange: function(e) {
this.bindDate = e.detail.value;
@ -443,9 +453,9 @@
url: '/pages/selectUnit/selectUnit?floorId=' + this.floorId
});
},
_loadRepairTypes:function(){
_loadRepairTypes: function() {
let _communityInfo = context.getCurrentCommunity();
let _that =this;
let _that = this;
let dataObj = {
page: 1,
row: 50,
@ -461,12 +471,12 @@
let _json = res.data;
if (_json.code == 0) {
_that.repairTypes = _json.data;
let selected = _that.repairTypes[_that.repairTypeIndex] //
_that.repairType = selected.repairType //id
let _payFeeFlag = selected.payFeeFlag;
if(_payFeeFlag == 'T'){
if (_payFeeFlag == 'T') {
_that.priceScope = selected.priceScope;
}
}
@ -480,7 +490,7 @@
}
});
}
}
};
</script>

100
utils/translate-image.js Normal file
View File

@ -0,0 +1,100 @@
/**
* 压缩
* @param {Object} imgSrc 图片url
* @param {Object} callback 回调设置返回值
*/
export function translate(imgSrc, callback) {
var img = new Image();
img.src = imgSrc;
img.onload = function () {
var that = this;
var h = that.height;
// 默认按比例压缩
var w = that.width;
var canvas = document.createElement('canvas');
var ctx = canvas.getContext('2d');
var anw = document.createAttribute("width");
anw.nodeValue = w;
var anh = document.createAttribute("height");
anh.nodeValue = h;
canvas.setAttributeNode(anw);
canvas.setAttributeNode(anh);
ctx.drawImage(that, 0, 0, w, h);
//压缩比例
var quality = 0.3;
var base64 = canvas.toDataURL('image/jpeg', quality);
canvas = null;
// var blob = base64ToBlob(base64);
// console.log(333);
// console.log(base64)
//Blob对象转blob地址
// var blobUrl = window.URL.createObjectURL(blob);
callback(base64);
}
}
/**
* base转Blob对象
* @param {Object} base64 base64地址
*/
export function base64ToBlob(base64) {
var arr = base64.split(','),
mime = arr[0].match(/:(.*?);/)[1],
bstr = atob(arr[1]),
n = bstr.length,
u8arr = new Uint8Array(n);
while (n--) {
u8arr[n] = bstr.charCodeAt(n);
}
return new Blob([u8arr], {
type: mime
});
}