attributecategory.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. $(function () {
  2. $("#jqGrid").Grid({
  3. url: '../attributecategory/list',
  4. rownumWidth:60,
  5. colModel: [
  6. {label: 'id', name: 'id', index: 'id', key: true, hidden: true},
  7. {label: '名称', name: 'name', index: 'name', width: 80},
  8. {
  9. label: '是否可用', name: 'enabled', index: 'enabled', width: 80, formatter: function (value, options, row) {
  10. return value === 0 ?
  11. '<span class="label label-danger">禁用</span>' :
  12. '<span class="label label-success">启用</span>';
  13. }
  14. }]
  15. });
  16. });
  17. var vm = new Vue({
  18. el: '#rrapp',
  19. data: {
  20. showList: true,
  21. title: null,
  22. attributeCategory: {
  23. enabled: '1'
  24. },
  25. ruleValidate: {
  26. name: [
  27. {required: true, message: '名称不能为空', trigger: 'blur'}
  28. ]
  29. },
  30. q: {
  31. name: ''
  32. },
  33. status: ''
  34. },
  35. methods: {
  36. query: function () {
  37. vm.reload();
  38. },
  39. add: function () {
  40. vm.showList = false;
  41. vm.title = "新增";
  42. vm.attributeCategory = {enabled: '1'};
  43. },
  44. update: function (event) {
  45. var id = getSelectedRow("#jqGrid");
  46. if (id == null) {
  47. return;
  48. }
  49. vm.showList = false;
  50. vm.title = "修改";
  51. vm.getInfo(id)
  52. },
  53. saveOrUpdate: function (event) {
  54. var url = vm.attributeCategory.id == null ? "../attributecategory/save" : "../attributecategory/update";
  55. if (vm.status) {
  56. vm.attributeCategory.enabled = '1';
  57. } else {
  58. vm.attributeCategory.enabled = '0';
  59. }
  60. Ajax.request({
  61. type: "POST",
  62. url: url,
  63. contentType: "application/json",
  64. params: JSON.stringify(vm.attributeCategory),
  65. successCallback: function () {
  66. alert('操作成功', function (index) {
  67. vm.reload();
  68. });
  69. }
  70. });
  71. },
  72. del: function (event) {
  73. var ids = getSelectedRows("#jqGrid");
  74. if (ids == null) {
  75. return;
  76. }
  77. confirm('确定要删除选中的记录?', function () {
  78. Ajax.request({
  79. type: "POST",
  80. url: "../attributecategory/delete",
  81. contentType: "application/json",
  82. params: JSON.stringify(ids),
  83. successCallback: function () {
  84. alert('操作成功', function (index) {
  85. vm.reload();
  86. });
  87. }
  88. });
  89. });
  90. },
  91. getInfo: function (id) {
  92. Ajax.request({
  93. url: "../attributecategory/info/" + id,
  94. async: true,
  95. successCallback: function (r) {
  96. vm.attributeCategory = r.attributeCategory;
  97. if (vm.attributeCategory.enabled == 1) {
  98. vm.status = true;
  99. } else {
  100. vm.status = false;
  101. }
  102. }
  103. });
  104. },
  105. reload: function (event) {
  106. vm.showList = true;
  107. var page = $("#jqGrid").jqGrid('getGridParam', 'page');
  108. $("#jqGrid").jqGrid('setGridParam', {
  109. postData: {'name': vm.q.name},
  110. page: page
  111. }).trigger("reloadGrid");
  112. vm.handleReset('formValidate');
  113. },
  114. changeEnable: function () {
  115. if (vm.status) {
  116. vm.attributeCategory.enabled = 1;
  117. } else {
  118. vm.attributeCategory.enabled = 0;
  119. }
  120. },
  121. handleSubmit: function (name) {
  122. handleSubmitValidate(this, name, function () {
  123. vm.saveOrUpdate()
  124. });
  125. },
  126. handleReset: function (name) {
  127. handleResetForm(this, name);
  128. }
  129. }
  130. });