course_store.js
8.3 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
178
define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
var Controller = {
index: function () {
// 初始化表格参数配置
Table.api.init({
extend: {
index_url: 'course_store/index' + location.search,
add_url: 'course_store/add',
edit_url: 'course_store/edit',
del_url: 'course_store/del',
detail_url: 'course_sign/index',
import_url: 'course_sign/import',
table: 'course_store',
}
});
var table = $("#table");
// 初始化表格
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url,
pk: 'id',
sortName: 'id',
search: true,
showExport: false,
commonSearch: false,
searchFormVisible: false,
clickToSelect: false,
dblClickToEdit: false,
columns: [
[
{checkbox: true},
{field: 'id', title: __('Id')},
{field: 'course.name', title: __('Course_id')},
{field: 'store.name', title: __('Store_id')},
{field: 'date', title: __('Date'), operate: 'RANGE', addclass: 'datetimerange'},
{field: 'time_start', title: __('Time_start')},
{field: 'count', title: __('Count')},
{field: 'notify_count', title: __('Notify_count')},
{field: 'sign_count', title: __('Sign_count')},
{field: 'time_end', title: __('Time_end')},
{field: 'status', title: __('Status'), formatter: function (value) {
var color = 'red';
if (value === 'new') {
color = 'green';
}
if (value === 'cancel') {
color = 'black';
}
return '<span style="color:' + color + '">' + __(value) + '</span>';
}},
{
field : 'operate', title: __('Operate'), table: table, buttons: [
{
name : 'publish',
text : '发布',
title : __('Publish'),
icon : 'fa fa-check',
classname: 'btn btn-xs btn-primary btn-publish',
}, {
name : 'detail',
text : __('Detail'),
icon : 'fa fa-list',
classname: 'btn btn-info btn-xs btn-detail btn-dialog',
}
],
events: Table.api.events.operate, formatter: function (value, row, index) {
var that = $.extend({}, this);
that.buttons[0].extend = 'data-publish-id="' + row.id + '" data-publish-status="' + row.status + '"';
that.buttons[1].url = 'course_sign/index?ids=' + row.id;
var table = $(that.table).clone(true);
if (row.status === 'confirmed') {
$(table).data("operate-edit", null);
$(table).data("operate-del", null);
that.buttons[0].text = '取消';
}
if (row.status === 'cancel') {
$(table).data("operate-edit", null);
$(table).data("operate-del", null);
$(table).data("operate-publish", null);
}
if (row.status === 'new') {
$(table).data("operate-detail", null);
}
that.table = table;
return Table.api.formatter.operate.call(that, value, row, index);
}
}
]
]
});
// 为表格绑定事件
Table.api.bindevent(table);
//发布
$(document).on("click",".btn-publish",function (e) {
var id = $(this).data('publish-id');
var status = $(this).data('publish-status');
e.stopPropagation();
e.preventDefault();
//事件冒泡阻止
var that = this;
var table = $(that).closest('table');
var options = table.bootstrapTable('getOptions');
if(status === 'confirmed'){
Layer.open({title: '取消', content: '是否取消此课程', btn: '确定',yes:function (row) {
$.ajax({
type : "POST",
url : "course_store/publish",
data : {
id : id
},
dataType: "json",
success : function (data) {
// console.log(data);
if (data.code === 1) {
Layer.msg('取消成功');
Layer.closeAll();
$('.btn-refresh').trigger('click')
} else {
Layer.msg('取消失败');
Layer.closeAll()
}
}
})
}})
}
if(status === 'new'){
Layer.open({title: '发布', content: '是否发布此课程', btn: '确定',yes:function (row) {
$.ajax({
type : "POST",
url : "course_store/publish",
data : {
id : id
},
dataType: "json",
success : function (data) {
// console.log(data);
if (data.code === 1) {
Layer.msg('发布成功');
Layer.closeAll();
$('.btn-refresh').trigger('click')
} else {
Layer.msg('发布失败');
Layer.closeAll()
}
}
})
}})
}
});
},
add: function () {
Controller.api.bindevent();
$(document).on("dp.change", "#add-form .datetimepicker", function () {
$(this).parent().prev().find("input").trigger("change");
});
$(document).on("fa.event.appendfieldlist", "#add-form .btn-append", function (e, obj) {
Form.events.selectpage(obj);
Form.events.datetimepicker(obj);
});
},
edit: function () {
Controller.api.bindevent();
},
api: {
bindevent: function () {
Form.api.bindevent($("form[role=form]"));
},
},
};
return Controller;
});