1
0

usercoupon.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. $(function () {
  2. let userId = getQueryString("userId");
  3. let url = '../usercoupon/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_id', width: 80},
  13. {label: '优惠券', name: 'couponName', index: 'coupon_id', width: 80},
  14. {label: '优惠券序号', name: 'couponNumber', index: 'coupon_number', width: 80},
  15. {
  16. label: '下发时间', name: 'addTime', index: 'add_time', width: 80, formatter: function (value) {
  17. return transDate(value);
  18. }
  19. },
  20. {
  21. label: '使用时间', name: 'usedTime', index: 'used_time', width: 80, formatter: function (value) {
  22. return transDate(value);
  23. }
  24. },
  25. {label: '订单Id', name: 'orderId', index: 'order_id', width: 80}],
  26. viewrecords: true,
  27. height: 550,
  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. userCoupon: {},
  57. q: {
  58. userName: '',
  59. couponName: ''
  60. }
  61. },
  62. methods: {
  63. query: function () {
  64. vm.reload();
  65. },
  66. add: function () {
  67. vm.showList = false;
  68. vm.title = "新增";
  69. vm.userCoupon = {};
  70. },
  71. update: function (event) {
  72. var id = getSelectedRow();
  73. if (id == null) {
  74. return;
  75. }
  76. vm.showList = false;
  77. vm.title = "修改";
  78. vm.getInfo(id)
  79. },
  80. saveOrUpdate: function (event) {
  81. var url = vm.userCoupon.id == null ? "../usercoupon/save" : "../usercoupon/update";
  82. $.ajax({
  83. type: "POST",
  84. url: url,
  85. contentType: "application/json",
  86. data: JSON.stringify(vm.userCoupon),
  87. success: function (r) {
  88. if (r.code === 0) {
  89. alert('操作成功', function (index) {
  90. vm.reload();
  91. });
  92. } else {
  93. alert(r.msg);
  94. }
  95. }
  96. });
  97. },
  98. del: function (event) {
  99. var ids = getSelectedRows();
  100. if (ids == null) {
  101. return;
  102. }
  103. confirm('确定要删除选中的记录?', function () {
  104. $.ajax({
  105. type: "POST",
  106. url: "../usercoupon/delete",
  107. contentType: "application/json",
  108. data: JSON.stringify(ids),
  109. success: function (r) {
  110. if (r.code == 0) {
  111. alert('操作成功', function (index) {
  112. $("#jqGrid").trigger("reloadGrid");
  113. });
  114. } else {
  115. alert(r.msg);
  116. }
  117. }
  118. });
  119. });
  120. },
  121. getInfo: function (id) {
  122. $.get("../usercoupon/info/" + id, function (r) {
  123. vm.userCoupon = r.userCoupon;
  124. });
  125. },
  126. reload: function (event) {
  127. vm.showList = true;
  128. var page = $("#jqGrid").jqGrid('getGridParam', 'page');
  129. $("#jqGrid").jqGrid('setGridParam', {
  130. postData: {'userName': vm.q.userName, 'couponName': vm.q.couponName},
  131. page: page
  132. }).trigger("reloadGrid");
  133. }
  134. }
  135. });