classifiedSearch.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. $(document).ready(function() {
  2. var titleControl = $("#title");
  3. var typeControl = $("#type");
  4. var typeListControl = $("#typeList");
  5. var dateControl = $("#date");
  6. var deptControl = $("#dept");
  7. var deptListControl = $("#deptList");
  8. var authorControl = $("#author");
  9. var authorListControl = $("#authorList");
  10. // 资源类型
  11. typeControl.on("keyup", function(e) {
  12. debounce(getTypeList, 200);
  13. });
  14. function getTypeList() {
  15. var value = typeControl.val().trim();
  16. if (value === "") {
  17. typeListControl.empty();
  18. return;
  19. }
  20. fetchJSON("/api/query/attrib?keyword=" + value, {}, "get", function(ret) {
  21. $('#loading').modal('hide');
  22. if (ret.code === 0) {
  23. typeListControl.empty();
  24. for (var i = 0; i < ret.data.length; i++) {
  25. typeListControl.append($("<option>", { value: ret.data[i].id, text: ret.data[i].name }));
  26. }
  27. } else console.log(ret.msg);
  28. });
  29. }
  30. // 资源日期
  31. layui.use("laydate", function() {
  32. var laydate = layui.laydate;
  33. laydate.render({ elem: "#date", type: "date", range: true });
  34. });
  35. // 资源单位
  36. deptControl.on("keyup", function(e) {
  37. debounce(getDeptList, 200);
  38. });
  39. function getDeptList() {
  40. var value = deptControl.val().trim();
  41. if (value === "") {
  42. deptListControl.empty();
  43. return;
  44. }
  45. fetchJSON("/api/query/dept?keyword=" + value, {}, "get", function(ret) {
  46. if (ret.code === 0) {
  47. deptListControl.empty();
  48. for (var i = 0; i < ret.data.length; i++) {
  49. deptListControl.append($("<option>", { value: ret.data[i], text: ret.data[i] }));
  50. }
  51. } else console.log(ret.msg);
  52. });
  53. }
  54. // 资源作者
  55. $("#author").on("keyup", function(e) {
  56. debounce(getAuthorList, 200);
  57. });
  58. function getAuthorList() {
  59. var value = authorControl.val().trim();
  60. if (value === "") {
  61. authorListControl.empty();
  62. return;
  63. }
  64. fetchJSON("/api/query/author?keyword=" + value, {}, "get", function(ret) {
  65. if (ret.code === 0) {
  66. authorListControl.empty();
  67. for (var i = 0; i < ret.data.length; i++) {
  68. authorListControl.append($("<option>", { value: ret.data[i], text: ret.data[i] }));
  69. }
  70. } else console.log(ret.msg);
  71. });
  72. }
  73. $("#search").on("click", function(e) {
  74. e.preventDefault();
  75. var title = titleControl.val().trim();
  76. var type = typeControl.val().trim();
  77. var date = dateControl.val().trim();
  78. var dept = deptControl.val().trim();
  79. var author = authorControl.val().trim();
  80. if (title === "" && type === "" && date === "" && dept === "" && author === "") {
  81. titleControl.focus();
  82. return;
  83. }
  84. window.location.href =
  85. "list_class.html?n=" +
  86. encodeURIComponent(title) +
  87. "&t=" +
  88. encodeURIComponent(type) +
  89. "&d=" +
  90. encodeURIComponent(date) +
  91. "&e=" +
  92. encodeURIComponent(dept) +
  93. "&a=" +
  94. encodeURIComponent(author);
  95. });
  96. });