model-mapping-configuration.ctrl.js 4.22 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
invoiceModule.controller('modelMappingConfigurationController', ['$scope', '$log', '$timeout', '$translate',
    'messagebox', 'vatOutputInvoiceManageService',
function ($scope, $log, $timeout, $translate, messagebox, vatOutputInvoiceManageService) {
    var mappingGridInstance = null;
  
    //初始化mapping datagrid 树
    var initMappingGrid = function () {
        $scope.dataMappingGridOptions = {
            keyExpr: "id",
            height: '300px',
            showRowLines: true,
            showColumnLines: true,
            showBorders: true,
            allowColumnResizing: true,
            allowColumnReordering: false,
            columnAutoWidth: true,
            hoverStateEnabled: true,
            bindingOptions: {
                dataSource: 'mappingDataSource'
            },
            selection: {
                mode: "single"
            },
            sorting: {
                mode: 'none'
            },
            paging: {
                enabled: false,
            },
            onSelectionChanged: function (data) {
                $scope.selectedItem = data.selectedRowsData;
            },
            onContentReady: function (e) {
                mappingGridInstance = e.component;
            },
            columns: [
                { dataField: 'id', visible: false },
                { dataField: 'modelSeries', visible: false },
                { dataField: 'cabinConfiguration', visible: false },
                {
                    caption: $translate.instant('ModelSeries') + ' - '
                        + $translate.instant('CabinConfiguration'),
                    alignment: 'center',
                    calculateCellValue: function (data) {
                        return data.modelSeries + '-' + data.cabinConfiguration;
                    }
                },
                {
                    dataField: 'makeAndModel',
                    caption: $translate.instant('MakeAndModel'),
                    alignment: 'center'
                },
            ]
        };
    };

    var refreshDataSource = function () {
        return vatOutputInvoiceManageService.getModelMappingConfig().then(function (data) {
            if (data && data.data) {
                $scope.mappingDataSource = data.data;
            }
            else {
                $scope.mappingDataSource = [];
            }

            $timeout(function () {
                $scope.selectedItem = mappingGridInstance.getSelectedRowsData();
            }, 100);
        });
    };

    //关闭弹窗口
    $scope.hidePopPanel = function () {
        $scope.$parent.isOpen = false;
        $scope.$dismiss({ $value: 'cancel' });
    };

    $scope.addMapping = function () {
        $scope.eventService.addOrEdit(refreshDataSource);
    };

    $scope.editMapping = function () {
        if (_.isEmpty($scope.selectedItem) || _.isEmpty($scope.selectedItem[0])) {
            messagebox.warning('SelectMappingCheck');
            return;
        }

        $scope.eventService.addOrEdit(refreshDataSource, $scope.selectedItem[0]);
    };

    $scope.deleteMapping = function () {
        if (_.isEmpty($scope.selectedItem) || _.isEmpty($scope.selectedItem[0])) {
            messagebox.confirm('SelectMappingCheck');
            return;
        }

        messagebox.confirm($translate.instant('ConfirmCancelMapping'), '', constant.teslaConfirmClassName).then(function (isConfirm) {
            if (isConfirm) {
                vatOutputInvoiceManageService.deleteModelMappingConfig($scope.selectedItem[0].id)
                    .then(function (data) {
                        if (!data || !data.data) {
                            messagebox.warning('UnknownError');
                        }
                        else if (!data.data.result) {
                            messagebox.warning(_.isEmpty(data.data.resultMsg) ? 'UnknownError' : data.data.resultMsg);
                        }
                        else {
                            refreshDataSource();
                        }
                    });
            }
        });
    };

    (function initialize() {
        $log.debug('modelMappingConfigurationController.ctor()...');

        $scope.selectedItem = null;
        initMappingGrid();
        refreshDataSource();
    })();
}]);