updateDeviceModelCtrl.js
6.86 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
(function (angular) {
function updateDeviceModelCtrl($scope, parentData,$rootScope, customerService, $uibModalInstance) {
console.log(parentData)
// 3-轩宇
$scope.channelType = $rootScope.loginUser.channelConfig.channelType
$scope.required = ($scope.channelType == 3)
// 非轩宇渠道,“设备安装时当前里程”、“下次保养里程”、“下次保养时间”、“上次保养里程”、“上次保养时间”为非必填项。
// 但若只要有其中一项为非空。则此5个字段,必须全部填入。
$scope.otherRequired = false
$scope.phoneError = false
$scope.addData = {
imei: '',
name: '',
phone: '',
plateNum: '',
standNo: '',
gender:'',
isChange:''
};
$scope.model = {
}
function loadCarList() {
if (parentData.vehicleBrandId) {
$scope.model.carBrand = {id:parentData.vehicleBrandId, name: parentData.vehicleBrand};
$scope.changeCarBrand(parentData.vehicleBrandId);
}
if (parentData.vehicleChildsBrandId) {
$scope.model.carSmallBrand = {id:parentData.vehicleChildsBrandId, name: parentData.vehicleChildsBrandName};
$scope.changeCarSmallBrand(parentData.vehicleChildsBrandId)
}
if (parentData.vehicleSeriesId) {
$scope.model.carSeries = {id:parentData.vehicleSeriesId, name: parentData.vehicleSeriesName};
$scope.changeCarSeries(parentData.vehicleSeriesId)
}
if (parentData.vehicleTypeId) {
$scope.model.carType = {id:parentData.vehicleTypeId, name: parentData.vehicleTypeName};
}
}
function load() {
console.log( $scope.carBrandOptions)
$scope.addData.imei = parentData.imei;
$scope.addData.name = parentData.name;
$scope.addData.phone = parentData.phone;
$scope.addData.plateNum = parentData.plateNum;
$scope.addData.standNo = parentData.standNo;
$scope.addData.gender = parentData.gender;
$scope.addData.isChange = parentData.isChange;
$scope.isAuth = ( parentData.isAuth == '1' || parentData.isAuth == 1);
}
load();
$scope.form = {
nextTime: '',
lastTime: ''
}
$scope.today = moment()
$scope.submitted = false;
$scope.handleAddClose = function () {
$uibModalInstance.close();
}
$scope.model = {};
//获取品牌车型
function getAllVehicleBrand() {
return new Promise(function (resolve, reject) {
customerService.getAllVehicleBrand(function (res) {
$scope.carBrandOptions = res.data;
resolve();
});
})
}
//车辆品牌值改变事件
$scope.changeCarBrand = function (id) {
for (var i = 0; i < $scope.carBrandOptions.length; i++) {
if ($scope.carBrandOptions[i].id == id) {
$scope.carSmallBrandOptions = JSON.parse(JSON.stringify($scope.carBrandOptions[i].childs));
break;
}
}
$scope.carSeriesOptions = [];
$scope.carTypeOptions = [];
$scope.model.carSmallBrand = '';
$scope.model.carSeries = '';
$scope.model.carType = '';
};
//车辆品牌值改变事件
$scope.changeCarSmallBrand = function (id) {
for (var i = 0; i < $scope.carSmallBrandOptions.length; i++) {
if ($scope.carSmallBrandOptions[i].id == id) {
$scope.carSeriesOptions = JSON.parse(JSON.stringify($scope.carSmallBrandOptions[i].childs));
break;
}
}
$scope.carTypeOptions = [];
$scope.model.carSeries = '';
$scope.model.carType = '';
};
//车系值改变事件
$scope.changeCarSeries = function (id) {
customerService.getCardType({
carSeriesId: id
}, function (res) {
if (res.data) {
$scope.carTypeOptions = res.data;
}
});
$scope.model.carType = '';
};
// 必填项校验
function checkColumn() {
var flag = true;
var requiredAttr = [
'name',
'phone',
'standNo'
]
for (var i = 0; i < requiredAttr.length; i++) {
if (!$scope.addData[requiredAttr[i]]) {
flag = false;
return flag;
}
}
/*var reg = new RegExp("^[1][3,4,5,6,7,8,9][0-9]{9}$");
console.log(reg.test($scope.addData.phone))
$scope.phoneError = false;
if (!reg.test($scope.addData.phone)) {
$scope.phoneError = true;
}*/
var requiredXuanyuAttr = [
'plateNum',
'gender',
'isChange'
]
if ($scope.required) {
for (var i = 0; i < requiredXuanyuAttr.length; i++) {
if (!$scope.addData[requiredXuanyuAttr[i]]) {
flag = false;
return flag;
}
}
}
return flag;
};
/**
* 下拉框绑定的值是一个对象,需要获取值
* @param fieldName
* @returns {*}
*/
function getSelectValue(objName, id, tempObjName) {
var obj = tempObjName ? $scope.tempModel[tempObjName] : $scope.model[objName];
return (obj && obj[id]) ? obj[id] : '';
}
/**
* 获取参数(所有查询都从此获取)
*/
function getParams() {
$scope.addData.id = parentData.id;
$scope.addData.vehicleBrandId = getSelectValue('carBrand', 'id');
$scope.addData.vehicleBrand = getSelectValue('carBrand', 'name');
$scope.addData.vehicleChildsBrandId = getSelectValue('carSmallBrand', 'id');
$scope.addData.vehicleChildsBrandName = getSelectValue('carSmallBrand', 'name');
$scope.addData.vehicleSeriesId = getSelectValue('carSeries', 'id');
$scope.addData.vehicleSeriesName = getSelectValue('carSeries', 'name');
$scope.addData.vehicleTypeId = getSelectValue('carType', 'id');
$scope.addData.vehicleTypeName = getSelectValue('carType', 'name');
// return params;
}
$scope.handleAddConfirm = function () {
console.log($scope.model)
$scope.submitted = true;
getParams();
var flag = checkColumn();
// console.log(flag)
if (!flag) {
return;
}
var params = JSON.parse(JSON.stringify($scope.addData));
console.log(params)
customerService.updateDevice(params, function (res) {
if (res.returnCode == '0') {
$uibModalInstance.close(true);
swal({
title: "添加成功",
text: "",
type: "success",
timer: 2000,
showConfirmButton: false
});
} else {
swal({
title: res.message,
text: "",
type: 'error',
confirmButtonText: '确定',
showConfirmButton: true
});
}
})
};
(function () {
getAllVehicleBrand().then(() => {
loadCarList();
});
})();
}
angular.module('customer').controller('updateDeviceModelCtrl', updateDeviceModelCtrl);
})(angular);