Sin Descripción

updateinfo-res01.js 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. mui.ready(function() {
  2. mui.plusReady(function() {
  3. var userid = plus.storage.getItem('userid');
  4. var ws = plus.webview.currentWebview();
  5. var oDt = document.getElementsByClassName("frmtype");
  6. var service = document.getElementsByClassName("textareabox");
  7. function personalMessage() {
  8. mui.ajax(baseUrl + "/ajax/resource/" + ws.rsId, {
  9. dataType: 'json', //数据格式类型
  10. type: 'GET', //http请求类型
  11. timeout: 10000, //超时设置
  12. success: function(data) {
  13. plus.nativeUI.closeWaiting();
  14. ws.show("slide-in-right", 150);
  15. var $data = data.data;
  16. //资源基本信息
  17. oDt[0].value = $data.resourceName;
  18. service[0].innerText = $data.supportedServices
  19. },
  20. error: function() {
  21. plus.nativeUI.toast("服务器链接超时", toastStyle);
  22. return;
  23. }
  24. });
  25. }
  26. function trim(str) { //删除左右两端的空格   
  27. return str.replace(/(^\s*)|(\s*$)/g, "");  
  28. }
  29. oDt[0].addEventListener("blur", function() {
  30. var length = trim(oDt[0].value);
  31. if(!length)
  32. plus.nativeUI.toast("资源名称不能为空");
  33. });
  34. service[0].addEventListener("blur", function() {
  35. var length = trim(service[0].innerText);
  36. if(!length)
  37. plus.nativeUI.toast("应用用途不能为空");
  38. });
  39. function savePro() {
  40. var $data = {};
  41. $data.resourceName = oDt[0].value;
  42. $data.supportedServices = service[0].innerText;
  43. if(ws.rsId) {
  44. $data.resourceId = ws.rsId;
  45. mui.ajax(baseUrl + "/ajax/resource/nameAndSupport", {
  46. "type": "post",
  47. "async": true,
  48. "data": $data,
  49. "error": function(type, xhr, errorThrown) {
  50. console.log(JSON.stringify(type));
  51. console.log(JSON.stringify(xhr));
  52. console.log(JSON.stringify(errorThrown));
  53. },
  54. "success": function(data) {
  55. var y = JSON.stringify(data)
  56. if(data.success) {
  57. var web = plus.webview.getWebviewById("resinforupdate.html");
  58. var web1 = plus.webview.getWebviewById("proinforupdate.html");
  59. mui.fire(web1,"newId");
  60. mui.fire(web, "resourceMess");
  61. mui.back();
  62. } else {
  63. plus.nativeUI.toast("服务器链接超时", toastStyle);
  64. return;
  65. }
  66. }
  67. });
  68. } else {
  69. $data.professorId = userid;
  70. mui.ajax(baseUrl + "/ajax/resource", {
  71. "type": "post",
  72. "async": true,
  73. "data": $data,
  74. "success": function(data) {
  75. var y = JSON.stringify(data)
  76. if(data.success) {
  77. var id = data.data;
  78. plus.nativeUI.showWaiting();
  79. var web = plus.webview.create("../html/resinforupdate.html", "resinforupdate.html", {}, {
  80. resourceId: id
  81. }); //后台创建webview并打开show.html
  82. web.addEventListener("loaded", function() {}, false);
  83. } else {
  84. plus.nativeUI.toast("服务器链接超时", toastStyle);
  85. return;
  86. }
  87. }
  88. });
  89. }
  90. }
  91. if(ws.rsId) {
  92. personalMessage()
  93. }
  94. document.getElementsByClassName("topsave")[0].addEventListener("click", function() {
  95. var length1 = trim(oDt[0].value);
  96. var length2 = trim(service[0].innerText);
  97. if(length1 && length2) {
  98. savePro();
  99. } else if(!length1 && length2) {
  100. plus.nativeUI.toast("资源名称不能为空");
  101. } else if(length1 && !length2) {
  102. plus.nativeUI.toast("应用用途不能为空");
  103. } else if(!length1 && !length2) {
  104. plus.nativeUI.toast("资源名称不能为空&&应用用途不能为空");
  105. }
  106. });
  107. });
  108. })