Authored by LiQZ

套装

module.exports = function (app) {
app.get("/product/bundle/index", "product.productBundle.Index", function(req, res) {
this.$extend = {
moduleName: "营销管理",
pageName: "套餐管理"
}
});
app.get("/product/bundle/add", "product.productBundle.Edit", function(req, res) {
this.$extend = {
moduleName: "营销管理",
pageName: "增加套餐",
action: "/product/bundle/save"
}
});
// app.get("/product/bundle/:id", "product.productBundle.Edit", productBundle_findProductBundleByID, function(apiReq, req, res) {
// this.$extend = {
// moduleName: "营销管理",
// pageName: "编辑套餐",
// action: "/product/bundle/save",
// data: apiReq.data
// }
//
// });
app.post("/product/bundle/list", "productBundle_productBundleList");
app.post("/product/bundle/stop", "productBundle_productBundleStop");
app.post("/product/bundle/save", "productBundle_productBundleSaveOrUpdate");
}
... ...
/**
* 商品套餐
*/
module.exports={
namespace:"productBundle",
apis:{
productBundleList:{
title: "单品列表 ajax 分页",
url: '/productBundleList',
params: [
{name: 'page', type: 'Number'},
{name: 'size', type: 'Number'}
]
},
productBundleSaveOrUpdate: {
title: "保存编辑",
url: '/productBundleSaveOrUpdate',
params: [
{ name: 'id', type: 'Number'},
{ name: 'productSkn', type: 'String'},
{ name: 'discount', type: 'Number'},
{ name: 'startTime', type: 'Number'},
{ name: 'endTime', type: 'Number'}
]
},
productBundleStop: {
title: "终止",
url: "/productBundleStop",
params: [
{ name: 'id', type: 'Number'}
]
},
findProductBundleByID: {
title: "查询单个商品套装",
url: "/findProductBundleByID",
params: [
{ name: 'id', type: 'Number'}
]
}
}
}
... ...
<%include '../../../common/views/__ui/header'%>
<%include '../../../common/views/__partail/ListHeader'%>
<style type="text/css" media="all">
.fileinput-button {
width: 284px;
height: 200px;
}
.fileinput-button .fileinput-button-icon {
height: auto;
line-height: auto;
}
input[type=file] {
height: 200px;
width: 284px;
}
</style>
<div class="data.contentDatapanel">
<form id="add-form" class="form-horizontal form-bordered" type="<%type%>" action="<%action%>">
<div class="panel-group">
<div class="panel-group" id="editor-group">
<% if data %>
<input type="hidden" id="id" value="<%data.id%>">
<%/if%>
<div class="pannel">
<div class="panel-body">
<div class="row">
<% if data %>
<div class="form-group">
<label class="col-sm-2 control-label">组合套餐号:</label>
<div class="col-sm-3"> <p class="form-control-static"><% data.id %></p> </div>
</div>
<%/if%>
<div class="form-group">
<label class="col-sm-2 control-label">有效时间:</label>
<div class="col-sm-2">
<input id="beginTimeStr" data-time="" value="<%if data%><% data.beginTimeStr %><%/if%>" type="text" class="form-control" jsaction="time" placeholder="开始时间" readonly required>
</div>
<div class="col-sm-1" style="width: 28px;">~</div>
<div class="col-sm-2">
<input id="endTimeStr" data-time="" value="<%if data%><% data.endTimeStr %><%/if%>" type="text" class="form-control" jsaction="time" placeholder="结束时间" readonly required>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">套餐商品:</label>
<div class="col-sm-4">
<input type="hidden" id="productSkn" value="">
<table class="table table-bordered">
<thead>
<tr>
<th>SKN</th>
<th>排序</th>
</tr>
</thead>
<tbody>
<tr>
<td> <input type="text" name="productSkn" class="form-control" maxlength="10" style="width: 150px;" value="<% if data%><% data.productSkn1 %><%/if%>"> </td>
<td>
<button type="button" class="btn btn-default btn-sm btn-down"><span class="glyphicon glyphicon-chevron-down"></span></button>
</td>
</tr>
<tr>
<td> <input type="text" name="productSkn" class="form-control" maxlength="10" style="width: 150px;" value="<% if data%><% data.productSkn2 %><%/if%>"> </td>
<td>
<div class="btn-group">
<button type="button" class="btn btn-default btn-sm btn-up"><span class="glyphicon glyphicon-chevron-up"></span></button>
<button type="button" class="btn btn-default btn-sm btn-down"><span class="glyphicon glyphicon-chevron-down"></span></button>
</div>
</td>
</tr>
<tr>
<td> <input type="text" name="productSkn" class="form-control" maxlength="10" style="width: 150px;" value="<% if data%><% data.productSkn3 %><%/if%>"> </td>
<td>
<div class="btn-group">
<button type="button" class="btn btn-default btn-sm btn-up"><span class="glyphicon glyphicon-chevron-up"></span></button>
<button type="button" class="btn btn-default btn-sm btn-down"><span class="glyphicon glyphicon-chevron-down"></span></button>
</div>
</td>
</tr>
<tr>
<td> <input type="text" name="productSkn" class="form-control" maxlength="10" style="width: 150px;" value="<% if data%><% data.productSkn4 %><%/if%>"> </td>
<td><button type="button" class="btn btn-default btn-sm btn-up"><span class="glyphicon glyphicon-chevron-up"></span></button>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">优惠力度:</label>
<div class="col-sm-3">
<input type="text" id="discount" placeholder="折扣" class="form-control" required maxlength="10" value="<% if data%><% data.discount %><%/if%>">
<span class="help-inline red">支持0.01-1之间的数字</span>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="pannel">
<div class="col-md-10"></div>
<div class="col-md-2">
<input id="add-btn" class="btn btn-success add-btn" type="button" value="保存"></input>
<a class="btn btn-default btn-sm" href="/product/bundle/index">取消</a>
</div>
</div>
</div>
</form>
</div>
... ...
<%include '../../../common/views/__ui/header'%>
<%include '../../../common/views/__partail/ListHeader'%>
<div class="contentpanel">
<div class="panel panel-default" style="margin-bottom: 10px;">
<div class="panel-body" style="padding-bottom: 0px; padding-left: 10px;">
<div class="col-md-12"><a href="/product/bundle/add" class="btn btn-success "><i class="fa fa-plus"></i><% pageName %></a></div>
</div>
<div class="panel-body">
<div class="row">
<label class="control-label pull-left" style="margin-top: 10px; margin-left: 10px;">领取名称:</label>
<div class="panel-col" style="width: 154px;">
<input name="receiveActivityName" id="receiveActivityName" type="text" value="" class="form-control" placeholder="请输入领取名称关键字" />
</div>
<label class="control-label pull-left" style="margin-top: 10px;">创建时间:</label>
<div class="panel-col">
<input type="text" id="starttime" class="form-control panel-input hasDatepicker" readonly required name="start_time" placeholder="开始时间" value="">
</div>
<div class="panel-col">
<input type="text" id="endtime" class="form-control panel-input hasDatepicker" readonly required name="end_time" placeholder="结束时间" value="">
</div>
<div class="panel-col2" style="position: relative">
<a id="filter-btn" href="javascript:;" class="btn btn-info">筛选</a>
<a id="all-btn" href="" class="btn btn-info">全部</a>
</div>
</div>
</div>
</div>
<div class="panel">
<div class="panel-body nopadding">
<div id="table-box" class="dataTables_wrapper no-footer">
</div>
</div>
</div>
</div>
... ...
var $ = require('jquery'), common = require('../../../common/common');
var e = new common.edit('#editor-group');
e.on("validate", function () {
if (new Date($("#beginTimeStr").val()).getTime() >= new Date($("#endTimeStr").val()).getTime()) {
return "开始时间必须小于结束时间";
}
var discount = $("#discount").val();
if (!/^1|0\.[0-9][0-9]$/.test(discount) || discount > 1.0) {
return "折扣格式不正确";
}
var skns = '';
$("input[name='productSkn']").each(function (index) {
var skn = $(this).val();
if (skn && skn.length > 1) {
skns = skns + skn + "/";
}
});
var lio = skns.lastIndexOf("/");
if (lio == -1) {
return "请填写商品 SKN";
}
$("#productSkn").val(skns.substring(0, lio));
});
e.init();
// submit
$('#add-btn').click(function(option) {
e.submit($('#add-form').attr('action'), function(option) {
var data = option.data;
// convert date
data.startTime = toSeconds(data.beginTimeStr);
data.endTime = toSeconds(data.endTimeStr);
data.popupPic = $("#popupPic").parent().find("img").attr("src");
option.beforeSend = function() {
$('#add-btn').addClass('disabled');
};
option.success = function(res) {
if (res.code == "200") {
e.$tip('提交成功', function() {
location.href = "/activity/yohocoin/index";
}, 'growl-success');
} else {
$('#add-btn').removeClass('disabled');
e.$tip(res.message);
}
return false;
}
option.error = function(res) {
e.$tip("提交失败");
};
});
});
$(".btn-up").click(function() {
var tr = $(this).parents("tr");
var ipt = tr.find("input[name='productSkn']");
var prev = tr.prev().find("input[name='productSkn']");
var val = ipt.val();
ipt.val(prev.val());
prev.val(val);
});
$(".btn-down").click(function() {
var tr = $(this).parents("tr");
var ipt = tr.find("input[name='productSkn']");
var next = tr.next().find("input[name='productSkn']");
var val = ipt.val();
ipt.val(next.val());
next.val(val);
});
function toSeconds(strDate) {
var seconds = new Date(strDate).getTime() / 1000;
return seconds;
}
$("#set_default_img").click(function() {
$("#popupPic").parent().find("img").attr("src", default_img);
});
... ...
/*
*@time: 2016.10.10
*@author: LiQZ
*/
var $ = require('jquery'), common = require('../../../common/common');
require('../../../common/util/datepicker');
//日期插件
$('.hasDatepicker').fdatepicker({
format: 'yyyy-mm-dd hh:ii:ss',
pickTime: true
});
var tableGird = new common.grid({
el: "#table-box",
size: 30,
parms: function() {
var startTime = common.util.__input('starttime');
var endTime = common.util.__input('endtime');
return {
receiveActivityName: common.util.__input('receiveActivityName'),
beginTime: toSeconds(startTime),
endTime: toSeconds(endTime)
};
},
columns: [
{ display: "组合套餐号", name: "id" },
{ display: "SKN", render: function(items) {
return items.productSkn;
}},
{ display: "有效期", render: function(items) {
return items.startTime + items.endTime;
}},
{ display: "折扣", render: function(items) {
return items.discount;
}},
{ display: "状态", render: function(items) {
return '';
}},
{ display: "操作信息", render: function(items) {
return '';
}},
{ display: "操作", render: function(items) {
var HtmArr = [];
HtmArr.push('<a href="/activity/yohocoin/update/' + items.id + '" data-id="' + items.id + '" class="btn btn-primary btn-xs">编辑</a>');
HtmArr.push('<a href="javascript:void(0);" data-id="' + items.id + '" class="btn btn-danger btn-xs delete">删除</a>');
return HtmArr.join('');
}
}]
});
tableGird.init('/product/bundle/list');
$("#filter-btn").click(function() {
tableGird.reload(1);
});
function toSeconds(strDate) {
var seconds = new Date(strDate).getTime() / 1000;
return seconds;
}
function toDate(seconds) {
if (!$.isNumeric(seconds) || seconds <= 0) { return ''; }
var date = new Date(seconds * 1000);
return fixTwo(date.getFullYear()) + '-' + fixTwo((date.getMonth() + 1)) + '-' + fixTwo(date.getDate()) + ' ' + fixTwo(date.getHours()) + ':' + fixTwo(date.getMinutes()) + ':' + fixTwo(date.getSeconds());
}
function fixTwo(number) {
return number < 10? "0" + number: number;
}
/**
* 删除--点击事件
*/
$(document).on('click', '.delete', function () {
var id = $(this).attr("data-id");
common.dialog.confirm("警告",
"确认删除?",
function () {
common.util.__ajax({
url: '/yohoCoinActivity/delYohoCoinActivity',
data: { id: id }
}, function () {
tableGird.reload();
});
});
});
/*
* 复制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><p>&lt;a class="yoho-coin" ' +
'href="javascript:;" data-token="7173278a4a86"&gt;有货币领取按钮&lt;/a&gt;</p><p><b>注:必须引入 JS 插件</b></p>'
});
});
... ...