expensesUpdate.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. var isModify = false, isJGmodify = false,isQkmodify=false,
  2. expenses, expenseName,
  3. patiCode,
  4. signStatus,
  5. isSigned;
  6. var $doctorJGInput;
  7. var $doctorQkInput;
  8. mui.init({
  9. beforeback: function() {
  10. if(isModify || isJGmodify||isQkmodify){
  11. mui.confirm("您有未保存的变动,是否保存?", "提示", ["保存", "不了"], function(e) {
  12. if(e.index == 0) {
  13. submit();
  14. } else {
  15. plus.webview.currentWebview().close();
  16. }
  17. })
  18. return false;
  19. }
  20. }
  21. });
  22. /**
  23. * 获取患者信息
  24. */
  25. function getPatientInfo(){
  26. var docCode = JSON.parse(plus.storage.getItem("docInfo")).code;
  27. sendPost("doctor/patient_group/patient", {
  28. code: patiCode,
  29. jyStatus: signStatus=='yjy'? '1' : ''
  30. }, null, function(res) {
  31. if(res.status == 200) {
  32. sendGet("/doctor/admin-teams/team/members/"+patiCode, {}, null, function(res1){
  33. if(res1.status==200 && res1.data.teamId){
  34. // res1.data.isLeader = true; //测试用
  35. res.data.signStatus = signStatus;
  36. res.data.qkys = res1.data.doctorName;
  37. res.data.qkysCode = res1.data.doctor;
  38. res.data.jgs = res1.data.healthDoctorName;
  39. res.data.jgsCode = res1.data.healthDoctorCode;
  40. res.data.teamName = res1.data.teamName;
  41. res.data.ModifyJgs = res1.data.isLeader;
  42. if(res.data.ssSign){
  43. res.data.Modifqk = false;
  44. }else{
  45. res.data.Modifqk = true;
  46. }
  47. oldQy = res1.data;
  48. $("#pati_info").html(template("info_tmpl", res.data));
  49. $doctorJGInput = $('#healthManagement input');
  50. $doctorQkInput = $('#dortor_qke input');
  51. setExpenses(); //初始化政府补贴下拉框
  52. if(res1.data.isLeader && $doctorJGInput.length > 0)
  53. getTeamMember(oldQy.teamId); // 初始化健管师下拉框
  54. if(res.data.ssSign){
  55. $(".no").show();
  56. }
  57. } else
  58. mui.toast("获取居民签约团队失败!");
  59. })
  60. } else {
  61. mui.toast(res.msg);
  62. }
  63. });
  64. }
  65. /**
  66. * 获取政府补贴数据
  67. */
  68. function setExpenses() {
  69. var $expenses = $('#li_expenses');
  70. if($expenses.length > 0) {
  71. expenses = $expenses.attr('data-code');
  72. if(signStatus!='yjy'){
  73. $('.header-link').show();
  74. }
  75. var expensesCode = [];
  76. var expensesName = [];
  77. sendGet("/common/getDictByDictName?name=SIGN_EXPENSES", null, null, function(res) {
  78. if(res.status == 200) {
  79. var expensesList = res.list;
  80. for(var i = 0; i < expensesList.length; i++) {
  81. if(expenses == expensesList[i].code){
  82. expenseName = expensesList[i].value;
  83. $expenses.val(expensesList[i].value);
  84. }
  85. expensesCode.push(expensesList[i].code);
  86. expensesName.push(expensesList[i].value);
  87. }
  88. checkQy(expensesCode, expensesName);
  89. };
  90. });
  91. }
  92. }
  93. function checkQy(expensesCode, expensesName){
  94. sendPost("/doctor/family_contract/medical_insurance_num", {patient: patiCode}, null, function(res) {
  95. isSigned = res.data.status;
  96. if(signStatus != 'yjy')
  97. activExpensesM(expensesCode, expensesName);
  98. });
  99. }
  100. function setExpensesSelect(code, name) {
  101. var $li_expenses = $('#li_expenses');
  102. var mobiscroll = $li_expenses.mobiscroll('getInst');
  103. var valueText = "{keys:'"+code+"',values:'"+name+"'}";
  104. mobiscroll.setVal([valueText]);
  105. $li_expenses.val(name);
  106. $li_expenses.attr("data-code", code);
  107. }
  108. /**
  109. * 设置政府补贴下拉框
  110. */
  111. function activExpensesM(expensesCode, expensesName) {
  112. if(isSigned == 0){
  113. $('#li_expenses').mobiscroll({
  114. theme: 'ios',
  115. lang: 'zh',
  116. customWheels: true,
  117. wheels: [
  118. [{
  119. keys: expensesCode,
  120. values: expensesName
  121. }]
  122. ],
  123. onSelect: function(valueText, inst) {
  124. var dd = eval("[" + valueText + "]");
  125. $(this).val(dd[0].values).attr("data-code", dd[0].keys);
  126. isModify = expenses != dd[0].keys;
  127. toggleModify();
  128. },
  129. onShow: function() {
  130. if($(this).attr('data-init') == "1") {
  131. $(this).attr('data-init', "0");
  132. $('#li_expenses').mobiscroll("selectWheel", [$(this).attr('data-code')]);
  133. }
  134. }
  135. });
  136. } else {
  137. $('#li_expenses').on('tap', function(){
  138. mui.toast("已成功签约,无法变更");
  139. })
  140. }
  141. };
  142. /**
  143. * 提交
  144. */
  145. function submit(t) {
  146. if(!isModify && !isJGmodify&&!isQkmodify)
  147. return;
  148. plus.nativeUI.showWaiting();
  149. var p = {patient: patiCode}
  150. if(isModify){
  151. p.expensesType = $('#li_expenses').attr('data-code');
  152. }
  153. if(isJGmodify){
  154. p.healthDoctor = $doctorJGInput.attr("data-code");
  155. }if(isQkmodify){
  156. p.doctor = $doctorQkInput.attr("data-code");
  157. }
  158. sendPost("/doctor/family_contract/sign_info_update", p, null,
  159. function(res) {
  160. if(res.status == 200) {
  161. expenses = $('#li_expenses').attr('data-code');
  162. oldQy.healthDoctorCode = $doctorJGInput.attr('data-code');
  163. oldQy.healthDoctorName = $doctorJGInput.val();
  164. oldQy.doctor = $doctorQkInput.attr('data-code');
  165. oldQy.doctorName = $doctorQkInput.val();
  166. isModify = false;
  167. isJGmodify = false;
  168. isQkmodify = false;
  169. toggleModify();
  170. mui.toast("保存成功!");
  171. plus.nativeUI.closeWaiting();
  172. if(!t)
  173. plus.webview.currentWebview().close();
  174. } else {
  175. if(isModify){
  176. setExpensesSelect(expenses, expenseName);
  177. isModify = false;
  178. }
  179. if(isJGmodify){
  180. setJGSelect(oldQy.healthDoctorCode, oldQy.healthDoctorName);
  181. isJGmodify = false;
  182. }
  183. if(isQkmodify){
  184. setQkSelect(oldQy.doctor,oldQy.doctorName);
  185. isQkmodify = false;
  186. }
  187. toggleModify();
  188. plus.nativeUI.closeWaiting();
  189. mui.toast(res.msg);
  190. }
  191. })
  192. }
  193. //获取团队成员
  194. function getTeamMember(teamCode){
  195. plus.nativeUI.showWaiting();
  196. sendGet("/doctor/admin-teams/"+ teamCode + "/members", {}, null, function(res){
  197. if(res.status == 200){
  198. var jgs= [],qk=[],
  199. jgCodes =[], jgNames = [],qkCodes=[],qkNames=[];
  200. $.each(res.data, function(i, v) {
  201. if(v.level == 3 || v.level==2){
  202. jgs.push(v);
  203. }
  204. if(v.level==2){
  205. qk.push(v);
  206. }
  207. });
  208. qkCodes = _.pluck(qk, 'code')
  209. qkNames = _.pluck(qk, 'name');
  210. // 萃取数组对象中code、name,返回一个数组
  211. jgCodes = _.pluck(jgs, 'code');
  212. jgNames = _.pluck(jgs, 'name');
  213. activHealthM(jgCodes, jgNames);
  214. activDoctorM(qkCodes, qkNames)
  215. } else
  216. mui.toast("获取团队成员失败!");
  217. plus.nativeUI.closeWaiting();
  218. })
  219. }
  220. function activDoctorM(codes, names) {
  221. $doctorQkInput.mobiscroll({
  222. theme: 'ios',
  223. lang: 'zh',
  224. customWheels: true,
  225. wheels: [
  226. [{
  227. keys: codes,
  228. values: names
  229. }]
  230. ],
  231. onSelect: function(valueText, inst) {
  232. var dd = eval("[" + valueText + "]");
  233. var curDocCode = dd[0].keys;
  234. $(this).val(dd[0].values);
  235. $doctorQkInput.attr("data-code", curDocCode);
  236. isQkmodify = oldQy.doctor != curDocCode;
  237. toggleQkModify();
  238. }
  239. });
  240. setQkSelect(oldQy.doctor, oldQy.doctorName);
  241. };
  242. function activHealthM(codes, names) {
  243. $doctorJGInput.mobiscroll({
  244. theme: 'ios',
  245. lang: 'zh',
  246. customWheels: true,
  247. wheels: [
  248. [{
  249. keys: codes,
  250. values: names
  251. }]
  252. ],
  253. onSelect: function(valueText, inst) {
  254. var dd = eval("[" + valueText + "]");
  255. var curDocCode = dd[0].keys;
  256. $(this).val(dd[0].values);
  257. $doctorJGInput.attr("data-code", curDocCode);
  258. isJGmodify = oldQy.healthDoctorCode != curDocCode;
  259. toggleModify();
  260. }
  261. });
  262. setJGSelect(oldQy.healthDoctorCode, oldQy.healthDoctorName);
  263. };
  264. function setJGSelect(code, name) {
  265. var mobiscroll = $doctorJGInput.mobiscroll('getInst');
  266. var valueText = "{keys:'"+code+"',values:'"+name+"'}";
  267. mobiscroll.setVal([valueText]);
  268. $doctorJGInput.val(name);
  269. $doctorJGInput.attr("data-code", code);
  270. }
  271. function setQkSelect(code, name) {
  272. var mobiscroll = $doctorJGInput.mobiscroll('getInst');
  273. var valueText = "{keys:'"+code+"',values:'"+name+"'}";
  274. mobiscroll.setVal([valueText]);
  275. $doctorQkInput.val(name);
  276. $doctorQkInput.attr("data-code", code);
  277. }
  278. function toggleModify(){
  279. console.log(isModify+ ","+ isJGmodify)
  280. $('.link').toggleClass('c-ccc', !(isModify || isJGmodify) );
  281. }
  282. function toggleQkModify(){
  283. console.log(isModify+ ","+ isQkmodify)
  284. $('.link').toggleClass('c-ccc', !(isModify || isQkmodify) );
  285. }