area_extend.js
9.0 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
define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
var Controller = {
index: function () {
// 初始化表格参数配置
Table.api.init({
extend: {
index_url: 'area_extend/index' + location.search,
add_url: 'area_extend/add' + location.search,
edit_url: 'area_extend/edit' + location.search,
del_url: 'area_extend/del',
multi_url: 'area_extend/multi',
table: 'area_extend',
},
queryParams:function(params){
var filter = JSON.parse(params.filter);
var op = JSON.parse(params.op);
var level = Fast.api.query('level');
var province_id = Fast.api.query('province_id');
var city_id = Fast.api.query('city_id');
if(province_id) filter.province_id = province_id;
if(city_id) filter.city_id = city_id;
if(level) filter.level = level;
else filter.level = 1;
params.filter = JSON.stringify(filter);
params.op = JSON.stringify(op);
return params;
}
});
var table = $("#table");
// 初始化表格
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url,
pk: 'id',
sortName: 'weigh',
columns: [
[
{checkbox: true},
{field: 'id', title: __('Id')},
{field: 'province.name', title: __('Province_id')},
{field: 'city.name', title: __('City_id')},
{field: 'county.name', title: __('County_id')},
{field: 'level', title: __('Level'), operate: false,visible:false},
{
field: 'is_special',
title: __('Is_special'),
searchList: {"1": __('Is_special 1'), "2": __('Is_special 2')},
formatter: Table.api.formatter.normal, operate: false
},
{field: 'postage1', title: __('Postage1'), operate: false},
{field: 'postage2', title: __('Postage2'), operate: false},
{field: 'starttime1', title: __('Starttime1'), operate: false},
{field: 'endtime1', title: __('Endtime1'), operate: false},
{field: 'starttime2', title: __('Starttime2'), operate: false},
{field: 'endtime2', title: __('Endtime2'), operate: false},
{field: 'weigh', title: __('Weigh'), operate: false},
{
field: 'createtime',
title: __('Createtime'),
operate: false,
addclass: 'datetimerange',
formatter: Table.api.formatter.datetime
},
{
field: 'updatetime',
title: __('Updatetime'),
operate: false,
addclass: 'datetimerange',
formatter: Table.api.formatter.datetime
},
{
field: 'operate',
title: __('Operate'),
table: table,
events: Table.api.events.operate,
formatter: Table.api.formatter.operate,
buttons: [
{
name: 'level', title: '市级信息', icon: 'fa fa-bars',
classname: 'btn btn-xs btn-warning btn-dialog',
url: 'area_extend/index?province_id={province_id}&level=2',
extend: "data-area='[\"80%\",\"90%\"]'",
hidden:function (row) {
if(row.level == 1) return false;
else return true;
}
},{
name: 'level', title: '县级信息', icon: 'fa fa-bars',
classname: 'btn btn-xs btn-warning btn-dialog',
url: 'area_extend/index?province_id={province_id}&city_id={city_id}&level=3',
extend: "data-area='[\"80%\",\"91%\"]'",
hidden:function (row) {
if(row.level == 2) return false;
else return true;
}
}
]
}
]
]
});
// 为表格绑定事件
Table.api.bindevent(table);
},
add: function () {
Controller.api.bindevent();
var province_id = Fast.api.query('province_id');
var city_id = Fast.api.query('city_id');
var level = Fast.api.query('level');
if(level == 2){
$('.city').show();
$("#c-province_id").val(province_id);
$("#c-province_id").attr('disabled',true);
$("#c-level").val(2);
$("#c-city_id").data("params", function (obj) {
return {custom: {pid: province_id}};
});
}else if(level == 3){
$('.city').show();
$('.county').show();
$("#c-province_id").val(province_id);
$("#c-city_id").val(city_id);
$("#c-province_id").attr('disabled',true);
$("#c-city_id").attr('disabled',true);
$("#c-level").val(3);
$("#c-county_id").data("params", function (obj) {
return {custom: {pid: city_id}};
});
}
$('#c-is_special').change(function () {
if ($(this).val() === '1'){
$('.send').show();
}else {
$('.send').hide();
}
});
},
edit: function () {
Controller.api.bindevent();
var province_id = Fast.api.query('province_id');
var city_id = Fast.api.query('city_id');
var level = Fast.api.query('level');
if(level == 2){
$('.city').show();
$("#c-province_id").val(province_id);
$("#c-province_id").attr('disabled',true);
$("#c-level").val(2);
$("#c-city_id").data("params", function (obj) {
return {custom: {pid: province_id}};
});
}else if(level == 3){
$('.city').show();
$('.county').show();
$("#c-province_id").val(province_id);
$("#c-city_id").val(city_id);
$("#c-province_id").attr('disabled',true);
$("#c-city_id").attr('disabled',true);
$("#c-level").val(3);
$("#c-county_id").data("params", function (obj) {
return {custom: {pid: city_id}};
});
}
$('#c-is_special').change(function () {
if ($(this).val() === '1'){
$('.send').show();
}else {
$('.send').hide();
}
});
// $("#c-city_id").data("params", function (obj) {
// var id = $("#c-province_id").val() ? $("#c-province_id").val() : -1;
// return {custom: {pid: id}};
// });
// $("#c-province_id").on('change', function () {
// $("#c-city_id").val('');
// $("#c-city_id_text").val('');
// $("#c-county_id").val('');
// $("#c-county_id_text").val('');
// });
// $("#c-county_id").data("params", function (obj) {
// var id = $("#c-city_id").val() ? $("#c-city_id").val() : -1;
// return {custom: {pid: id}};
// });
// $("#c-city_id").on('change', function () {
// $("#c-county_id").val('');
// $("#c-county_id_text").val('');
// });
},
api: {
bindevent: function () {
Form.api.bindevent($("form[role=form]"));
}
}
};
return Controller;
});