orders.js
11.6 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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
var Controller = {
index: function () {
// 初始化表格参数配置
Table.api.init({
extend: {
index_url: 'workorder/orders/index' + location.search,
add_url: 'workorder/orders/add',
edit_url: 'workorder/orders/edit',
del_url: 'workorder/orders/del',
multi_url: 'workorder/orders/multi',
import_url: 'workorder/orders/import',
records_url: 'workorder/orders/records',
table: 'workorder_orders',
}
});
var table = $("#table");
//默认字段
var columns = [
{checkbox: true},
{field: 'id', title: __('Id'), operate: false},
{
field: 'user.nickname',
title: __('User_id'),
addclass: 'selectpage',
extend: 'data-source="user/user/index" data-field="nickname"',
operate: '=',
formatter: Table.api.formatter.search
},
{
field: 'urgentrank.name',
title: __('Urgency'),
addclass: 'selectpage',
extend: 'data-source="workorder/urgentrank/index" data-field="name"',
operate: '=',
formatter: Table.api.formatter.search
},
{
field: 'category.name',
title: __('Category_id'),
addclass: 'selectpage',
extend: 'data-source="workorder/category/index" data-field="name"',
operate: '=',
formatter: Table.api.formatter.search
},
{
field: 'engineers.title',
title: __('Engineer_id'),
addclass: 'selectpage',
extend: 'data-source="workorder/engineers/index" data-field="title"',
operate: '=',
formatter: Controller.api.formatter.search
}
];
//动态追加字段
$.each(Config.fields, function (i, j) {
var data = {field: j.field, title: j.title, operate: 'like'};
//如果是图片,加上formatter
if (j.type == 'image') {
data.formatter = Table.api.formatter.image;
} else if (j.type == 'images') {
data.formatter = Table.api.formatter.images;
} else if (j.type == 'radio' || j.type == 'checkbox' || j.type == 'select' || j.type == 'selects') {
data.formatter = Controller.api.formatter.values;
data.extend = j.values;
let values_obj = {};
for (var item in j.values) {
values_obj[item] = j.values[item];
}
;
data.searchList = values_obj
}
columns.push(data);
});
columns.push({
field: 'status',
title: __('Status'),
searchList: {
"0": __('Status 0'),
"1": __('Status 1'),
"2": __('Status 2'),
"3": __('Status 3'),
"4": __('Status 4'),
"5": __('Status 5')
},
formatter: Table.api.formatter.status
});
columns.push({
field: 'updatetime',
sortable: true,
title: __('Updatetime'),
operate: 'RANGE',
addclass: 'datetimerange',
formatter: Table.api.formatter.datetime
});
columns.push({
field: 'createtime',
sortable: true,
title: __('Createtime'),
operate: 'RANGE',
addclass: 'datetimerange',
formatter: Table.api.formatter.datetime
});
//追加操作字段
columns.push({
field: 'operate',
title: __('Operate'),
table: table,
events: Table.api.events.operate,
formatter: Table.api.formatter.operate,
buttons: [
{
name: 'records',
title: '查看沟通记录',
classname: 'btn btn-xs btn-info btn-dialog',
icon: 'fa fa-file-text-o',
url: $.fn.bootstrapTable.defaults.extend.records_url,
}
]
});
// 初始化表格
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url,
pk: 'id',
sortName: 'id',
columns: columns
});
// 为表格绑定事件
Table.api.bindevent(table);
},
records: function () {
$.fn.popover.Constructor.DEFAULTS.sanitize = false;
$("[rel=engineer_popo]").popover({
trigger: 'manual',
title: this.title,
html: true,
content: function () {
let engineer_id = $(this).data('engineer_id');
return $('.engineer_info_' + engineer_id).html();
},
animation: true
}).on("mouseenter", function () {
var _this = this;
$(this).popover("show");
$(this).siblings(".popover").on("mouseleave", function () {
$(_this).popover('hide');
});
}).on("mouseleave", function () {
var _this = this;
setTimeout(function () {
if (!$(".popover:hover").length) {
$(_this).popover("hide")
}
}, 100);
});
$("[rel=userInfo_popo]").popover({
trigger: 'manual',
title: this.title,
html: true,
content: function () {
return $('.user_info').html();
},
animation: true
}).on("mouseenter", function () {
var _this = this;
$(this).popover("show");
$(this).siblings(".popover").on("mouseleave", function () {
$(_this).popover('hide');
});
}).on("mouseleave", function () {
var _this = this;
setTimeout(function () {
if (!$(".popover:hover").length) {
$(_this).popover("hide")
}
}, 100);
});
$(document).on('click', '.item_meta_text img', function (e) {
var img_obj = $(e.target)[0];
if (img_obj) {
var scrollTop = $(window).scrollTop();
layer.photos({
photos: {
"title": "图片预览",
"id": "recordimg",
data: [
{
"src": img_obj.src
}
]
},
end: function () {
$(window).scrollTop(scrollTop)
},
anim: 5
});
}
})
},
recyclebin: function () {
// 初始化表格参数配置
Table.api.init({
extend: {
'dragsort_url': ''
}
});
var table = $("#table");
// 初始化表格
table.bootstrapTable({
url: 'workorder/orders/recyclebin' + location.search,
pk: 'id',
sortName: 'id',
columns: [
[
{checkbox: true},
{field: 'id', title: __('Id')},
{field: 'title', title: __('Title'), align: 'left'},
{
field: 'deletetime',
title: __('Deletetime'),
operate: 'RANGE',
addclass: 'datetimerange',
formatter: Table.api.formatter.datetime
},
{
field: 'operate',
width: '130px',
title: __('Operate'),
table: table,
events: Table.api.events.operate,
buttons: [
{
name: 'Restore',
text: __('Restore'),
classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
icon: 'fa fa-rotate-left',
url: 'workorder/orders/restore',
refresh: true
},
{
name: 'Destroy',
text: __('Destroy'),
classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
icon: 'fa fa-times',
url: 'workorder/orders/destroy',
refresh: true
}
],
formatter: Table.api.formatter.operate
}
]
]
});
// 为表格绑定事件
Table.api.bindevent(table);
},
add: function () {
Controller.api.bindevent();
},
edit: function () {
Controller.api.bindevent();
},
api: {
bindevent: function () {
Form.api.bindevent($("form[role=form]"));
},
formatter: {
values: function (value, row, index) {
var extend = this.extend;
if (!value) {
return '';
}
var valueArr = value.toString().split(/,/);
var result = [];
$.each(valueArr, function (i, j) {
result.push(typeof extend[j] !== 'undefined' ? extend[j] : j);
});
return result.join(',');
},
search: function (value, row, index) {
if (!value) {
return '无';
} else {
var that = $.extend({}, this);
var table = $(that.table).clone(true);
that.table = table;
return Table.api.formatter.search.call(that, value, row, index);
}
}
}
}
};
return Controller;
});