liveModalCtrl.js
9.25 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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
(function(angular) {
function liveModalCtrl($scope, Utils, sendProConfig, DTColumnBuilder, DTOptionsBuilder, $http, $uibModalInstance, wechatauthService) {
console.log(sendProConfig)
var defaultConfig = {
pageTitle: '导入', //弹框标题
ajaxUrl: '', //导入服务地址
downloadType: '', //下载导入模板类型
importTemplate: '模版', //下载导入模板文件名
errorDown: '门店导入报错下载.xlsx' //导入excel错误文件名
};
$scope.sendProConfig = sendProConfig;
$scope.searchData = {
carBrand: '',
carSmallBrand: '',
keyword: ''
};
//已选-分页参数
$scope.firstPage = 1; //第一页
$scope.lastPage = 1; //最后页
$scope.pageSizeList = [10]; //分页大小选项
$scope.pageSize = $scope.pageSizeList[0]; //分页大小 - pageSize
$scope.total = 0; //分页总条数
$scope.pages = [];
$scope.pageNum = 3; //分页格子数量
$scope.page = 1; //当前页数 - pageNum
function setPage(length, amount, num, first) {
let pages = []
let page = Math.ceil(length / amount)
if (page <= num) {
for (var i = 1; i <= page; i++) {
pages.push(i)
}
}
if (page > num) {
for (var i = first; i < first + num; i++) {
pages.push(i)
}
}
return pages
}
// $scope.sizeChange = function (val) {
// $scope.model.pageSize = val
// $scope.sub(1)
// }
$scope.sub = function(page) {
$scope.firstPage = page >= $scope.pageNum ? page - Math.floor($scope.pageNum / 2) : 1
if (($scope.lastPage - $scope.pageNum) >= 0) {
if ($scope.firstPage > $scope.lastPage - $scope.pageNum) {
$scope.firstPage = $scope.lastPage - $scope.pageNum + 1
}
}
$scope.page = page
// $scope.model.pageNum = page
getMerchantList();
}
// 分页-end
// /**
// * 关闭弹框方法
// * */
$scope.handleClose = function() {
$uibModalInstance.dismiss(0);
};
$scope.handleConfirm = function() {
var selectedList = $scope.dtInstance.getSelectedList();
var param = {
liveId: $scope.sendProConfig.id,
merchants: []
}
selectedList.forEach(function(item) {
param.merchants.push({
merchantId: item.merchantId,
merchantName: item.merchantName
})
})
wechatauthService.shareLiveRoom(param, function(res) {
if (res.returnCode == '0') {
swal({
title: "操作成功",
text: "",
type: "success",
timer: 1000,
showConfirmButton: false
});
$uibModalInstance.close();
}
})
};
// 获取已分享门店
function sharedMerchants() {
var param = {
liveId: $scope.sendProConfig.id,
}
wechatauthService.sharedMerchants(param, function(res) {
console.log(res);
})
}
//获取品牌车型
function getAllVehicleBrand() {
return new Promise(function(resolve, reject) {
wechatauthService.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.searchData.carSmallBrand = '';
};
$scope.condition = {};
$scope.dtInstance = {};
$scope.selectingList = $scope.sendProConfig.selectedMerchant || [];
$scope.dtOption = {
id: 'merchantId',
selectingList: {
data: $scope.selectingList,
columns: [{
prop: 'merchantName',
title: '门店名称',
width: '80px',
ellipsis: true
}]
},
selectedList: {
data: $scope.sendProConfig.selectedMerchant,
columns: [{
prop: 'merchantName',
title: '门店名称',
width: '80px',
ellipsis: true
}]
}
};
$scope.tableCheck = true
//
$scope.proStoreList = []
$scope.handleSearch = function() {
getMerchantList()
}
$scope.handleReset = function() {
$scope.searchData = {
carBrand: '',
carSmallBrand: '',
keyword: ''
};
$scope.carSmallBrandOptions = [];
getMerchantList();
}
// $scope.importMerchant = [];
$scope.isShowErrorMsg = false;
$scope.importRes = {
succNum: 0,
failNum: 0
};
$scope.handleImportStore = function() {
var file = $("#file_asset_a")[0].files[0];
if (null == file) {
return;
}
var fileName = file.name
var b = '';
if (fileName) {
var a = fileName.split('.');
b = a[a.length - 1];
}
if (!fileName || b != 'xlsx') {
alert("文件格式不正确,请上传以.xlsx,.xls 为后缀名的文件。");
return;
};
$http({
url: 'newCar/boutique/importSendMerchant',
method: 'POST',
headers: {
'Content-Type': undefined
},
transformRequest: function() {
var formData = new FormData();
formData.append('file', file);
// console.log(file)
return formData;
}
}).success(function(data) {
// console.log(data)
// 删除倒数第一位开始的一个元素
if (data.returnCode == '0' && null != data.data) {
// console.log(data.data.list)
$scope.importRes = data.data
$scope.isShowErrorMsg = true;
var selectedIds = [];
var importMerchant = $scope.dtInstance.getSelectedList();
$scope.dtInstance.getSelectedList().forEach(function(item) {
selectedIds.push(item.merchantId)
})
data.data.list.forEach(function(item) {
if (!selectedIds.includes(item.merchantId)) {
importMerchant.push({
merchantId: Number(item.merchantId),
merchantName: item.merchantName
})
}
})
// console.log(importMerchant)
$scope.dtInstance.changeSelectingData(importMerchant, true);
$scope.dtInstance.selectAll(importMerchant, 'merchantId');
} else {
alert("上传失败,请重新上传");
}
});
$("#file_asset_a").val("");
}
/**
* 下载模板
* */
$scope.exportExcelTemplate = function() {
var data = {
downloadType: '19',
name: '门店模板'
};
var options = {
url: 'common/downloadTemplate'
};
Utils.exportExcel(options, data);
};
$scope.options = $.extend(defaultConfig, sendProConfig);
$scope.exportExcel = function() {
$http({
url: 'excelResultOut/export',
method: "GET", //接口方法
headers: {
'Content-type': 'application/json'
},
responseType: 'arraybuffer'
}).success(function(data, status, headers, config) {
var blob = new Blob([data], {
type: "application/vnd.ms-excel"
});
var objectUrl = URL.createObjectURL(blob);
var a = document.createElement('a');
document.body.appendChild(a);
a.setAttribute('style', 'display:none');
a.setAttribute('href', objectUrl);
var filename = $scope.options.errorDown;
a.setAttribute('download', filename);
a.click();
URL.revokeObjectURL(objectUrl);
}).error(function(data, status, headers, config) {});
};
/**
* 下拉框绑定的值是一个对象,需要获取值
* @param fieldName
* @returns {*}
*/
function getSelectValue(objName, id, tempObjName) {
var obj = tempObjName ? $scope.tempModel[tempObjName] : $scope.searchData[objName];
return (obj && obj[id]) ? obj[id] : '';
}
/**
* 获取参数(所有查询都从此获取)
*/
function getParams() {
var params = {}
params.carBrandId = getSelectValue('carBrand', 'id');
params.carChildsBrandId = getSelectValue('carSmallBrand', 'id');
return params;
}
$scope.loading = false
function getMerchantList() {
var params = getParams()
params.keyword = $scope.searchData.keyword
params.currentPage = $scope.page
params.pageSize = $scope.pageSize
wechatauthService.getMerchantList(params, function(res) {
$scope.total = res.data.total
$scope.lastPage = res.data.pages
$scope.pages = setPage($scope.total, $scope.pageSize, $scope.pageNum, $scope.firstPage)
$scope.selectingList = res.data.list;
$scope.dtOption.selectingList.data = $scope.selectingList;
$scope.dtInstance.changeSelectingData($scope.selectingList, true)
})
}
(function() {
getAllVehicleBrand();
setTimeout(() => {
getMerchantList();
// sharedMerchants();
}, 100)
})();
}
angular.module('wechatauth').controller('liveModalCtrl', liveModalCtrl);
})(angular);