fixed-assets-rule-enginee.ctrl.js 10.7 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 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244
systemConfigurationModule.controller('fixedAssetsRuleEngineeController', ['$scope', '$translate', '$log', 'ruleEngineService', 'KeyValueConfigService', 'orgService', 'templateGroupService', 'ruleEngineOp', 'ruleEngineComparer','$timeout',
    function ($scope, $translate, $log, ruleEngineService, KeyValueConfigService, orgService, templateGroupService, ruleEngineOp, ruleEngineComparer, $timeout) {
        $scope.mappingData = [];
        $scope.mainData = [
            {
                id: 1, code: "1", name: "房屋、建筑物", year: "20年",
                mapData: [
                    { id: 1, name: "1 房屋、建筑物", keyValue: "土地、房屋及构建物" },
                    { id: 2, name: "1 房屋、建筑物", keyValue: "土地、海域及无居民海岛" },
                    { id: 3, name: "1 房屋、建筑物", keyValue: "房屋" },
                    { id: 4, name: "1 房屋、建筑物", keyValue: "构建物" }
                ]
            },
            {
                id: 2, code: "2", name: "飞机、火车、轮船、机器、机械和其它生成设备", year: "10年",
                mapData: [
                   { id: 1, name: "2 飞机、火车、轮船、机器、机械和其它生成设备", keyValue: "通用设备" },
                   { id: 2, name: "2 飞机、火车、轮船、机器、机械和其它生成设备", keyValue: "计算机设备及软件" },
                   { id: 3, name: "2 飞机、火车、轮船、机器、机械和其它生成设备", keyValue: "办公设备" },
                   { id: 4, name: "2 飞机、火车、轮船、机器、机械和其它生成设备", keyValue: "车辆" }
                ]
            },
            {
                id: 3, code: "3", name: "与生存经营活动有关的器具、工具、家具等", year: "5年",
                mapData: [
                   { id: 1, name: "3 与生存经营活动有关的器具、工具、家具等", keyValue: "专用设备" },
                   { id: 2, name: "3 与生存经营活动有关的器具、工具、家具等", keyValue: "探矿、采矿、选矿和造块设备" },
                   { id: 3, name: "3 与生存经营活动有关的器具、工具、家具等", keyValue: "石油天然气开采专用设备" },
                   { id: 4, name: "3 与生存经营活动有关的器具、工具、家具等", keyValue: "石油和化学工业专用设备" }
                ]
            },
            {
                id: 4, code: "4", name: "飞机、火车、轮船以外的运输工具", year: "4年",
                mapData: [
                       { id: 1, name: "4 飞机、火车、轮船以外的运输工具", keyValue: "文物" },
                       { id: 2, name: "4 飞机、火车、轮船以外的运输工具", keyValue: "陈列品" },
                ]
            },
            {
                id: 5, code: "5", name: "电子设备", year: "3年",
                mapData: [
                      { id: 1, name: "5 电子设备", keyValue: "图书、档案" }
                ]
            },
        ];
        var editModalSelector = ".fixed-assets-rule-enginee #edit-modal";
        var mappingModalSelector = ".fixed-assets-rule-enginee #map-modal"
        //清空
        $scope.resetEditingObject = function () {
            $scope.editingObject = { code: "", name: "", year: "" };
        }
        //创建
        $scope.createNewData = function () {
            $scope.isEdit = false;

            $scope.resetEditingObject();

            $(editModalSelector).modal('show');
        };

        //保存当前正在编辑数据行,经过界面初步校验后才会进入本功能
        $scope.saveEditRow = function () {
            if ($scope.editingObject.year)
                $scope.editingObject.year = $scope.editingObject.year + "年";
            $scope.mainData.push($scope.editingObject);
            $(editModalSelector).modal('hide');
        };

        //取消保存当前编辑行
        $scope.cancelEditOS = function () {
            $(editModalSelector).modal('hide');
        };
        //删除
        $scope.delete = function (data) {
            var index = $scope.mainData.indexOf(data);
            if (index !== -1) {
                $scope.mainData.splice(index, 1);
            }
        };
        $scope.editRow = function (data) {
            $scope.isEdit = true;
            $scope.editingObject = angular.copy(data)
            if (data.year) {
                var m = data.year.substring(0, data.year.length - 1);
                $scope.editingObject.year = m;
            }

            $(editModalSelector).modal('show');
        };
        $scope.editMapping = function (data) {
            $scope.mappingData = data.mapData;
            $(mappingModalSelector).modal('show');
            $timeout(function () {
                loadDetailMap();
            }, 100);          
        };
        $scope.deleteMap = function (data) {
            var index = $scope.mappingData.indexOf(data);
            if (index !== -1) {
                $scope.mappingData.splice(index, 1);
            }
        };
        $scope.saveMapRow = function () {
            $(mappingModalSelector).modal('hide');
        };

        //初始化invoice datagrid 树
        var InitInvoiceGrid = function () {

            var allowFilter = false;
            $scope.fixedAssetsGridOptions = {
                bindingOptions: {
                    dataSource: 'mainData',
                },
                hoverStateEnabled: true,
                headerFilter: {
                    visible: true,
                    height: 300,
                },
                selection: {
                    mode: "single"
                },
                paging: {
                    enabled: false,
                },
                allowColumnResizing: true,
                columnAutoWidth: true,
                showRowLines: true,
                showColumnLines: true,
                //rowAlternationEnabled: true,
                showBorders: true,
                noDataText: $translate.instant('NoDataText'),
                selectAllText: $translate.instant('SelectAll'),
                onContentReady: function (e) {
                    $scope.invoiceGridInstance = e.component;
                },
                columns: [
                            { dataField: 'code', caption: '标准固定资产代码', allowHeaderFiltering: allowFilter, alignment: 'left', width: 150 },
                    {
                        dataField: 'name', caption: '标准固定资产名称', allowHeaderFiltering: allowFilter, width: 450
                    },
                    { dataField: 'year', caption: '折旧年限', width: 100, allowHeaderFiltering: allowFilter },
                    {
                        dataField: 'id', caption: $translate.instant('Operation'), allowHeaderFiltering: allowFilter, alignment: 'center',
                        cellTemplate: function (container, options) {
                            try {
                                var data = options.data;

                                $("<span class='span-btn' />")
                                       .text("编辑")
                                       .on('click', function () {
                                           $scope.editRow(data);
                                       })
                                   .appendTo(container);

                                $("<span class='span-btn' />")
                                    .text("删除")
                                    .on('click', function () {
                                        $scope.delete(data);
                                    })
                                .appendTo(container);

                                $("<span class='span-btn' />")
                                    .text("对应关系维护")
                                    .on('click', function () {
                                        $scope.editMapping(data);
                                    })
                                .appendTo(container);



                            }
                            catch (e) {
                                $log.error(e);
                            }
                        }
                    },
                ],
            };
        };

        var loadDetailMap = function () {
            var allowFilter = false;
            $scope.fixedAssetsMapGridOptions = {
                bindingOptions: {
                    dataSource: 'mappingData',
                },
                //dataSource:$scope.mappingData,
                hoverStateEnabled: true,
                headerFilter: {
                    visible: true,
                    height: 300,
                },
                selection: {
                    mode: "single"
                },
                paging: {
                    enabled: false,
                },
                allowColumnResizing: true,
                columnAutoWidth: true,
                showRowLines: true,
                showColumnLines: true,
                //rowAlternationEnabled: true,
                showBorders: true,
                noDataText: $translate.instant('NoDataText'),
                selectAllText: $translate.instant('SelectAll'),
                onContentReady: function (e) {
                    $scope.invoiceGridInstance = e.component;
                },
                columns: [
                    { dataField: 'name', caption: '标准固定资产分类', allowHeaderFiltering: allowFilter, alignment: 'left', width: 300 },
                    {
                        dataField: 'keyValue', caption: '企业固定资产名称关键字', allowHeaderFiltering: allowFilter, width: 300
                    },

                    {
                        dataField: 'id', caption: $translate.instant('Operation'), allowHeaderFiltering: allowFilter, alignment: 'center',
                        cellTemplate: function (container, options) {
                            try {
                                var data = options.data;
                                $("<span class='span-btn' />")
                                    .text("删除")
                                    .on('click', function () {
                                        $scope.deleteMap(data);
                                    })
                                .appendTo(container);

                            }
                            catch (e) {
                                $log.error(e);
                            }
                        }
                    },
                ],
            };
        };

        //-----------custom table---end--------------------------
        (function initalization() {
            InitInvoiceGrid();
            loadDetailMap();
        })();
    }]);