viewMerchantDetailCtrl.js 4.92 KB
(function (angular) {
    function viewMerchantDetailCtrl($scope,respondentsService,questionItemService,param,DTColumnBuilder,DTOptionsBuilder,Utils) {
        $scope.mark = param.mark;
        $scope.qnId = param.id;
        $scope.qnCode = param.code;
        $scope.qnName = param.qnName;
        $scope.condition = {
            condition:{
                qnCode: $scope.qnCode
            }
        };
        $scope.condition1 = {
            condition:{
                qnId: $scope.qnId
            }
        };
        $scope.statusList = [
            {value : 0, text : '待完善'},
            {value : 1, text : '待发送'},
            {value : 2, text : '已发送'},
            {value : 3, text : '已撤回'}];

        $scope.tabs = [
            {text: '调查商户明细', active: true, value: 1},
            {text: '被调查商户明细', active: false, value: 2}
        ];

        $scope.statusList = [
            { id: '', name: '全部' },
            { id: 1, name: '待提交' },
            { id: 2, name: '已提交' }
        ];

        $scope.dtColumns = [
            DTColumnBuilder.newColumn('userName').withOption('width',60).withTitle('调查商户名称'),
            DTColumnBuilder.newColumn('accountName').withOption('width',60).withTitle('调查商户账号'),
            DTColumnBuilder.newColumn('answerStatus').withOption('width',60).withTitle('当前状态').renderWith(function(data, type, full, oSettings) {
                for(var i in $scope.statusList){
                    if(data === $scope.statusList[i].id){
                        return $scope.statusList[i].name;
                    }
                }
            }),
            DTColumnBuilder.newColumn('updatedDate').withOption('width',60).withTitle('更新时间')
        ];

        $scope.dtOptions = DTOptionsBuilder.newOptions()
            .withOption('id','id')
            .withFixedColumns({
                leftColumns: 1,
                rightColumns: 0
            })
            .withOption('num', true);

        $scope.dtInstance = {
            serverData : respondentsService.list
        };

        $scope.dtColumns1 = [
            DTColumnBuilder.newColumn('name').withOption('width',600).withTitle('被调查商户名称')
        ];

        $scope.dtOptions1 = DTOptionsBuilder.newOptions()
            .withOption('id','id')
            .withFixedColumns({
                leftColumns: 1,
                rightColumns: 0
            })
            .withOption('num', true);

        $scope.dtInstance1 = {
            serverData : questionItemService.list
        };

        $scope.changeTabs = function (index) {
            $scope.tabs.forEach(e =>e.active = false);
            $scope.tabs[index].active = true;
        };

        $scope.getParam = function () {
            var obj = {
                condition:{
                    qnCode: $scope.qnCode
                }
            };
            if($scope.fieldName && $scope.fieldText){
                obj.condition[$scope.fieldName] = $scope.fieldText;
            }
            if($scope.status){
                obj.condition.answerStatus = $scope.status.id;
            }
            return obj;
        };

        $scope.select = function () {
            var obj = $scope.getParam();
            $scope.dtInstance.query(obj);
        };
        
        $scope.export = function () {
            var options = $scope.getParam().condition;
            Utils.exportExcel2('inquiryUser/exportRespondents',options,$scope.qnCode +'-'+$scope.qnName+ '-'+ '调查商户明细列表');
        };

        $scope.export1 = function () {
            var options = $scope.getParam1().condition;
            Utils.exportExcel2('questionItems/exportQuestionItems',options,$scope.qnCode +'-'+$scope.qnName+'-'+ '被调查商户明细列表');
        };

        $scope.getParam1 = function () {
            var obj = {
                condition:{
                    qnId: $scope.qnId
                }
            };
            if($scope.name){
                obj.condition.name = $scope.name;
            }
            return obj;
        };

        $scope.select1 = function () {
            var obj = {
                condition:{
                    qnId: $scope.qnId
                }
            };
            if($scope.name){
                obj.condition.name = $scope.name;
            }
            $scope.dtInstance1.query(obj);
        };

        $scope.init = function () {
            $scope.fieldName = 'userName';
            if($scope.mark){
                $scope.tabs.forEach(e =>e.active = false);
                for(var i in $scope.tabs){
                    if($scope.tabs[i].value === $scope.mark){
                        $scope.tabs[i].active = true;
                        break;
                    }
                }
            }
        };
        $scope.init();

    }

    angular.module('questionnaire')
        .controller('viewMerchantDetailCtrl', viewMerchantDetailCtrl);
})(angular);