goodsattribute.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. var goodsId = getQueryString("goodsId");
  2. $(function () {
  3. let url = '../goodsattribute/list';
  4. if (goodsId) {
  5. url += '?goodsId=' + goodsId;
  6. }
  7. $("#jqGrid").jqGrid({
  8. url: url,
  9. datatype: "json",
  10. colModel: [
  11. {label: 'id', name: 'id', index: 'id', key: true, hidden: true},
  12. {label: '商品', name: 'goodsName', index: 'goods_id', width: 80},
  13. {label: '属性', name: 'attributeName', index: 'attribute_id', width: 80},
  14. {label: '属性值', name: 'value', index: 'value', width: 80}],
  15. viewrecords: true,
  16. height: 550,
  17. rowNum: 10,
  18. rowList: [10, 30, 50],
  19. rownumbers: true,
  20. rownumWidth: 25,
  21. autowidth: true,
  22. multiselect: true,
  23. pager: "#jqGridPager",
  24. jsonReader: {
  25. root: "page.list",
  26. page: "page.currPage",
  27. total: "page.totalPage",
  28. records: "page.totalCount"
  29. },
  30. prmNames: {
  31. page: "page",
  32. rows: "limit",
  33. order: "order"
  34. },
  35. gridComplete: function () {
  36. $("#jqGrid").closest(".ui-jqgrid-bdiv").css({"overflow-x": "hidden"});
  37. }
  38. });
  39. });
  40. let vm = new Vue({
  41. el: '#rrapp',
  42. data: {
  43. showList: true,
  44. title: null,
  45. goodsAttribute: {},
  46. ruleValidate: {
  47. name: [
  48. {required: true, message: '名称不能为空', trigger: 'blur'}
  49. ]
  50. },
  51. q: {
  52. name: ''
  53. },
  54. attributes: []
  55. },
  56. methods: {
  57. query: function () {
  58. vm.reload();
  59. },
  60. add: function () {
  61. vm.showList = false;
  62. vm.title = "新增";
  63. vm.goodsAttribute = {};
  64. vm.getAttributes();
  65. },
  66. update: function (event) {
  67. let id = getSelectedRow();
  68. if (id == null) {
  69. return;
  70. }
  71. vm.showList = false;
  72. vm.title = "修改";
  73. vm.getInfo(id);
  74. vm.getAttributes();
  75. },
  76. saveOrUpdate: function (event) {
  77. let url = vm.goodsAttribute.id == null ? "../goodsattribute/save" : "../goodsattribute/update";
  78. vm.goodsAttribute.goodsId = goodsId;
  79. $.ajax({
  80. type: "POST",
  81. url: url,
  82. contentType: "application/json",
  83. data: JSON.stringify(vm.goodsAttribute),
  84. success: function (r) {
  85. if (r.code === 0) {
  86. alert('操作成功', function (index) {
  87. vm.reload();
  88. });
  89. } else {
  90. alert(r.msg);
  91. }
  92. }
  93. });
  94. },
  95. del: function (event) {
  96. let ids = getSelectedRows();
  97. if (ids == null) {
  98. return;
  99. }
  100. confirm('确定要删除选中的记录?', function () {
  101. $.ajax({
  102. type: "POST",
  103. url: "../goodsattribute/delete",
  104. contentType: "application/json",
  105. data: JSON.stringify(ids),
  106. success: function (r) {
  107. if (r.code == 0) {
  108. alert('操作成功', function (index) {
  109. $("#jqGrid").trigger("reloadGrid");
  110. });
  111. } else {
  112. alert(r.msg);
  113. }
  114. }
  115. });
  116. });
  117. },
  118. getAttributes: function () {
  119. $.get("../attribute/queryAll", function (r) {
  120. vm.attributes = r.list;
  121. });
  122. },
  123. getInfo: function (id) {
  124. $.get("../goodsattribute/info/" + id, function (r) {
  125. vm.goodsAttribute = r.goodsAttribute;
  126. });
  127. },
  128. reloadSearch: function () {
  129. vm.q = {
  130. name: ''
  131. }
  132. vm.reload();
  133. },
  134. reload: function (event) {
  135. vm.showList = true;
  136. let page = $("#jqGrid").jqGrid('getGridParam', 'page');
  137. $("#jqGrid").jqGrid('setGridParam', {
  138. postData: {'name': vm.q.name},
  139. page: page
  140. }).trigger("reloadGrid");
  141. vm.handleReset('formValidate');
  142. },
  143. handleSubmit: function (name) {
  144. handleSubmitValidate(this, name, function () {
  145. vm.saveOrUpdate()
  146. });
  147. },
  148. handleReset: function (name) {
  149. handleResetForm(this, name);
  150. }
  151. }
  152. });