subtotal.js 4.07 KB
/**
 * Created by DEV005 on 2015/2/26.
 * 赵星
 */

angular.module("xn/template/subtotal.html",[]).run(["$templateCache", function($templateCache) {
    "use strict";
    $templateCache.put("xn/template/calendar/xnReceiptsTotal.html",
            "<label  class=\"xn-label form-total-title\">{{title}} :</label>"+
            "<div class=\"form-total\">"+
            "<span>{{receiptsTotal.integer[7] | moneyCharacter}}</span>"+
            "<span class=\"fc-yellow-2\">仟</span>"+
            "<span>{{receiptsTotal.integer[6] | moneyCharacter}}</span>"+
            "<span class=\"fc-yellow-2\">佰</span>"+
            "<span>{{receiptsTotal.integer[5] | moneyCharacter}}</span>"+
            "<span class=\"fc-yellow-2\">拾</span>"+
            "<span>{{receiptsTotal.integer[4] | moneyCharacter}}</span>"+
            "<span class=\"fc-yellow-2\">万</span>"+
            "<span>{{receiptsTotal.integer[3] | moneyCharacter}}</span>"+
            "<span class=\"fc-yellow-2\">仟</span>"+
            "<span>{{receiptsTotal.integer[2] | moneyCharacter}}</span>"+
            "<span class=\"fc-yellow-2\">佰</span>"+
            "<span>{{receiptsTotal.integer[1] | moneyCharacter}}</span>"+
            "<span class=\"fc-yellow-2\">拾</span>"+
            "<span>{{receiptsTotal.integer[0] | moneyCharacter}}</span>"+
            "<span class=\"fc-yellow-2\">元</span>"+
            "<span>{{receiptsTotal.decimal[0] | moneyCharacter}}</span>"+
            "<span class=\"fc-yellow-2\">角</span>"+
            "<span>{{receiptsTotal.decimal[1] | moneyCharacter}}</span>"+
            "<span class=\"fc-yellow-2\">分</span>"+
            "</div>"+
            "<div class=\"total-money xn-text-right\">{{receiptsTotal.total | money}}</div>"
    );
}]);

angular.module("xn.directive.subtotal",["xn/template/subtotal.html"])
    .filter("moneyCharacter", [
        function () {
            return function (input) {
                var money="";
                switch (input)
                {
                    case "0":
                        money="零";
                        break;
                    case "1":
                        money="壹";
                        break;
                    case "2":
                        money="贰";
                        break;
                    case "3":
                        money="叁";
                        break;
                    case "4":
                        money="肆";
                        break;
                    case "5":
                        money="伍";
                        break;
                    case "6":
                        money="陆";
                        break;
                    case "7":
                        money="柒";
                        break;
                    case "8":
                        money="捌";
                        break;
                    case "9":
                        money="玖";
                        break;
                    default :
                        money="/";
                        break;

                }
                return money;
            };
        }
    ])
    .directive('xnReceiptsTotal',function() {
    return {
        restrict: "A",
        templateUrl: "xn/template/calendar/xnReceiptsTotal.html",
        scope: {receiptsTotal:'=ngModel',
            title:"@title"},
        require: "?ngModel",
        link: function (scope, elem, attrs, ngModel) {
            if (!ngModel) return;

            var receiptsTotal = scope.receiptsTotal={list:[],odd:[],total:{},decimal:{},integer:{}};
            attrs.$observe("sumAmount", function (value){
                if(!scope.title){
                    scope.title="合计金额";
                }
                scope.receiptsTotal.total=angular.copy(value);
                scope.receiptsTotal.odd =Number(value).toFixed(2).toString().split("");
                scope.receiptsTotal.integer= scope.receiptsTotal.odd.slice(0,-3);
                scope.receiptsTotal.decimal= scope.receiptsTotal.odd.slice(-2);
                scope.receiptsTotal.integer.reverse();
            });

        }
    }
});