Newer
Older
import {ActionSheetController, IonicPage, LoadingController, NavController, ToastController} from 'ionic-angular';
import {Camera, CameraOptions} from "@ionic-native/camera";
import {ModifyPasswordPage} from "../modifyPassword/modifyPassword";
import {Storage} from '@ionic/storage';
import {AppGlobal, AppService} from "../../../../service/http.service";
import {EditPersonInfoPage} from '../editPersonInfo/editPersonInfo';
import {FileTransferObject, FileUploadOptions, FileTransfer} from "@ionic-native/file-transfer";
import {CommonService} from "../../../../provide/common.service";
import {TabsService} from "../../../tabs/tabs.service";
import {MineService} from "../../../mine-pages/mine.service";
@IonicPage()
@Component({
selector: 'page-personInfo',
templateUrl: 'personInfo.html'
})
export class PersonInfoPage {
orgName = '';
user: any;
gender: object;
userid: '';
picUrl = AppGlobal.domain + '/wisdomgroup/modules/common/file/showImgByFileid/';
mineInfo;
constructor(public navCtrl: NavController,public camera:Camera,public commonSer:CommonService,
public storage: Storage,public actionSheetCtrl:ActionSheetController,public tabSer:TabsService,
public appService: AppService,public loadingCtrl:LoadingController,
public toast: ToastController,public transfer: FileTransfer,) {
this.user = this.storage.get("user").then((value) => {
this.user = value;
this.gender = this.user.userDetail.user.gender;
});
}
getUserInfo(){
this.tabSer.getUserIntegral().subscribe(
(res) => {
this.mineInfo = res.data;
}
)
//选择头像
tackePic() {
const actionSheet = this.actionSheetCtrl.create({
buttons: [
{
text: '拍照',
role: 'fromCamera',
handler: () => {
this.selectPicture(1);
}
}, {
text: '从相册中选',
role: 'fromPhoto',
handler: () => {
console.log('fromPhoto');
this.selectPicture(0);
}
}, {
text: '取消',
role: 'cancel',
handler: () => {
console.log('Cancel clicked');
}
}
]
});
actionSheet.present();
}
//选择图片
selectPicture(srcType) {
const options: CameraOptions = {
destinationType: this.camera.DestinationType.FILE_URI,
encodingType: this.camera.EncodingType.PNG,
mediaType: this.camera.MediaType.PICTURE,
sourceType: srcType,
saveToPhotoAlbum: false
};
const option: FileUploadOptions = {
},
fileName:'image.png'
};
this.camera.getPicture(options).then((imagedata) => {
let filePath = imagedata;
if(filePath.indexOf('?') !== -1){ //获取文件名
filePath = filePath.split('?')[0];
}
let arr = filePath.split('/');
option.fileName = arr[arr.length -1];
this.upload(imagedata, option);
})
}
upload(file, options) {
const uploadLoading = this.loadingCtrl.create({
content: '上传中...',
dismissOnPageChange:true,
enableBackdropDismiss:true,
});
uploadLoading.present();
const fileTransfer: FileTransferObject = this.transfer.create();
fileTransfer.upload(file, AppGlobal.domain + '/wisdomgroup/modules/common/file/icon/upload', options).then(
(res) => {
uploadLoading.dismiss();
this.commonSer.toast('上传成功');
}, err => {
uploadLoading.dismiss();
this.commonSer.toast('上传错误');
});
fileTransfer.onProgress((listener)=>{
let per =<any> (listener.loaded / listener.total) *100;
per = Math.round(per*Math.pow(10,2))/Math.pow(10,2)
uploadLoading.setContent('上传中...' + per + '%' );
})