common.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. var s_home2 = "home2.html",
  2. s_home1 = "home1.html",
  3. s_admin = "admin.html",
  4. s_mine = "mine.html";
  5. /**
  6. * 返回消息页面
  7. */
  8. function back2Xiaoxi(){
  9. baseBack("xiaoxi.html");
  10. }
  11. /**
  12. * 返回消息并刷新
  13. */
  14. function backxiaoxi(){
  15. var old_back = mui.back;
  16. mui.back = function() {
  17. var wobj = plus.webview.getWebviewById("xiaoxi.html");//获取全科、健康医生页面的讨论组 ID
  18. //html/home/html/xiaoxi.html
  19. if(wobj!=null){
  20. mui.fire(wobj, "refresh");
  21. // wobj.reload(true);//刷新
  22. }
  23. if(self.opener && self.opener()){
  24. mui.fire(self.opener(), "xiaoxiUpdate");
  25. }
  26. old_back();
  27. }
  28. }
  29. /**
  30. * 返回消息并刷新
  31. */
  32. function backzhidingzixun(){
  33. var old_back = mui.back;
  34. mui.back = function() {
  35. var wobj = plus.webview.getWebviewById("zhidingzixun");//获取全科、健康医生页面的讨论组 ID
  36. if(wobj){
  37. mui.fire(wobj, "refresh");
  38. // wobj.reload(true);
  39. }
  40. old_back();
  41. }
  42. }
  43. /**
  44. * 返回全科与建管首页
  45. */
  46. function back2home(){
  47. baseBack("home2.html");
  48. }
  49. function back2OneByOneGongzuozu(){
  50. baseBack("dlz");
  51. }
  52. function baseBack(htmlId){
  53. var oldback = mui.back;
  54. mui.back = function() {
  55. var ww = plus.webview.getWebviewById(htmlId);
  56. if(ww){
  57. mui.fire(plus.webview.getWebviewById(htmlId), "refresh");
  58. }
  59. oldback();
  60. }
  61. }
  62. /**
  63. * 判断是否多角色
  64. */
  65. function isMultiRole(){
  66. if(!plus.storage.getItem("docInfo")){
  67. exit2Login();
  68. plus.storage.removeItem("isLoginOut");
  69. }
  70. var userRole = JSON.parse(plus.storage.getItem("userRole"));
  71. var docInfo = JSON.parse(plus.storage.getItem("docInfo"));
  72. var doctorType = docInfo.level;
  73. //alert(JSON.stringify(userRole));
  74. //plus.storage.getItem('docType')!='10' &&
  75. //doctorType!='10' &&
  76. return doctorType!=10 && userRole && userRole.length>0;
  77. }
  78. /**
  79. * 初始化切换页面
  80. */
  81. function initQiehuanDom(){
  82. // if(true){//v1.1.3暂不发布
  83. // $('#qiehuan').hide();
  84. // return true;
  85. // }
  86. var flag = isMultiRole();
  87. if(flag)
  88. $('#qiehuan').show();
  89. else
  90. $('#qiehuan').hide();
  91. $('#qiehuan').on('tap', function(){
  92. mui.fire(plus.webview.getWebviewById("main"), "showQiehuan");
  93. })
  94. }
  95. /**
  96. * 设置医生头像
  97. * @param {Object} sex
  98. * @param {Object} docType
  99. */
  100. function setDocPhoto(sex, docType){
  101. docType = docType || plus.storage.getItem("docType");
  102. if(docType=="10"){
  103. return sex==2? "../../../images/s-female.png" : "../../../images/s-male.png";
  104. }
  105. return sex==2? "../../../images/d-female.png" : "../../../images/d-male.png";
  106. }
  107. /**
  108. * 设置医生头像
  109. * @param {Object} p
  110. * @param {Object} sex
  111. * @param {Object} docType
  112. */
  113. function setTemDocPhoto(p, sex, docType){
  114. if (!p || p.length == 0) {
  115. return setDocPhoto(sex, docType);
  116. }
  117. return getImgUrl(p);
  118. }
  119. /**
  120. * 初始化医生头像
  121. * @param {Object} domId
  122. * @param {Object} p
  123. * @param {Object} sex
  124. * @param {Object} docType
  125. */
  126. function initDocPhoto(domId, p, sex, docType){
  127. document.getElementById(domId).onerror = function(){
  128. this.src = setDocPhoto(sex, docType);
  129. }
  130. $('#'+ domId).attr("src", setTemDocPhoto(p, sex, docType));
  131. }
  132. /**
  133. * 刷新医生头像
  134. */
  135. function flushDocPhoto(photo){
  136. var docInfo = JSON.parse(plus.storage.getItem("docInfo"));
  137. docInfo.photo = photo;
  138. plus.storage.setItem("docInfo", JSON.stringify(docInfo));
  139. var wv = plus.webview.getWebviewById(s_admin);
  140. if(wv)
  141. mui.fire(wv, "flushDocPhoto");
  142. wv = plus.webview.getWebviewById(s_home1);
  143. if(wv)
  144. mui.fire(wv, "flushDocPhoto");
  145. wv = plus.webview.getWebviewById(s_home2);
  146. if(wv)
  147. mui.fire(wv, "flushDocPhoto");
  148. wv = plus.webview.getWebviewById(s_mine);
  149. if(wv)
  150. mui.fire(wv, "flushDocPhoto");
  151. }
  152. /**
  153. * 自定义刷新头像事件
  154. */
  155. window.addEventListener("flushDocPhoto", function(e){
  156. var docInfo = JSON.parse(plus.storage.getItem("docInfo"));
  157. $('#doc_photo').attr("src", docInfo.photo);
  158. })
  159. /**
  160. * 开启主从页面
  161. * @param {Object} id 主页面id
  162. * @param {Object} subPage 子页面路径, 基于header1
  163. * @param {Object} title 主题
  164. * @param {Object} extras 参数(带到子页面)
  165. * @param {Object} subId 子页面id
  166. * openWindowWithSub("health-record", "health-record.html", "居民详情")
  167. */
  168. function openWindowWithSub(id, subPage, title, extras, subId){
  169. extras = extras || {};
  170. mui.openWindow({
  171. url: '../../header1.html',
  172. id: id,
  173. extras: {
  174. title: title,
  175. subPage: subPage,
  176. subId: subId,
  177. extras: extras
  178. }
  179. });
  180. }
  181. /*
  182. * 查看协议书
  183. */
  184. function toXieYiShu(index) {
  185. mui.openWindow("../../qygl/html/xieyishu.html", "xieyishu");
  186. }
  187. /**
  188. * 设置疾病类型
  189. * @param {Object} d
  190. */
  191. function setDiseases(d, t) {
  192. if(!d || d.length == 0)
  193. return t==1? "" : "无";
  194. var v = "";
  195. for(var k in d){
  196. v += "、" + d[k].diseaseName;
  197. }
  198. return v.substring(1);
  199. }
  200. /**
  201. * 跳转到个人单项修改页面
  202. * @param {Object} key
  203. * @param {Object} value
  204. */
  205. function gotoModify(key, value){
  206. mui.openWindow({
  207. url: "modify.html",
  208. id: "modify.html",
  209. extras:{
  210. key: key,
  211. value: value
  212. }
  213. })
  214. }
  215. function isPasswordPrompt(){
  216. plus.nativeUI.showWaiting();
  217. var docInfo = JSON.parse(plus.storage.getItem("docInfo"));
  218. var isPasswordPrompt = plus.storage.getItem('isPasswordPrompt');
  219. plus.nativeUI.closeWaiting();
  220. if(docInfo.isPasswordPrompt == 0 && !isPasswordPrompt){
  221. plus.storage.setItem('isPasswordPrompt', "0");
  222. mui.confirm("为了给您提供更好的服务,我们上线了账号密码登录功能,为了您的账户安全,快来设置您的登录密码~", "提示", ["立即设置"], function(e){
  223. mui.openWindow({
  224. url: "../../mine/html/shezhimima.html",
  225. id: "shezhimima.html",
  226. extras:{
  227. mobile: docInfo.mobile
  228. }
  229. })
  230. })
  231. return true;
  232. }
  233. return false;
  234. }
  235. function checkIdcard(idcard){
  236. var userAgent = plus.navigator.getUserAgent(),
  237. index = userAgent.indexOf("}"),
  238. s = userAgent.substr(0, index+1),
  239. item = JSON.parse(s);
  240. if(!isPasswordPrompt() && !idcard && !item.observer){
  241. mui.confirm("如果医生未绑定身份证号,可能影响被关注量和咨询效率,是否前往绑定?", "提示", ["立即绑定", "以后再说"], function(e) {
  242. if(e.index==0){
  243. mui.openWindow({
  244. url: "../../mine/html/modify.html",
  245. id: "modify.html",
  246. extras:{
  247. key: "idcard",
  248. value: ""
  249. }
  250. })
  251. return ;
  252. }
  253. });
  254. }
  255. }
  256. function getUid(){
  257. return JSON.parse(plus.storage.getItem("docInfo")).code;
  258. }
  259. function validMobile(){
  260. var mobile = $.trim($('.reg-mobile').val());
  261. if(!isphone(mobile)){
  262. mui.toast("请输入有效的手机号码");
  263. return;
  264. }
  265. return mobile;
  266. }
  267. /*判断输入是否为合法的手机号码*/
  268. function isphone(inputString)
  269. {
  270. var partten = /^0?(13[0-9]|15[0-9]|18[0-9]|14[57]|17[0-9]|16[0-9]|19[0-9])[0-9]{8}$/;
  271. if(partten.test(inputString))
  272. {
  273. return true;
  274. }
  275. else
  276. {
  277. return false;
  278. }
  279. }
  280. var chineseReg = /.*[\u4e00-\u9fa5]+.*$/;
  281. function validPsd(){
  282. var psd = $.trim($('.reg-psd').val());
  283. if(chineseReg.test(psd)){
  284. mui.toast("密码不可包含中文!");
  285. return;
  286. }
  287. if(psd.length<6){
  288. mui.toast("密码不得少于6位!");
  289. return;
  290. }
  291. return psd;
  292. }