提交 | 用户 | 时间
|
062075
|
1 |
|
A |
2 |
window.I = { |
|
3 |
personModal:$("#personModal"), |
|
4 |
addPerson: $("#addPerson"), |
|
5 |
sxBtn: $("#sxBtn"), |
|
6 |
tempVehicleSaveBtn:$("#tempVehicleSaveBtn"), |
|
7 |
businessNo: $("#businessNo").val(), |
|
8 |
vehicleId: $("#vehicleId").val(), |
|
9 |
} |
|
10 |
|
|
11 |
var Obj = { |
|
12 |
id: null, |
|
13 |
businessNo: I.businessNo, |
|
14 |
vehicleId: I.vehicleId, |
|
15 |
userName: null, |
|
16 |
idCard: '', |
|
17 |
phone: '', |
|
18 |
province: '', |
|
19 |
city: '', |
|
20 |
area: '', |
|
21 |
street: '', |
|
22 |
provinceCityArea: '', |
|
23 |
} |
|
24 |
|
|
25 |
// 星期一待做 1: 城市选择器 2、验证数据 3、配车后提示人员添加-车辆任务人员添加 4、发卡页面添加人员 5、做一个统一查询页面 6、业务单页面弹出展示 |
|
26 |
var ViewModel = function() { |
|
27 |
var self = this; |
|
28 |
self.list = ko.observableArray(); |
|
29 |
self.o = ko.observable(ko.mapping.fromJS(Obj)); |
|
30 |
self.toAddPersons = function () { |
|
31 |
var o = ko.mapping.fromJS(Obj) |
|
32 |
vm.o(o) |
|
33 |
I.personModal.modal("show"); |
|
34 |
} |
|
35 |
self.showPerson = function (item) { |
|
36 |
getById(item); |
|
37 |
} |
|
38 |
self.delPerson = function (item) { |
|
39 |
delPerson(item); |
|
40 |
} |
|
41 |
} |
|
42 |
|
|
43 |
$(function () { |
|
44 |
window.vm = new ViewModel(); |
|
45 |
ko.applyBindings(vm); |
|
46 |
autoHeight(); |
|
47 |
getVehiclePersonList(); |
|
48 |
pageInit(); |
|
49 |
}); |
|
50 |
function isIdCardNo(value) { |
|
51 |
return /^[1-9]\d{5}(18|19|20|(3\d))\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/.test(value); |
|
52 |
} |
|
53 |
function pageInit() { |
|
54 |
jQuery.validator.addMethod("isIdCardNo", function (value, element){ |
|
55 |
return this.optional(element) || isIdCardNo(value); |
|
56 |
},"请正确输入您的身份证号码"); |
|
57 |
I.tempVehicleSaveBtn.on("click",function (e){ |
|
58 |
e.preventDefault(); |
|
59 |
if (valid()) { |
|
60 |
var o = ko.mapping.toJS(vm.o()); |
|
61 |
if (o.id) update(o); |
|
62 |
else add(o); |
|
63 |
} |
|
64 |
}) |
|
65 |
I.sxBtn.on("click",function(e){ |
|
66 |
getVehiclePersonList(); |
|
67 |
let $this = $(this) |
|
68 |
$this.attr("disabled",""); |
|
69 |
setTimeout(function (){ $this.removeAttr("disabled")},5000); |
|
70 |
}) |
|
71 |
window.address_picker = new addressPicker({ |
|
72 |
id: "city", level: 3, data: cityData3, |
|
73 |
btnConfig: [{ |
|
74 |
text: '清除数据', click: function () { |
|
75 |
address_picker.clearSelectedData(); |
|
76 |
$("#city").val(''); |
|
77 |
} |
|
78 |
}] |
|
79 |
}); |
|
80 |
address_picker.on("click",function () { |
|
81 |
var obj = address_picker.getCurrentObject(); |
|
82 |
if(obj.level === 3) { |
|
83 |
var val = address_picker.getTotalValueAsText(); |
|
84 |
$("#city").val(val); |
|
85 |
setProvinceCityArea(val); |
|
86 |
} |
|
87 |
}) |
|
88 |
I.personModal.on('hidden.bs.modal', function (e) { |
|
89 |
$("#city").val(''); |
|
90 |
clearError(); |
|
91 |
}); |
|
92 |
$("#city").on("click",function(event){ |
|
93 |
var display = $(".adp-wraper").css("display"); |
|
94 |
setTimeout(function () { |
|
95 |
$(document).one("click", |
|
96 |
function () { |
|
97 |
// $(".adp-wraper").hide(); |
|
98 |
address_picker.hide(); |
|
99 |
}); |
|
100 |
},300); |
|
101 |
event.stopPropagation(); //阻止事件向上冒泡 |
|
102 |
}) |
|
103 |
|
|
104 |
} |
|
105 |
function setProvinceCityArea(val){ |
|
106 |
if(!val || val.trim()=='') { |
|
107 |
vm.o().province(''); |
|
108 |
vm.o().city(''); |
|
109 |
vm.o().area(''); |
|
110 |
return; |
|
111 |
} |
|
112 |
var arr = val.split("/") |
|
113 |
for(var i=0,len=arr.length;i<len;i++) { |
|
114 |
if(i==0) vm.o().province(arr[i].trim()); |
|
115 |
if(i==1) vm.o().city(arr[i].trim()); |
|
116 |
if(i==2) vm.o().area(arr[i].trim()); |
|
117 |
} |
|
118 |
} |
|
119 |
function getVehiclePersonList () { |
|
120 |
$.post("/businessVehiclePerson/list.htm", {vehicleId: I.vehicleId, businessNo: I.businessNo}, |
|
121 |
function (data, textStatus, jqXHR) { |
|
122 |
if (data.code >= 1) { |
|
123 |
swal({title: '', text: data.errmsg, type: 'error', confirmButtonText: '确定'}); |
|
124 |
return; |
|
125 |
} |
|
126 |
if (data.code == 0) { |
|
127 |
vm.list.removeAll() |
|
128 |
data.list.forEach(l=>{ |
|
129 |
l.provinceCityArea = l.province + l.city + l.area + " " + l.street |
|
130 |
}); |
|
131 |
if(isList(data.list)) vm.list.push(...data.list); |
|
132 |
} |
|
133 |
}) |
|
134 |
} |
|
135 |
|
|
136 |
function getById(item){ |
|
137 |
$.post("/businessVehiclePerson/get.htm", {id: item.id}, |
|
138 |
function (data, textStatus, jqXHR) { |
|
139 |
if (data.code >= 1) { |
|
140 |
swal({title: '', text: data.errmsg, type: 'error', confirmButtonText: '确定'}); |
|
141 |
return; |
|
142 |
} |
|
143 |
if (data.code == 0) { |
|
144 |
I.personModal.modal("show"); |
|
145 |
var item = data.item; |
|
146 |
$("#city").val(item.province + " / " + item.city + " / " + item.area) |
|
147 |
var arr = getProvinceCityArea(item.province,item.city,item.area); |
|
148 |
address_picker.setSelectedData(arr); |
|
149 |
console.log(arr) |
|
150 |
var newItem = ko.mapping.fromJS(item) |
|
151 |
vm.o(newItem); |
|
152 |
getVehiclePersonList(); |
|
153 |
} |
|
154 |
}) |
|
155 |
} |
|
156 |
|
|
157 |
function delPerson(item) { |
|
158 |
swal({ |
|
159 |
title: "是否确认删除?", text: "", type: "warning", |
|
160 |
showCancelButton: true, |
|
161 |
confirmButtonColor: "#1c84c6", |
|
162 |
confirmButtonText: "确定", |
|
163 |
cancelButtonText: "取消", |
|
164 |
closeOnConfirm: true, |
|
165 |
closeOnCancel: true, |
|
166 |
}, function (isConfirm) { |
|
167 |
if (isConfirm) { |
|
168 |
$.post("/businessVehiclePerson/del.htm", {id: item.id}, |
|
169 |
function (data, textStatus, jqXHR) { |
|
170 |
if (data.code >= 1) { |
|
171 |
swal({title: '', text: data.errmsg, type: 'error', confirmButtonText: '确定'}); |
|
172 |
return; |
|
173 |
} |
|
174 |
if (data.code == 0) { |
|
175 |
parent.showErrmsg("删除成功!"); |
|
176 |
getVehiclePersonList(); |
|
177 |
} |
|
178 |
}) |
|
179 |
} |
|
180 |
}); |
|
181 |
} |
|
182 |
function update() { |
|
183 |
var o = ko.mapping.toJS(vm.o()); |
|
184 |
$.post("/businessVehiclePerson/update.htm", o, |
|
185 |
function (data, textStatus, jqXHR) { |
|
186 |
if (data.code >= 1) { |
|
187 |
swal({title: '', text: data.errmsg, type: 'error', confirmButtonText: '确定'}); |
|
188 |
return; |
|
189 |
} |
|
190 |
if (data.code == 0) { |
|
191 |
parent.showErrmsg("更新成功!"); |
|
192 |
I.personModal.modal("hide"); |
|
193 |
getVehiclePersonList(); |
|
194 |
} |
|
195 |
}) |
|
196 |
} |
|
197 |
|
|
198 |
function getProvinceCityArea(province,city,area){ |
|
199 |
let array = [] |
|
200 |
cityData3.forEach(({text,value,children}) =>{ |
|
201 |
if(text === province) { array[0] = value; |
|
202 |
children.forEach(({text,value,children}) => { |
|
203 |
if(text === city) { array[1] = value; |
|
204 |
children.forEach(({text,value}) => { |
|
205 |
if(text === area) { array[2] = value;} |
|
206 |
}); |
|
207 |
} |
|
208 |
}); |
|
209 |
} |
|
210 |
}) |
|
211 |
return array; |
|
212 |
} |
|
213 |
|
|
214 |
function add(item) { |
|
215 |
$.post("/businessVehiclePerson/add.htm", item, |
|
216 |
function (data, textStatus, jqXHR) { |
|
217 |
if (data.code >= 1) { |
|
218 |
swal({title: '', text: data.errmsg, type: 'error', confirmButtonText: '确定'}); |
|
219 |
return; |
|
220 |
} |
|
221 |
if (data.code == 0) { |
|
222 |
parent.showErrmsg("新增成功!"); |
|
223 |
I.personModal.modal("hide"); |
|
224 |
getVehiclePersonList(); |
|
225 |
} |
|
226 |
}) |
|
227 |
} |
|
228 |
|
|
229 |
|
|
230 |
function valid(){ |
|
231 |
var isValid = false; |
|
232 |
var iF = $('#form'); |
|
233 |
iF.validate({ |
|
234 |
rules: { |
|
235 |
'userName': { |
|
236 |
required: true, |
|
237 |
// isPlateNumber: true |
|
238 |
}, |
|
239 |
'idCard': { |
|
240 |
required: true, |
|
241 |
isIdCardNo: true, |
|
242 |
}, |
|
243 |
'dataPhone': { |
|
244 |
required: true, |
|
245 |
isPhone: true |
|
246 |
}, |
|
247 |
'street': { |
|
248 |
required: true, |
|
249 |
}, |
|
250 |
'city': { |
|
251 |
required: true, |
|
252 |
} |
|
253 |
}, |
|
254 |
messages: { |
|
255 |
'userName': { |
|
256 |
required: '不能为空!', |
|
257 |
}, |
|
258 |
'idCard': { |
|
259 |
required: '不能为空!', |
|
260 |
isIdCardNo: '身份证号码不正确' |
|
261 |
}, |
|
262 |
'dataPhone': { |
|
263 |
required: '不能为空!', |
|
264 |
isPhone: '手机号不正确!' |
|
265 |
}, |
|
266 |
'street': { |
|
267 |
required: '不能为空!', |
|
268 |
}, |
|
269 |
'city': { |
|
270 |
required: '不能为空!', |
|
271 |
} |
|
272 |
}, |
|
273 |
errorPlacement: function (err, element) { |
|
274 |
var p = element.parents('.form-group').eq(0); |
|
275 |
var d = p.find('.text-error').eq(0); |
|
276 |
d.css('color', '#D9534F'); |
|
277 |
err.appendTo(d); |
|
278 |
} |
|
279 |
}) |
|
280 |
isValid = iF.valid(); |
|
281 |
return isValid; |
|
282 |
} |
|
283 |
|
|
284 |
|
|
285 |
function clearError() { |
|
286 |
$('#form input').removeClass('error'); |
|
287 |
$('#form .text-error').html(''); |
|
288 |
} |
|
289 |
|
|
290 |
function autoHeight() { |
|
291 |
$('.page-content').css('min-height', $(parent.window).height() - 117); |
|
292 |
$('.table-responsive').css('height', $(parent.window).height() - 275); |
|
293 |
$('.split').css('left', $('.table-vehicleId').width() + 12); |
|
294 |
} |