selectHardware.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. $(function () {
  2. let url = ``
  3. // let url = `http://8.135.106.227:8004/`
  4. let gName = 'Gridtable'
  5. let grtable = document.querySelector("#gridtb")
  6. grtable.GM({
  7. gridManagerName: gName,
  8. height: '400px',
  9. ajaxData: function (setting) {
  10. // 传入分页及排序的配置项
  11. return getList(Object.assign({}, setting.pageData, setting.sortData));
  12. },
  13. ajaxType: "POST",
  14. checkboxConfig: {
  15. useRowCheck: true,
  16. useRadio: true,
  17. },
  18. query: { pluginId: 1 },
  19. supportAjaxPage: true,
  20. columnData: [
  21. {
  22. key: "code",
  23. text: "硬件编号",
  24. },
  25. {
  26. key: "devTypeName",
  27. text: "硬件类型",
  28. },
  29. {
  30. key: "name",
  31. text: "热点名字",
  32. },
  33. {
  34. key: "id",
  35. text: "id",
  36. }
  37. ],
  38. });
  39. // 确认事件
  40. $('#gcommit').click(function () {
  41. let item = Array.from(GridManager.getCheckedTr(gName))
  42. if (item.length<=0) {
  43. alert('请选择设备')
  44. return
  45. }
  46. window.editTool.hotpoint.addHardware(item[0])
  47. $('.jsGrid-body').hide()
  48. //alert(item)
  49. console.log(GridManager.getCheckedTr(gName));
  50. })
  51. // 取消事件
  52. $('#gcancel,.gr-header>img').click(function () {
  53. $('.jsGrid-body').hide()
  54. console.log(GridManager.getCheckedTr(gName));
  55. })
  56. //搜索事件
  57. $('.gr-header > .search').click(function () {
  58. var _query = {
  59. title: document.querySelector('[name="title"]').value,
  60. type: document.querySelector('[name="type"]').value,
  61. content: document.querySelector('[name="content"]').value,
  62. cPage: 1
  63. };
  64. grtable.GM('setQuery', _query, function(){
  65. console.log('setQuery执行成功');
  66. });
  67. })
  68. //设备添加
  69. $('#grAdd').click(function () {
  70. $('.jsGrid-body').show()
  71. })
  72. //设备删除
  73. $('#grDel').click(function () {
  74. })
  75. // 阻止冒泡
  76. $('.jsGrid-con').on('click keydown keyup keypress',function (event) {
  77. event.stopPropagation();
  78. })
  79. let getList = function(params) {
  80. return new Promise((resolve, reject) => {
  81. $.ajax({
  82. method: 'GET',
  83. headers: {
  84. 'Content-Type': 'application/json'
  85. },
  86. dataType: 'json',
  87. contentType: 'application/json',
  88. url: url + 'api/device/list',
  89. success: function(data) {
  90. console.log(data);
  91. if (data.code === 0) {
  92. resolve({
  93. ...data,
  94. totals:data.data.length
  95. });
  96. }
  97. else {
  98. reject(data);
  99. }
  100. }
  101. })
  102. })
  103. };
  104. })