brandManagerCtrl.js
2.71 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
(function (angular) {
function brandManagerCtrl($scope,supplierService,param,SweetAlertX,DTColumnBuilder,DTOptionsBuilder,$http,$state,$uibModal) {
$scope.brandCondition = {
condition:{
supplierCode: param.supplierCode
}
};
$scope.brandDtColumns = [
DTColumnBuilder.newColumn('brandName').withOption('width',20).withTitle('品牌'),
DTColumnBuilder.newColumn(null).withTitle(function(){
return '操作';
}).withOption('width', 40).withClass('text-center').renderWith(function(data, type, full, oSettings) {
var str = '<div class="form-inline">'
+'<div class="form-group" ng-show="'+ !data.bindProduce +'" ><a class="btn btn-link" ng-click="deleteBrand(\''+ data.id +'\')">删除</a></div>'
+'<div class="form-group" ng-show="'+ data.bindProduce +'" ><p class="btn" >该品牌已关联产品,不可删除</p></div>';
str += '</div>';
return str;
})
];
$scope.brandDtOptions = DTOptionsBuilder.newOptions()
.withOption('id','id')
.withFixedColumns({
leftColumns: 1,
rightColumns: 0
})
.withOption('num', true);
$scope.brandDtInstance = {
serverData : supplierService.listBrand
};
$scope.addBrand = function(){
var obj = {};
obj.supplierCode = param.supplierCode;
if(!$scope.brandName){
SweetAlertX.alert('','请输入品牌名称','error');
return;
}
obj.brandName = $scope.brandName;
supplierService.addBrand(obj,function (data) {
if(data && data.data){
SweetAlertX.alert('','添加成功','success');
$scope.brandDtInstance.query($scope.brandCondition);
}else if(data && data.message){
SweetAlertX.alert('',data.message,'error');
}else {
SweetAlertX.alert('','添加失败','error');
}
})
}
$scope.deleteBrand = function (id) {
supplierService.deleteBrand({id:id},function (data) {
if(data && data.data > 0){
SweetAlertX.alert('','删除成功','success');
$scope.brandDtInstance.query($scope.brandCondition);
}else {
SweetAlertX.alert('','删除失败','error');
}
})
}
}
angular.module('electronicDirectory')
.controller('brandManagerCtrl', brandManagerCtrl);
})(angular);