123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247 |
- $(function () {
- $("#jqGrid").Grid({
- url: '../coupon/list',
- rownumWidth:60,
- colModel: [
- {label: 'id', name: 'id', index: 'id', key: true, hidden: true},
- {label: '优惠券名称', name: 'name', index: 'name', width: 120},
- {label: '金额', name: 'typeMoney', index: 'type_money', width: 80},
- {
- label: '发放方式', name: 'sendType', index: 'send_type', width: 80, formatter: function (value) {
- if (value == 0) {
- return '按订单发放';
- } else if (value == 1) {
- return '按用户发放';
- } else if (value == 2) {
- return '商品转发送券';
- } else if (value == 3) {
- return '按商品发放';
- } else if (value == 4) {
- return '新用户注册';
- } else if (value == 5) {
- return '线下发放';
- } else if (value == 7) {
- return '包邮优惠';
- }
- return '-';
- }
- },
- {label: '最小金额', name: 'minAmount', index: 'min_amount', width: 80},
- {label: '最大金额', name: 'maxAmount', index: 'max_amount', width: 80},
- {
- label: '发放开始时间',
- name: 'sendStartDate',
- index: 'send_start_date',
- width: 120,
- formatter: function (value) {
- return transDate(value);
- }
- },
- {
- label: '发放结束时间', name: 'sendEndDate', index: 'send_end_date', width: 120, formatter: function (value) {
- return transDate(value);
- }
- },
- {
- label: '使用开始时间',
- name: 'useStartDate',
- index: 'use_start_date',
- width: 120,
- formatter: function (value) {
- return transDate(value);
- }
- },
- {
- label: '使用结束时间', name: 'useEndDate', index: 'use_end_date', width: 120, formatter: function (value) {
- return transDate(value);
- }
- },
- {label: '最小商品金额', name: 'minGoodsAmount', index: 'min_goods_amount', width: 80},
- {
- label: '操作', width: 70, sortable: false, formatter: function (value, col, row) {
- if (row.sendType == 1 || row.sendType == 3) {
- 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>';
- }
- return '';
- }
- }]
- });
- });
- var vm = new Vue({
- el: '#rrapp',
- data: {
- showList: true,
- showCard: false,
- showGoods: false,
- title: null,
- coupon: {sendType: 0},
- ruleValidate: {
- name: [
- {required: true, message: '优惠券名称不能为空', trigger: 'blur'}
- ]
- },
- q: {
- name: ''
- },
- goods: [],
- goodss: [],
- user: [],
- users: [],
- selectData: {},
- sendSms: ''//是否发送短信
- },
- methods: {
- query: function () {
- vm.reload();
- },
- add: function () {
- vm.showList = false;
- vm.showCard = true;
- vm.showGoods = false;
- vm.title = "新增";
- vm.coupon = {sendType: 0};
- },
- update: function (event) {
- var id = getSelectedRow("#jqGrid");
- if (id == null) {
- return;
- }
- vm.showList = false;
- vm.showCard = true;
- vm.showGoods = false;
- vm.title = "修改";
- vm.getInfo(id)
- },
- saveOrUpdate: function (event) {
- var url = vm.coupon.id == null ? "../coupon/save" : "../coupon/update";
- Ajax.request({
- type: "POST",
- url: url,
- contentType: "application/json",
- params: JSON.stringify(vm.coupon),
- successCallback: function (r) {
- alert('操作成功', function (index) {
- vm.reload();
- });
- }
- });
- },
- del: function (event) {
- var ids = getSelectedRows("#jqGrid");
- if (ids == null) {
- return;
- }
- confirm('确定要删除选中的记录?', function () {
- Ajax.request({
- type: "POST",
- url: "../coupon/delete",
- contentType: "application/json",
- params: JSON.stringify(ids),
- successCallback: function (r) {
- alert('操作成功', function (index) {
- vm.reload();
- });
- }
- });
- });
- },
- getInfo: function (id) {
- Ajax.request({
- url: "../coupon/info/" + id,
- async: true,
- successCallback: function (r) {
- vm.coupon = r.coupon;
- }
- });
- },
- reload: function (event) {
- vm.showList = true;
- vm.showCard = false;
- vm.showGoods = false;
- var page = $("#jqGrid").jqGrid('getGridParam', 'page');
- $("#jqGrid").jqGrid('setGridParam', {
- postData: {'name': vm.q.name},
- page: page
- }).trigger("reloadGrid");
- vm.handleReset('formValidate');
- },
- handleSubmit: function (name) {
- handleSubmitValidate(this, name, function () {
- vm.saveOrUpdate()
- });
- },
- handleReset: function (name) {
- handleResetForm(this, name);
- },
- publish: function (id, sendType) {
- vm.showGoods = true;
- vm.goods = [];
- vm.user = [];
- vm.getGoodss();
- vm.getUsers();
- vm.selectData = {id: id, sendType: sendType};
- vm.sendSms = false;
- openWindow({
- title: "发放",
- area: ['600px', '350px'],
- content: jQuery("#sendDiv")
- })
- },
- getUsers: function () {
- Ajax.request({
- url: "../user/queryAll",
- async: true,
- successCallback: function (r) {
- vm.users = r.list;
- }
- });
- },
- publishSubmit: function () {
- var sendType = vm.selectData.sendType;
- if (sendType == 1 && vm.user.length == 0) {
- vm.$Message.error('请选择下发会员');
- return;
- }
- if (sendType == 3 && vm.goods.length == 0) {
- vm.$Message.error('请选择下发商品');
- return;
- }
- confirm('确定下发优惠券?', function () {
- Ajax.request({
- type: "POST",
- dataType: 'json',
- url: "../coupon/publish",
- contentType: "application/json",
- params: JSON.stringify({
- sendType: vm.selectData.sendType,
- couponId: vm.selectData.id,
- goodsIds: vm.goods.toString(),
- userIds: vm.user.toString(),
- sendSms: vm.sendSms
- }),
- successCallback: function (r) {
- alert('操作成功', function (index) {
- vm.reload();
- vm.showGoods = false;
- vm.showList = true;
- });
- }
- });
- });
- },
- getGoodss: function () {
- Ajax.request({
- url: "../goods/queryAll/",
- async: true,
- successCallback: function (r) {
- vm.goodss = r.list;
- }
- });
- }
- }
- });
|