workorder.js
7.7 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
define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
var Controller = {
index: function () {
// 初始化表格参数配置
Table.api.init({
extend: {
index_url: 'inspection/workorder/index' + location.search,
add_url: 'inspection/workorder/add',
edit_url: 'inspection/workorder/edit',
del_url: 'inspection/workorder/del',
multi_url: 'inspection/workorder/multi',
import_url: 'inspection/workorder/import',
table: 'inspection_workorder',
}
});
var table = $("#table");
// 初始化表格
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url,
pk: 'id',
sortName: 'id',
columns: [
[
{checkbox: true},
{field: 'id', title: __('Id')},
{field: 'warning.title', title: __('Warning_id'), operate: 'LIKE'},
{field: 'lng', title: __('Lng'), operate: 'LIKE'},
{field: 'lat', title: __('Lat'), operate: 'LIKE'},
{field: 'message', title: __('Message'), operate: 'LIKE',events:{
// click事件 绑定到test1类上,e 事件对象, value 当前这个表格格子的值,row 当前行数据,index当前行索引值
'click .message-box':function (e,value,row,index) {
layer.open({
title:__('Message'),
type:1,
content:`<div style="padding: 10px 15px;">${value}</div>`,
area:['30%', '50%'],
});
}
},formatter:function (value, row, index) {
// value 当前这个表格格子的值,row 当前行数据,index当前行索引值
return `<div style="width:160px;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;">
<a href="javascript:void(0);" class="message-box">${value}</a>
</div>`;
}},
{field: 'images', title: __('Images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
{field: 'files', title: __('Files'), operate: false, formatter: function (value, row, index) {
value = value == null || value.length === 0 ? '' : value.toString();
var classname = typeof this.classname !== 'undefined' ? this.classname : 'img-sm img-center';
var arr = value != '' ? value.split(',') : [];
var html = [];
var suffix, url;
$.each(arr, function (i, value) {
value = Fast.api.cdnurl(value, true);
suffix = /[\.]?([a-zA-Z0-9]+)$/.exec(value);
suffix = suffix ? suffix[1] : 'file';
url = Fast.api.fixurl("ajax/icon?suffix=" + suffix);
html.push('<a href="' + value + '" target="_blank"><img src="' + url + '" class="' + classname + '"></a>');
});
return html.join(' ');
}
},
{field: 'staff.staff_name', title: __('Staff_id'), operate: 'LIKE'},
{field: 'start_time', title: __('Start_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
{field: 'end_time', title: __('End_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
{field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1'),"2":__('Status 2'),"3":__('Status 3'),"4":__('Status 4')}, formatter: Table.api.formatter.status},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
buttons:[
{
name: 'dealResult',//按钮name属性
text: '查看处理结果',//按钮文本
title: function (row) {
return row.warning_title + '处理结果'
},//窗口title
classname: 'btn btn-xs btn-primary btn-dialog',
icon: 'fa fa-list-alt',
url: 'inspection/workorder/dealList?id={id}',
//fastadmin js中设置弹窗大小
extend:' data-area=["80%","80%"]',
callback: function (data) {
// Layer.alert("接收到回传数据:" + JSON.stringify(data), {title: "回传数据"});
},
visible: function (row) {
let status = parseInt(row.status);
if (status === 0){
return false;
}else{
//返回true时按钮显示,返回false隐藏
return true;
}
}
},
]
}
]
]
});
// 为表格绑定事件
Table.api.bindevent(table);
},
add: function () {
Controller.api.bindevent();
},
edit: function () {
Controller.api.bindevent();
},
dealList: function () {
Controller.api.bindevent();
},
api: {
bindevent: function () {
//监听异常上报,自动填充数据
$('#c-warning_id').on('change',function () {
let warning_id = $('#c-warning_id').val();
Fast.api.ajax({
loading:false,
url:'inspection/workorder/getWarningById?id=' + warning_id,
success:function (ret) {
if (ret.code === 1){
$('#c-images').val(ret.data.cover_images);
$('#c-message').val(ret.data.message);
$('#c-lng').val(ret.data.lng);
$('#c-lat').val(ret.data.lat);
$('#c-staff_id').val(ret.data.staff_id);
$('#c-staff_id').selectPageRefresh();
}
}
})
});
Form.api.bindevent($("form[role=form]"));
}
}
};
return Controller;
});