myOptimizingSuggestCtrl.js 10.4 KB
(function (angular) {
    function myOptimizingSuggestCtrl($scope, complainSuggestService,opinionFeedbackService,DTColumnBuilder,DTOptionsBuilder,$state,$http,$sce) {

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

        $scope.dtColumns = [
            DTColumnBuilder.newColumn('productName').withOption('width',120).withTitle('产品名称'),
            DTColumnBuilder.newColumn('productCode').withOption('width',120).withTitle('产品编号'),
            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('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>';
                str += '</div>';
                return str;
            })
        ];

        $scope.dtOptions = DTOptionsBuilder.newOptions()
            .withOption('id','id')
            .withOption('lengthMenu', [20,40,60,100])
            .withFixedColumns({
                leftColumns: 0,
                rightColumns: 0
            })
            // .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 = 2;
                    params.condition.source = 1;
                }else {
                    params.condition = {
                        type:2,
                        source: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.changeTabs = function (index) {
            $scope.tabs.forEach(e =>e.active = false);
            $scope.tabs[index].active = true;
            if (index == 0) {
                $state.go('electronicDirectory.myOpinionFeedback');
            }
        };

        $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.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;
            $scope.comment.imagesList.forEach(e => e.active = false);
            $scope.comment.media_video = false;
            $scope.comment.media_img = false;
        }


        $scope.init=function(){
            $scope.fieldName1='productName';
            $scope.fieldName2='supplierName';
            $scope.fieldName3='userName';
            complainSuggestService.getTagList(function(res){
                $scope.tagOptions = res.data;
            });
        };
        $scope.init();

        $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 = 2;
            params.source = 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;
            }
            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.export=function(){
            var option = $scope.getParams().condition;
            $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('myOptimizingSuggestCtrl', myOptimizingSuggestCtrl);
})(angular);