No Description

updateinfo-res02.js 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. mui.ready(function() {
  2. mui.plusReady(function() {
  3. var userid = plus.storage.getItem('userid');
  4. var ws = plus.webview.currentWebview();
  5. //查询学术领域
  6. var subjectShow = function(data) {
  7. if(data != undefined && data.length != 0) {
  8. var subs = new Array();
  9. if(data.indexOf(',')) {
  10. subs = data.split(',');
  11. } else {
  12. subs[0] = data;
  13. }
  14. if(subs.length > 0) {
  15. var html = [];
  16. for(var i = 0; i < subs.length; i++) {
  17. html.push("<li>" + subs[i] + "<em class='mui-icon mui-icon-closeempty'></em></li>");
  18. };
  19. document.getElementsByClassName("labelshow")[0].innerHTML = html.join('');
  20. }
  21. }
  22. }
  23. function personalMessage() {
  24. mui.ajax(baseUrl + "/ajax/resource/" + ws.rsId, {
  25. dataType: 'json', //数据格式类型
  26. type: 'GET', //http请求类型
  27. timeout: 10000, //超时设置
  28. success: function(data) {
  29. plus.nativeUI.closeWaiting();
  30. ws.show("slide-in-right", 150);
  31. var $data = data.data;
  32. //学术领域
  33. if($data.subject) {
  34. subjectShow($data.subject);
  35. }
  36. },
  37. error: function() {
  38. plus.nativeUI.toast("服务器链接超时", toastStyle);
  39. return;
  40. }
  41. });
  42. }
  43. function trim(str) { //删除左右两端的空格   
  44. return str.replace(/(^\s*)|(\s*$)/g, "");  
  45. }
  46. mui(".labelshow").on("tap", "em", function() {
  47. var val = this.parentNode;
  48. document.getElementsByClassName('labelshow')[0].removeChild(val);
  49. });
  50. document.getElementsByClassName("addlabelbtn")[0].addEventListener("tap", function() {
  51. var addContent = document.getElementsByTagName('input')[0].value;
  52. var content = trim(addContent);
  53. if(content) {
  54. var node = document.createElement("li");
  55. node.innerHTML = content + '<em class="mui-icon mui-icon-closeempty"></em>';
  56. document.getElementsByClassName("labelshow")[0].appendChild(node);
  57. } else {
  58. plus.nativeUI.toast("添加内容不能为空", toastStyle);
  59. }
  60. });
  61. document.getElementsByClassName("topsave")[0].addEventListener("tap", function() {
  62. var subjects = document.getElementsByTagName("li");
  63. var subjectAll = "";
  64. if(subjects.length > 0) {
  65. for(var i = 0; i < subjects.length; i++) {
  66. subjectAll += subjects[i].innerText;
  67. subjectAll += ',';
  68. };
  69. subjectAll = subjectAll.substring(0, subjectAll.length - 1);
  70. }
  71. mui.ajax(baseUrl + '/ajax/resource/subject', {
  72. data: {
  73. "resourceId": ws.rsId,
  74. "subject": subjectAll
  75. },
  76. dataType: 'json', //数据格式类型
  77. async: true,
  78. type: 'POST', //http请求类型
  79. timeout: 10000, //超时设置
  80. success: function(data) {
  81. if(data.success) {
  82. plus.nativeUI.showWaiting();
  83. var web = plus.webview.getWebviewById("resinforupdate.html");
  84. mui.fire(web, "resourceMess");
  85. mui.back();
  86. }
  87. },
  88. error: function() {
  89. plus.nativeUI.toast("服务器链接超时", toastStyle);
  90. return;
  91. }
  92. });
  93. });
  94. personalMessage();
  95. });
  96. })