shipintijiao.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. mui.plusReady(function() {
  2. var self = plus.webview.currentWebview();
  3. var doctorCode = self.doctorCode;
  4. var dept =self.dept;
  5. var name = self.name;
  6. var src = self.photo;
  7. if (name) {
  8. document.getElementById("doc_name").innerHTML = name + '<span class="level ml5"><img src="../images/x2.png"></span>';
  9. }
  10. if (dept) {
  11. document.getElementById("doc_dept").innerHTML = dept;
  12. }
  13. if (src) {
  14. document.getElementById("doc_img").src = getImgUrl(src);
  15. }
  16. var userAgent = plus.storage.getItem(agentName);
  17. if(userAgent){
  18. var jsonstr = $.parseJSON(userAgent);
  19. var uid = jsonstr.uid;
  20. var name = decodeURI(jsonstr.name);
  21. document.getElementById("labName").innerHTML = name;
  22. // var params = {};
  23. // params.code = uid;
  24. // mui.ajax(server + "patient/info", {
  25. // data: params,
  26. // type: 'POST',
  27. // dataType: 'json',
  28. // error: function(res) {
  29. // mui.toast('用户获取失败');
  30. // plus.nativeUI.closeWaiting();
  31. // },
  32. // success: function(res) {
  33. // plus.nativeUI.closeWaiting();
  34. // if (res.status == 200) {
  35. // var name = res.data.name;
  36. // document.getElementById("labName").innerHTML = name;
  37. // } else {
  38. // mui.toast('用户获取失败')
  39. // }
  40. // }
  41. // });
  42. }
  43. document.querySelector("#commit").addEventListener("tap", function() {
  44. var data = {};
  45. data.doctor = doctorCode;
  46. data.content = $("#remark").val();
  47. data.scheduling = "";
  48. data.appo_date = "2016-05-09";
  49. data.appo_week = 1;
  50. data.hour_begin = "08:30:00";
  51. data.hour_end = "18:00:00";
  52. if (validate(data)) {
  53. //验证通过执行
  54. //upload(data);
  55. plus.nativeUI.closeWaiting();
  56. mui.openWindow({
  57. url: "vedio-consulting-commit-success.html",
  58. id: "vedio-consulting-commit-success",
  59. extras: {
  60. type: 1
  61. },
  62. waiting: {
  63. autoShow: false
  64. }
  65. });
  66. }
  67. });
  68. })
  69. //验证信息
  70. function validate(data) {
  71. if (data.content == '') {
  72. plus.nativeUI.closeWaiting();
  73. mui.toast('请详细描述您的症状');
  74. return false;
  75. }
  76. if (data.content.length > 500) {
  77. plus.nativeUI.closeWaiting();
  78. mui.toast('请用500字以内完成您的症状描述');
  79. return false;
  80. }
  81. return true;
  82. }
  83. // 上传文件
  84. function upload(data) {
  85. plus.nativeUI.showWaiting();
  86. var files = getImages();
  87. if (files.length <= 0) {
  88. data.images = "";
  89. data.imageUrls = "";
  90. doSubmit(data);
  91. } else {
  92. var task = plus.uploader.createUpload(server + 'upload/image', {
  93. method: "POST"
  94. },
  95. function(t, status) { //上传完成
  96. if (status == 200) {
  97. var jsonstr = $.parseJSON(t.responseText);
  98. if(jsonstr.status == 200){
  99. data.images = jsonstr.images;
  100. data.imageUrls = jsonstr.urls;
  101. doSubmit(data);
  102. }
  103. else {
  104. plus.nativeUI.closeWaiting();
  105. mui.toast(jsonstr.msg);
  106. }
  107. } else {
  108. plus.nativeUI.closeWaiting();
  109. mui.toast("上传失败:" + status);
  110. }
  111. }
  112. );
  113. task.addData("client", "HelloH5+");
  114. task.addData("uid", getUid());
  115. for (var i = 0; i < files.length; i++) {
  116. var f = files[i];
  117. task.addFile(f, {});
  118. }
  119. task.start();
  120. }
  121. }
  122. //提交咨询
  123. function doSubmit(data) {
  124. sendPost('patient/consult_movi/add', data, 'json', 'post', submitFailed, submitSuccess);
  125. }
  126. function submitFailed(res) {
  127. plus.nativeUI.closeWaiting();
  128. if (res && res.msg) {
  129. plus.nativeUI.toast(res.msg);
  130. } else {
  131. plus.nativeUI.toast("提交失败");
  132. }
  133. }
  134. function submitSuccess(res) {
  135. plus.nativeUI.closeWaiting();
  136. if (res.status == 200) {
  137. mui.openWindow({
  138. url: "vedio-consulting-commit-success.html",
  139. id: "vedio-consulting-commit-success",
  140. extras: {
  141. type: 1
  142. },
  143. waiting: {
  144. autoShow: false
  145. }
  146. });
  147. mui.toast('提交成功');
  148. } else {
  149. submitFailed(res);
  150. }
  151. }
  152. function voicePop(n) {
  153. $(".win-broadcast,.win-broadcast-mb").show();
  154. $("#voice-finish").click(function() {
  155. $("#voice" + n).show();
  156. $(".win-broadcast,.win-broadcast-mb").hide();
  157. });
  158. }
  159. function voicePopClose() {
  160. $(".win-broadcast,.win-broadcast-mb").hide();
  161. }
  162. $(function() {
  163. $('.broadcast-icon').on('click',function(){
  164. $('.broadcast-shadow-panel').removeClass('c-hide');
  165. });
  166. $('.win-cancle').on('click',function(){
  167. $('.broadcast-shadow-panel').addClass('c-hide');
  168. });
  169. //显示隐藏选择图片按钮
  170. $(".add-btn").on("click", function() {
  171. //getImages();
  172. $(".over-lay").show();
  173. $(".ins-img-btn").show();
  174. });
  175. $("[data-btn=cancelOver]").on("click", function() {
  176. $(".over-lay").hide();
  177. $(".ins-img-btn").hide();
  178. });
  179. });
  180. //查看图片
  181. function viewImg(dom) {
  182. var $img = $(dom);
  183. var thissrc = $img.attr("date");
  184. var mWid = $(window).width();
  185. var mHei = $(window).height();
  186. var nHtml = '<div class="delimgpop"><div class="del-img-box"><div class="del-img-con"><img class="del-pop-img" src="' + thissrc + '" style="max-width:' + mWid + 'px; max-height:' + mHei + 'px;"></div></div></div>';
  187. $("body").append(nHtml);
  188. $(".delimgpop").click(function() {
  189. $(this).remove()
  190. });
  191. };
  192. //删除图片
  193. function delImg(dom) {
  194. var $li = $(dom).parent();
  195. $li.remove();
  196. return;
  197. }
  198. /* 复选框兼容 */
  199. $(document).on("click", ".input-group-pack > input[type=checkbox]", function() {
  200. var $cpChk = $(this).parent();
  201. if ($(this).attr("checked") == "checked") {
  202. $cpChk.removeClass("checked");
  203. $(this).removeAttr("checked");
  204. } else {
  205. $cpChk.addClass("checked");
  206. $(this).attr("checked", true);
  207. }
  208. });
  209. // 拍照添加文件
  210. function appendByCamera() {
  211. plus.camera.getCamera().captureImage(function(p) {
  212. //拍照完成,隐藏选择对话框
  213. hideImageChooseDialog();
  214. plus.io.resolveLocalFileSystemURL(p, function(entry) {
  215. var localurl = entry.toLocalURL();
  216. appendFile(localurl);
  217. });
  218. }, function(e) {
  219. //取消拍照,隐藏选择对话框
  220. hideImageChooseDialog();
  221. });
  222. };
  223. //隐藏图片方法
  224. function hideImageChooseDialog() {
  225. $(".over-lay").hide();
  226. $(".ins-img-btn").hide();
  227. };
  228. // 从相册添加文件
  229. function appendByGallery() {
  230. plus.gallery.pick(function(p) {
  231. appendFile(p);
  232. });
  233. }
  234. // 从相册中选择多张图片
  235. function galleryImgs() {
  236. // 从相册中选择图片
  237. plus.gallery.pick(function(e) {
  238. for (var i in e.files) {
  239. appendFile(e.files[i]);
  240. }
  241. }, function(e) {
  242. //取消拍照,隐藏选择对话框
  243. hideImageChooseDialog();
  244. }, {
  245. filter: "image",
  246. multiple: true
  247. });
  248. }
  249. // 添加文件
  250. function appendFile(p) {
  251. var $li = $('<li>' + ' <img src="' + p + '" date="' + p + '" onclick="viewImg(this)">' + ' <a href="javascript:;" class="del-img" onclick="delImg(this)"><i class="iconfont icon-laji"></i></a>' + '</li>');
  252. var $add_img_li = $("#add_img_li");
  253. $add_img_li.before($li);
  254. $(".over-lay").hide();
  255. $(".ins-img-btn").hide();
  256. }
  257. // 产生一个随机数
  258. function getUid() {
  259. return Math.floor(Math.random() * 100000000 + 10000000).toString();
  260. }
  261. //获取需要上传的图片
  262. function getImages() {
  263. var images = [];
  264. $("#img_ul").find("img").each(function() {
  265. var imgSrc = $(this).attr("src");
  266. images.push(imgSrc);
  267. });
  268. return images;
  269. }
  270. //字数限制
  271. function statInputNum(textArea, numItem) {
  272. var $text = $(textArea);
  273. var max = numItem;
  274. $text.on("input propertychange", function() {
  275. var $curText = $(this);
  276. var $count = $curText.siblings(".word-count");
  277. var curLength = $curText.val().length;
  278. if (curLength >= max) {
  279. var num = $curText.val().substr(0, max - 1);
  280. $curText.val(num);
  281. $count.text(max + "/" + max + "个字");
  282. } else {
  283. $count.text(curLength + "/" + max + "个字");
  284. }
  285. });
  286. };
  287. $.event.special.valuechange = {
  288. teardown: function(namespaces) {
  289. $(this).unbind('.valuechange');
  290. },
  291. handler: function(e) {
  292. $.event.special.valuechange.triggerChanged($(this));
  293. },
  294. add: function(obj) {
  295. $(this).on('keyup.valuechange cut.valuechange paste.valuechange input.valuechange', obj.selector, $.event.special.valuechange.handler)
  296. },
  297. triggerChanged: function(element) {
  298. var current = element[0].contentEditable === 'true' ? element.html() : element.val(),
  299. previous = typeof element.data('previous') === 'undefined' ? element[0].defaultValue : element.data('previous')
  300. if (current !== previous) {
  301. element.trigger('valuechange', [element.data('previous')])
  302. element.data('previous', current)
  303. }
  304. }
  305. }