'use strict';
/**
* controller for User Profile Example
*/
app.controller('thirdPartyCompanyCtrl', ["$rootScope", "$scope", "$state", "$timeout", "$interval", "$modal", "SweetAlert", "i18nService", "uiGridConstants", "uiGridGroupingConstants", "Restangular", "api_user_data", "api_login",'api_wechatfile', function ($rootScope, $scope, $state, $timeout, $interval, $modal, SweetAlert, i18nService, uiGridConstants, uiGridGroupingConstants, Restangular, api_user_data, api_login,api_wechatfile) {
$scope.langs = i18nService.getAllLangs();
$scope.lang = 'zh-cn';
i18nService.setCurrentLang($scope.lang);
var loginUser = $rootScope.user;
$scope.xinzeng = false;
$scope.shanchu = false;
$scope.bianji = false;
$scope.chongzhimima = false;
for (var i = 0; i < loginUser.menu.length; i++) {
if (loginUser.menu[i].link == "renyuanguanli_xinzeng") {
$scope.xinzeng = true
}
if (loginUser.menu[i].link == "renyuanguanli_shanchu") {
$scope.shanchu = true
}
if (loginUser.menu[i].link == "renyuanguanli_bianji") {
$scope.bianji = true
}
if (loginUser.menu[i].link == "renyuanguanli_chongzhimima") {
$scope.chongzhimima = true
}
}
$scope.gridOptions = {};
$scope.gridOptions.data = 'myData';
$scope.gridOptions.enableColumnResizing = true;
$scope.gridOptions.enableFiltering = true;
$scope.gridOptions.enableGridMenu = true;
$scope.gridOptions.enableRowSelection = true;
$scope.gridOptions.showGridFooter = true;
$scope.gridOptions.showColumnFooter = false;
$scope.gridOptions.fastWatch = true;
$scope.gridOptions.useExternalFiltering = true;
$scope.gridOptions.useExternalPagination = true;
$scope.gridOptions.paginationPageSizes = [10, 20, 50, 100];
$scope.gridOptions.paginationPageSize = 10;
$scope.gridOptions.multiSelect = false;
$scope.gridOptions.rowTemplate= "
";
$scope.gridOptions.rowIdentity = function (row) {
return row.id;
};
$scope.gridOptions.getRowIdentity = function (row) {
return row.id;
};
//remote data
$scope.gridOptions.columnDefs = [{
name: 'item',
displayName: '序号',
width: '5%',
minWidth: '70',
enableFiltering: false,
cellTemplate: '' +
'
{{row.entity.item}}
' +
'
'
},
{
name: 'name',
displayName: '公司名称',
width: '20%',
minWidth: '100',
enableFiltering: false
},
{
name: 'contacts',
displayName: '公司联系人',
width: '20%',
minWidth: '100',
enableFiltering: false
},
{
name: 'phone',
displayName: '联系人电话',
width: '20%',
minWidth: '120',
enableFiltering: false
},
{
name: 'serviceTypeNames',
displayName: '公司服务种类',
width: '20%',
minWidth: '120',
enableFiltering: false,
// cellTemplate: '' +
// '
{{row.entity.userType.value == 2 ?row.entity.company.name:row.entity.userType.name}}
' +
// '
'
},
{
name: '操作',
width: '10%',
minWidth: '100',
cellTemplate: '',
enableFiltering: false
}
];
$scope.groupdata = {};
$scope.my_data = [];
$scope.select_treedata = [];
$scope.propTypeOptions = [];
$scope.saveData = function (data) {
var modelData = {
model: {
company: data
}
};
modelData.model.company = {
categoryTypeIds: data.categoryTypeIds,//故障现象
contacts: data.contacts,//联系人
id: data.id,//id
phone: data.phone,//联系电话
name: data.name,//公司名称
startTime: data.startTime,//开始时间
endTime: data.endTime,//结束时间
serviceTypeIds: data.serviceTypeIds,//服务分类ids
serviceTypeNames: data.serviceTypeNames//服务分类名称s
}
console.log(modelData)
$state.go('app.system.form', {
formKey: 'company_edit',
service: 'api_user_data',
model: JSON.stringify(modelData)
});
};
$scope.addData = function () {
var modelData = {
model: {
user: {}
}
};
$state.go('app.system.form', {
formKey: 'company_edit',
service: 'api_user_data',
model: JSON.stringify(modelData)
});
}
$scope.removeData = function () {
var modalInstance = $modal.open({
templateUrl: 'assets/views/delete.html',
controller: function ($scope, scope, $modalInstance, api_bpm_data) {
var rmvList = [];
$scope.title = '第三方公司删除';
$scope.connect = '确定要删除此第三方公司?';
angular.forEach(scope.selected.items, function (item) {
rmvList.push(item.id);
});
$scope.ok = function () {
$modalInstance.close(rmvList);
};
$scope.cancel = function () {
$modalInstance.dismiss('cancel');
};
},
size: 'sm',
resolve: {
scope: function () {
return $scope;
}
}
});
modalInstance.result.then(function (selectedItem) {
if (selectedItem) {
if (selectedItem.length > 0) {
api_user_data.rmvData('company', selectedItem).then(function (response) {
if (response.data[0].deleteFlag != 0) {
SweetAlert.swal({
title: "删除成功!",
type: "success",
confirmButtonColor: "#007AFF"
}, function () {
$scope.myData = _.reject($scope.myData, function (o) {
return _.includes(selectedItem, o.id);
});
$scope.selected = {
items: []
};
$scope.gridOptions.totalItems = $scope.gridOptions.totalItems - selectedItem.length;
$scope.gridApi.grid.selection.selectedCount = 0;
});
} else {
SweetAlert.swal({
title: "无法删除!",
text: "【"+response.data[0].name+"】已经绑定了用户或耗材!",
type: "error"
});
}
})
}
}
})
}
//获取公司服务种类
$scope.company_service_type = [];
$scope.getCompanyServiceTypes = function(){
api_wechatfile.getDictionary({
key: "company_service_type",
type: "list"
}).then(function (res) {
$scope.company_service_type = res;
$scope.refreshData('expand-right', $scope.fileData);
$scope.timer = $interval(function () {
$scope.refreshData('expand-right', $scope.fileData);
}, $rootScope.refreshTime);
})
}
$scope.getCompanyServiceTypes();
$scope.selected = {
items: []
}
$scope.editted = {
items: []
}
$scope.gridOptions.onRegisterApi = function (gridApi) {
$scope.gridApi = gridApi;
gridApi.pagination.on.paginationChanged($scope, function (newPage, pageSize) {
var filtersData = $scope.memoryfilterData;
filtersData.idx = newPage - 1;
filtersData.sum = pageSize;
$scope.fileData.idx = newPage - 1;
$scope.fileData.sum = pageSize;
defaultFilterData = filtersData;
$scope.refreshData('expand-right', $scope.fileData);
});
gridApi.selection.on.rowSelectionChanged($scope, function (scope) {
var j = 0;
for (var i = 0; i <= scope.grid.appScope.selected.items.length; i++) {
if (scope.grid.appScope.selected.items[i] == scope.entity) {
j++;
break;
}
}
if (j == 1) {
scope.grid.appScope.selected.items.splice(i, 1);
} else {
scope.grid.appScope.selected.items.push(scope.entity)
}
});
gridApi.core.on.filterChanged($scope, function () {
var grid = this.grid;
var filtersData = $scope.memoryfilterData;
angular.forEach(grid.columns, function (item) {
if (item.enableFiltering) {
if (angular.isDefined(item.filters[0].term) && item.filters[0].term != '') {
if (angular.isUndefined(filtersData['company'])) {
filtersData['company'] = {};
filtersData['company']['flag'] = -1;
filtersData['company'][item.field] = item.filters[0].term;
} else {
filtersData.company.flag = -1;
filtersData.company[item.field] = item.filters[0].term;
}
}
}
});
$scope.memoryfilterData = filtersData;
$scope.refreshData('expand-right', $scope.fileData);
});
};
var defaultFilterData = {
"idx": 0,
"sum": 10
};
$scope.memoryfilterData = {
"idx": 0,
"sum": 10
}
$scope.ldloading = {};
$scope.fileData = {
"idx": 0,
"sum": 10,
"company": {}
}
$scope.treeItem = "";
$scope.onFilterCallback = function (item) {
$scope.treeItem = item
}
// 搜索
$scope.searchData = function () {
if ($scope.treeItem) {
$scope.fileData.company.groupdata = $scope.treeItem
}
if($scope.fileData.company.name){
$scope.fileData.company.selectType= "pinyin_qs"
}
$scope.refreshData('expand-right', $scope.fileData);
}
// 清空
$scope.clean = function () {
delete $scope.fileData.company.account;
delete $scope.fileData.company.name;
delete $scope.fileData.company.groupdata;
$scope.treeItem = "";
$scope.refreshData('expand-right', $scope.fileData);
}
//刷新
$scope.refresh = function (style, filterData) {
$scope.selected = {
items: []
};
if ($scope.gridApi) {
$scope.gridApi.grid.selection.selectedCount = 0;
}
$scope.refreshData('expand-right', $scope.fileData);
}
//获取列表数据
$scope.refreshData = function (style, filterData) {
console.log(filterData)
$scope.ldloading[style.replace('-', '_')] = true;
if (angular.isUndefined(filterData)) {
filterData = defaultFilterData;
}
if (angular.isDefined($scope.searchTypes)) {
filterData['searchType'] = $scope.searchTypes;
}
$scope.myData = [];
filterData['flag'] = -1;
console.log("filterData=" + JSON.stringify(filterData))
api_user_data.fetchDataList('company', filterData).then(function (data) {
var myData = Restangular.stripRestangular(data);
$scope.gridOptions.totalItems = myData.totalNum;
//数据转换start
myData.list.forEach(function(v){
if(v.serviceTypeIds){
var sArr = v.serviceTypeIds.split(',');
var sNameArr = [];
$scope.company_service_type.forEach(function(v1){
sArr.forEach(function(v2){
if(v1.id == v2){
sNameArr.push(v1.name);
}
})
})
v.serviceTypeNames = sNameArr.join(',');//公司服务种类名称
}
})
console.log(myData.list);
//数据转换end
$scope.myData = myData.list;
for (var i = 0; i < $scope.myData.length; i++) {
$scope.myData[i]['item'] = i + 1 + filterData.idx * filterData.sum
}
$scope.ldloading[style.replace('-', '_')] = false;
}, function () {
$scope.ldloading[style.replace('-', '_')] = false;
});
};
$scope.$on('$destroy', function () {
$interval.cancel($scope.timer)
});
}]);