goodsspecification.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. $(function () {
  2. let goodsId = getQueryString("goodsId");
  3. let url = '../goodsspecification/list';
  4. if (goodsId) {
  5. url += '?goodsId=' + goodsId;
  6. }
  7. $("#jqGrid").Grid({
  8. url: url,
  9. rownumWidth:60,
  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: 'brandName', index: 'brand_name', width: 80},
  14. {label: '规格名称', name: 'specificationName', index: 'specification_id', width: 80},
  15. {label: '规格说明', name: 'value', index: 'value', width: 80},
  16. {
  17. label: '规格图片', align:'center', name: 'picUrl', index: 'pic_url', width: 80, formatter: function (value) {
  18. return transImg(value);
  19. }
  20. }]
  21. });
  22. });
  23. var vm = new Vue({
  24. el: '#rrapp',
  25. data: {
  26. showList: true,
  27. title: null,
  28. goodsSpecification: {},
  29. ruleValidate: {
  30. name: [
  31. {required: true, message: '名称不能为空', trigger: 'blur'}
  32. ]
  33. },
  34. q: {
  35. name: '',
  36. brandId: '',
  37. },
  38. goodss: [],
  39. specifications: [],
  40. brands:[]
  41. },
  42. mounted:function(){
  43. this.getBrands()
  44. },
  45. methods: {
  46. getSpecification: function () {
  47. Ajax.request({
  48. url: "../specification/queryAll",
  49. async: true,
  50. successCallback: function (r) {
  51. vm.specifications = r.list;
  52. }
  53. });
  54. },
  55. /**
  56. * 获取品牌
  57. */
  58. getBrands: function () {
  59. Ajax.request({
  60. url: "../brand/queryAll",
  61. async: true,
  62. successCallback: function (r) {
  63. vm.brands = r.list;
  64. }
  65. });
  66. },
  67. getGoodss: function () {
  68. Ajax.request({
  69. url: "../goods/queryAll/",
  70. async: true,
  71. successCallback: function (r) {
  72. vm.goodss = r.list;
  73. }
  74. });
  75. },
  76. query: function () {
  77. vm.reload();
  78. },
  79. add: function () {
  80. vm.showList = false;
  81. vm.title = "新增";
  82. vm.goodsSpecification = {};
  83. vm.getSpecification();
  84. vm.getGoodss();
  85. },
  86. update: function (event) {
  87. var id = getSelectedRow("#jqGrid");
  88. if (id == null) {
  89. return;
  90. }
  91. vm.showList = false;
  92. vm.title = "修改";
  93. vm.getInfo(id)
  94. },
  95. saveOrUpdate: function (event) {
  96. var url = vm.goodsSpecification.id == null ? "../goodsspecification/save" : "../goodsspecification/update";
  97. Ajax.request({
  98. type: "POST",
  99. url: url,
  100. contentType: "application/json",
  101. params: JSON.stringify(vm.goodsSpecification),
  102. successCallback: function (r) {
  103. alert('操作成功', function (index) {
  104. vm.reload();
  105. });
  106. }
  107. });
  108. },
  109. del: function (event) {
  110. var ids = getSelectedRows("#jqGrid");
  111. if (ids == null) {
  112. return;
  113. }
  114. confirm('确定要删除选中的记录?', function () {
  115. Ajax.request({
  116. type: "POST",
  117. url: "../goodsspecification/delete",
  118. contentType: "application/json",
  119. params: JSON.stringify(ids),
  120. successCallback: function (r) {
  121. alert('操作成功', function (index) {
  122. vm.reload();
  123. });
  124. }
  125. });
  126. });
  127. },
  128. getInfo: function (id) {
  129. Ajax.request({
  130. url: "../goodsspecification/info/" + id,
  131. async: true,
  132. successCallback: function (r) {
  133. vm.goodsSpecification = r.goodsSpecification;
  134. vm.getSpecification();
  135. vm.getGoodss();
  136. }
  137. });
  138. },
  139. reload: function (event) {
  140. vm.getBrands()
  141. vm.showList = true;
  142. var page = $("#jqGrid").jqGrid('getGridParam', 'page');
  143. $("#jqGrid").jqGrid('setGridParam', {
  144. postData: {'name': vm.q.name,'brandId': vm.q.brandId},
  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 + ' 太大,不能超过 2M。'
  159. });
  160. },
  161. handleSuccess: function (res, file) {
  162. this.goodsSpecification.picUrl = ''
  163. this.goodsSpecification.picUrl = file.response.url;
  164. },
  165. eyeImage: function () {
  166. var url = vm.goodsSpecification.picUrl;
  167. eyeImage(url);
  168. },
  169. handleSubmit: function (name) {
  170. handleSubmitValidate(this, name, function () {
  171. vm.saveOrUpdate()
  172. });
  173. },
  174. handleReset: function (name) {
  175. handleResetForm(this, name);
  176. }
  177. }
  178. });