jiluxiangqing.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. // 基本信息(包括userAgent)
  2. var baseInfo = null,
  3. // 基础环境信息(包括当前webview)
  4. baseEnv = null;
  5. //文章列表
  6. $articleView = $(".mui-table-view");
  7. var article = '';
  8. var batchNo = "";
  9. var mscroll = null;
  10. // 获取登录相关信息
  11. var getBaseInfo = function() {
  12. // 登录的相关信息
  13. var userAgent = JSON.parse(plus.storage.getItem("userAgent"))
  14. return {
  15. userAgent: userAgent
  16. }
  17. },
  18. // 获取基础环境信息
  19. getBaseEnvPromise = function () {
  20. var env = {
  21. webview: plus&&plus.webview.currentWebview()
  22. };
  23. var self = plus.webview.currentWebview();
  24. return Promise.resolve().then(function(res) {
  25. return env;
  26. });
  27. },
  28. //事件绑定
  29. bindEvents = function(){
  30. $articleView.on('tap','.patient-list li',function() {
  31. var patientCode = $(this).attr('data-code');
  32. openWebviewExtras("../../huanzhe/html/huanzhexinxi.html",{patiCode:patientCode});
  33. })
  34. },
  35. loadArticlePromise = function() {
  36. plus.nativeUI.showWaiting();
  37. return new Promise(function(resolve, reject) {
  38. sendPost("doctor/health/edu/log",{
  39. article: article,
  40. batchNo: batchNo
  41. },function(res){
  42. plus.nativeUI.closeWaiting();
  43. if(res.msg){
  44. mui.toast(res.msg);
  45. }else{
  46. mui.toast("加载失败!");
  47. }
  48. },function(res){
  49. plus.nativeUI.closeWaiting();
  50. if(res.status==200){
  51. resolve(res.list)
  52. }else{
  53. if(res.msg){
  54. mui.toast(res.msg);
  55. }else{
  56. mui.toast("加载失败!");
  57. }
  58. }
  59. })
  60. });
  61. },
  62. initScroll = function () {
  63. var page = 1;
  64. mscroll = mui('.mui-scroll-wrapper').pullRefresh({
  65. down: {
  66. callback: function() {
  67. var self = this;
  68. loadArticlePromise()
  69. .then(function(list) {
  70. if(list && list.length) {
  71. var data = list[0];
  72. var txtContent = $('<div>').append(data.content).text();
  73. data.txtContent = txtContent;
  74. var html = template('liTempl',data);
  75. $('.mui-table-view').html(html);
  76. }
  77. self.endPulldownToRefresh();
  78. })
  79. .catch(function(e) {
  80. console && console.error(e)
  81. })
  82. }
  83. }
  84. });
  85. };
  86. template.helper("dateFormat", function(d) {
  87. return new Date(d).format('yyyy-MM-dd hh:mm')
  88. });
  89. // 页面业务处理流程开始
  90. new Promise(function(resolve, reject) {
  91. // TODO 临时放开
  92. //resolve(true);
  93. mui.plusReady(function() {
  94. // plus已经准备好,可以往下执行
  95. resolve(true);
  96. });
  97. }).then(function() {
  98. // 获取基础环境信息
  99. return getBaseEnvPromise().then(function(env) {
  100. baseEnv = env;
  101. }).then(function() {
  102. // 获取登录基本信息
  103. baseInfo = getBaseInfo();
  104. var self = plus.webview.currentWebview();
  105. article = self.article;
  106. batchNo = self.batchNo || "";
  107. initScroll();
  108. // 绑定页面事件
  109. bindEvents();
  110. mscroll.pulldownLoading();
  111. })
  112. }).catch(function(e) {
  113. plus.nativeUI.closeWaiting();
  114. console && console.error(e);
  115. });
  116. template.helper("setPhoto", function(p) {
  117. return getImgUrl(p);
  118. });