invoice-relevance-modal.ctrl.js 10.5 KB
Newer Older
eddie.woo's avatar
eddie.woo committed
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 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318
commonModule.
controller('invoiceRelevanceModalController', ['SweetAlert', '$scope', '$log', '$translate', '$location', '$timeout', '$interval', '$uibModal',
    function (SweetAlert, $scope, $log, $translate, $location, $timeout, $interval, $uibModal) {

        $scope.items = ['item1', 'item2', 'item3'];
        $scope.animationsEnabled = true;
        var templateUrl = '';
        $scope.isShow = false;
        $scope.selected = {
            item: $scope.items[0]
        };

        //当前选中的发票
        $scope.currentInvoice = '';

        //初始化NIS模板页面控件
        var initNISPageControl = function () {
            var simpleProducts = [
                "原料采购",
                "非原料集中采购",
                "报销"
            ];
            //发票来源
            $("#invoiceSourceNIS").dxSelectBox({
                items: simpleProducts
            });
            //收货单号输入框
            $("#acceptNOsNIS").dxTextBox({
                value: "",
                placeholder: "请输入收货单号",
            });
            //商品种类
            $("#productTypeNIS").dxSelectBox({
                items: ["原料"],
                value: '原料',
                readOnly: true
            });
            //是否计入进项税额
            $("#isIncludedInTaxAmountNIS").dxSelectBox({
                items: ['是', '否'],
                value: '是',
                readOnly: true
            });
        };

        //初始化CSSP-四家模板页面控件
        var initCSSPFourPageControl = function () {
            var sales =
                [{ "orderId": 10248 },
                { "orderId": 10249 },
                { "orderId": 10250 },
                { "orderId": 10251 }];
            var simpleProducts = [
                "原料采购",
                "非原料集中采购",
                "报销"
            ];
            //发票来源
            $("#invoiceSourceCSSPFour").dxSelectBox({
                items: simpleProducts
            });
            //采购单号输入框
            $("#purchaseOrderCSSPFour").dxTextBox({
                value: "",
                placeholder: "请输入采购单号",
            });
            //商品种类
            $("#productTypeCSSPFour").dxSelectBox({
                items: ["原料"],
                value: '原料',
                readOnly: true
            });
            //是否计入进项税额
            $("#isIncludedInTaxAmountCSSPFour").dxSelectBox({
                items: ['是', '否'],
                value: '是',
                readOnly: true
            });
            //初始化公司代码code
            var dataGrid = $("#company-code-container").dxDataGrid({
                dataSource: sales,
                selection: {
                    mode: "multiple",
                    showCheckBoxesMode: 'always'
                },
                paging: {
                    pageSize: 10
                },
                filterRow: {
                    visible: true
                },
                columns: [{
                    dataField: "orderId",
                    caption: "公司代码",
                    width: 150
                }]
            }).dxDataGrid("instance");
            //初始化成本中心code
            var dataGrid = $("#cost-center-container").dxDataGrid({
                dataSource: sales,
                selection: {
                    mode: "multiple",
                    showCheckBoxesMode: 'always'
                },
                paging: {
                    pageSize: 10
                },
                filterRow: {
                    visible: true
                },
                columns: [{
                    dataField: "orderId",
                    caption: "成本中心",
                    width: 150
                }]
            }).dxDataGrid("instance");
            
            //凭证号输入框
            $("#voucherNoCSSPFour").dxTextBox({
                value: "",
                placeholder: "请输入凭证号",
            });
        };

        //初始化CSSP模板页面控件
        var initCSSPPageControl = function () {
            var simpleProducts = [
                "原料采购",
                "非原料集中采购",
                "报销"
            ];
            //发票来源
            $("#invoiceSourceCSSP").dxSelectBox({
                items: simpleProducts
            });
            //采购单号输入框
            $("#purchaseOrderCSSP").dxTextBox({
                value: "",
                placeholder: "请输入采购单号",
            });
            //商品种类
            $("#productTypeCSSP").dxSelectBox({
                items: ["原料"],
                value: '原料',
                readOnly: true
            });
            //强制应税checkbox
            $("#forceTaxCheckboxCSSP").dxCheckBox({
                value: true,
                width: 80,
                text: "强制应税"
            });

            //强制应税原因
            $("#forceTaxReasonCSSP").dxTextArea({
                value: '',
                height: 90
            })

            //是否计入进项税额
            $("#isIncludedInTaxAmountCSSP").dxSelectBox({
                items: ['是', '否'],
                value: '是',
                readOnly: true
            });

            //凭证号输入框
            $("#voucherNoCSSP").dxTextBox({
                value: "",
                placeholder: "请输入凭证号",
            });
        };

        //初始化报销模板页面控件
        var initApplyForReimbursementPageControl = function () {
            var simpleProducts = [
                "原料采购",
                "非原料集中采购",
                "报销"
            ];
            //发票来源
            $("#invoiceSourceReibursement").dxSelectBox({
                items: simpleProducts
            });
            //员工编号输入框
            $("#purchaseOrderReibursement").dxTextBox({
                value: "",
                placeholder: "请输入员工编号",
            });
            //商品种类
            $("#productTypeReibursement").dxSelectBox({
                items: ["原料"],
                value: '原料',
                readOnly: true
            });

            //是否计入进项税额
            $("#isIncludedInTaxAmountReibursement").dxSelectBox({
                items: ['是', '否'],
                value: '是',
                readOnly: true
            });

            //凭证号输入框
            $("#voucherNoReibursement").dxTextBox({
                value: "",
                placeholder: "请输入凭证号",
            });
        };

        //当前页面的事件
        var thisPageService = {
            //保存NIS数据
            saveNisData: function (modalInstance) {
                SweetAlert.swal('保存Nis数据成功!');
                modalInstance.close($scope.selected.item);
                modalInstance.dismiss('cancel');
            }
        };


        //当前modal的服务
        var thisModalService = {
            createInstance: function () {
                //判断当前需要打开的是哪一个modal
                if ($scope.relevanceType == 1) {
                    //NIS模板
                    templateUrl = 'relevance-nis.html';
                }
                else if ($scope.relevanceType == 2) {
                    //CSSP-四家模板
                    templateUrl = 'relevance-cssp-four.html';
                }
                else if ($scope.relevanceType == 3) {
                    //CSSP
                    templateUrl = 'relevance-cssp.html';
                }
                else if ($scope.relevanceType == 4) {
                    //报销
                    templateUrl = 'relevance-apply-for-reimbursement.html';
                }

                //实例化一个modal并打开
                var modalInstance = $uibModal.open({
                    animation: true,
                    templateUrl: templateUrl,
                    scope: $scope,
                    backdrop: 'static',
                    windowClass: 'invoice-relevance-modal-wrapper',
                    resolve: {
                        items: function () {//items是一个回调函数
                            return $scope.items;//这个值会被模态框的控制器获取到
                        }
                    }
                });

                //modal关闭之后接收返回值的函数
                modalInstance.result.then(function (data) {
                    //设置isShow变量为false
                    $scope.isShow = false;
                    //设置关联的类型为-1
                    $scope.relevanceType = -1;
                    $scope.selected = data;//模态框的返回值

                }, function () {
                    $log.info('Modal dismissed at: ' + new Date());
                });

                //点击modal窗口上的确定事件
                $scope.save = function () {
                    if ($scope.relevanceType == 1) {
                        thisPageService.saveNisData(modalInstance);
                    }
                };


                //点击modal窗口上的取消事件
                $scope.cancel = function () {
                    //设置isShow变量为false
                    $scope.isShow = false;
                    //设置关联的类型为-1
                    $scope.relevanceType = -1;
                    modalInstance.dismiss('cancel');
                };

            }
        };





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

            $scope.$watch('isShow', function (newValue, oldValue) {
                if (newValue === true) {
                    thisModalService.createInstance();
                    $timeout(function () {
                        if ($scope.relevanceType == 1) {
                            initNISPageControl();
                        }
                        else if ($scope.relevanceType == 2) {
                            initCSSPFourPageControl();
                        }
                        else if ($scope.relevanceType == 3) {
                            initCSSPPageControl();
                        }
                        else if ($scope.relevanceType == 4) {
                            initApplyForReimbursementPageControl();
                        }
                    }, 500);

                }
            });
        })();
    }
]);