complainAuditCtrl.js 13.8 KB
(function(angular) {
	function complainAuditCtrl($scope, complainSuggestService, $resource, DTOptionsBuilder, DTColumnBuilder, $compile,Utils,$uibModal,$filter,$http,$sce) {
		$scope.displayStatusOptions=[
	    	                    {id:'',name:'全部'},
	    	                    {id:0,name:'待审核'},
	    	                    {id:1,name:'不公布'},
	    	                    {id:2,name:'已公布'}
	    	                 ];
		// 加入列头
		$scope.dtColumns = [
		                    DTColumnBuilder.newColumn('orderCode').withOption('width',120).withTitle('SAP订单编号'),
		                    DTColumnBuilder.newColumn('productName').withOption('width',100).withTitle('产品名称'),
		                    DTColumnBuilder.newColumn('productCode').withOption('width',120).withTitle('产品编号'),
		                    DTColumnBuilder.newColumn('displayStatus').withOption('width',100).withTitle('当前状态').renderWith(function(e, dt, node, config){
		                    	switch(node.displayStatus){
		                    		case 0:
		                    			return "待审核";
		                    		case 1:
		                    			return "不公布";
		                    		case 2:
		                    			return "公布";
		                    	}
		                    	return "";
		                    }),
		                    DTColumnBuilder.newColumn('userName').withOption('width',120).withTitle('门店名称'),
		                    DTColumnBuilder.newColumn('userPhone').withOption('width',120).withTitle('联系人手机号'),
		                    DTColumnBuilder.newColumn('supplierName').withOption('width',120).withTitle('供应商名称'),
		                    DTColumnBuilder.newColumn('supplierCode').withOption('width',120).withTitle('供应商SAP代码'),
		                    DTColumnBuilder.newColumn('suppliePhone').withOption('width',120).withTitle('供应商联系电话'),
		                    DTColumnBuilder.newColumn('loss').withOption('width',120).withTitle('造成损失'),
                            DTColumnBuilder.newColumn('accountName').withOption('width',80).withTitle('提交人'),
		                    DTColumnBuilder.newColumn('createdDate').withOption('width',120).withTitle('提交时间').renderWith(function(e, dt, node, config){
                            	 return $filter('date')(new Date(node.createdDate), 'yyyy-MM-dd HH:mm:ss');
                            }),
		                    DTColumnBuilder.newColumn(null).withOption('width', 140).withTitle('操作').withClass('text-center').renderWith(function(data, type, full, oSettings) {
		                        var str = '';
                                str += '<div class="form-group"><a class="btn btn-link" ng-click="getById(\'' + data.id + '\')">查看</a></div>';
		                        if(data.displayStatus == 0 && data.status != 3){
		                        	str += '<div class="form-group"><a class="btn btn-link" ng-click="openConfirmDialog('+ data.id +')">审核</a></div>';
		                        }
		                        if(str != ''){
		                        	str = '<div class="form-inline">' + str + '</div>'
		                        }
		                        return str;
		                    })
		                ];
		
		// 将自定义头部加入
		$scope.dtOptions = DTOptionsBuilder.newOptions()
		.withOption('lengthMenu', [20,40,60,100])
            .withFixedColumns({
                leftColumns: 0,
                rightColumns: 1
            })
		.withOption('select', {type: 'checkbox'})
		.withOption('num', true)
	    .withOption('completeCb', function() {
	        setTimeout(function(){
	            $compile(angular.element('.dt-head-ctrl').contents())($scope);
	        },0)
	    }).withButtons([{
     		text : '批量审核',
           	action : function(e, dt, node, config) {
           		$scope.complainAudit('批量审核');
          	}
     	},{
        	text : '导出Excel',
           	action : function(e, dt, node, config) {
           		$scope.exportExcel();
           	}
        }]);
		
		
		$scope.quertCount = function(){
			var param = $scope.getParams().condition;
			complainSuggestService.count(param, function(result){
				if (result.data) {
            	   $scope.count = result.data.countRecord;
            	   angular.forEach($scope.tagOptions, function(to){
            		   to.count = 0;
            		   for(var i = 0;i < result.data.tagCount.length;i++){
            			   if(to.tagCode == result.data.tagCount[i].tagCode){
            				   to.count = result.data.tagCount[i].totalCount;
            				   break;
            			   }
            		   }
                  });
				} else {
					$scope.count={
            			  complainCount:0,
            			  waitDisplayCount:0,
            			  displayCount:0,
            			  notDisplayCount:0
					}
					angular.forEach($scope.tagOptions, function(to){
						to.count = 0;
	                });
				}
            });
		}
		
		// 数据请求
	    $scope.dtInstance = {
	        serverData :  function(param){
	        	$scope.quertCount();
	        	if(param.condition){
                    param.condition.type = 1;
                }else {
                    param.condition = {
                        type:1
                    }
                }
       		 	return complainSuggestService.getList(param);
       		}  
	    };

        $scope.comment = {};
        $scope.dialog = false;
        $scope.getById = function (id) {
            $scope.dialog = true;
            $scope.comment = {};
            complainSuggestService.getById({ id: id }, function (res) {
                if (res.data) {
                    $scope.comment = res.data;
                    $scope.comment.duration = {
                        minute: '00',
                        second: '00'
                    }
                    let imagesList = []
                    $scope.comment.imgList.forEach(i => {
                        imagesList.push({
                        active: false,
                        url: i
                    })
                })
                    $scope.comment.imagesList = imagesList
                    setTimeout(function () {
                        setTime()
                    }, 1000)
                }
            })
        }
        function setTime() {
            if ((angular.element("#comment-video")[0])){
                console.log(angular.element("#comment-video")[0].duration)
                $scope.comment.duration = {
                    minute: parseInt((angular.element("#comment-video")[0].duration % 3600) / 60) < 10 ? '0' + parseInt((angular.element("#comment-video")[0].duration % 3600) / 60) : parseInt((angular.element("#comment-video")[0].duration % 3600) / 60),
                    second: Math.ceil(angular.element("#comment-video")[0].duration % 60) < 10 ? '0' + Math.ceil(angular.element("#comment-video")[0].duration % 60) : Math.ceil(angular.element("#comment-video")[0].duration % 60)
                }
            }
            $scope.$apply()
        }

        $scope.videoUrl = function (url) {
            return $sce.trustAsResourceUrl(url)
        }

        $scope.media_img = ''
        // 图片视频切换
        $scope.showMedia = (el, index) =>{
            $scope.playBox = true;
            if(el == 'video') {
                $scope.comment.media_video = !$scope.comment.media_video;
                $scope.comment.media_img = false;
                $scope.comment.imagesList.forEach(e => e.active = false);
            } else {
                $scope.comment.imagesList.forEach(e => e.active = false)
                $scope.media_img = $scope.comment.imgList[index]
                $scope.comment.media_img = true
                $scope.comment.imagesList[index].active = true
            }
        }
        $scope.hidePlayBox = () => {
            $scope.playBox = false;
            if($scope.comment.imagesList){
                $scope.comment.imagesList.forEach(e => e.active = false);
            }
            $scope.comment.media_video = false;
            $scope.comment.media_img = false;
        }


        $scope.$watch('minLoss',function(newValue,oldValue){
            var reg = /^[0-9]*$/;
            if (!reg.test(newValue)) {
                $scope.minLoss = null;
            }
        })

        $scope.$watch('maxLoss',function(newValue,oldValue){
            var reg = /^[0-9]*$/;
            if (!reg.test(newValue)) {
                $scope.maxLoss = null;
            }
        })

	    $scope.tableSearch = function(){
	    	var params = $scope.getParams();
	        $scope.dtInstance.query(params);
	    };
	    
	    $scope.exportExcel=function(){
            var option = $scope.getParams().condition;
            $http({
                url: 'setmining/complainSuggest/export',
                method: "GET",//接口方法
                params: option,
                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="投诉审核列表.xlsx";
                a.setAttribute('download', filename);
                a.click();
                URL.revokeObjectURL(objectUrl);
            }).error(function (data, status, headers, config) {
            });
        };
        
        $scope.complainAudit=function(message){
        	var _selectedItems = $scope.dtInstance.getSelectItems();
            if(_selectedItems.length == 0){
            	swal({type: 'error',title: '',html: true,text: '请勾选要' + message + '的数据 <br/>' ,confirmButtonText: "确定"});
            	return;
            }
            var _ids = [];
            angular.forEach(_selectedItems, function(o){
                 _ids.push(o.id);
            });
            $scope.openConfirmDialog(_ids);
        };
        
        $scope.openConfirmDialog=function(ids){
        	var params = {};
        	params.ids = ids;
        	$uibModal.open({
                animation: true,
                templateUrl: 'complainAuditSelectModal',
                controller: 'complainAuditSelectCtrl',
                size: '20sm',
                resolve: {
                    params: params,
                    dtInstance: $scope.dtInstance,
                    queryParams: $scope.getParams()
                }
            }).result.then(function(){
                // $scope.getById(ids);
            });
        };
	    $scope.getParams = function(){
	    	var params = {};
	    	params.type = 1;//投诉
	    	if($scope.fieldName1 && $scope.fieldText1){
	    		params[$scope.fieldName1] = $scope.fieldText1;
            }
	    	if($scope.fieldName2 && $scope.fieldText2){
	    		params[$scope.fieldName2] = $scope.fieldText2;
            }
	    	if($scope.fieldName3 && $scope.fieldText3){
	    		params[$scope.fieldName3] = $scope.fieldText3;
            }
            if($scope.createTime && $scope.createTime.startDate && $scope.createTime.endDate){
            	params.startDate = $scope.createTime.startDate.format('YYYY-MM-DD HH:mm:ss');
            	params.endDate = $scope.createTime.endDate.format('YYYY-MM-DD HH:mm:ss');
            }
            if($scope.minLoss){
            	params.minLoss = $scope.minLoss;
            }
            if($scope.maxLoss){
            	params.maxLoss = $scope.maxLoss;
            }
            if($scope.displayStatus){
            	params.displayStatus = $scope.displayStatus.id;
            }
            var tagCodeList = [];
            angular.forEach($scope.tagOptions, function(o){
            	if(o.selected){
                	tagCodeList.push(o.tagCode);
            	}
            });
            if(tagCodeList.length > 0){
            	params.tagCodeList=tagCodeList;
            }
            var obj = {
                condition:params
            }
	        return obj;
	    };

        $scope.selectTag = function(index){
        	if($scope.tagOptions[index].selected){
        		$scope.tagOptions[index].selected = false;
        	}else{
        		$scope.tagOptions[index].selected = true;
        	}
        };
        
        $scope.init=function(){
        	$scope.fieldName1='productName';
        	$scope.fieldName2='supplierName';
        	$scope.fieldName3='userName';
        	complainSuggestService.getTagList(function(res){
    			$scope.tagOptions = res.data;
    		});
        };
        $scope.init();
		
	}

	function complainAuditSelectCtrl($scope, $uibModalInstance, complainSuggestService, params, dtInstance, queryParams){
    	$scope.auditSelect = '2';
    	$scope.confirm = function() {
            $scope.isWorking = true;
            params.displayStatus = $scope.auditSelect;
            complainSuggestService.auditDisplay(params, function(result){
                if(result.returnCode == '0'){
                    $uibModalInstance.close();
                    swal({type: 'success',title: '',text: result.message,closeOnConfirm: false,confirmButtonText: "确定",timer: 3000});
                    dtInstance.query(queryParams);
                }else{
                    $uibModalInstance.close();
                    swal({type: 'error',title: '',text: result.message,closeOnConfirm: false,confirmButtonText: "确定",timer: 3000 });
                }
                $scope.isWorking = false;
            });
        };
    	$scope.cancel = function() {
            $uibModalInstance.dismiss('cancel');
            dtInstance.query(queryParams);
        };
    }

	angular.module('electronicDirectory').controller('complainAuditCtrl', complainAuditCtrl)
	.controller('complainAuditSelectCtrl', complainAuditSelectCtrl);
})(angular);