search.matchWords.Index.js
5.05 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
webpackJsonp([150],[
/* 0 */
/***/ function(module, exports, __webpack_require__) {
/*
*@time: 2016-11-09 11:09:56
*@author: LiQZ
* App.template
*/
var $ = __webpack_require__(1), common = __webpack_require__(2);
var artTemplate = common.artTemplate;
// 下拉框
new common.dropDown({
el: "#status"
});
new common.dropDown({
el: "#time_status"
});
$.timepicker.datetimeRange($('#start_time'), $('#end_time'));
var tableGird = new common.grid({
el: "#table-box",
parms: function() {
return {
matchWordName: $("#matchWordName").val(),
status: $("#status").val(),
timeStatus: $("#time_status").val(),
startTime: timeToSeconds($("#start_time").val()),
endTime: timeToSeconds($("#end_time").val()),
}
},
columns: [
{ display: "ID", name: "id" },
{ display: "匹配词", name: "matchWordName"},
{ display: "PC链接", name: "matchPcUrl"},
{ display: "移动端链接", name:"matchAppUrl"},
{ display: "开启状态", name:"status", render: function(item) {
if (item.status == 0) {return "开启"; } else { return "关闭"; }
}},
{ display: "时间状态", name:"status", render: function(item) {
var now = Date.parse(new Date())/1000;
// 未开始
if (item.startTime > now) {
return "未开始";
}
// 进行中
if (item.startTime <= now && item.endTime >= now) {
return "进行中";
}
// 已结束
if (item.endTime < now) {
return "已结束";
}
return "时间设置错误";
}},
{ display: "开始时间", name:"startTime", render: function(item) {
return common.util.__secondsFormat(item.startTime);
}},
{ display: "结束时间", name:"endTime", render: function(item) {
return common.util.__secondsFormat(item.endTime);
}},
{ display: "操作", render: function(items) {
var HtmArr = [];
HtmArr.push('<a href="javascript:void(0);" data-index="' + items.__index + '" class="btn btn-primary btn-xs btn_edit">编辑</a>');
if (items.status == 0) {
HtmArr.push('<a href="javascript:;" data-id="' + items.id + '" class="btn btn-danger btn-xs close-btn">关闭</a>');
} else {
HtmArr.push('<a href="javascript:;" data-id="' + items.id + '" class="btn btn-success btn-xs open-btn">开启</a>');
}
return HtmArr.join('');
}
}]
});
tableGird.init('/search/matchWords/list');
$(document).on("click", "#filter-btn", function () {
tableGird.reload();
});
//开启
$('#table-box').on('click', '.open-btn', function() {
var param = {
id: $(this).data('id'),
status: '0'
}
common.util.__ajax({
url: '/search/matchWords/triggerStatus',
data: param
}, function(res) {
tableGird.reload();
});
});
//关闭
$('#table-box').on('click', '.close-btn', function() {
var param = {
id: $(this).data('id'),
status: '1'
}
common.util.__ajax({
url: '/search/matchWords/triggerStatus',
data: param
}, function(res) {
tableGird.reload();
});
});
function timeToSeconds(time) {
if (time) {
time = time.replace(/-/g,'/'); // 通用性好一点
return new Date(time).getTime() / 1000;
}
}
/**************************************
* 添加编辑
**************************************/
var Bll = {
toast:function(url, item, hint) {
var e = new common.edit("#baseform");
var dialog = common.dialog.confirm(hint, artTemplate("template", item), function() {
e.submit(url, function (option) {
console.log(option.data);
option.data.startTime = new Date(option.data.startTime).getTime() / 1000;
option.data.endTime = new Date(option.data.endTime).getTime() / 1000;
option.success=function() {
dialog.close();
tableGird.reload();
};
option.error=function(){};
});
return false;
});
e.on("validate", function() {
var matchWordName = $("#baseform").find("#matchWordName").val();
if (matchWordName.indexOf(",") >= 0) {
return "请使用英文 , 分割";
}
});
e.init();
}
};
$('#btn_add').on('click', function() {
var item = { "status": 0 }; // 默认开启
Bll.toast('/search/matchWords/save', item, "创建匹配词");
});
$(document).on('click', '.btn_edit', function() {
var item = tableGird.rows[$(this).data("index")];
Bll.toast('/search/matchWords/save', item, "编辑匹配词");
});
/***/ }
]);