goodsspecification.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. $(function () {
  2. let goodsId = getQueryString("goodsId");
  3. let url = '../goodsspecification/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: 'specificationName', index: 'specification_id', width: 80},
  14. {label: '规格说明', name: 'value', index: 'value', width: 80},
  15. {
  16. label: '规格图片', name: 'picUrl', index: 'pic_url', width: 80, formatter: function (value) {
  17. return transImg(value);
  18. }
  19. }],
  20. viewrecords: true,
  21. height: 550,
  22. rowNum: 10,
  23. rowList: [10, 30, 50],
  24. rownumbers: true,
  25. rownumWidth: 25,
  26. autowidth: true,
  27. multiselect: true,
  28. pager: "#jqGridPager",
  29. jsonReader: {
  30. root: "page.list",
  31. page: "page.currPage",
  32. total: "page.totalPage",
  33. records: "page.totalCount"
  34. },
  35. prmNames: {
  36. page: "page",
  37. rows: "limit",
  38. order: "order"
  39. },
  40. gridComplete: function () {
  41. $("#jqGrid").closest(".ui-jqgrid-bdiv").css({"overflow-x": "hidden"});
  42. }
  43. });
  44. });
  45. var vm = new Vue({
  46. el: '#rrapp',
  47. data: {
  48. showList: true,
  49. title: null,
  50. goodsSpecification: {},
  51. ruleValidate: {
  52. name: [
  53. {required: true, message: '名称不能为空', trigger: 'blur'}
  54. ]
  55. },
  56. q: {
  57. name: ''
  58. },
  59. goodss: [],
  60. specifications: []
  61. },
  62. methods: {
  63. getSpecification: function () {
  64. $.get("../specification/queryAll", function (r) {
  65. vm.specifications = r.list;
  66. });
  67. },
  68. getGoodss: function () {
  69. $.get("../goods/queryAll/", function (r) {
  70. vm.goodss = r.list;
  71. });
  72. },
  73. query: function () {
  74. vm.reload();
  75. },
  76. add: function () {
  77. vm.showList = false;
  78. vm.title = "新增";
  79. vm.goodsSpecification = {};
  80. vm.getSpecification();
  81. vm.getGoodss();
  82. },
  83. update: function (event) {
  84. var id = getSelectedRow();
  85. if (id == null) {
  86. return;
  87. }
  88. vm.showList = false;
  89. vm.title = "修改";
  90. vm.getInfo(id)
  91. },
  92. saveOrUpdate: function (event) {
  93. var url = vm.goodsSpecification.id == null ? "../goodsspecification/save" : "../goodsspecification/update";
  94. $.ajax({
  95. type: "POST",
  96. url: url,
  97. contentType: "application/json",
  98. data: JSON.stringify(vm.goodsSpecification),
  99. success: function (r) {
  100. if (r.code === 0) {
  101. alert('操作成功', function (index) {
  102. vm.reload();
  103. });
  104. } else {
  105. alert(r.msg);
  106. }
  107. }
  108. });
  109. },
  110. del: function (event) {
  111. var ids = getSelectedRows();
  112. if (ids == null) {
  113. return;
  114. }
  115. confirm('确定要删除选中的记录?', function () {
  116. $.ajax({
  117. type: "POST",
  118. url: "../goodsspecification/delete",
  119. contentType: "application/json",
  120. data: JSON.stringify(ids),
  121. success: function (r) {
  122. if (r.code == 0) {
  123. alert('操作成功', function (index) {
  124. $("#jqGrid").trigger("reloadGrid");
  125. });
  126. } else {
  127. alert(r.msg);
  128. }
  129. }
  130. });
  131. });
  132. },
  133. getInfo: function (id) {
  134. $.get("../goodsspecification/info/" + id, function (r) {
  135. vm.goodsSpecification = r.goodsSpecification;
  136. vm.getSpecification();
  137. vm.getGoodss();
  138. });
  139. },
  140. reload: function (event) {
  141. vm.showList = true;
  142. var page = $("#jqGrid").jqGrid('getGridParam', 'page');
  143. $("#jqGrid").jqGrid('setGridParam', {
  144. postData: {'name': vm.q.name},
  145. page: page
  146. }).trigger("reloadGrid");
  147. vm.handleReset('formValidate');
  148. },
  149. handleFormatError: function (file) {
  150. this.$Notice.warning({
  151. title: '文件格式不正确',
  152. desc: '文件 ' + file.name + ' 格式不正确,请上传 jpg 或 png 格式的图片。'
  153. });
  154. },
  155. handleMaxSize: function (file) {
  156. this.$Notice.warning({
  157. title: '超出文件大小限制',
  158. desc: '文件 ' + file.name + ' 太大,不能超过 100K。'
  159. });
  160. },
  161. handleSuccess: function (res, file) {
  162. vm.goodsSpecification.picUrl = file.response.url;
  163. },
  164. eyeImage: function () {
  165. var url = vm.goodsSpecification.picUrl;
  166. eyeImage(url);
  167. },
  168. handleSubmit: function (name) {
  169. handleSubmitValidate(this, name, function () {
  170. vm.saveOrUpdate()
  171. });
  172. },
  173. handleReset: function (name) {
  174. handleResetForm(this, name);
  175. }
  176. }
  177. });