product.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. $(function () {
  2. let goodsId = getQueryString("goodsId");
  3. let url = '../product/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: 120},
  13. {label: '店铺名称', name: 'brandName', index: 'brand_name', width: 80},
  14. {
  15. label: '商品规格',
  16. name: 'specificationValue',
  17. index: 'goods_specification_ids',
  18. width: 100,
  19. formatter: function (value, options, row) {
  20. return value.replace(row.goodsName + " ", '');
  21. }
  22. },
  23. {label: '商品序列号', name: 'goodsSn', index: 'goods_sn', width: 80},
  24. {label: '商品库存', name: 'goodsNumber', index: 'goods_number', width: 80},
  25. {label: '零售价格(元)', name: 'retailPrice', index: 'retail_price', width: 80},
  26. {label: '市场价格(元)', name: 'marketPrice', index: 'market_price', width: 80}]
  27. });
  28. });
  29. let vm = new Vue({
  30. el: '#rrapp',
  31. data:function() {
  32. const validateGoodsIdCheck = function (rule, value, callback) {
  33. if (value === '' || !value) {
  34. callback(new Error('商品不能为空'));
  35. }else {
  36. callback();
  37. }
  38. };
  39. return {
  40. showList: true,
  41. onlyOne:!!getQueryString("goodsId"),
  42. title: null,
  43. product: {
  44. goodsId:'',
  45. goodsName: '',
  46. brandName: '',
  47. specificationValue: '',
  48. goodsSn: null,
  49. goodsNumber: '',
  50. retailPrice: '',
  51. marketPrice: '',
  52. },
  53. ruleValidate: {
  54. goodsId: [
  55. { required: true, validator: validateGoodsIdCheck, trigger: 'change' }
  56. ],
  57. goodsSn: [
  58. {required: true, message: '序列号不能为空', trigger: 'blur'}
  59. ]
  60. },
  61. q: {
  62. goodsName: ''
  63. },
  64. goodss: [],
  65. attribute: [],
  66. color: [], guige: [], weight: [],
  67. colors: [],
  68. guiges: [],
  69. weights: [],
  70. type: ''
  71. }
  72. },
  73. methods: {
  74. query: function () {
  75. vm.reload();
  76. },
  77. add: function () {
  78. vm.showList = false;
  79. vm.title = "新增";
  80. vm.product = {};
  81. vm.getGoodss();
  82. vm.type = 'add';
  83. },
  84. update: function (event) {
  85. let id = getSelectedRow("#jqGrid");
  86. if (id == null) {
  87. return;
  88. }
  89. vm.showList = false;
  90. vm.title = "修改";
  91. vm.type = 'update';
  92. vm.getInfo(id)
  93. },
  94. changeGoods: function (opt) {
  95. let goodsId = opt.value;
  96. if(!goodsId)return;
  97. Ajax.request({
  98. url: "../goods/info/" + goodsId,
  99. async: true,
  100. successCallback: function (r) {
  101. if (vm.type == 'add') {
  102. var temp = {
  103. goodsSn:r.goods.goodsSn,
  104. goodsNumber:r.goods.goodsNumber,
  105. retailPrice:r.goods.retailPrice,
  106. marketPrice:r.goods.marketPrice
  107. }
  108. vm.product= Object.assign({},vm.product,temp)
  109. }
  110. Ajax.request({
  111. url: "../goodsspecification/queryAll?goodsId=" + goodsId + "&specificationId=1",
  112. async: true,
  113. successCallback: function (r) {
  114. vm.colors = r.list;
  115. }
  116. });
  117. Ajax.request({
  118. url: "../goodsspecification/queryAll?goodsId=" + goodsId + "&specificationId=2",
  119. async: true,
  120. successCallback: function (r) {
  121. vm.guiges = r.list;
  122. }
  123. });
  124. Ajax.request({
  125. url: "../goodsspecification/queryAll?goodsId=" + goodsId + "&specificationId=4",
  126. async: true,
  127. successCallback: function (r) {
  128. vm.weights = r.list;
  129. }
  130. });
  131. }
  132. });
  133. },
  134. saveOrUpdate: function (event) {
  135. let url = vm.product.id == null ? "../product/save" : "../product/update";
  136. if(vm.attribute.indexOf(1) == -1)vm.color = [];
  137. if(vm.attribute.indexOf(2) == -1)vm.guige = [];
  138. if(vm.attribute.indexOf(4) == -1)vm.weight = [];
  139. vm.product.goodsSpecificationIds = vm.color + '_' + vm.guige + '_' + vm.weight;
  140. Ajax.request({
  141. type: "POST",
  142. url: url,
  143. contentType: "application/json",
  144. params: JSON.stringify(vm.product),
  145. successCallback: function (r) {
  146. alert('操作成功', function (index) {
  147. vm.reload();
  148. });
  149. }
  150. });
  151. },
  152. del: function (event) {
  153. let ids = getSelectedRows("#jqGrid");
  154. if (ids == null) {
  155. return;
  156. }
  157. confirm('确定要删除选中的记录?', function () {
  158. Ajax.request({
  159. type: "POST",
  160. url: "../product/delete",
  161. contentType: "application/json",
  162. params: JSON.stringify(ids),
  163. successCallback: function (r) {
  164. alert('操作成功', function (index) {
  165. vm.reload();
  166. });
  167. }
  168. });
  169. });
  170. },
  171. getInfo: function (id) {
  172. vm.attribute = [];
  173. Ajax.request({
  174. url: "../product/info/" + id,
  175. async: true,
  176. successCallback: function (r) {
  177. vm.product = r.product;
  178. let goodsSpecificationIds = vm.product.goodsSpecificationIds.split("_");
  179. goodsSpecificationIds.forEach(function (goodsSpecificationId, index) {
  180. let specificationIds = goodsSpecificationId.split(",").filter(function (id){return !!id}).map(function (id) {return Number(id) });
  181. if (index == 0) {
  182. vm.color = specificationIds;
  183. if (specificationIds.length > 0) {
  184. vm.attribute.push(1);
  185. }
  186. } else if (index == 1) {
  187. vm.guige = specificationIds;
  188. if (specificationIds.length > 0) {
  189. vm.attribute.push(2);
  190. }
  191. } else if (index == 2) {
  192. vm.weight = specificationIds;
  193. if (specificationIds.length > 0) {
  194. vm.attribute.push(4);
  195. }
  196. }
  197. });
  198. vm.getGoodss();
  199. }
  200. });
  201. },
  202. reload: function (event) {
  203. vm.showList = true;
  204. let page = $("#jqGrid").jqGrid('getGridParam', 'page');
  205. $("#jqGrid").jqGrid('setGridParam', {
  206. postData: {'goodsName': vm.q.goodsName},
  207. page: page
  208. }).trigger("reloadGrid");
  209. vm.handleReset('formValidate');
  210. },
  211. handleSubmit: function (name) {
  212. handleSubmitValidate(this, name, function () {
  213. vm.saveOrUpdate()
  214. });
  215. },
  216. handleReset: function (name) {
  217. handleResetForm(this, name);
  218. },
  219. getGoodss: function () {
  220. Ajax.request({
  221. url: "../goods/queryAll/",
  222. async: true,
  223. successCallback: function (r) {
  224. vm.goodss = r.list;
  225. }
  226. });
  227. }
  228. }
  229. });