coupon.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. $(function () {
  2. $("#jqGrid").Grid({
  3. url: '../coupon/list',
  4. rownumWidth:60,
  5. colModel: [
  6. {label: 'id', name: 'id', index: 'id', key: true, hidden: true},
  7. {label: '优惠券名称', name: 'name', index: 'name', width: 120},
  8. {label: '金额', name: 'typeMoney', index: 'type_money', width: 80},
  9. {
  10. label: '发放方式', name: 'sendType', index: 'send_type', width: 80, formatter: function (value) {
  11. if (value == 0) {
  12. return '按订单发放';
  13. } else if (value == 1) {
  14. return '按用户发放';
  15. } else if (value == 2) {
  16. return '商品转发送券';
  17. } else if (value == 3) {
  18. return '按商品发放';
  19. } else if (value == 4) {
  20. return '新用户注册';
  21. } else if (value == 5) {
  22. return '线下发放';
  23. } else if (value == 7) {
  24. return '包邮优惠';
  25. }
  26. return '-';
  27. }
  28. },
  29. {label: '最小金额', name: 'minAmount', index: 'min_amount', width: 80},
  30. {label: '最大金额', name: 'maxAmount', index: 'max_amount', width: 80},
  31. {
  32. label: '发放开始时间',
  33. name: 'sendStartDate',
  34. index: 'send_start_date',
  35. width: 120,
  36. formatter: function (value) {
  37. return transDate(value);
  38. }
  39. },
  40. {
  41. label: '发放结束时间', name: 'sendEndDate', index: 'send_end_date', width: 120, formatter: function (value) {
  42. return transDate(value);
  43. }
  44. },
  45. {
  46. label: '使用开始时间',
  47. name: 'useStartDate',
  48. index: 'use_start_date',
  49. width: 120,
  50. formatter: function (value) {
  51. return transDate(value);
  52. }
  53. },
  54. {
  55. label: '使用结束时间', name: 'useEndDate', index: 'use_end_date', width: 120, formatter: function (value) {
  56. return transDate(value);
  57. }
  58. },
  59. {label: '最小商品金额', name: 'minGoodsAmount', index: 'min_goods_amount', width: 80},
  60. {
  61. label: '操作', width: 70, sortable: false, formatter: function (value, col, row) {
  62. if (row.sendType == 1 || row.sendType == 3) {
  63. return '<button class="ivu-btn ivu-btn-primary ivu-btn-circle ivu-btn-small" onclick="vm.publish(' + row.id + ',' + row.sendType + ')"><i class="ivu-icon ivu-icon-android-send"></i>发放</button>';
  64. }
  65. return '';
  66. }
  67. }]
  68. });
  69. });
  70. var vm = new Vue({
  71. el: '#rrapp',
  72. data: {
  73. showList: true,
  74. showCard: false,
  75. showGoods: false,
  76. title: null,
  77. coupon: {sendType: 0},
  78. ruleValidate: {
  79. name: [
  80. {required: true, message: '优惠券名称不能为空', trigger: 'blur'}
  81. ]
  82. },
  83. q: {
  84. name: ''
  85. },
  86. goods: [],
  87. goodss: [],
  88. user: [],
  89. users: [],
  90. selectData: {},
  91. sendSms: ''//是否发送短信
  92. },
  93. methods: {
  94. query: function () {
  95. vm.reload();
  96. },
  97. add: function () {
  98. vm.showList = false;
  99. vm.showCard = true;
  100. vm.showGoods = false;
  101. vm.title = "新增";
  102. vm.coupon = {sendType: 0};
  103. },
  104. update: function (event) {
  105. var id = getSelectedRow("#jqGrid");
  106. if (id == null) {
  107. return;
  108. }
  109. vm.showList = false;
  110. vm.showCard = true;
  111. vm.showGoods = false;
  112. vm.title = "修改";
  113. vm.getInfo(id)
  114. },
  115. saveOrUpdate: function (event) {
  116. var url = vm.coupon.id == null ? "../coupon/save" : "../coupon/update";
  117. Ajax.request({
  118. type: "POST",
  119. url: url,
  120. contentType: "application/json",
  121. params: JSON.stringify(vm.coupon),
  122. successCallback: function (r) {
  123. alert('操作成功', function (index) {
  124. vm.reload();
  125. });
  126. }
  127. });
  128. },
  129. del: function (event) {
  130. var ids = getSelectedRows("#jqGrid");
  131. if (ids == null) {
  132. return;
  133. }
  134. confirm('确定要删除选中的记录?', function () {
  135. Ajax.request({
  136. type: "POST",
  137. url: "../coupon/delete",
  138. contentType: "application/json",
  139. params: JSON.stringify(ids),
  140. successCallback: function (r) {
  141. alert('操作成功', function (index) {
  142. vm.reload();
  143. });
  144. }
  145. });
  146. });
  147. },
  148. getInfo: function (id) {
  149. Ajax.request({
  150. url: "../coupon/info/" + id,
  151. async: true,
  152. successCallback: function (r) {
  153. vm.coupon = r.coupon;
  154. }
  155. });
  156. },
  157. reload: function (event) {
  158. vm.showList = true;
  159. vm.showCard = false;
  160. vm.showGoods = false;
  161. var page = $("#jqGrid").jqGrid('getGridParam', 'page');
  162. $("#jqGrid").jqGrid('setGridParam', {
  163. postData: {'name': vm.q.name},
  164. page: page
  165. }).trigger("reloadGrid");
  166. vm.handleReset('formValidate');
  167. },
  168. handleSubmit: function (name) {
  169. handleSubmitValidate(this, name, function () {
  170. vm.saveOrUpdate()
  171. });
  172. },
  173. handleReset: function (name) {
  174. handleResetForm(this, name);
  175. },
  176. publish: function (id, sendType) {
  177. vm.showGoods = true;
  178. vm.goods = [];
  179. vm.user = [];
  180. vm.getGoodss();
  181. vm.getUsers();
  182. vm.selectData = {id: id, sendType: sendType};
  183. vm.sendSms = false;
  184. openWindow({
  185. title: "发放",
  186. area: ['600px', '350px'],
  187. content: jQuery("#sendDiv")
  188. })
  189. },
  190. getUsers: function () {
  191. Ajax.request({
  192. url: "../user/queryAll",
  193. async: true,
  194. successCallback: function (r) {
  195. vm.users = r.list;
  196. }
  197. });
  198. },
  199. publishSubmit: function () {
  200. var sendType = vm.selectData.sendType;
  201. if (sendType == 1 && vm.user.length == 0) {
  202. vm.$Message.error('请选择下发会员');
  203. return;
  204. }
  205. if (sendType == 3 && vm.goods.length == 0) {
  206. vm.$Message.error('请选择下发商品');
  207. return;
  208. }
  209. confirm('确定下发优惠券?', function () {
  210. Ajax.request({
  211. type: "POST",
  212. dataType: 'json',
  213. url: "../coupon/publish",
  214. contentType: "application/json",
  215. params: JSON.stringify({
  216. sendType: vm.selectData.sendType,
  217. couponId: vm.selectData.id,
  218. goodsIds: vm.goods.toString(),
  219. userIds: vm.user.toString(),
  220. sendSms: vm.sendSms
  221. }),
  222. successCallback: function (r) {
  223. alert('操作成功', function (index) {
  224. vm.reload();
  225. vm.showGoods = false;
  226. vm.showList = true;
  227. });
  228. }
  229. });
  230. });
  231. },
  232. getGoodss: function () {
  233. Ajax.request({
  234. url: "../goods/queryAll/",
  235. async: true,
  236. successCallback: function (r) {
  237. vm.goodss = r.list;
  238. }
  239. });
  240. }
  241. }
  242. });