cart.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. $(function () {
  2. let userId = getQueryString("userId");
  3. let url = '../cart/list';
  4. if (userId) {
  5. url += '?userId=' + userId;
  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: 'userName', index: 'user_name', width: 80},
  13. {label: '会员昵称', name: 'nickName', index: 'nick_name', width: 80},
  14. // {label: 'sessionId', name: 'sessionId', index: 'session_id', width: 80 },
  15. {label: '商品', name: 'goodsName', index: 'goods_name', width: 100},
  16. {label: '商品序列号', name: 'goodsSn', index: 'goods_sn', width: 30},
  17. // {label: '产品Id', name: 'productId', index: 'product_id', width: 80 },
  18. {label: '产品名称', name: 'goodsName', index: 'goods_name', width: 80},
  19. {label: '市场价', name: 'marketPrice', index: 'market_price', width: 30},
  20. {label: '零售价格', name: 'retailPrice', index: 'retail_price', width: 30},
  21. {label: '数量', name: 'number', index: 'number', width: 20},
  22. {label: '规格属性', name: 'goodsSpecifitionNameValue', index: 'goods_specifition_name_value', width: 100}
  23. // {label: 'product表对应的goods_specifition_ids', name: 'goodsSpecifitionIds', index: 'goods_specifition_ids', width: 80 },
  24. // {label: '', name: 'checked', index: 'checked', width: 80 },
  25. // {label: '商品图片', name: 'listPicUrl', index: 'list_pic_url', width: 80 }
  26. ]
  27. });
  28. });
  29. var vm = new Vue({
  30. el: '#rrapp',
  31. data: {
  32. showList: true,
  33. title: null,
  34. cart: {},
  35. q: {
  36. name: ''
  37. }
  38. },
  39. methods: {
  40. query: function () {
  41. vm.reload();
  42. },
  43. add: function () {
  44. vm.showList = false;
  45. vm.title = "新增";
  46. vm.cart = {};
  47. },
  48. update: function (event) {
  49. var id = getSelectedRow("#jqGrid");
  50. if (id == null) {
  51. return;
  52. }
  53. vm.showList = false;
  54. vm.title = "修改";
  55. vm.getInfo(id)
  56. },
  57. saveOrUpdate: function (event) {
  58. var url = vm.cart.id == null ? "../cart/save" : "../cart/update";
  59. Ajax.request({
  60. type: "POST",
  61. url: url,
  62. contentType: "application/json",
  63. params: JSON.stringify(vm.cart),
  64. successCallback: function (r) {
  65. alert('操作成功', function (index) {
  66. vm.reload();
  67. });
  68. }
  69. });
  70. },
  71. del: function (event) {
  72. var ids = getSelectedRows("#jqGrid");
  73. if (ids == null) {
  74. return;
  75. }
  76. confirm('确定要删除选中的记录?', function () {
  77. Ajax.request({
  78. type: "POST",
  79. url: "../cart/delete",
  80. contentType: "application/json",
  81. params: JSON.stringify(ids),
  82. successCallback: function (r) {
  83. alert('操作成功', function (index) {
  84. vm.reload();
  85. });
  86. }
  87. });
  88. });
  89. },
  90. getInfo: function (id) {
  91. Ajax.request({
  92. url: "../cart/info/" + id,
  93. async: true,
  94. successCallback: function (r) {
  95. vm.cart = r.cart;
  96. }
  97. });
  98. },
  99. reload: function (event) {
  100. vm.showList = true;
  101. var page = $("#jqGrid").jqGrid('getGridParam', 'page');
  102. $("#jqGrid").jqGrid('setGridParam', {
  103. postData: {'name': vm.q.name},
  104. page: page
  105. }).trigger("reloadGrid");
  106. }
  107. }
  108. });