commonModule.
controller('invoiceManualAddModalController', ['SweetAlert', '$scope', '$log', '$translate', '$location', '$timeout', '$interval', '$uibModal',
    function (SweetAlert, $scope, $log, $translate, $location, $timeout, $interval, $uibModal) {

        $scope.animationsEnabled = true;
        var templateUrl = '';
        $scope.isShow = false;
        $scope.pleaseSelect = $translate.instant("ChoosePlaceholder");
        $scope.pleaseInput = ''; //$translate.instant('InputPlaceholder'),
        $scope.invoiceEntityOptions = {}
        $scope.invoiceEntity = {};
        //当前页面的事件
        var thisPageService = {
            //保存NIS数据
            saveNisData: function (modalInstance) {
               // SweetAlert.swal('保存Nis数据成功!');
                modalInstance.close($scope.invoiceEntity);
                modalInstance.dismiss('cancel');
             
            }
        };

        //当前modal的服务
        var thisModalService = {
            createInstance: function () {

                //实例化一个modal并打开
                var modalInstance = $uibModal.open({
                    animation: true,
                    templateUrl: 'addNewInvoiceTemplate.html',
                    scope: $scope,
                    backdrop: 'static',  //点击父页面不会自动关闭 
                    windowClass: 'invoice-manual-add-modal-wrapper',
                    //resolve: {
                    //    items: function () {//items是一个回调函数
                    //        return $scope.items;//这个值会被模态框的控制器获取到
                    //    }
                    //}
                });

                //modal关闭之后接收返回值的函数
                modalInstance.result.then(function (data) {
                    //设置isShow变量为false
                    $scope.isUpdate = true;
                    $scope.operateType = null;
                    $scope.invoiceEntity = data;//模态框的返回值

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

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


                //点击modal窗口上的取消事件
                $scope.cancel = function () {
                    $scope.operateType = null;
                    modalInstance.dismiss('cancel');
                };

            }
        };

        //文本框初始化
        var initTextBoxContorls = function () {

            var isShowClearButton = false;

            $scope.invoiceEntityOptions = {
                //1. 发票代码
                txtInvoiceCodeOptions: {
                    bindingOptions: {
                        value: 'invoiceEntity.invoiceCode',
                    },
                    placeholder: $scope.pleaseInput,
                    showClearButton: isShowClearButton,
                },
                //2. 票面金额 (含税
                txtAmountOptions: {
                    bindingOptions: {
                        value: 'invoiceEntity.amount',
                    },
                    placeholder: $scope.pleaseInput,
                    showClearButton: isShowClearButton,
                },
                //3. 发票号码
                txtInvoiceNumberOptions: {
                    bindingOptions: {
                        value: 'invoiceEntity.invoiceNumber',
                    },
                    placeholder: $scope.pleaseInput,
                    showClearButton: isShowClearButton,
                },
                //4. 税额
                //txtTaxAmountOptions: {
                //    bindingOptions: {
                //        value: 'invoiceEntity.taxAmount',
                //    },
                //    placeholder: $scope.pleaseInput,
                //    showClearButton: isShowClearButton,
                //},
                ////5. 购方税号
                //txtBuyerTaxNumberOptions: {
                //    bindingOptions: {
                //        value: 'invoiceEntity.buyerTaxNumber',
                //    },
                //    placeholder: $scope.pleaseInput,
                //    showClearButton: isShowClearButton,
                //},
                //6. 开票日期
                txtInvoiceDateOptions: {
                    bindingOptions: {
                        value: 'invoiceEntity.invoiceDate',
                    },
                    displayFormat:constant.date.dateFormat,
                    placeholder: $scope.pleaseInput,
                    showClearButton: isShowClearButton,
                },
                ////7. 消方税号
                //txtSellerTaxNumberOptions: {
                //    bindingOptions: {
                //        value: 'invoiceEntity.sellerTaxNumber',
                //    },
                //    placeholder: $scope.pleaseInput,
                //    showClearButton: isShowClearButton,
                //},
                txtRemarksOptions: {
                    bindingOptions: {
                        value: 'invoiceEntity.remarks'
                    },
                    //displayFormat:
                    placeholder: $scope.pleaseInput,
                    showClearButton: isShowClearButton,
                },
            }
        };


        (function initialize() {
            $log.debug('invoiceManualAddModalController.ctor()...');
            initTextBoxContorls();
            //thisModalService.createInstance();

            $scope.$watch('operateType', function (newValue, oldValue) {
                if (newValue) {

                    thisModalService.createInstance();

                    //if (newValue == constant.Operation.Add) {
                    //    thisModalService.createInstance();
                    //}
                    //else if (newValue == constant.Operation.Edit) {
                    //    thisModalService.createInstance();
                    //}
                }
            });
        })();
    }
]);