product.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. $(function () {
  2. let goodsId = getQueryString("goodsId");
  3. let url = '../product/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, width: 120},
  12. {label: '商品', name: 'goodsName', index: 'goods_id', width: 380},
  13. {
  14. label: '商品规格',
  15. name: 'goodsSpecificationNameValue',
  16. index: 'goods_specification_ids',
  17. width: 160,
  18. formatter: function (value, options, row) {
  19. return value.replace(row.goodsName + " ", '');
  20. }
  21. },
  22. {label: '商品序列号', name: 'goodsSn', index: 'goods_sn', width: 180},
  23. // {label: '商品库存', name: 'goodsNumber', index: 'goods_number', width: 80},
  24. // {label: '零售价格(元)', name: 'retailPrice', index: 'retail_price', width: 80},
  25. // {label: '市场价格(元)', name: 'marketPrice', index: 'market_price', width: 80}
  26. ],
  27. viewrecords: true,
  28. height: 550,
  29. rowNum: 10,
  30. rowList: [10, 30, 50],
  31. rownumbers: true,
  32. rownumWidth: 25,
  33. autowidth: true,
  34. shrinkToFit: false,
  35. autoScroll: true, //开启水平滚动条
  36. width: 1500,
  37. multiselect: true,
  38. pager: "#jqGridPager",
  39. jsonReader: {
  40. root: "page.list",
  41. page: "page.currPage",
  42. total: "page.totalPage",
  43. records: "page.totalCount"
  44. },
  45. prmNames: {
  46. page: "page",
  47. rows: "limit",
  48. order: "order"
  49. },
  50. gridComplete: function () {
  51. $("#jqGrid").closest(".ui-jqgrid-bdiv").css({"overflow-x": "scroll"});
  52. }
  53. });
  54. });
  55. let vm = new Vue({
  56. el: '#rrapp',
  57. data: {
  58. showList: true,
  59. title: null,
  60. product: {},
  61. ruleValidate: {
  62. name: [
  63. {required: true, message: '名称不能为空', trigger: 'blur'}
  64. ]
  65. },
  66. q: {
  67. goodsName: ''
  68. },
  69. goodss: [],
  70. attribute: [],
  71. color: [], guige: [], weight: [],
  72. type: ''
  73. },
  74. methods: {
  75. query: function () {
  76. vm.reload();
  77. },
  78. add: function () {
  79. vm.showList = false;
  80. vm.title = "新增";
  81. vm.product = {};
  82. vm.getGoodss();
  83. vm.type = 'add';
  84. },
  85. update: function (event) {
  86. let id = getSelectedRow();
  87. if (id == null) {
  88. return;
  89. }
  90. vm.showList = false;
  91. vm.title = "修改";
  92. vm.type = 'update';
  93. vm.getInfo(id)
  94. },
  95. changeGoods: function (opt) {
  96. let goodsId = opt.value;
  97. $.get("../goods/info/" + goodsId, function (r) {
  98. if (vm.type == 'add') {
  99. vm.product.goodsSn = r.goods.goodsSn;
  100. vm.product.goodsNumber = r.goods.goodsNumber;
  101. vm.product.retailPrice = r.goods.retailPrice;
  102. }
  103. });
  104. },
  105. saveOrUpdate: function (event) {
  106. let url = vm.product.id == null ? "../product/save" : "../product/update";
  107. vm.product.goodsSpecificationIds = vm.color + '_' + vm.guige + '_' + vm.weight;
  108. $.ajax({
  109. type: "POST",
  110. url: url,
  111. contentType: "application/json",
  112. data: JSON.stringify(vm.product),
  113. success: function (r) {
  114. if (r.code === 0) {
  115. alert('操作成功', function (index) {
  116. vm.reload();
  117. });
  118. } else {
  119. alert(r.msg);
  120. }
  121. }
  122. });
  123. },
  124. del: function (event) {
  125. let ids = getSelectedRows();
  126. if (ids == null) {
  127. return;
  128. }
  129. confirm('确定要删除选中的记录?', function () {
  130. $.ajax({
  131. type: "POST",
  132. url: "../product/delete",
  133. contentType: "application/json",
  134. data: JSON.stringify(ids),
  135. success: function (r) {
  136. if (r.code == 0) {
  137. alert('操作成功', function (index) {
  138. $("#jqGrid").trigger("reloadGrid");
  139. });
  140. } else {
  141. alert(r.msg);
  142. }
  143. }
  144. });
  145. });
  146. },
  147. getInfo: function (id) {
  148. $.get("../product/info/" + id, function (r) {
  149. vm.product = r.product;
  150. vm.getGoodss();
  151. });
  152. },
  153. reload: function (event) {
  154. vm.showList = true;
  155. let page = $("#jqGrid").jqGrid('getGridParam', 'page');
  156. $("#jqGrid").jqGrid('setGridParam', {
  157. postData: {'goodsName': vm.q.goodsName},
  158. page: page
  159. }).trigger("reloadGrid");
  160. vm.handleReset('formValidate');
  161. },
  162. handleSubmit: function (name) {
  163. handleSubmitValidate(this, name, function () {
  164. vm.saveOrUpdate()
  165. });
  166. },
  167. handleReset: function (name) {
  168. handleResetForm(this, name);
  169. },
  170. getGoodss: function () {
  171. $.get("../goods/queryAll/", function (r) {
  172. vm.goodss = r.list;
  173. });
  174. }
  175. }
  176. });