company.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /**
  2. * 单位管理初始化
  3. */
  4. var Company = {
  5. id: "CompanyTable", //表格id
  6. seItem: null, //选中的条目
  7. table: null,
  8. layerIndex: -1
  9. };
  10. /**
  11. * 初始化表格的列
  12. */
  13. Company.initColumn = function () {
  14. return [
  15. {field: 'selectItem', radio: true},
  16. {title: 'id', field: 'id', align: 'center', valign: 'middle', visible: false},
  17. {title: '单位简称', field: 'shortName', align: 'center', valign: 'middle', sortable: false},
  18. {title: '单位全称', field: 'name', align: 'center', valign: 'middle', sortable: false},
  19. {title: '统一社会信用代码(不可修改)', field: 'code', align: 'center', valign: 'middle', sortable: false},
  20. {title: '排序', field: 'sn', align: 'center', valign: 'middle', sortable: true},
  21. {title: '备注', field: 'description', align: 'center', valign: 'middle', sortable: false}
  22. ]
  23. };
  24. /**
  25. * 检查是否选中
  26. */
  27. Company.check = function () {
  28. var selected = $('#' + this.id).bootstrapTable('getSelections');
  29. if (selected.length == 0) {
  30. Feng.info("请先选中表格中的某一记录!");
  31. return false;
  32. } else {
  33. Company.seItem = selected[0];
  34. return true;
  35. }
  36. };
  37. /**
  38. * 点击添加单位
  39. */
  40. Company.openAddCompany = function () {
  41. var index = layer.open({
  42. type: 2,
  43. title: '添加单位',
  44. area: ['800px', '380px'], //宽高
  45. fix: false, //不固定
  46. maxmin: true,
  47. content: '/admin/company/add'
  48. });
  49. this.layerIndex = index;
  50. };
  51. /**
  52. * 打开查看单位详情
  53. */
  54. Company.openCompanyDetail = function () {
  55. if (this.check()) {
  56. var index = layer.open({
  57. type: 2,
  58. title: '单位详情',
  59. area: ['800px', '380px'], //宽高
  60. fix: false, //不固定
  61. maxmin: true,
  62. content: '/admin/company/edit/id/' + Company.seItem.id
  63. });
  64. this.layerIndex = index;
  65. }
  66. };
  67. Company.select = function () {
  68. if (this.check()) {
  69. var index = layer.open({
  70. type: 2,
  71. title: '单位详情',
  72. area: ['800px', '380px'], //宽高
  73. fix: false, //不固定
  74. maxmin: true,
  75. content: '/admin/company/view/id/' + Company.seItem.id
  76. });
  77. this.layerIndex = index;
  78. }
  79. }
  80. /**
  81. * 删除单位
  82. */
  83. Company.delete = function () {
  84. if (this.check()) {
  85. var operation = function () {
  86. var ajax = new $ax("/admin/company/delete", function () {
  87. Feng.success("删除成功!");
  88. Company.table.refresh();
  89. }, function (data) {
  90. Feng.error("删除失败!" + data.responseJSON.message + "!");
  91. });
  92. ajax.set("id", Company.seItem.id);
  93. ajax.start();
  94. };
  95. Feng.confirm("是否刪除该单位?", operation);
  96. }
  97. };
  98. /**
  99. * 查询表单提交参数对象
  100. * @returns {{}}
  101. */
  102. Company.formParams = function () {
  103. var queryData = {};
  104. queryData['name'] = $("#name").val();
  105. queryData['code'] = $("#code").val();
  106. return queryData;
  107. }
  108. /**
  109. * 查询单位列表
  110. */
  111. Company.search = function () {
  112. Company.table.refresh({query: Company.formParams()});
  113. };
  114. /**
  115. * 重置
  116. */
  117. Company.reset = function () {
  118. $("#name").val("");
  119. $("#code").val("");
  120. };
  121. $(function () {
  122. var defaultColunms = Company.initColumn();
  123. var table = new BSTable(Company.id, "/admin/company/list", defaultColunms);
  124. table.setPaginationType("server");
  125. table.setQueryParams(Company.formParams());
  126. Company.table = table.init();
  127. });