refund-reason.ctrl.js 3.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
commonModule.controller('refundReasonController', ['$log', '$translate', '$uibModal', '$scope', '$document', 'InvoiceManageService', 'SweetAlert',
    function ($log, $translate, $uibModal, $scope, $document, InvoiceManageService, SweetAlert) {
        'use strict';

        $scope.refundReason = {
            reasonSelectOptions: {
                bindingOptions: {
                    dataSource: 'reasons'
                },
                width: "60%",
                height:"32px",
                onSelectionChanged: function (e) {
                    var selectItem = e.selectedItem;
                    if (selectItem.id === 4) {
                        $scope.refundReason.remarkEntity.value = null;
                        //OtherReason
                        $('#otherReasonRemark').show();
                    } else {
                        $('#otherReasonRemark').hide();
                        $scope.refundReason.remarkEntity.id = selectItem.id;
                        $scope.refundReason.remarkEntity.value = selectItem.value;
                    }
                },
                valueExpr: 'id',
                displayExpr: 'value',
                placeHolder: $translate.instant('ChoosePlaceholder')

            },
            otherReasonOptions: {
                bindingOptions: {
                    value: 'refundReason.remarkEntity.value'
                }
               
            },
            remarkEntity: {
                id: null,
                value: null
            }

        };
        $scope.refundReasonModal = {
            modalInstance: null,
            open: function () {
                var parentSelector = '.refund-reason-modal';
                var parentElem = parentSelector ? angular.element($document[0].querySelector(parentSelector)) : undefined;

                var modalInstance = $uibModal.open({
                    animation: true,
                    ariaLabelledBy: 'modal-title',
                    ariaDescribedBy: 'modal-body',
                    templateUrl: 'refund-reason.html',
                    windowClass: 'reason-modal',
                    scope: $scope,
                    appendTo: parentElem,
                });

                $scope.refundReasonModal.modalInstance = modalInstance;
            },
            close: function () {
                if ($scope.refundReasonModal.modalInstance) {
                    $scope.isShow = false;
                    //发票IDs 退票原因
                    var dto = {
                        invoiceIDs: $scope.invoiceIds,
                        remark: $scope.refundReason.remarkEntity.id + '_' + $scope.refundReason.remarkEntity.value,
                        type: null,
                        userID: null
                    };
                    InvoiceManageService.addRefundRemark(dto).success(function (res) {
                        if (_.isFunction($scope.refreshTable)) {
                            $scope.refreshTable();
                        }                       
                        $scope.refundReasonModal.modalInstance.close();
                    }).error(function () {
                        SweetAlert.error('', $translate.instant('CommonFail'));
                    });
                    

                }
            },
            cancel: function () {
                if ($scope.refundReasonModal.modalInstance) {
                    $scope.isShow = false;
                    $scope.refundReasonModal.modalInstance.dismiss('cancel');
                }
            }
        };

    }
]);