coupondetail.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. let cacheData = {
  2. }
  3. var brandName = getQueryString("brandName");
  4. var couponname = getQueryString("name");
  5. $(function () {
  6. let couponId = getQueryString("couponId");
  7. let url = '../coupon/useDetailList';
  8. if (couponId) {
  9. url += '?couponId=' + couponId;
  10. }
  11. $("#jqGrid").Grid({
  12. url: url,
  13. rownumWidth:60,
  14. loadComplete:function()
  15. {
  16. var rowNum = $("#jqGrid").find('.jqgrow').length;
  17. if(!rowNum)
  18. {
  19. if(!$("#emptyRecords").html())
  20. {
  21. $("#jqGrid").append('<div id="emptyRecords" style="width:100%; height:200px; text-align:center;">'
  22. +'<div style="width:220px; height:100px; padding-top:40px; clear:both; margin:0 auto ;position: absolute;top: 190px;left: 50%;transform: translateX(-50%);">'
  23. +'<div>暂无人领取优惠券</div>'
  24. +'</div></div>');
  25. console.log('wwwww',$("#gridTable").parent());
  26. }
  27. $("#emptyRecords").show();
  28. }
  29. else
  30. {
  31. $("#emptyRecords").hide();
  32. }
  33. },
  34. colModel: [
  35. {label: 'idx', name: 'idx', index: 'id', key: true, hidden: true},
  36. {label: '优惠券编码', name: 'couponSn', index: 'coupon_sn', width: 80},
  37. {
  38. label: '发放类型', name: 'sendType', index: 'send_type', width: 80, formatter: function (value) {
  39. if (value == 0) {
  40. return '全场赠券';
  41. } else if (value == 1) {
  42. return '会员赠券';
  43. } else if (value == 2) {
  44. return '购物赠券';
  45. } else if (value == 3) {
  46. return '注册赠券';
  47. }
  48. return '-';
  49. }
  50. },
  51. {label: '订单号', name: 'orderSn', index: 'order_sn', width: 80},
  52. {label: '会员编码', name: 'userId', index: 'user_id', width: 80},
  53. {label: '会员名称', name: 'userName', index: 'user_name', width: 80},
  54. {label: '使用状态', name: 'useStatus', index: 'use_status', width: 80,
  55. formatter: function (value) {
  56. if (value == 1) {
  57. return '已领取';
  58. } else if (value == 2) {
  59. return '已使用';
  60. } else if (value == 3) {
  61. return '已过期';
  62. } else if (value == 4) {
  63. return '已作废';
  64. }
  65. return '-';
  66. }},
  67. {label: '状态变更时间', name: 'updateTime', index: 'update_time', width: 80},
  68. {
  69. label: '操作', width: 100, align:'center', sortable: false, formatter: function (value, col, row) {
  70. cacheData[col.rowId] = row
  71. if (row.useStatus == 1) {
  72. return '<button class="btn btn-outline btn-warning" onclick="vm.void(' + col.rowId + ');event.cancelBubble=true;"><i></i>&nbsp;作废</button>'
  73. }
  74. return '';
  75. }
  76. }]
  77. });
  78. });
  79. var vm = new Vue({
  80. el: '#rrapp',
  81. data: {
  82. showList: true,
  83. title: null,
  84. userCoupon: {},
  85. q: {
  86. userName: '',
  87. couponName: ''
  88. },
  89. brandName:brandName,
  90. name:couponname
  91. },
  92. methods: {
  93. query: function () {
  94. vm.reload();
  95. },
  96. add: function () {
  97. vm.showList = false;
  98. vm.title = "新增";
  99. vm.userCoupon = {};
  100. },
  101. update: function (event) {
  102. var id = getSelectedRow("#jqGrid");
  103. if (id == null) {
  104. return;
  105. }
  106. vm.showList = false;
  107. vm.title = "修改";
  108. vm.getInfo(id)
  109. },
  110. saveOrUpdate: function (event) {
  111. var url = vm.userCoupon.id == null ? "../usercoupon/save" : "../usercoupon/update";
  112. Ajax.request({
  113. type: "POST",
  114. url: url,
  115. contentType: "application/json",
  116. params: JSON.stringify(vm.userCoupon),
  117. successCallback: function (r) {
  118. alert('操作成功', function (index) {
  119. vm.reload();
  120. });
  121. }
  122. });
  123. },
  124. void: function (rowId) {
  125. let row = cacheData[rowId]
  126. let msg = '作废后,优惠券将无法使用,是否继续?'
  127. confirm(msg, function () {
  128. Ajax.request({
  129. url: '../usercoupon/cancelUserCoupon?userId='+row.userId+'&couponId='+row.id,
  130. contentType: "application/json",
  131. successCallback: function (r) {
  132. alert('操作成功', function (index) {
  133. vm.reload();
  134. });
  135. }
  136. });
  137. })
  138. },
  139. del: function (event) {
  140. var ids = getSelectedRows("#jqGrid");
  141. if (ids == null) {
  142. return;
  143. }
  144. confirm('确定要删除选中的记录?', function () {
  145. Ajax.request({
  146. type: "POST",
  147. url: "../usercoupon/delete",
  148. contentType: "application/json",
  149. params: JSON.stringify(ids),
  150. successCallback: function (r) {
  151. alert('操作成功', function (index) {
  152. vm.reload();
  153. });
  154. }
  155. });
  156. });
  157. },
  158. getInfo: function (id) {
  159. Ajax.request({
  160. url: "../usercoupon/info/" + id,
  161. async: true,
  162. successCallback: function (r) {
  163. vm.userCoupon = r.userCoupon;
  164. }
  165. });
  166. },
  167. reload: function (event) {
  168. vm.showList = true;
  169. var page = $("#jqGrid").jqGrid('getGridParam', 'page');
  170. $("#jqGrid").jqGrid('setGridParam', {
  171. postData: {'userName': vm.q.userName, 'couponName': vm.q.couponName},
  172. page: page
  173. }).trigger("reloadGrid");
  174. }
  175. }
  176. });