Skip to content
personInfo.ts 4.84 KiB
Newer Older
wangqinghua's avatar
wangqinghua committed
import {Component} from '@angular/core';
wangqinghua's avatar
wangqinghua committed
import {ActionSheetController, IonicPage, LoadingController, NavController, ToastController} from 'ionic-angular';
import {Camera, CameraOptions} from "@ionic-native/camera";
wangqinghua's avatar
wangqinghua committed
import {ModifyPasswordPage} from "../modifyPassword/modifyPassword";
import {Storage} from '@ionic/storage';
import {AppGlobal, AppService} from "../../../../service/http.service";
import {EditPersonInfoPage} from '../editPersonInfo/editPersonInfo';
wangqinghua's avatar
wangqinghua committed
import {FileTransferObject, FileUploadOptions, FileTransfer} from "@ionic-native/file-transfer";
import {CommonService} from "../../../../provide/common.service";
wangqinghua's avatar
wangqinghua committed
import {TabsService} from "../../../tabs/tabs.service";
import {MineService} from "../../../mine-pages/mine.service";
wangqinghua's avatar
wangqinghua committed

wangqinghua's avatar
wangqinghua committed

@IonicPage()
@Component({
    selector: 'page-personInfo',
    templateUrl: 'personInfo.html'
})

export class PersonInfoPage {
    orgName = '';
    user: any;
    gender: object;
    userid: '';
wangqinghua's avatar
wangqinghua committed

    picUrl = AppGlobal.domain + '/wisdomgroup/modules/common/file/showImgByFileid/';
    mineInfo;
wangqinghua's avatar
wangqinghua committed

wangqinghua's avatar
wangqinghua committed
    constructor(public navCtrl: NavController,public camera:Camera,public commonSer:CommonService,
wangqinghua's avatar
wangqinghua committed
                public storage: Storage,public actionSheetCtrl:ActionSheetController,public tabSer:TabsService,
wangqinghua's avatar
wangqinghua committed
                public appService: AppService,public loadingCtrl:LoadingController,
                public toast: ToastController,public transfer: FileTransfer,) {
wangqinghua's avatar
wangqinghua committed

    }

    ionViewWillEnter(): void {
wangqinghua's avatar
wangqinghua committed
        this.getUserInfo();
wangqinghua's avatar
wangqinghua committed
        this.user = this.storage.get("user").then((value) => {
            this.user = value;
            this.gender = this.user.userDetail.user.gender;
        });
    }

wangqinghua's avatar
wangqinghua committed
    getUserInfo(){
        this.tabSer.getUserIntegral().subscribe(
            (res) => {
                this.mineInfo = res.data;
            }
        )
wangqinghua's avatar
wangqinghua committed
    }

wangqinghua's avatar
wangqinghua committed
    modifyPwd() {
        this.navCtrl.push("ModifyPasswordPage")
wangqinghua's avatar
wangqinghua committed
    }

    //不同的code代表修改不同的数据,1房间,2座机,3邮箱
wangqinghua's avatar
wangqinghua committed
    edit() {
        this.navCtrl.push("EditPersonInfoPage");
wangqinghua's avatar
wangqinghua committed
    }

wangqinghua's avatar
wangqinghua committed
    //选择头像
    tackePic() {
        const actionSheet = this.actionSheetCtrl.create({
wangqinghua's avatar
wangqinghua committed
            cssClass:'cameraAction',
wangqinghua's avatar
wangqinghua committed
            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 = {
wangqinghua's avatar
wangqinghua committed
            quality: 50,
wangqinghua's avatar
wangqinghua committed
            destinationType: this.camera.DestinationType.FILE_URI,
            encodingType: this.camera.EncodingType.PNG,
            mediaType: this.camera.MediaType.PICTURE,
            sourceType: srcType,
            saveToPhotoAlbum: false
        };
        const option: FileUploadOptions = {
wangqinghua's avatar
wangqinghua committed
            httpMethod: 'post',
wangqinghua's avatar
wangqinghua committed
            headers: {
wangqinghua's avatar
wangqinghua committed
                'Accept': 'application/json',
wangqinghua's avatar
wangqinghua committed
            },
            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();
wangqinghua's avatar
wangqinghua committed
        fileTransfer.upload(file, AppGlobal.domain + '/wisdomgroup/modules/common/file/icon/upload', options).then(
wangqinghua's avatar
wangqinghua committed
            (res) => {
                uploadLoading.dismiss();
                this.commonSer.toast('上传成功');
wangqinghua's avatar
wangqinghua committed
                this.getUserInfo();
wangqinghua's avatar
wangqinghua committed
            }, err => {
                uploadLoading.dismiss();
                this.commonSer.toast('上传错误');
            });
wangqinghua's avatar
wangqinghua committed
        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 + '%' );
        })
wangqinghua's avatar
wangqinghua committed
    }

wangqinghua's avatar
wangqinghua committed
    goBack() {
        this.navCtrl.popToRoot();
    }

}