dailiqianyue-next.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816
  1. // 基本信息(包括userAgent、上个页面传递的数据)
  2. var baseInfo = null,
  3. // 基础环境信息(包括当前webview)
  4. baseEnv = null;
  5. //记录当前选择的服务类型
  6. var currService,
  7. initDiseases; //初始化时,默认的疾病类型
  8. // 顶部信息提示容器
  9. var $headerPromptMessage = $('#header_prompt_message'),
  10. // 疾病类型li容器
  11. $disease = $("#disease"),
  12. // 提交按钮
  13. $upload = $('#upload'),
  14. // 居民分组
  15. $groupInput = $("#li_group input"),
  16. // 疾病类型
  17. $diseaseInput = $("#disease input"),
  18. // 全科医生
  19. $doctorQKInput = $('#dortor_qke input[data-val=dortor_qke]'),
  20. // 健康管理师
  21. $doctorJGInput = $('#healthManagement input[data-val=healthManagement]'),
  22. // 政府补贴费
  23. $expensesInput = $("#li_expenses input"),
  24. // 家庭医生签约协议(勾选框)
  25. $agree = $(".input-group-pack"),
  26. // 签约团队
  27. $doctorQytdInput = $('#dortor_qke div[data-val=dortor_qytd]'),
  28. // 居民标签
  29. $juminLabels = $('#jumin_labels input[data-val=jumin_labels]'),
  30. //服务类型
  31. $juminServices = $("#jumin_services input[data-val=jumin_services]");
  32. var self;
  33. mui.plusReady(function(){
  34. self = plus.webview.currentWebview();
  35. })
  36. // 获取基本信息(包括userAgent、上个页面传递的数据)
  37. var getBaseInfoPromise = function() {
  38. var baseInfo = {
  39. // 登录相关信息
  40. userAgent: JSON.parse(plus.storage.getItem("userAgent")),
  41. // 上一个页面传递的表单数据
  42. accessData: baseEnv.webview.accessData,
  43. // 上一个页面传递的登录者信息
  44. docInfo: baseEnv.webview.docInfo
  45. };
  46. return getSingedInfoPromise(baseInfo.accessData.unencIdcard).then(function(data) {
  47. baseInfo.signedData = data;
  48. return baseInfo;
  49. });
  50. },
  51. // 获取基础环境信息
  52. getBaseEnv = function () {
  53. return {
  54. webview: plus.webview.currentWebview()
  55. };
  56. },
  57. // 打开协议书页面
  58. toXieYiShu = function() {
  59. mui.openWindow('../../qygl/html/xieyishu.html', 'xieyishu', {});
  60. },
  61. // 获取已签约信息
  62. getSingedInfoPromise = function(idcard) {
  63. // TODO 已签约三师示例数据
  64. // idcard = "360827199404102174";
  65. return getReqPromise("doctor/family_contract/patient_sanshi_signinfo",{idCard: idcard}).then(function(res) {
  66. if(res.status == 200) {
  67. var patientCode,disease="",diseaseName="";
  68. if(res.data.patient) {
  69. patientCode = res.data.patient.code;
  70. }
  71. if(res.data.diseases!==undefined) {
  72. initDiseases = res.data.diseases;
  73. disease = _.pluck(res.data.diseases, 'disease').join(",");
  74. diseaseName = _.pluck(res.data.diseases, 'diseaseName').join(",");
  75. $juminLabels.val(diseaseName).attr("data-code",JSON.stringify({health: "",disease: disease, custom: "" }));
  76. }
  77. return $.extend(res.data,{
  78. patientCode: patientCode,
  79. disease: disease,
  80. diseaseName: diseaseName
  81. });
  82. }
  83. return null;
  84. });
  85. },
  86. // 获取全科医生
  87. qke = function (){
  88. var userAgent = baseInfo.userAgent,
  89. hospital =userAgent.hospital;
  90. getReqPromise("/doctor/findDoctorByLevelAndHospital",{hospital:hospital,level:2})
  91. .then(function(res) {
  92. if(res.status == 200) {
  93. var doctors = res.doctors,
  94. qkeCodes=[],
  95. qkeNames=[];
  96. // 萃取数组对象中code、name,返回一个数组
  97. qkeCodes = _.pluck(doctors, 'code');
  98. qkeNames = _.pluck(doctors, 'name');
  99. qkeSelect(qkeCodes,qkeNames);
  100. }
  101. }).catch(function(e) {
  102. console && console.error(e);
  103. });
  104. },
  105. setQKSelectReadonly = function(readonly) {
  106. if(readonly) {
  107. // 获取全科医生下拉框mibiscroll实例
  108. var doctorQKMobiscroll = $doctorQKInput.mobiscroll('getInst');
  109. doctorQKMobiscroll.settings.readonly = true;
  110. $doctorQKInput.css('pointer-events','none');
  111. }
  112. },
  113. setQKSelect = function(doctor,doctorName) {
  114. // 获取全科医生下拉框mibiscroll实例
  115. var doctorQKMobiscroll = $doctorQKInput.mobiscroll('getInst');
  116. var valueText = "{keys:'"+doctor+"',values:'"+doctorName+"'}";
  117. doctorQKMobiscroll.setVal([valueText]);
  118. $doctorQKInput.val(doctorName);
  119. $doctorQKInput.attr("data-code",doctor);
  120. },
  121. // 设置全科医生下拉框
  122. qkeSelect = function (qkeCodes,qkeNames) {
  123. var docInfo = baseInfo.docInfo,
  124. signedData = baseInfo.signedData;
  125. $doctorQKInput.mobiscroll({
  126. theme: 'ios',
  127. lang: 'zh',
  128. customWheels: true,
  129. wheels: [
  130. [{
  131. keys: qkeCodes,
  132. values: qkeNames
  133. }]
  134. ],
  135. onSelect: function(valueText, inst) {
  136. var dd = eval("[" + valueText + "]"),
  137. name=dd[0].values,
  138. currExpenses = dd[0].keys;
  139. $(this).val(name);
  140. $doctorQKInput.attr("data-code",currExpenses);
  141. }
  142. });
  143. // if(docInfo.docType == 2) {
  144. // setQKSelect(docInfo.code, docInfo.name);
  145. // }
  146. //
  147. if(docInfo.docType == 2) {
  148. setQKSelect(docInfo.code, docInfo.name);
  149. }
  150. /*if(checkSignedSanshi(signedData)) { // 已签约三师
  151. if(checkSanshiComnunity(docInfo,signedData)) { // 三师签约中全科医生在当前医生所在社区
  152. // if(checkLoginerIsSanshi(data.docInfo,data.signedData)) { // 三师签约中全科医生是当前医生
  153. // } else { // 三师签约中全科医生不是当前医生
  154. // }
  155. // TODO 全科医生选择框设值为签约的全科医生,且不能变更
  156. setQKSelect(signedData.doctor, signedData.doctorName);
  157. setQKSelectReadonly(true);
  158. } else { // 三师签约中全科医生不在当前医生所在社区
  159. mui.toast("病人已签约三师");
  160. }
  161. $headerPromptMessage.find('.j-disease').text(signedData.diseases[0].diseaseName);
  162. $headerPromptMessage.find('.j-doctor').text(signedData.doctorName);
  163. $headerPromptMessage.show();
  164. }*/
  165. },
  166. // 获取健康管理医生列表
  167. reqDoctorJG = function() {
  168. // 登录者信息
  169. var docInfo = baseInfo.docInfo,
  170. // 登录医生的类别。1:专科医生,2:全科医生,3:健康管理师
  171. docType = docInfo.docType,
  172. // 所在机构(社区)
  173. hospital = docInfo.hospital,
  174. // 请求路径,根据医生类别不同而不同
  175. url,
  176. // 请求参数
  177. params;
  178. if(docType==2){
  179. url = "/doctor/doctor_combobox";
  180. // type: 医生类别
  181. params={type:3,hospital:hospital}
  182. }else{
  183. url = "/doctor/findDoctorByLevelAndHospital";
  184. // level: 医生类别
  185. params={hospital:hospital,level:docType}
  186. }
  187. getReqPromise(url,params).then(function(res) {
  188. var doctors, healthManagementCodes, healthManagementNames;
  189. if(res.status == 200) {
  190. // 如果是健康管理师 取res.doctors,如果是全科医生取res.list
  191. doctors = (docType==3)? res.doctors: ((docType==2)? res.list: []);
  192. // 萃取数组对象中code、name,返回一个数组
  193. healthManagementCodes = _.pluck(doctors, 'code');
  194. healthManagementNames = _.pluck(doctors, 'name');
  195. activHealthM(healthManagementCodes, healthManagementNames);
  196. };
  197. }).catch(function(e) { console && console.error(e); });
  198. },
  199. setJGSelect = function(doctor,doctorName) {
  200. // 获取健康管理师下拉框mibiscroll实例
  201. var doctorJGMobiscroll = $doctorJGInput.mobiscroll('getInst');
  202. var valueText = "{keys:'"+doctor+"',values:'"+doctorName+"'}";
  203. doctorJGMobiscroll.setVal([valueText]);
  204. $doctorJGInput.val(doctorName);
  205. $doctorJGInput.attr("data-code",doctor);
  206. },
  207. // 健康管理师下拉框
  208. activHealthM = function activHealthM(codes,names) {
  209. var docInfo = baseInfo.docInfo,
  210. signedData = baseInfo.signedData;
  211. $doctorJGInput.mobiscroll({
  212. theme: 'ios',
  213. lang: 'zh',
  214. customWheels: true,
  215. wheels: [
  216. [{
  217. keys: codes,
  218. values: names
  219. }]
  220. ],
  221. onSelect: function(valueText, inst) {
  222. var dd = eval("[" + valueText + "]");
  223. $(this).val(dd[0].values);
  224. $(this).attr('data-code',dd[0].keys);
  225. }
  226. });
  227. // 健康管理师登录,下拉框默认为其本人
  228. if(docInfo.docType==3) {
  229. setJGSelect(docInfo.code, docInfo.name);
  230. }
  231. },
  232. setExpensesSelect = function(key,name) {
  233. // 获取政府补贴下拉框mibiscroll实例
  234. var expensesMobiscroll = $expensesInput.mobiscroll('getInst');
  235. var valueText = "{keys:'"+key+"',values:'"+name+"'}";
  236. expensesMobiscroll.setVal([valueText]);
  237. $expensesInput.val(name);
  238. $expensesInput.attr("data-code",key);
  239. },
  240. // 获取政府补贴数据
  241. setExpenses = function (){
  242. var expensesCodes=[],expensesNames=[];
  243. getReqPromise("/common/getDictByDictName?name=SIGN_EXPENSES",null, "GET")
  244. .then(function(res) {
  245. if(res.status == 200) {
  246. var expensesList = res.list;
  247. // 萃取数组对象中code、value属性值,返回一个数组
  248. expensesCodes = _.pluck(expensesList, 'code');
  249. expensesNames = _.pluck(expensesList, 'value');
  250. activExpensesM(expensesCodes,expensesNames);
  251. };
  252. }).catch(function(e) {
  253. console && console.error(e);
  254. });
  255. },
  256. // 设置政府补贴下拉框
  257. activExpensesM = function (expensesCodes,expensesNames) {
  258. $expensesInput.mobiscroll({
  259. theme: 'ios',
  260. lang: 'zh',
  261. customWheels: true,
  262. wheels: [
  263. [{
  264. keys: [expensesCodes[1],expensesCodes[0],expensesCodes[3],expensesCodes[2]],
  265. values: [expensesNames[1],expensesNames[0],expensesNames[3],expensesNames[2]]
  266. }]
  267. ],
  268. onSelect: function(valueText, inst) {
  269. var dd = eval("[" + valueText + "]"),
  270. name=dd[0].values,
  271. currExpenses = dd[0].keys;
  272. $(this).val(name);
  273. $expensesInput.attr("data-code",currExpenses);
  274. }
  275. });
  276. setExpensesSelect(expensesCodes[0],expensesNames[0]);
  277. },
  278. // 疾病类型初始化设值
  279. initDiseaseTypes = function() {
  280. var signedData = baseInfo.signedData,
  281. diseases = signedData.diseases,
  282. values = "",
  283. names = "";
  284. if(diseases) {
  285. values = _.pluck(diseases, 'disease').join(',');
  286. names = _.pluck(diseases, 'diseaseName').join(',');
  287. }
  288. $diseaseInput.attr('data-code',values)
  289. $diseaseInput.val(names);
  290. },
  291. //普通 老年 高血 糖尿 孕妇 儿童 贫困 计生 重性 残疾 结核
  292. filterSer = function(name){
  293. var $li = $('.dw-bf').find('div.dw-li');
  294. $li.addClass('dw-v');
  295. var nameArr = name.split(',');
  296. $.map(nameArr,function(item,index){
  297. if(item.trim() == '普通人群'){
  298. var arr = [2,3,6,7,8,9,10]
  299. $.map(arr,function(it,index){
  300. $li.eq(it).removeClass('dw-v')
  301. })
  302. }
  303. if(item.trim() == '老年人'){
  304. var arr = [4,5]
  305. $.map(arr,function(it,index){
  306. $li.eq(it).removeClass('dw-v')
  307. })
  308. }
  309. if(item.trim() == '高血压' ||item.trim() == '糖尿病'||item.trim() == '贫困人口'||item.trim() == '计生特殊人群'||item.trim() == '重性精神疾病'||item.trim() == '残疾人'||item.trim() == '结核病' ){
  310. var arr = [0]
  311. $.map(arr,function(it,index){
  312. $li.eq(it).removeClass('dw-v')
  313. })
  314. }
  315. if(item.trim() == '0-6岁儿童'){
  316. var arr = [1,4]
  317. $.map(arr,function(it,index){
  318. $li.eq(it).removeClass('dw-v')
  319. })
  320. }
  321. if(item.trim() == '孕产妇'){
  322. var arr = [1,5]
  323. $.map(arr,function(it,index){
  324. $li.eq(it).removeClass('dw-v')
  325. })
  326. }
  327. })
  328. },
  329. //获得服务类型数据
  330. getServiceData = function(){
  331. var url = "/doctor/sign/getSigndict";
  332. sendGet(url, {}, null, function(res){
  333. fillServiceDropdown(res);
  334. }, true);
  335. },
  336. //设置服务类型下拉
  337. fillServiceDropdown = function(data){
  338. var $serviceSel = $('#selFuwu'),
  339. data = data.data,
  340. html="";
  341. for(i=0; i<data.length; i++){
  342. html += '<option value="'+data[i].code+'">'+data[i].name+'</option>'
  343. }
  344. $serviceSel.html(html);
  345. $serviceSel.mobiscroll().select({
  346. theme: 'ios',
  347. lang: 'zh',
  348. display: 'bottom',
  349. rows:6,
  350. placeholder:'请选择服务类型',
  351. onSelect: function ( valueText, inst) {
  352. // var vArr = valueText.split(',');
  353. //判断服务类型是否变更
  354. $juminLabels.val("").attr("data-code",JSON.stringify({health: "",disease: "", custom: "" }));
  355. currService = inst._tempValue?inst._tempValue.join(','):'';
  356. },
  357. onChange: function (event, inst) {
  358. filterSer(event)
  359. },
  360. onShow: function (event, inst) {
  361. filterSer(inst)
  362. }
  363. })
  364. },
  365. // 获取表单数据
  366. getInputs = function() {
  367. var data = {
  368. group: $groupInput.attr("data-code"), // 居民分组
  369. //disease: $diseaseInput.attr("data-code") , // 慢病类别code
  370. doctorQK: $doctorQKInput.attr("data-code"), // 全科医生code
  371. teamCode: $doctorQytdInput.attr("data-code"), // 签约团队code
  372. doctorNameQK: $doctorQKInput.val(), // 全科医生名字
  373. doctorJG: $doctorJGInput.attr("data-code"), // 健康管理师code
  374. doctorNameJG: $doctorJGInput.val(), // 健康管理师名字
  375. expenses: $expensesInput.attr("data-code"), // 政府补贴费
  376. agree: $agree.hasClass("checked") ,// 家庭医生签约协议(是否勾选)
  377. juminLabels: $juminLabels.attr("data-code"), // 居民标签
  378. juminServices: $juminServices.attr("data-code") //服务类型
  379. };
  380. return data;
  381. },
  382. // 必输验证
  383. validRequired = function(data) {
  384. var fieldsStr = "doctorQK,doctorJG,juminLabels",
  385. fieldMap = {
  386. doctorQK:"全科医生",doctorJG:"健康管理师",teamCode: "签约团队",juminLabels: "居民标签"
  387. },
  388. fields = fieldsStr.split(","),
  389. invalidField;
  390. invalidField = _.find(fields,function(key) {
  391. return !data[key];
  392. });
  393. if(invalidField) {
  394. mui.toast(fieldMap[invalidField]+'不能为空');
  395. return false;
  396. } else {
  397. return true;
  398. }
  399. },
  400. // 输入格式验证
  401. validFormat = function(data) {
  402. return true;
  403. },
  404. // 检查是否签约三师
  405. checkSignedSanshi = function(signedData) {
  406. // signStatus: 0-->病人未注册或三师跟家庭签约都没有,1-->有三师签约,2-->有签约家庭医生
  407. var signStatus = signedData.signStatus;
  408. return signStatus==1;
  409. },
  410. // 检查三师签约中全科医生是否在当前医生所在社区
  411. checkSanshiComnunity = function(loginerData,signedData) {
  412. // 三师中全科医生所在社区主编码(截取前8位,后两位是服务站)
  413. var sanShiHospital = signedData.hospital.slice(0,8),
  414. // 该医生(登录者)所在社区主编码(截取前8位,后两位是服务站)
  415. hospital = loginerData.hospital.slice(0,8);
  416. return sanShiHospital == hospital;
  417. },
  418. // 检查三师签约中全科医生是否是当前医生
  419. checkLoginerIsSanshi = function(loginerData,signedData) {
  420. // 三师签约中全科医生code
  421. var sanShiDoctor = signedData.doctor,
  422. // 该医生(登录者)编码
  423. doctor = loginerData.code;
  424. return sanShiDoctor == doctor;
  425. },
  426. validInputByDBPromise = function(data) {
  427. return true;
  428. },
  429. //获取签约团队
  430. getQytd = function(){
  431. var userAgent = baseInfo.userAgent;
  432. getReqPromise("/doctor/admin-teams/team/"+ baseInfo.docInfo.code +"/teamsLimit",{}, "GET")
  433. .then(function(res) {
  434. if(res.status == 200) {
  435. var teams = res.data,
  436. teamCodes=[],
  437. teamNames=[];
  438. // 萃取数组对象中code、name,返回一个数组
  439. teamCodes = _.pluck(teams, 'id');
  440. // teamNames = _.pluck(teams, 'name');
  441. for(var i = 0; i < teams.length; i++){
  442. var signTeam;
  443. var signCount = teams[i].signCount;
  444. var signLimitNumber = teams[i].signLimitNumber;
  445. if(signCount >= signLimitNumber){
  446. signTeam = teams[i].name + "<span style='color:red'>(已达上限)</span>";
  447. $('#upload').css({pointerEvents:'none',backgroundColor:"#ccc"});
  448. }else{
  449. signTeam = teams[i].name + "(签约人数为"+signCount+"人)";
  450. }
  451. teamNames.push(signTeam);
  452. }
  453. qytdSelect(teamCodes, teamNames);
  454. }
  455. }).catch(function(e) {
  456. console && console.error(e);
  457. });
  458. },
  459. // 设置团队下拉框
  460. qytdSelect = function (teamCodes,teamNames) {
  461. // 登录者信息
  462. var docInfo = baseInfo.docInfo,
  463. // 登录医生的类别。1:专科医生,2:全科医生,3:健康管理师
  464. docType = docInfo.docType;
  465. $doctorQytdInput.mobiscroll({
  466. theme: 'ios',
  467. lang: 'zh',
  468. customWheels: true,
  469. wheels: [
  470. [{
  471. keys: teamCodes,
  472. values: teamNames
  473. }]
  474. ],
  475. onSelect: function(valueText, inst) {
  476. var valueTextZy = valueText.replace("<span style='color:red'>", "<span style=\\\'color:red\\\'>");
  477. var dd = eval("[" + valueTextZy + "]"),
  478. name=dd[0].values,
  479. currExpenses = dd[0].keys;
  480. // $(this).val(name);
  481. $(this).html(name);
  482. if($doctorQytdInput.html(name).toString().length>18){
  483. $doctorQytdInput.css({textAlign:'left'});
  484. }else{
  485. $doctorQytdInput.css({textAlign:'right'});
  486. }
  487. $doctorQytdInput.attr("data-code",currExpenses);
  488. // 修复bug#2303 当修改团队时应该清空全科医生及健管师选项中选择的信息
  489. if(docType == 2) {
  490. $doctorJGInput.val('').attr("data-code",'');
  491. } else if(docType == 3) {
  492. $doctorQKInput.val('').attr("data-code",'');
  493. }
  494. getTeamMember(currExpenses);
  495. }
  496. });
  497. if(teamCodes.length == 1){
  498. setQytdSelect(teamCodes[0], teamNames[0]);
  499. getTeamMember(teamCodes[0]);
  500. }
  501. },
  502. //获取团队成员
  503. getTeamMember= function(teamCode){
  504. plus.nativeUI.showWaiting();
  505. sendGet("/doctor/admin-teams/"+ teamCode + "/members", {}, null, function(res){
  506. if(res.status == 200){
  507. var qka = [], jgs= [],
  508. qkCodes=[], jgCodes =[],
  509. qkNames=[], jgNames = [];
  510. $.each(res.data, function(i, v) {
  511. if(v.level == 2){
  512. qka.push(v);
  513. jgs.push(v);
  514. }
  515. else if(v.level == 3)
  516. jgs.push(v);
  517. });
  518. // 萃取数组对象中code、name,返回一个数组
  519. qkCodes = _.pluck(qka, 'code');
  520. qkNames = _.pluck(qka, 'name');
  521. qkeSelect(qkCodes, qkNames);
  522. jgCodes = _.pluck(jgs, 'code');
  523. jgNames = _.pluck(jgs, 'name');
  524. activHealthM(jgCodes, jgNames);
  525. } else
  526. mui.toast("获取团队成员失败!");
  527. plus.nativeUI.closeWaiting();
  528. },true)
  529. },
  530. //设置签约团队默认值
  531. setQytdSelect = function(code, name) {
  532. // 获取全科医生下拉框mibiscroll实例
  533. var mobiscroll = $doctorQytdInput.mobiscroll('getInst');
  534. var valueText = "{keys:'"+code+"',values:'"+name+"'}";
  535. mobiscroll.setVal([valueText]);
  536. $doctorQytdInput.html(name);
  537. $doctorQytdInput.attr("data-code", code);
  538. },
  539. // 所有输入验证
  540. validInputsPromise = function() {
  541. // 表单数据
  542. var data = getInputs();
  543. return Promise.resolve()
  544. .then(function() {
  545. var flag = validRequired(data);
  546. if(!flag) throw new Error("必输校验失败");
  547. return flag;
  548. })
  549. .then(function(flag) {
  550. var flag = validFormat(data);
  551. if(!flag) throw new Error("格式校验失败");
  552. return flag;
  553. })
  554. .then(function() {
  555. return validInputByDBPromise(data);
  556. })
  557. .then(function() {
  558. if(!data.agree) {
  559. mui.toast("您还未接受签约协议");
  560. throw new Error("未接受签约协议");
  561. return false;
  562. }
  563. return true;
  564. })
  565. .then(function(flag) {
  566. if(flag) return data;
  567. });
  568. },
  569. sendData = function (data) {
  570. var submitUrl = "doctor/family_contract/agent",
  571. docInfo = baseInfo.docInfo,
  572. juminLabels = JSON.parse($juminLabels.attr("data-code")),
  573. params = $.extend({},data,baseInfo.accessData,{
  574. doctor: data.doctorQK, //全科医生code
  575. doctorName: data.doctorNameQK, //全科医生名字
  576. signDoctorCode: docInfo.code, // 签约人code
  577. signDoctorName: docInfo.name, // 签约人名字
  578. signDoctorLevel: docInfo.docType, // 签约人等级
  579. healthDoctor: data.doctorJG,
  580. healthDoctorName: data.doctorNameJG,
  581. healthLabel: juminLabels.health,
  582. customLabel: juminLabels.custom,
  583. disease: juminLabels.disease,
  584. adminTeamCode:$doctorQytdInput.attr("data-code"),
  585. sevId: currService
  586. });
  587. getReqPromise(submitUrl, params).then(function(res) {
  588. plus.nativeUI.closeWaiting();
  589. if(res.status == 200) {
  590. mui.toast('代理签约成功')
  591. var hzWv = plus.webview.getWebviewById("huanzhe.html");
  592. if(hzWv) {
  593. mui.fire(hzWv, "update");
  594. }
  595. var syWv = plus.webview.getWebviewById("home2.html");
  596. if(syWv) {
  597. mui.fire(syWv, "refreshPatCount");
  598. }
  599. setTimeout(function() {
  600. backToPage(self)
  601. }, 500)
  602. }else{
  603. mui.toast(res.msg)
  604. }
  605. }).catch(function(e) {
  606. plus.nativeUI.closeWaiting();
  607. console && console.error(e);
  608. });
  609. },
  610. bindEvents = function() {
  611. // 提交
  612. $upload.on('tap', function() {
  613. plus.nativeUI.showWaiting();
  614. validInputsPromise().then(function(data) {
  615. if(data) {
  616. sendData(data);
  617. }
  618. }).catch(function(e) {
  619. plus.nativeUI.closeWaiting();
  620. console && console.error(e);
  621. });
  622. });
  623. // 选择分组
  624. $("body").on("click","#li_group",function(){
  625. mui.openWindow({
  626. url:"../../qygl/html/xiaoxichuli_fzgl.html",
  627. id:"xiaoxichuli_fzgl.html"
  628. })
  629. })
  630. // 选择居民标签
  631. .on("click","#jumin_labels",function(){
  632. var teamCode = $doctorQytdInput.attr("data-code");
  633. if($.trim(teamCode)) {
  634. //判断当前服务类型是否已经选择
  635. if(!currService){
  636. mui.confirm('请先选择服务类型', "提示", ["确定"], function(){});
  637. return false;
  638. }
  639. mui.openWindow({
  640. url:"../../huanzhe/html/disease-label-choose.html",
  641. id:"disease-label-choose",
  642. extras: $.extend({
  643. teamCode: teamCode,
  644. showData: $juminLabels.attr("data-code") || null,
  645. serviceCode: currService
  646. },baseInfo.signedData)
  647. })
  648. } else {
  649. mui.confirm('请先选择签约团队', "提示", ["确定"], function(){});
  650. }
  651. })
  652. // 点击家庭医生签约协议(勾选框)
  653. .on('click', '.input-group-pack', function() {
  654. $(this).toggleClass("checked");
  655. });
  656. $diseaseInput.on('click',function() {
  657. var view = plus.webview.getWebviewById("xuanzejibing"),
  658. createNew = false,
  659. signedData = baseInfo.signedData;
  660. if(view){ // 如果页面已经缓存
  661. view.close();
  662. createNew = true;
  663. }
  664. var diseaseCodes = null,
  665. diseaseNames = null;
  666. if($diseaseInput.val().trim()) {
  667. diseaseCodes = $diseaseInput.attr('data-code').split(',');
  668. }
  669. mui.openWindow({
  670. url: "../../huanzhe/html/xuanzejibing.html",
  671. id:"xuanzejibing",
  672. // 是否重新创建页面webview,防止页面缓存
  673. createNew: createNew,
  674. // 跳转页面传参
  675. extras: {
  676. diseases: signedData.diseases
  677. },
  678. });
  679. });
  680. /*分组事件*/
  681. window.addEventListener("group", function group(e) {
  682. var groupcode=e.detail.code
  683. var groupName=e.detail.name
  684. $groupInput.val(groupName).attr("data-code",groupcode)
  685. });
  686. /*居民标签*/
  687. window.addEventListener("setJuMinLabels", function setJuMinLabels(e) {
  688. var health = e.detail.health,
  689. disease = e.detail.disease,
  690. custom = e.detail.custom,
  691. labelName = e.detail.labelName;
  692. $juminLabels.val(labelName).attr("data-code",JSON.stringify({health: health,disease: disease, custom: custom }));
  693. });
  694. /*疾病类型回填事件*/
  695. window.addEventListener("setDiseaseTypes", function setDiseaseTypes(e) {
  696. var diseases = e.detail.diseases,
  697. values = _.pluck(diseases, 'disease').join(','),
  698. names = _.pluck(diseases, 'diseaseName').join(',');
  699. // 更新疾病类型选择的值
  700. baseInfo.signedData.diseases = diseases;
  701. $diseaseInput.val(names);
  702. $diseaseInput.attr('data-code',values);
  703. });
  704. };
  705. // 页面业务处理流程开始
  706. new Promise(function(resolve, reject) {
  707. mui.plusReady(function() {
  708. // plus已经准备好,可以往下执行
  709. resolve(true);
  710. })
  711. }).then(function() {
  712. var docInfo = JSON.parse(plus.storage.getItem("docInfo"));
  713. if(docInfo.level == 3){
  714. $doctorJGInput.val(docInfo.name).attr('data-code', docInfo.code);
  715. } else if(docInfo.level == 2){
  716. $doctorQKInput.val(docInfo.name).attr('data-code', docInfo.code);
  717. }
  718. $doctorQKInput.on('tap', function(){
  719. mui.confirm('请先选择签约团队', "提示", ["确定"], function(){});
  720. })
  721. $doctorJGInput.on('tap', function(){
  722. mui.confirm('请先选择签约团队', "提示", ["确定"], function(){});
  723. })
  724. // 获取基础环境信息
  725. baseEnv = getBaseEnv();
  726. // 获取基本信息
  727. getBaseInfoPromise().then(function(data) {
  728. baseInfo = data;
  729. }).then(function() {
  730. // 请求并获取签约团队
  731. getQytd();
  732. // 请求并初始化全科医生下拉框数据
  733. qke();
  734. // 请求并初始化健康管理师下拉框数据
  735. // reqDoctorJG();
  736. // 请求并初始化政府补贴下拉框数据
  737. setExpenses();
  738. // 疾病类型初始化赋值
  739. initDiseaseTypes();
  740. // 请求并初始化服务类型下拉框数据
  741. getServiceData();
  742. // 绑定页面事件
  743. bindEvents();
  744. });
  745. }).catch(function(e) {
  746. plus.nativeUI.closeWaiting();
  747. console && console.error(e);
  748. })
  749. //关闭页面操作
  750. var closeList = [];
  751. function backToPage(wv){
  752. if(wv.id == "home2.html"){
  753. var self = plus.webview.currentWebview();
  754. wv.show();
  755. mui.later(function(){
  756. for(i=0; i<closeList.length; i++){
  757. closeList[i].close('none');
  758. }
  759. self.close('none');
  760. }, 500);
  761. return false;
  762. }else{
  763. var opener = wv.opener();
  764. if(opener.id != "home2.html"){
  765. closeList.push(opener);
  766. }
  767. backToPage(opener);
  768. }
  769. }