opinionFeedbackManagerCtrl.js 16.2 KB
(function (angular) {
    function opinionFeedbackManagerCtrl($scope, complainSuggestService,opinionFeedbackService,DTColumnBuilder,DTOptionsBuilder,$state,$http,SweetAlertX,$sce) {

        $scope.statusOptions=[
            {id:'',name:'全部'},
            {id:0,name:'待处理'},
            {id:1,name:'待下架'},
            {id:2,name:'已下架'},
            {id:3,name:'已删除'}
        ];

        $scope.statusOptionsArray=[
            {id:0,name:'待处理'},
            {id:1,name:'待下架'},
            {id:2,name:'已下架'},
            {id:3,name:'已删除'}
        ];

        $scope.tabs = [
            {text: '产品投诉', active: true, value: 1},
            {text: '优化建议', active: false, value: 2}
        ];

        $scope.conditions = [
            {text: '总投诉列表', active: true, value: 1},
            {text: '期限内待处理投诉', active: false, value: 2},
            {text: '超时未处理投诉', active: false, value: 3}
        ];

        $scope.dtColumns = [
            DTColumnBuilder.newColumn('orderCode').withOption('width',120).withTitle('SAP订单编号'),
            DTColumnBuilder.newColumn('productName').withOption('width',120).withTitle('产品名称'),
            DTColumnBuilder.newColumn('productCode').withOption('width',120).withTitle('产品编号'),
            DTColumnBuilder.newColumn('status').withOption('width',60).withTitle('状态').renderWith(function(data, type, full, oSettings) {
                return $scope.statusOptionsArray[data].name;
            }),
            DTColumnBuilder.newColumn('userName').withOption('width',120).withTitle('门店名称'),
            DTColumnBuilder.newColumn('userPhone').withOption('width',120).withTitle('联系人手机号'),
            DTColumnBuilder.newColumn('supplierName').withOption('width',160).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('提交时间'),
            DTColumnBuilder.newColumn(null).withTitle(function () {
                return '操作';
            }).withOption('width', 150).withClass('text-center').renderWith(function (data, type, full, oSettings) {
                var str = '<div class="form-inline">';
                str += '<div class="form-group"><a class="btn btn-link" ng-click="getById(\'' + data.id + '\')">查看</a></div>';
                if(data.status != 3){
                    str += '<div class="form-group"><a class="btn btn-link" ng-click="deleteById(\'' + data.id + '\')">删除</a></div>';
                }
                str += '</div>';
                return str;
            })
        ];

        $scope.dtOptions = DTOptionsBuilder.newOptions()
            .withOption('id','id')
            .withOption('lengthMenu', [20,40,60,100])
            .withFixedColumns({
                leftColumns: 0,
                rightColumns: 1
            })
            // .withOption('lengthMenu', [20,40,60,100])
            // .withOption('select', {
            //     type: 'checkbox'
            // })
            .withOption('num', true)
            // .withButtons([{
            //     text : '导出Excel',
            //     action : function(e, dt, node, config) {
            //         $scope.export();
            //     }
            // }]);

        $scope.dtInstance = {
            serverData : function (params) {
                $scope.quertCount();
                if(params.condition){
                    params.condition.type = 1;//投诉
                }else {
                    params.condition = {
                        type:1
                    }
                }
                return complainSuggestService.getList(params);
            }
        };

        $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.deleteById = function (id) {
            SweetAlertX.confirm({
                text: "是否要删除此投诉!",
                confirmButtonText: "确认",
                cancelButtonText: "取消"
            }, function () {
                opinionFeedbackService.updateStatus({ids:id,status:3},function (res) {
                    if(res && res.data){
                        swal({
                            type: 'success',
                            title: '',
                            html: true,
                            text: '删除成功',
                            showConfirmButton: false,
                            timer: 2000
                        });
                        $scope.tableSearch();
                    }else {
                        swal({
                            type: 'error',
                            title: '',
                            html: true,
                            text: '删除失败 ' + (res.message || ''),
                            confirmButtonText: "确定"
                        });
                    }
                })
            });
        };

        $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;
                    if($scope.comment.grade){
                        var lis = $("ul.cleanfloat li");
                        for(var i = 0; i < $scope.comment.grade; i++){
                            lis.eq(i).addClass('star_color');
                        }
                    }
                    var appealImagesList = [];
                    if($scope.comment.appeal){
                        $scope.comment.appeal.imgList.forEach(i => {
                            appealImagesList.push({
                            active: false,
                            url: i
                        })
                    })
                        $scope.comment.appealImagesList = appealImagesList;
                    }
                    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)
                }
            }
            if ((angular.element("#comment-appeal-video")[0])){
                console.log(angular.element("#comment-appeal-video")[0].duration)
                $scope.comment.appeal.duration = {
                    minute: parseInt((angular.element("#comment-appeal-video")[0].duration % 3600) / 60) < 10 ? '0' + parseInt((angular.element("#comment-appeal-video")[0].duration % 3600) / 60) : parseInt((angular.element("#comment-appeal-video")[0].duration % 3600) / 60),
                    second: Math.ceil(angular.element("#comment-appeal-video")[0].duration % 60) < 10 ? '0' + Math.ceil(angular.element("#comment-appeal-video")[0].duration % 60) : Math.ceil(angular.element("#comment-appeal-video")[0].duration % 60)
                }
            }
            $scope.$apply()
        }

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

        // 图片视频切换
        $scope.showMedia = (type,el, index) =>{
            $scope.playBox = true;
            if(el == 'video') {
                if(type == 1){//投诉视频
                    $scope.videoType = 1;
                    $scope.comment.media_video = !$scope.comment.media_video;
                }else {//申诉视频
                    $scope.videoType = 2;
                    $scope.comment.media_video = !$scope.comment.appeal.media_video;
                }
            } else {
                if(type == 1){//投诉图片
                    $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
                }else {//申诉图片
                    $scope.comment.appealImagesList.forEach(e => e.active = false);
                    $scope.media_img = $scope.comment.appeal.imgList[index]
                    $scope.comment.media_img = true;
                    $scope.comment.appealImagesList[index].active = true
                }
            }
        }

        $scope.hidePlayBox = () => {
            $scope.playBox = false;
            if($scope.comment.imagesList){
                $scope.comment.imagesList.forEach(e => e.active = false);
            }
            if($scope.comment.appealImagesList){
                $scope.comment.appealImagesList.forEach(e => e.active = false);
            }
            $scope.comment.media_video = false;
            $scope.comment.media_img = false;
        }

        $scope.close = function () {
            $scope.dialog = false;
            $("ul.cleanfloat li").removeClass("star_color");
        };

        $scope.init=function(){
            $scope.title = '意见反馈管理';
            $scope.showStatus = true;
            $scope.showSupplier = true;
            $scope.fieldName1='productName';
            $scope.fieldName2='supplierName';
            $scope.fieldName3='userName';
            complainSuggestService.getTagList(function(res){
                $scope.tagOptions = res.data;
            });
        };
        $scope.init();

        $scope.changeTabs=function (index) {
            $scope.tabs.forEach(e =>e.active = false);
            $scope.tabs[index].active = true;
            if (index == 1) {
                $state.go('electronicDirectory.optimizingSuggestManager');
            }
        }

        $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.selectTag = function(index){
            if($scope.tagOptions[index].selected){
                $scope.tagOptions[index].selected = false;
            }else{
                $scope.tagOptions[index].selected = true;
            }
        };

        $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.status){
                params.status = $scope.status.id;
            }
            if($scope.untreatedType != null){
                params.status = 0;
                params.untreatedType = $scope.untreatedType;
            }
            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.tableSearch = function(){
            var params = $scope.getParams();
            $scope.dtInstance.query(params);
        };

        $scope.changeCondition = function(index){
            $scope.conditions.forEach(e =>e.active = false);
            $scope.conditions[index].active = true;
            if(index == 0){
                $scope.showStatus = true;
                $scope.untreatedType = null;
            }else if(index == 1){
                $scope.untreatedType = 0;
                $scope.showStatus = false;
            }else if(index == 2){
                $scope.untreatedType = 1;
                $scope.showStatus = false;
            }
            var params = $scope.getParams();
            $scope.dtInstance.query(params);
        };

        $scope.export=function(){
            var option = $scope.getParams().condition;
            option.exportType = 1;
            $http({
                url: 'setmining/opinionFeedback/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) {
            });
        };


    }

    angular.module('electronicDirectory')
        .controller('opinionFeedbackManagerCtrl', opinionFeedbackManagerCtrl);
})(angular);