| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 | 
							
- var fileUrl;
 
- var fileHttpUrl;
 
- //上传图片
 
- var isModify = false;
 
- var exper, intro, mobile;
 
- var isOK = false;
 
- var mobileModify = false;
 
- function uploadSingleImg(expertise, introduce, mobileVal) {
 
- 	plus.nativeUI.showWaiting();
 
- 	exper = expertise;
 
- 	intro = introduce;
 
- 	mobile = mobileVal;
 
- 	
 
- 	if (isModify) {
 
- 		uploader();
 
- 	} else {
 
- 		var param = {
 
- 			photo: "",
 
- 			sex:"",
 
- 			province:"",
 
- 			city:"",
 
- 			expertise: exper,
 
- 			introduce: intro,
 
- 			mobile: mobile
 
- 		}
 
- 		sendPost("doctor/save", param, function() {
 
- 		}, handSendSucc1);
 
- 	}
 
- }
 
- function uploader() {
 
- 	
 
- 	var uploadServerUrl = server + "upload/image";
 
- 	var task = plus.uploader.createUpload(uploadServerUrl, {
 
- 		method: "post"
 
- 	}, function(t, status) {
 
- 		if (status == 200) {
 
- 			fileHttpUrl = JSON.parse(t.responseText).urls;
 
- 			saveInfo();
 
- 		} else {
 
- 			mui.toast("头像修改失败,请稍后重试");
 
- 			plus.nativeUI.closeWaiting();
 
- 		}
 
- 	});
 
- 	task.addFile(fileUrl, {})
 
- 	task.start();
 
- }
 
- function saveInfo() {
 
- 	var param = {
 
- 		photo: fileHttpUrl,
 
- 		expertise: exper,
 
- 		introduce: intro,
 
- 		mobile: mobile
 
- 	}
 
- 	sendPost("doctor/save", param, function() {
 
- 	}, handSendSucc);
 
- }
 
- function handSendSucc(res) {
 
- 	if (res.status == 200) {
 
- 		if(mobileModify){
 
- 			logout();
 
- 			return;
 
- 		}
 
- 		plus.nativeUI.closeWaiting();
 
- //		mui.toast("资料修改成功");
 
- 		flushDocPhoto(res.data);//刷新头像
 
- //		var wv = plus.webview.getWebviewById("mine.html");
 
- //		if (wv) {
 
- //			mui.fire(wv, 'updataPhoto', {
 
- //				photo: res.data
 
- //			});
 
- //		}
 
- 	}
 
- 	mui.toast(res.msg);
 
- 	plus.nativeUI.closeWaiting();
 
- 	isModify=false;
 
- }
 
- function handSendSucc1(res) {
 
- 	if (res.status == 200) {
 
- 		if(mobileModify){
 
- 			logout();
 
- 			return;
 
- 		}
 
- 	}
 
- 	mui.toast(res.msg);
 
- 	plus.nativeUI.closeWaiting();
 
- }
 
- // 弹出选择照片方式
 
- function showActionSheet(imgDom, imgFlag) {
 
- 	plus.nativeUI.actionSheet({
 
- 			cancel: "取消",
 
- 			buttons: [{
 
- 				title: "从相册选择"
 
- 			}, {
 
- 				title: "拍照"
 
- 			}]
 
- 		},
 
- 		function(event) {
 
- 			if (event.index == 1) {
 
- 				getGallery(imgDom, imgFlag);
 
- 			} else if (event.index == 2) {
 
- 				getCamera(imgDom, imgFlag);
 
- 			}
 
- 		}
 
- 	);
 
- };
 
- //获取相册
 
- function getGallery(imgDom, imgFlag) {
 
- 	plus.gallery.pick(function(cbFile) { //scb:SuccessCallBack
 
- 		imgDom.src = cbFile;
 
- 		handlePickSucc(cbFile);
 
- 	}, function(ecb) { //ecb:ErrorCallBack
 
- 	}, {
 
- 		filename: "_doc/gallery/",
 
- 		filter: "image"
 
- 	});
 
- }
 
- function handlePickSucc(srcUrl) {
 
- 	var lastIdx = srcUrl.lastIndexOf("/"),
 
- 		imgName = srcUrl;
 
- 	if(lastIdx>-1) {
 
- 		imgName = srcUrl.slice(lastIdx+1);
 
- 	}
 
- 	plus.zip.compressImage({
 
- 		src: srcUrl,
 
- 		dst: "_doc/compressImg/"+imgName,
 
- 		quality: 20,
 
- 		overwrite: true
 
- 	}, function(succ) {
 
- 		var urlSucc = succ.target;
 
- //		var size = succ.size;
 
- //		var width = succ.width;
 
- //		var height = succ.height;
 
- 		fileUrl = urlSucc;
 
- 		isModify = true; //修改标记
 
- 	}, function(err) {
 
- 		mui.toast("压缩失败:  " + err.message);
 
- 	});
 
- }
 
- // 调用系统摄像头
 
- function getCamera(imgDom, imgFlag) {
 
- //	var pp = plus.navigator.checkPermission("CAMERA");
 
- //	if(pp == "denied") {
 
- //		mui.toast("拍照权限未开启")
 
- //		return ;
 
- //	}
 
- 	var cmr = plus.camera.getCamera();
 
- 	cmr.captureImage(function(path) {
 
- 		console.log(path);
 
- 		/**
 
- 		 * 拍照成功后,图片本保存在本地,这时候我们需要调用本地文件
 
- 		 * http://www.html5plus.org/doc/zh_cn/io.html#plus.io.resolveLocalFileSystemURL
 
- 		 */
 
- 		plus.io.resolveLocalFileSystemURL(path, function(entry) {
 
- 			/*
 
- 			 * 将获取目录路径转换为本地路径URL地址
 
- 			 * http://www.html5plus.org/doc/zh_cn/io.html#plus.io.DirectoryEntry.toLocalURL
 
- 			 */
 
- 			imgDom.src = entry.toLocalURL();
 
- 			fileUrl = entry.toLocalURL();
 
- 			console.log(fileUrl);
 
- 			handlePickSucc(fileUrl);
 
- 		});
 
- 	}, function(error) {
 
- 		if(error.code==11 && error.message == "null") {
 
- 			plus.nativeUI.toast("您尚未授权拍照权限,无法使用拍照功能。");
 
- 		}
 
- 		// mui.toast(error.message)
 
- 	}, {
 
- 		filename: "_doc/camera/",
 
- 		index: 1 //ios指定主摄像头
 
- 	});
 
- }
 
- //登出
 
- function logout() {
 
- 	plus.storage.removeItem("userMobile");
 
- 	plus.storage.removeItem("flag");
 
- 	var userAgent = plus.storage.getItem("userAgent");
 
- 	imClient.Users.logout(userAgent.uid);	
 
- 	plus.storage.removeItem("userAgent");
 
- 	plus.storage.removeItem("docInfo");
 
- 	plus.storage.removeItem("docType");
 
- 	
 
- 	alert("您已修改手机号码,请重新登录!");
 
- 	mui.openWindow('../../login/html/login.html', 'login', {
 
- 		extras: {
 
- 			exit: "exit"
 
- 		},
 
- 		createNew: true,
 
- 		styles: {
 
- 			softinputMode: "adjustResize"
 
- 		}
 
- 	});
 
- 	mui.later(function() {
 
- 		plus.webview.currentWebview().close();
 
- 	}, 1000)
 
- }
 
 
  |