Authored by shuaiguo

添加兑券管理页面

/**
* Created by ty on 2016/6/23.
* 发券管理
*/
module.exports=function(app) {
/*发券管理主页*/
app.get("/exchangeCouponManager/queryList","operations.exchangeCoupon.Index", function () {
this.$extend = {
moduleName: "运营管理",
pageName: "兑券管理"
}
});
/*发券列表*/
app.post("/exchangeCouponManager/query/list","exchangeCoupon_queryList");
/*添加*/
app.post("/exchangeCouponManager/add","exchangeCoupon_add");
app.post("/exchangeCouponManager/update","exchangeCoupon_update");
app.post("/exchangeCouponManager/delete","exchangeCoupon_delete");
}
\ No newline at end of file
... ...
/**
* Created by ty on 2016/6/23.
* 发券管理
*/
module.exports={
namespace:"exchangeCoupon",
apis:{
queryList:{
title: "发券列表",
url: '/activity/couponExchangeActivity/queryList',
params: [
{name: 'name', type: 'string'},//名称
{name: 'page', type: 'Number'},
{name: 'size', type: 'Number'}
]
},
add:{
title: "添加",
url: '/activity/couponExchangeActivity/add',
params: [
{name: 'name', type: 'string'},//名称
{name: 'subName', type: 'string'}, // 副标题
{name: 'sendCouponId', type: 'string'}, // 券Id
{name: 'exchangeYohoCoinNum', type: 'Number'} // 使用有货币数量
]
},
update:{
title: "更新",
url: '/activity/couponExchangeActivity/update',
params: [
{name: 'name', type: 'string'},//名称
{name: 'subName', type: 'string'}, // 副标题
{name: 'sendCouponId', type: 'string'}, // 券Id
{name: 'exchangeYohoCoinNum', type: 'Number'} // 使用有货币数量
]
},
update:{
title: "删除",
url: '/activity/couponExchangeActivity/delete',
params: [
{name: 'id', type: 'Number'} // 兑券纪录Id
]
},
}
}
\ No newline at end of file
... ...
<%include '../../../common/views/__ui/header'%>
<%include '../../../common/views/__partail/ListHeader'%>
<div class="contentpanel">
<div class="panel panel-default" style="...">
<div class="panel-body" style="padding-bottom: 0">
<a class="btn btn-success" id="add-content"><i class="fa fa-plus"></i> 添加兑券</a>
</div>
<div class="panel-body">
<div class="row">
<div class="panel-col2">
<input type="text" value="" name="modelName" id="name-filter" placeholder="请输入发券关键字"
class="form-control">
</div>
<div class="panel-col">
<a id="filter-btn" href="javascript:;" class="btn btn-info">查询</a>
<a id="filter-all" href="/exchangeCouponManager/queryList" class="btn btn-info">全部</a>
</div>
<!-- <div class="panel-col2">
<a class="btn btn-primary" id="token" href="javascript:;">查看token使用方法>></a>
</div> -->
</div>
</div>
</div>
<div id="content-list"></div>
</div>
<!--编辑模态-->
<script type="text/template" id="template">
<div class="rows" id="baseform">
<div class="form-group">
<label class="col-sm-2 control-label">发券名称<i class="red">*</i></label>
<div class="col-sm-10">
<input type="text" value="[[name]]" class="form-control observe" data-field="name" placeholder="发券名称"
required="required"/>
</div>
</div>
[[each couponsIds as item index]]
<div class="form-group">
<label class="col-sm-2 control-label">优惠券ID<i class="red">*</i></label>
<div class="col-sm-7">
<select name="couponsIds" class="col-sm-10 observe select2-offscreen couponsIds"
data-field="couponsIds.[[index]].id" data-index="[[index]]">
<option value='[[item.id]]'>[[item.text||item.id||'请选择优惠券ID']]</option>
</select>
</div>
<div class="col-sm-2">
<a class="col-sm-4 btn btn-primary addBtn" data-index="[[index]]">+</a>
[[if index==0]]
<a class="col-sm-4 col-sm-offset-2 btn btn-danger delBtn" data-index="[[index]]">-</a>
[[else]]
<a class="col-sm-4 col-sm-offset-2 btn btn-danger delBtn" data-index="[[index]]">-</a>
[[/if]]
</div>
</div>
[[/each]]
</div>
</script>
\ No newline at end of file
... ...
/**
* Created by JiangMin on 2016/4/19.
*/
var $ = require('jquery'),
common = require('../../../common/common');
var ZeroClipboard = require("../../../common/util/ZeroClipboard.min");
ZeroClipboard.config({swfPath: "http://cdn.yoho.cn/yohobuy-portal/assets/images/ZeroClipboard.swf"});
/**
* 列表显示数据
* @type {common.grid}
*/
var g = new common.grid({
el: '#content-list',
hash: false,
//查询参数
parms: function () {
return {
name: common.util.__input('name-filter')
};
},
//列表显示
columns: [
{
display: "创建时间",
name: "createTime"
},
{
display: "兑券名称",
name: "name"
},
{
display: "副标题",
name: "subName"
},
{
display: "优惠券ID",
name: "sendCouponId",
// render: function (item) {
// var couponsIds = [];
// for (var i = 0; i < item.couponsIds.length; i++) {
// couponsIds.push(item.couponsIds[i].id);
// }
// return couponsIds.join(",");
// }
},
{
display: "兑换有货币数量",
name: "exchangeYohoCoinNum"
},
{
display: "token值",
name: "token",
render: function (item) {
return '<div class="col-sm-12" style="padding-left: 0">' +
'<input class="col-sm-10" style="border: 0px;padding-left: 0" value="' + item.token + '" readonly/> <br/>'
+ '<a data-index="' + item.__index + '" href="JavaScript:;" class="btn btn-xs info-copy" data-clipboard-text="' + item.token + '" id="copy-' + item.__index + '">复制链接</a></div>';
}
},
{
display: "操作",
name: "",
render: function (item) {
var arr = [];
arr.push('<a class="btn btn-xs btn-info update" data-index="' + item.__index + '">编辑</a>');
arr.push('<a class="btn btn-xs btn-danger delete" data-index="' + item.__index + '">删除</a>');
return arr.join('');
}
}
],
complete: function () {
new ZeroClipboard($(".info-copy"));
}
});
g.init("/exchangeCouponManager/query/list");
/*验证*/
var edit = new common.edit2(".modal-body");
var Bll = {
module: null,
__render: function (selecter, templater, data) {
$(selecter).html(common.util.__template2($("#" + templater).html(), data));
},
//弹框
toast: function (module, hint) {
Bll.module = module;
var d = new common.dialog({
title: hint + "发券",
content: common.util.__template2($("#template").html(), Bll.module),
width: '70%',
button: [
{
value: "保存",
callback: function () {
var couponIds = Bll.module.couponsIds || [];
var flag = true;
var ids = [];
for (var i = 0; i < couponIds.length; i++) {
ids.push(couponIds[i].id);
}
if (ids.join(",").indexOf("-1") > -1) {
flag = false;
common.util.__tip("请正确选择优惠券ID", "warning");
} else {
Bll.module.couponsIds = ids.join(",");
}
if (edit.validate() && flag) {
common.util.__ajax({
url: "/exchangeCouponManager/addOrUpdate",
data: Bll.module
}, function (res) {
if (res.code == '200') {
g.reload();
d.close();
}
else {
common.util.__tip(res.message, "warning");
}
});
}
return false;
},
css: "btn-primary"
},
{
"value": "取消",
"css": "btn-info"
}
]
});
Bll.__editRender();
},
renderDialog: function (templater) {
Bll.__render(".modal-body", templater, Bll.module);
Bll.__editRender();
},
__editRender: function () {
edit.init();
new common.dropDown({
el: '.couponsIds',
ajax: 'couponID'
});
}
};
/**
* 监听输入框变化
*/
$(document).on("change", ".observe", function () {
var $this = $(this);
var name = $this.data("field");
Bll.module = common.util.__buildobj(name, '.', Bll.module, function (obj, name1) {
if (name.indexOf('id') > -1) {
obj[name1] = $this.val();
obj["text"] = $this.find("option[value='" + $this.val() + "']").text();
}
obj[name1] = $this.val();
});
});
/*添加一行*/
$(document).on("click", ".addBtn", function () {
Bll.module.couponsIds.push({
"id": "",
"text": ""
});
Bll.renderDialog("template");
});
/**
* 删除行
*/
$(document).on("click", ".delBtn", function () {
var index = $(this).data("index");
if (Bll.module.couponsIds.length <= 1) {
common.util.__tip("至少有一张优惠券", "warning")
}
else {
Bll.module.couponsIds.splice(index, 1);
Bll.renderDialog("template");
}
});
/**
* 添加--点击事件
*/
$('#add-content').on('click', function () {
var item = {
"id": "",
"name": "",
"couponsIds": [
{
"id": "",
"text": ""
}
],
"status": 1
};
Bll.toast(item, "添加");
});
/**
* 编辑--点击事件
*/
$(document).on('click', '.update', function () {
var item = g.rows[$(this).data("index")];
var item1 = $.extend(true, {}, item);
Bll.toast(item1, "修改");
});
/**
* 删除--点击事件
*/
$(document).on('click', '.delete', function () {
var item = g.rows[$(this).data("index")];
common.dialog.confirm("警告",
"确认删除?",
function () {
common.util.__ajax({
url: '/couponSendManager/addOrUpdate',
data: {
id: item.id,
status: 0
}
}, function () {
g.reload();
});
});
});
/**
* 查询按钮--点击事件
*/
$(document).on('click', '#filter-btn', function () {
g.reload(1);
});
/**
* 复制token点击事件
*/
$(document).on('click', '.info-copy', function () {
common.util.__tip("Token链接已复制好,可贴粘", "success")
});
/**
* 查看token使用方法
*/
$(document).on('click', '#token', function () {
var a = new common.dialog({
title: "<h4>token使用方法</h4>",
width: '50%',
content: '<p>活动开发人员使用Token时,按照对应格式写在页面中,示例代码:</p>&lt;a class="yoho-conpon" ' +
'href="javascript:;" data-token="29-6ea9ab1baa0efb9e19094440c317e21b"&gt;领券按钮&lt;/a&gt;<h5>注:必须引入 JS 插件</h5>'
});
});
... ...