coupongrads.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. $(function () {
  2. let sendType = getQueryString("sendType");
  3. let menuName = getQueryString("menuName");
  4. let url = '../coupon/list';
  5. if (sendType) {
  6. url += '?sendType=' + sendType;
  7. vm.sendType = sendType;
  8. vm.menuName = menuName;
  9. }
  10. $("#jqGrid").Grid({
  11. url: url,
  12. colModel: [
  13. {label: 'id', name: 'id', index: 'id', key: true, hidden: true},
  14. {label: '优惠券名称', name: 'name', index: 'name', width: 120},
  15. /*{
  16. label: '优惠券类型', name: 'couponType', index: 'couponType', width: 80,
  17. formatter: function (value) {
  18. if (value == 0) {
  19. return '通用优惠券';
  20. } else if (value == 1) {
  21. return '门店优惠券';
  22. } else if (value == 2) {
  23. return '产品优惠券';
  24. }
  25. return '-';
  26. }
  27. },*/
  28. /*{
  29. label: '状态', name: 'status', index: 'status', width: 50,
  30. formatter: function (value) {
  31. if (value == 0) {
  32. return '失效';
  33. } else if (value == 1) {
  34. return '正常';
  35. }
  36. return '-';
  37. }
  38. },*/
  39. {label: '订单最小金额', name: 'minAmount', index: 'minAmount', width: 80},
  40. {label: '订单最大金额', name: 'maxAmount', index: 'maxAmount', width: 80},
  41. {label: '金额', name: 'typeMoney', index: 'type_money', width: 80},
  42. // {label: '最小商品金额', name: 'minGoodsAmount', index: 'min_goods_amount', width: 80},
  43. {label: '有效天数', name: 'invalidDays', index: 'invalidDays', width: 80},
  44. /*{
  45. label: '操作', width: 70, align: 'center', sortable: false,
  46. formatter: function (value, col, row) {
  47. if (row.couponType == 1) {
  48. return '<button class="btn btn-outline btn-info ivu-btn-small" onclick="vm.lookCouponStoreList(' + row.id + ',\'' + row.name + '\')"><i class="fa fa-info-circle"></i>&nbsp;门店列表</button>&nbsp;';
  49. } else if (row.couponType == 2) {
  50. return '<button class="btn btn-outline btn-info ivu-btn-small" onclick="vm.lookCouponProductList(' + row.id + ',\'' + row.name + '\')"><i class="fa fa-info-circle"></i>&nbsp;产品列表</button>&nbsp;';
  51. }
  52. return '';
  53. }
  54. }*/
  55. ]
  56. });
  57. });
  58. var vm = new Vue({
  59. el: '#rrapp',
  60. data: {
  61. showDiv: 1,// 1List 2edit 3publish 4store 5product
  62. title: null,
  63. menuName: null,
  64. sendType: 0,
  65. coupon: {sendType: 0, status: 1, couponType: 0, name: '', minAmount: 0, maxAmount: 0, minGoodsAmount: 0},
  66. ruleValidate: {
  67. name: [
  68. {required: true, message: '优惠券名称不能为空', trigger: 'blur'},
  69. ],
  70. },
  71. q: {
  72. name: ''
  73. },
  74. },
  75. methods: {
  76. query: function () {
  77. vm.reload();
  78. },
  79. add: function () {
  80. vm.showDiv = 2;
  81. vm.title = "新增";
  82. vm.coupon = {
  83. sendType: vm.sendType,
  84. status: 1,
  85. couponType: 0,
  86. name: '',
  87. minAmount: 0,
  88. maxAmount: 0,
  89. minGoodsAmount: 0
  90. };
  91. },
  92. update: function (event) {
  93. var id = getSelectedRow();
  94. if (id == null) {
  95. return;
  96. }
  97. vm.showDiv = 2;
  98. vm.title = "修改";
  99. vm.getInfo(id)
  100. },
  101. saveOrUpdate: function (event) {
  102. var url = vm.coupon.id == null ? "../coupon/save" : "../coupon/update";
  103. Ajax.request({
  104. url: url,
  105. params: JSON.stringify(vm.coupon),
  106. contentType: "application/json",
  107. type: 'POST',
  108. successCallback: function () {
  109. alert('操作成功', function (index) {
  110. vm.reload();
  111. });
  112. }
  113. });
  114. },
  115. del: function (event) {
  116. var ids = getSelectedRows();
  117. if (ids == null) {
  118. return;
  119. }
  120. confirm('确定要删除选中的记录?', function () {
  121. Ajax.request({
  122. url: "../coupon/delete",
  123. params: JSON.stringify(ids),
  124. contentType: "application/json",
  125. type: 'POST',
  126. successCallback: function () {
  127. alert('操作成功', function (index) {
  128. vm.reload();
  129. });
  130. }
  131. });
  132. });
  133. },
  134. getInfo: function (id) {
  135. Ajax.request({
  136. url: "../coupon/info/" + id,
  137. async: true,
  138. successCallback: function (r) {
  139. vm.coupon = r.coupon;
  140. }
  141. });
  142. },
  143. reload: function (event) {
  144. vm.showDiv = 1;
  145. var page = $("#jqGrid").jqGrid('getGridParam', 'page');
  146. $("#jqGrid").jqGrid('setGridParam', {
  147. postData: {'name': vm.q.name},
  148. page: page
  149. }).trigger("reloadGrid");
  150. vm.handleReset('formValidate');
  151. },
  152. handleSubmit: function (name) {
  153. handleSubmitValidate(this, name, function () {
  154. vm.saveOrUpdate()
  155. });
  156. },
  157. handleReset: function (name) {
  158. handleResetForm(this, name);
  159. },
  160. }
  161. });