/**
|
* 优惠券管理初始化
|
*/
|
var MyCoupon = {
|
id: "MyCouponTable", //表格id
|
seItem: null, //选中的条目
|
table: null,
|
layerIndex: -1
|
};
|
|
/**
|
* 初始化表格的列
|
*/
|
MyCoupon.initColumn = function () {
|
return [
|
{field: 'selectItem', checkbox: true},
|
{title: '添加时间', field: 'createTime', visible: true, align: 'center', valign: 'middle'},
|
{title: '优惠券编号', field: 'couponNo', visible: true, align: 'center', valign: 'middle'},
|
{title: '优惠券名称', field: 'name', visible: true, align: 'center', valign: 'middle'},
|
{title: '城市', field: 'cityName', visible: true, align: 'center', valign: 'middle'},
|
{title: '服务类型', field: 'serverType', visible: true, align: 'center', valign: 'middle',
|
formatter: function (value, row) {
|
if(value == 1){
|
return "普通商品";
|
}else if(value == 2){
|
return "黄金套餐";
|
}else if(value == 3){
|
return "钻石套餐";
|
}
|
return "通用";
|
}},
|
{title: '代金券', field: 'amount', visible: true, align: 'center', valign: 'middle'},
|
{title: '销售价格', field: 'price', visible: true, align: 'center', valign: 'middle'},
|
{title: '商品', field: 'goodsName', visible: true, align: 'center', valign: 'middle'},
|
{title: '有效期', field: 'beginTime', visible: true, align: 'center', valign: 'middle',
|
formatter: function (value, row) {
|
return row.beginTime + "-" + row.endTime;
|
}}
|
];
|
};
|
|
/**
|
* 检查是否选中
|
*/
|
MyCoupon.check = function () {
|
var selected = $('#' + this.id).bootstrapTable('getSelections');
|
if(selected.length == 0){
|
Feng.info("请先选中表格中的某一记录!");
|
return false;
|
}else{
|
MyCoupon.seItem = selected[0];
|
return true;
|
}
|
};
|
|
/**
|
* 点击添加优惠券
|
*/
|
MyCoupon.openMyCouponAdd = function () {
|
var index = layer.open({
|
type: 2,
|
title: '添加优惠券',
|
area: ['80%', '80%'], //宽高
|
fix: false, //不固定
|
maxmin: true,
|
content: Feng.ctxPath + '/myCoupon/myCouponPrice_add'
|
});
|
this.layerIndex = index;
|
};
|
|
/**
|
* 点击编辑优惠券
|
*/
|
MyCoupon.openMyCouponUpdate = function (id) {
|
var index = layer.open({
|
type: 2,
|
title: '编辑优惠券',
|
area: ['80%', '80%'], //宽高
|
fix: false, //不固定
|
maxmin: true,
|
content: Feng.ctxPath + '/myCoupon/myCoupon_update/' + id
|
});
|
this.layerIndex = index;
|
};
|
|
/**
|
* 打开查看优惠券详情
|
*/
|
MyCoupon.openMyCouponDetail = function (id) {
|
if(id == 0) {
|
// 如果id为0,则为批量删除
|
id = Feng.checkBoxIds(MyCoupon.id);
|
}
|
var index = layer.open({
|
type: 2,
|
title: '优惠券详情',
|
area: ['80%', '80%'], //宽高
|
fix: false, //不固定
|
maxmin: true,
|
content: Feng.ctxPath + '/myCoupon/detailPrice/' + id
|
});
|
this.layerIndex = index;
|
};
|
|
/**
|
* 删除/批量删除优惠券
|
*/
|
MyCoupon.delete = function(id){
|
var ids = id;
|
if(id == 0) {
|
// 如果id为0,则为批量删除
|
ids = Feng.checkBoxIds(MyCoupon.id);
|
}
|
if (ids.length != 0) {
|
var operation = function() {
|
// 加载动画层,0代表加载的风格,支持0-2
|
var index = parent.layer.load(0, {shade: false});
|
var ajax = new $ax(Feng.ctxPath + "/myCoupon/delete", function (data) {
|
// 关闭加载动画层
|
parent.layer.close(index);
|
Feng.success("删除成功!");
|
MyCoupon.table.refresh();
|
}, function (data) {
|
Feng.error("删除失败!" + data.responseJSON.message + "!");
|
});
|
ajax.set("ids", ids);
|
ajax.start();
|
};
|
Feng.confirm("是否删除所选中的数据?", operation);
|
}
|
};
|
|
/**
|
* 编辑优惠券状态
|
*/
|
MyCoupon.updateState = function (id, state) {
|
var ajax = new $ax(Feng.ctxPath + "/myCoupon/updateState", function (data) {
|
if(data.code == 200){
|
Feng.success("操作成功!");
|
MyCoupon.table.refresh();
|
} else {
|
Feng.error("操作失败!" + data.message);
|
}
|
}, function () {
|
Feng.error("操作失败!");
|
});
|
ajax.set("myCouponId", id);
|
ajax.set("state", state);
|
ajax.start();
|
};
|
|
/**
|
* 查询优惠券列表
|
*/
|
MyCoupon.search = function () {
|
var queryData = {};
|
queryData['type'] = 2;
|
queryData['name'] = $("#name").val();;
|
queryData['couponType'] = $("#couponType").val();
|
queryData['serverType'] = $("#serverType").val();
|
queryData['beginTime'] = $("#beginTime").val();
|
queryData['endTime'] = $("#endTime").val();
|
MyCoupon.table.refresh({query: queryData});
|
};
|
/**
|
* 重置查询条件
|
*/
|
MyCoupon.resetSearch = function () {
|
$("#name").val("");
|
$("#beginTime").val("");
|
$("#endTime").val("");
|
$("#couponType").val("");
|
$("#serverType").val("");
|
MyCoupon.search();
|
};
|
$(function () {
|
var defaultColunms = MyCoupon.initColumn();
|
var table = new BSTable(MyCoupon.id, "/myCoupon/list", defaultColunms);
|
// 设置物理分页server(逻辑分页client)
|
table.setPaginationType("server");
|
// 表单提交参数
|
var queryData = {};
|
queryData['type'] = 2;
|
queryData['name'] = $("#name").val();;
|
queryData['couponType'] = $("#couponType").val();
|
queryData['serverType'] = $("#serverType").val();
|
queryData['beginTime'] = $("#beginTime").val();
|
queryData['endTime'] = $("#endTime").val();
|
table.setQueryParams(queryData);
|
MyCoupon.table = table.init();
|
|
// 初始化开始时间、结束时间
|
laydate.render({
|
elem: '#beginTime', type:'datetime'
|
});
|
laydate.render({
|
elem: '#endTime', type:'datetime'
|
});
|
});
|