channelConfigAddCtrl.js
4.92 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
(function (angular) {
function channelConfigAddCtrl($scope, params, $http, $uibModalInstance, $uibModal,systemService,$filter,$rootScope) {
$scope.channelTypeList = [];
systemService.getChannelTypeList(function(res){
$scope.channelTypeList = res.data;
});
$scope.id = params.channelId;
$scope.ok = function () {
if($scope.creatForm.$invalid){
$scope.isInValidate = true;
return false;
}
var params = {};
if($scope.id){
params.id = $scope.id;
}
params.channelName = $scope.info.channelName;
params.channelType = $scope.info.channelType.confValue;
params.channelWebUrl = $scope.info.channelWebUrl;
params.channelWebName = $scope.info.channelWebName;
params.platformGroup = $scope.info.platformGroup;
params.channelLogo = $scope.info.channelLogo;
params.loginLogo = $scope.info.loginLogo;
params.wechatLoginLogo = $scope.info.wechatLoginLogo;
params.siteLogo = $scope.info.siteLogo;
params.platformChannelName = $scope.info.platformChannel.confKey;
params.platformChannelCode = $scope.info.platformChannel.confId;
params.wechatAppid = $scope.info.wechatAppid;
params.wechatPublicUrl = $scope.info.wechatPublicUrl;
systemService.addOrUpdateChannelConfig(params,function(res){
if(res.returnCode == 0){
swal({type: 'success',title: '',text: res.message||'操作成功',showConfirmButton:false,timer: 1500},function(){
window.sweetAlert.close();
$uibModalInstance.close();
});
}else{
swal({type: 'error',title: '',text: res.message||'操作失败',timer: 1500},function(){window.sweetAlert.close();});
}
});
};
/**
* 选择上传文件
* */
$scope.choseUploadFile=function(file,type){
if($(file).val()){
switch(type){
case 1:
$scope.uploadChannelLogo = $(file).val();
break;
case 2:
$scope.uploadLoginLogo = $(file).val();
break;
case 3:
$scope.uploadSiteLogo = $(file).val();
break;
case 4:
$scope.uploadWechatLoginLogo = $(file).val();
break;
}
$scope.$apply();
$scope.sendUploadFile($(file).val(),type);
};
};
$scope.sendUploadFile=function(fileName,type){
var b = '';
if(fileName){
var a = fileName.split('.');
b = a[a.length-1];
}
$scope.showLoadingImg = true;
$http({
url: 'common/uploadImage',
method: 'POST',
headers: {
'Content-Type': undefined
},
transformRequest: function() {
var formData = new FormData();
formData.append('file', $('#upfile_' + type)[0].files[0]);
return formData;
}
}).success(function (res) {
$scope.showValidate = false;
$scope.showLoadingImg = false;
if(res.returnCode == 0){
switch(type){
case 1:
$scope.info.channelLogo = res.data;
break;
case 2:
$scope.info.loginLogo = res.data;
break;
case 3:
$scope.info.siteLogo = res.data;
break;
case 4:
$scope.info.wechatLoginLogo = res.data;
break;
}
}else{
swal({
type: 'error',
title: '',
text: res.message||'操作失败',
showConfirmButton:false,
timer: 1500
},function(){
swal.close();
});
};
});
};
$scope.init = function(){
$scope.info={};
//平台商户渠道类型
systemService.getChannelDictList(function(res){
$scope.channelDictList = res.data;
if($scope.id){
systemService.getChannelConfigById({'id':$scope.id},function(res){
if(res.returnCode == 0){
$scope.info = res.data;
angular.forEach($scope.channelDictList, function(r){
if(r.confId == $scope.info.platformChannelCode){
$scope.info.platformChannel = r;
}
});
angular.forEach($scope.channelTypeList, function(r){
if(r.confValue == $scope.info.channelType){
$scope.info.channelType = r;
}
});
}else{
swal({type: 'error',title: '',text: res.message||'查询失败',timer: 1500},function(){window.sweetAlert.close();});
}
})
}
});
};
$scope.init();
}
angular.module('system').controller('channelConfigAddCtrl', channelConfigAddCtrl);
})(angular);