...
|
...
|
@@ -3,98 +3,41 @@ |
|
|
*/
|
|
|
'use strict';
|
|
|
var $ = require('jquery'),
|
|
|
Handlebars = require('yoho.handlebars');
|
|
|
Handlebars = require('yoho.handlebars'),
|
|
|
grid=require('../common/grid'),
|
|
|
dropDown = require('../common/dropDown');
|
|
|
|
|
|
require('../util/select2');
|
|
|
require('yoho.bootstrap')
|
|
|
|
|
|
exports.init = function() {
|
|
|
|
|
|
//下拉框
|
|
|
$('.select2-offscreen').select2();
|
|
|
new dropDown({el: '#filter-dep'});
|
|
|
|
|
|
/**
|
|
|
* 优惠码列表显示
|
|
|
* @param: data(优惠码json数据)
|
|
|
*/
|
|
|
function listShow(data,iscount) {
|
|
|
if(!iscount){
|
|
|
var a={0: 0, 1: 0, 2: 0, 3:0, 4: 0, all: 0};
|
|
|
$.each(data,function(index,item){
|
|
|
a[item.status]++;
|
|
|
a["all"]++;
|
|
|
})
|
|
|
___tabShow(a);
|
|
|
}
|
|
|
|
|
|
|
|
|
var tpl = Handlebars.compile($('#list-tpl').html());
|
|
|
|
|
|
$('tbody').html(tpl({
|
|
|
data: data
|
|
|
}));
|
|
|
|
|
|
//审核状态及操作按钮显示
|
|
|
$('tbody').find('tr').each(function() {
|
|
|
var $state = $(this).find('.state-title'),
|
|
|
$operate = $(this).find('.operate'),
|
|
|
cState = $state.text();
|
|
|
|
|
|
statusToText($state, cState);
|
|
|
switch (cState) {
|
|
|
case '0':
|
|
|
$operate.addClass('wait');
|
|
|
break;
|
|
|
case '1':
|
|
|
$operate.addClass('success');
|
|
|
break;
|
|
|
case '2':
|
|
|
$operate.addClass('back');
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 优惠码列表显示
|
|
|
* @param: data(请求json数据), callback(成功后执行的函数)
|
|
|
*/
|
|
|
function listOperate(data, callback) {
|
|
|
if (data.code === 200) {
|
|
|
callback();
|
|
|
} else {
|
|
|
$('#apply-alert .am-modal-hd').text('设置失败!');
|
|
|
$('#apply-alert').modal({
|
|
|
relatedTarget: this
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 状态数据转换为中文显示
|
|
|
* @param: $element(转换的节点), status(转换的状态字符串)
|
|
|
*/
|
|
|
function statusToText($element, status) {
|
|
|
function statusConvert(status) {
|
|
|
switch (status) {
|
|
|
case '0':
|
|
|
$element.text('待审核');
|
|
|
case 0:
|
|
|
return '待审核';
|
|
|
break;
|
|
|
case '1':
|
|
|
$element.text('审核通过');
|
|
|
case 1:
|
|
|
return '审核通过';
|
|
|
break;
|
|
|
case '2':
|
|
|
$element.text('驳回');
|
|
|
case 2:
|
|
|
return '驳回';
|
|
|
break;
|
|
|
case '3':
|
|
|
$element.text('过期');
|
|
|
case 3:
|
|
|
return '过期';
|
|
|
break;
|
|
|
case '4':
|
|
|
$element.text('作废');
|
|
|
case 4:
|
|
|
return '作废';
|
|
|
break;
|
|
|
default:
|
|
|
$element.text('全部');
|
|
|
return '全部';
|
|
|
break;
|
|
|
}
|
|
|
}
|
...
|
...
|
@@ -105,8 +48,6 @@ exports.init = function() { |
|
|
*/
|
|
|
function tabShow(param, indexStatus) {
|
|
|
var param = param || {};
|
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
type: 'POST',
|
|
|
dataType: 'json',
|
...
|
...
|
@@ -120,16 +61,15 @@ exports.init = function() { |
|
|
}));
|
|
|
|
|
|
$('.list-tabs').find('li').each(function() {
|
|
|
var status = $(this).data('status') + '';
|
|
|
var status = $(this).data('status');
|
|
|
|
|
|
statusToText($(this).find('span'), status);
|
|
|
$(this).find('span').text(statusConvert(status));
|
|
|
|
|
|
if (status === 'all') {
|
|
|
$(this).addClass('active').siblings().removeClass('active');
|
|
|
}
|
|
|
});
|
|
|
|
|
|
//console.log(index);
|
|
|
if (indexStatus === undefined) {
|
|
|
$('.list-tabs').find('[data-status="all"]').addClass('active').siblings().removeClass('active');
|
|
|
} else {
|
...
|
...
|
@@ -139,149 +79,84 @@ exports.init = function() { |
|
|
})
|
|
|
}
|
|
|
|
|
|
function ___tabShow(data){
|
|
|
var tpl = Handlebars.compile($('#tab-tpl').html());
|
|
|
//{0: "56", 1: "28", 2: "1", 4: "14", all: "99"}
|
|
|
$('.list-tabs ul').html(tpl({
|
|
|
data: data
|
|
|
}));
|
|
|
|
|
|
$('.list-tabs').find('li').each(function() {
|
|
|
var status = $(this).data('status') + '';
|
|
|
|
|
|
statusToText($(this).find('span'), status);
|
|
|
|
|
|
if (status === 'all') {
|
|
|
$(this).addClass('active').siblings().removeClass('active');
|
|
|
}
|
|
|
});
|
|
|
|
|
|
//console.log(index);
|
|
|
// if (indexStatus === undefined) {
|
|
|
// $('.list-tabs').find('[data-status="all"]').addClass('active').siblings().removeClass('active');
|
|
|
// } else {
|
|
|
// $('.list-tabs').find('[data-status="' + indexStatus + '"]').addClass('active').siblings().removeClass('active');
|
|
|
// }
|
|
|
}
|
|
|
tabShow();
|
|
|
|
|
|
//tab卡切换列表事件
|
|
|
$('.list-tabs').on('click', 'li', function() {
|
|
|
var status = $(this).data('status'),
|
|
|
filterDep = $('#filter-dep').val(),
|
|
|
filterId = $('#filter-id').val(),
|
|
|
filterName = $('#filter-name').val();
|
|
|
|
|
|
var param = {
|
|
|
status: status,
|
|
|
batchNo: filterId,
|
|
|
name: filterName,
|
|
|
reqDepartment: filterDep,
|
|
|
offset: 0
|
|
|
};
|
|
|
|
|
|
$(this).addClass('active').siblings().removeClass('active');
|
|
|
|
|
|
if (status === 'all') {
|
|
|
delete param.status;
|
|
|
}
|
|
|
|
|
|
if (filterDep === '全部') {
|
|
|
delete param.reqDepartment;
|
|
|
}
|
|
|
|
|
|
$.ajax({
|
|
|
type: 'POST',
|
|
|
dataType: 'json',
|
|
|
url: '/getPromotion',
|
|
|
data: param,
|
|
|
success: function(res) {
|
|
|
var param = {
|
|
|
reqDepartment: filterDep
|
|
|
};
|
|
|
|
|
|
if (filterDep === '全部') {
|
|
|
delete param.reqDepartment;
|
|
|
}
|
|
|
|
|
|
listShow(res.data.data,true);
|
|
|
}
|
|
|
});
|
|
|
});
|
|
|
|
|
|
//获取优惠码列表
|
|
|
$.ajax({
|
|
|
type: 'POST',
|
|
|
dataType: 'json',
|
|
|
url: '/getPromotion',
|
|
|
data: {
|
|
|
offset: 0
|
|
|
},
|
|
|
success: function(res) {
|
|
|
listShow(res.data.data);
|
|
|
}
|
|
|
g.reload();
|
|
|
});
|
|
|
|
|
|
//筛选事件
|
|
|
$('#filter-btn').on('click', function() {
|
|
|
var filterId = $('#filter-id').val(),
|
|
|
filterName = $('#filter-name').val(),
|
|
|
filterDep = $('#filter-dep').val(),
|
|
|
filterStatus = $('.list-tabs').find('.active').data('status'),
|
|
|
tabStatus = $('.list-tabs').find('.active').data('status'),
|
|
|
param = null,
|
|
|
tabParam = null;
|
|
|
|
|
|
//console.log(tabIndex);
|
|
|
|
|
|
param = {
|
|
|
status: filterStatus,
|
|
|
batchNo: filterId,
|
|
|
name: filterName,
|
|
|
reqDepartment: filterDep
|
|
|
}
|
|
|
|
|
|
tabParam = {
|
|
|
batchNo: filterId,
|
|
|
name: filterName,
|
|
|
reqDepartment: filterDep
|
|
|
}
|
|
|
|
|
|
if (filterStatus === 'all') {
|
|
|
delete param.status;
|
|
|
}
|
|
|
var btnAuthority = JSON.parse($("#btnAuthority").val());
|
|
|
|
|
|
if (filterDep === '全部') {
|
|
|
delete param.reqDepartment;
|
|
|
delete tabParam.reqDepartment;
|
|
|
}
|
|
|
var g=new grid({
|
|
|
el: '#basicTable',
|
|
|
size: 10,
|
|
|
parms:function(){
|
|
|
|
|
|
//筛选列表显示
|
|
|
$.ajax({
|
|
|
type: 'POST',
|
|
|
dataType: 'json',
|
|
|
url: '/getPromotion',
|
|
|
data: param,
|
|
|
success: function(res) {
|
|
|
if (res.code === 200) {
|
|
|
listShow(res.data.data);
|
|
|
} else {
|
|
|
$('#apply-alert .am-modal-hd').text('请输入正确的查询条件!');
|
|
|
$('#apply-alert').modal({
|
|
|
relatedTarget: this
|
|
|
});
|
|
|
return {
|
|
|
batchNo: $.trim($('#filter-id').val()) ||"",
|
|
|
status: parseInt($('.list-tabs').find('.active').data('status')) ||"",
|
|
|
name: $.trim($('#filter-name').val()) ||"",
|
|
|
reqDepartment:$.trim($('#filter-dep').val()) ||""
|
|
|
};
|
|
|
},
|
|
|
columns:[
|
|
|
{display:"批次号", name:"batchNo", render: function(item) {
|
|
|
return '<a href="/coupon/info/' + item.id + '">' + item.batchNo + '</a>';
|
|
|
}},
|
|
|
{display:"基本信息",name:"name", render: function(item) {
|
|
|
return '<p>名称:' + item.name + '</p><p>次数' + item.limitTimes + '</p><p>部门:' + item.reqDepartment + '</p>';
|
|
|
}},
|
|
|
{display: '使用期限', name: "name", render: function(item) {
|
|
|
return '<p>' + item.limitDateFrom + '</p><p>' + item.limitDateTo + '</p>'
|
|
|
}},
|
|
|
{display: '优惠码说明', name: "describe"},
|
|
|
{display: '申请人', name: "staff"},
|
|
|
{display: '状态', name: "status", render: function(item) {
|
|
|
var html = statusConvert(item.status);
|
|
|
if (item.reason) {
|
|
|
html += '<p style="color:red;">(' + item.reason + ')</p>';
|
|
|
}
|
|
|
|
|
|
}
|
|
|
})
|
|
|
|
|
|
//筛选tab显示
|
|
|
tabShow(tabParam, tabStatus);
|
|
|
return html;
|
|
|
}},
|
|
|
{display:"操作",name:"operate",render:function(items){
|
|
|
console.log(this);
|
|
|
var HtmArr=[];
|
|
|
if(btnAuthority.look){
|
|
|
HtmArr.push('<a href="/coupon/info/'+ items.id+'" class="btn btn-info btn-xs">查看详情</a>');
|
|
|
}
|
|
|
if(items.status == 0){
|
|
|
HtmArr.push('<a class="btn btn-primary btn-xs apply-success" data-id="'+ items.id+'" href="javascript:;">通过</a>');
|
|
|
HtmArr.push('<a class="btn btn-warning btn-xs apply-back" data-id="'+ items.id+'" href="javascript:;">驳回</a>');
|
|
|
HtmArr.push('<a class="btn btn-danger btn-xs apply-cancel" data-id="'+ items.id+'" href="javascript:;">作废</a>');
|
|
|
}
|
|
|
if(items.status == 1){
|
|
|
HtmArr.push('<a class="btn btn-danger btn-xs apply-cancel" data-id="'+ items.id+'" href="javascript:;">作废</a>');
|
|
|
}
|
|
|
if(items.status == 2){
|
|
|
HtmArr.push('<a class="btn btn-info btn-xs apply-modify" data-id="'+ items.id+'" href="/coupon/update/'+ items.id+'">修改</a>');
|
|
|
}
|
|
|
return HtmArr.join('');
|
|
|
}}
|
|
|
]
|
|
|
})
|
|
|
|
|
|
g.init($("#gridurl").val());
|
|
|
|
|
|
$("#filter-btn").click(function(){
|
|
|
tabShow({
|
|
|
batchNo: $.trim($('#filter-id').val()),
|
|
|
name: $.trim($('#filter-name').val()),
|
|
|
reqDepartment:$.trim($('#filter-dep').val())
|
|
|
}, parseInt($('.list-tabs').find('.active').data('status')))
|
|
|
g.reload();
|
|
|
});
|
|
|
|
|
|
//作废事件
|
|
|
$('.coupon-list-table').on('click', '.apply-cancel', function() {
|
|
|
$('#basicTable').on('click', '.apply-cancel', function() {
|
|
|
var that = this,
|
|
|
applyId = $(this).parents('.operate').data('id');
|
|
|
applyId = $(this).data('id');
|
|
|
|
|
|
$('#cancel-modal').modal();
|
|
|
$('#cancel-modal').on('click', '.btn-primary', function() {
|
...
|
...
|
@@ -302,14 +177,8 @@ exports.init = function() { |
|
|
reason: reason
|
|
|
},
|
|
|
success: function(data) {
|
|
|
listOperate(data, function() {
|
|
|
var $operate = $(that).parents('.operate');
|
|
|
|
|
|
$operate.attr('class', 'operate');
|
|
|
$operate.siblings('.state').find('.state-title').text('作废');
|
|
|
$operate.siblings('.state').find('.state-reason').text(reason);
|
|
|
window.location.reload();
|
|
|
});
|
|
|
$('#cancel-modal').modal('hide');
|
|
|
g.reload();
|
|
|
}
|
|
|
})
|
|
|
});
|
...
|
...
|
@@ -317,11 +186,11 @@ exports.init = function() { |
|
|
|
|
|
|
|
|
//通过事件
|
|
|
$('.coupon-list-table').on('click', '.apply-success', function() {
|
|
|
$('#basicTable').on('click', '.apply-success', function() {
|
|
|
var that = this,
|
|
|
$listBtn,
|
|
|
applyId = $(this).parents('.operate').data('id'),
|
|
|
applyState = $(this).parents('.operate').data('state');
|
|
|
applyId = $(this).data('id'),
|
|
|
applyState = $(this).data('state');
|
|
|
|
|
|
$('#success-modal').modal();
|
|
|
$('#success-modal').on('click', '.btn-primary', function() {
|
...
|
...
|
@@ -334,13 +203,8 @@ exports.init = function() { |
|
|
status: 1 //审核通过
|
|
|
},
|
|
|
success: function(data) {
|
|
|
listOperate(data, function() {
|
|
|
var $operate = $(that).parents('.operate');
|
|
|
|
|
|
$operate.removeClass('wait').addClass('success');
|
|
|
$operate.siblings('.state').find('.state-title').text('审核通过');
|
|
|
window.location.reload();
|
|
|
});
|
|
|
$('#success-modal').modal('hide');
|
|
|
g.reload();
|
|
|
}
|
|
|
})
|
|
|
});
|
...
|
...
|
@@ -379,11 +243,9 @@ exports.init = function() { |
|
|
});
|
|
|
|
|
|
//驳回事件
|
|
|
$('.coupon-list-table').on('click', '.apply-back', function() {
|
|
|
$('#basicTable').on('click', '.apply-back', function() {
|
|
|
var that = this,
|
|
|
applyId = $(this).parents('.operate').data('id');
|
|
|
|
|
|
console.log(11);
|
|
|
applyId = $(this).data('id');
|
|
|
|
|
|
$('#back-modal').modal();
|
|
|
$('#back-modal').on('click', '.btn-primary', function() {
|
...
|
...
|
@@ -402,14 +264,8 @@ exports.init = function() { |
|
|
reason: reason
|
|
|
},
|
|
|
success: function(data) {
|
|
|
listOperate(data, function() {
|
|
|
var $operate = $(that).parents('.operate');
|
|
|
|
|
|
$operate.attr('class', 'operate back');
|
|
|
$operate.siblings('.state').find('.state-title').text('驳回');
|
|
|
$operate.siblings('.state').find('.state-reason').text(reason);
|
|
|
window.location.reload();
|
|
|
});
|
|
|
$('#back-modal').modal('hide');
|
|
|
g.reload();
|
|
|
}
|
|
|
})
|
|
|
})
|
...
|
...
|
|