cart.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. $(function () {
  2. let userId = getQueryString("userId");
  3. let url = '../cart/list';
  4. if (userId) {
  5. url += '?userId=' + userId;
  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: 'userName', index: 'user_name', width: 20},
  13. // {label: 'sessionId', name: 'sessionId', index: 'session_id', width: 80 },
  14. {label: '商品', name: 'goodsName', index: 'goods_name', width: 100},
  15. {label: '商品序列号', name: 'goodsSn', index: 'goods_sn', width: 30},
  16. // {label: '产品Id', name: 'productId', index: 'product_id', width: 80 },
  17. {label: '规格名称', name: 'goodsName', index: 'goods_name', width: 80},
  18. {label: '市场价', name: 'marketPrice', index: 'market_price', width: 20},
  19. {label: '零售价格', name: 'retailPrice', index: 'retail_price', width: 30},
  20. {label: '数量', name: 'number', index: 'number', width: 20},
  21. {label: '规格属性', name: 'goodsSpecificationNameValue', index: 'goods_specification_name_value', width: 100}
  22. // {label: 'product表对应的goods_specifition_ids', name: 'goodsSpecificationIds', index: 'goods_specification_ids', width: 80 },
  23. // {label: '', name: 'checked', index: 'checked', width: 80 },
  24. // {label: '商品图片', name: 'listPicUrl', index: 'list_pic_url', width: 80 }
  25. ],
  26. viewrecords: true,
  27. height: 385,
  28. rowNum: 10,
  29. rowList: [10, 30, 50],
  30. rownumbers: true,
  31. rownumWidth: 25,
  32. autowidth: true,
  33. multiselect: true,
  34. pager: "#jqGridPager",
  35. jsonReader: {
  36. root: "page.list",
  37. page: "page.currPage",
  38. total: "page.totalPage",
  39. records: "page.totalCount"
  40. },
  41. prmNames: {
  42. page: "page",
  43. rows: "limit",
  44. order: "order"
  45. },
  46. gridComplete: function () {
  47. $("#jqGrid").closest(".ui-jqgrid-bdiv").css({"overflow-x": "hidden"});
  48. }
  49. });
  50. });
  51. var vm = new Vue({
  52. el: '#rrapp',
  53. data: {
  54. showList: true,
  55. title: null,
  56. cart: {},
  57. q: {
  58. name: ''
  59. }
  60. },
  61. methods: {
  62. query: function () {
  63. vm.reload();
  64. },
  65. add: function () {
  66. vm.showList = false;
  67. vm.title = "新增";
  68. vm.cart = {};
  69. },
  70. update: function (event) {
  71. var id = getSelectedRow();
  72. if (id == null) {
  73. return;
  74. }
  75. vm.showList = false;
  76. vm.title = "修改";
  77. vm.getInfo(id)
  78. },
  79. saveOrUpdate: function (event) {
  80. var url = vm.cart.id == null ? "../cart/save" : "../cart/update";
  81. $.ajax({
  82. type: "POST",
  83. url: url,
  84. contentType: "application/json",
  85. data: JSON.stringify(vm.cart),
  86. success: function (r) {
  87. if (r.code === 0) {
  88. alert('操作成功', function (index) {
  89. vm.reload();
  90. });
  91. } else {
  92. alert(r.msg);
  93. }
  94. }
  95. });
  96. },
  97. del: function (event) {
  98. var ids = getSelectedRows();
  99. if (ids == null) {
  100. return;
  101. }
  102. confirm('确定要删除选中的记录?', function () {
  103. $.ajax({
  104. type: "POST",
  105. url: "../cart/delete",
  106. contentType: "application/json",
  107. data: JSON.stringify(ids),
  108. success: function (r) {
  109. if (r.code == 0) {
  110. alert('操作成功', function (index) {
  111. $("#jqGrid").trigger("reloadGrid");
  112. });
  113. } else {
  114. alert(r.msg);
  115. }
  116. }
  117. });
  118. });
  119. },
  120. getInfo: function (id) {
  121. $.get("../cart/info/" + id, function (r) {
  122. vm.cart = r.cart;
  123. });
  124. },
  125. reload: function (event) {
  126. vm.showList = true;
  127. var page = $("#jqGrid").jqGrid('getGridParam', 'page');
  128. $("#jqGrid").jqGrid('setGridParam', {
  129. postData: {'name': vm.q.name},
  130. page: page
  131. }).trigger("reloadGrid");
  132. }
  133. }
  134. });