index.js
4.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/**
* 品牌管理
*/
'use strict';
var $ = require('jquery'),
Handlebars = require('yoho.handlebars'),
grid = require('../common/grid'),
dropDown = require('../common/dropDown');
require('../util/jquery.simplePagination');
require('../util/datepicker')($);
require('../util/jquery.gritter');
exports.init = function() {
//下拉框
new dropDown({el: "#status"});
new dropDown({el: "#brand-level"});
new dropDown({
el:'#brand-id',
ajax:'brand'
});
//日期插件
$('.hasDatepicker').fdatepicker({
format: 'yyyy-mm-dd'
});
var btnAuthority=JSON.parse($("#btnAuthority").val());
var g = new grid({
el: '#basicTable',
size: 10,
parms: function() {
return {
brandId: $.trim($('#brand-id').val()) || '',
status: $.trim($('#status').val()) || '',
brandLevel: $.trim($('#brand-level').val()) || '',
startTime: $.trim($('#starttime').val()) || '',
endTime: $.trim($('#endtime').val()) || ''
};
},
columns: [
{display: "LOGO", name: "brandIco",render:function(item){
return '<img src="'+item.brandIco+'" width="100" height="60"/>'
}},
{display: '品牌名称', name: "brandName"},
{display: '英文名称', name: "brandNameEn"},
{display: '品牌级别', name: "brandLevel"},
{display: '调性分', name: "brandTonality"},
{display: '创建时间', name: "createTime", render: function(item) {
var date = new Date(item.createTime * 1000);
return date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate() + ' '
+ date.getHours() + ':' + date.getMinutes() + ':' + date.getSeconds();
}},
{display: '操作', name:"status", render: function(items) {
var HtmArr = [];
if (btnAuthority.edit) {
HtmArr.push('<a href="/erpproduct/brands/edit/'+ items.id+'"" class="btn btn-info btn-xs">编辑</a>');
}
if (items.status === 0) {
HtmArr.push('<a data-id="' + items.id + '" href="JavaScript:;" class="btn btn-warning btn-xs open-brand">开启品牌</a>');
}
if (items.status === 1) {
HtmArr.push('<a data-id="' + items.id + '" href="JavaScript:;" class="btn btn-danger btn-xs close-brand">关闭品牌</a>');
}
return HtmArr.join('');
}}
]
})
g.init($("#gridurl").val());
$("#filter-btn").click(function(){
location.hash = '';
g.reload();
});
function operateAjax(options, callback) {
$.ajax({
type: 'POST',
url: options.url,
data: {
id: options.id,
status: options.status
},
dataType: 'json'
}).then(function(res) {
if (res.code === 200) {
$.gritter.add({
title: '操作成功',
class_name: 'growl-success',
sticky: false,
time: '1000',
after_open: function() {
callback && callback();
}
});
} else {
$.gritter.add({
title: '操作失败',
class_name: 'growl-danger',
sticky: false,
time: '1000'
});
}
})
}
//关闭品牌操作
$('tbody').on('click', '.close-brand', function() {
var that = this,
id = $(that).data('id');
$(that).attr('disabled', true);
operateAjax({
url: '/brand/edit',
id: id,
status: 0
}, function() {
g.reload();
})
});
//开启品牌操作
$('tbody').on('click', '.open-brand', function() {
var that = this,
id = $(that).data('id');
$(that).attr('disabled', true);
operateAjax({
url: '/brand/edit',
id: id,
status: 1
}, function() {
g.reload();
})
});
}