Ben hace 8 años
padre
commit
0cce42baf5

+ 28 - 2
miaomiao/www/js/controllers/home.js

xqd xqd xqd xqd xqd
@@ -60,8 +60,8 @@
           
             //});
         }]);
-    app.controller('dreamDetailCtrl', ["$scope", "$state", "msg", "common", "config", "homeService", "$ionicTabsDelegate", "$stateParams", "$ionicModal", "$timeout","$ionicScrollDelegate"
-        , function ($scope, $state, msg, common, config, homeService, $ionicTabsDelegate, $stateParams, $ionicModal, $itemout, $ionicScrollDelegate) {
+    app.controller('dreamDetailCtrl', ["$scope", "$state", "msg", "common", "config", "homeService", "$ionicTabsDelegate", "$stateParams", "$ionicModal", "$timeout", "$ionicScrollDelegate", "$interval"
+        , function ($scope, $state, msg, common, config, homeService, $ionicTabsDelegate, $stateParams, $ionicModal, $itemout, $ionicScrollDelegate, $interval) {
             var id = $stateParams.id;
             id=6;
             $scope.load = function (id) {
@@ -84,6 +84,7 @@
                 $scope.sort.slide1 = 'list-grow-animation';
                 $scope.sort.slide2 = 'slide-in-both-ways';
                 $scope.sort.slide3 = 'bounce-animation';
+                $interval.cancel($scope.multi.promise);
                 return;
                 $scope.tosupport = true;
                 $scope.vm.coin = 0;
@@ -98,10 +99,12 @@
             }
             $scope.index = 0;
             $scope.$on('$ionicView.beforeEnter', function () {
+                $scope.calcmultiplier();
                 $ionicTabsDelegate.showBar(false);
             });
             $scope.$on('$ionicView.leave', function () {
                 $ionicTabsDelegate.showBar(true);
+                $interval.cancel($scope.multi.promise);
             });
 
             $scope.vm = {
@@ -120,6 +123,27 @@
                 third: 'img/demo/head7.jpg',
                 slide: ''
             }
+            $scope.multi = {
+                a: 0.5,
+                b:new Date('2017-03-03'),
+                c: 20,
+                result: 0,
+                promise:null,
+            }
+            //实时计算支持乘数
+            $scope.calcmultiplier = function () {
+                $scope.multi.promise=$interval(function () {
+                    var date = new Date();
+                    var inter = date.getTime() - $scope.multi.b.getTime();
+                    var minutes = Math.floor(inter / (60 * 1000));
+                    var number = $scope.multi.a * minutes + $scope.multi.c;//js浮点运算会失真,根据muti.a的可能值范围,比如乘以100再除以100
+                    if (number<=1) {
+                        number = 1;
+                    }
+                    $scope.multi.result = number;
+                },1000);
+                //  点击支持取消   $interval.cancel($scope.multi.promise); 获取数据后重新开始执行
+            }
             $scope.supportDream = function (data) {
                 
                 if(!$scope.vm.coin){
@@ -137,11 +161,13 @@
                     //最新支持乘数
                 })
             };
+
             $scope.collectionDream = function(){
                 homeService.collectionDream(id).then(function(result){
                     //最新支持乘数
                 })
             }
+
             $scope.showText = function(){ 
                 $scope.aboutStyle = {
                     "white-space" : "normal"

+ 1 - 1
miaomiao/www/templates/home/dream-detail.html

xqd
@@ -77,7 +77,7 @@
                     <div class="col"><img ng-src="{{sort.third}}"  ng-class="sort.slide3"/></div>
                 </div>
                 <div class="item">
-                    <button class="button button-assertive" style="width:25%;white-space:normal;line-height:20px">支持乘数×2.8</button>
+                    <button class="button button-assertive" style="width:25%;white-space:normal;line-height:20px">支持乘数×{{multi.result}}</button>
                     <button class="button button-calm" style="width:50%" ng-click="support($event)">支持</button>
                     <button class="button button-outline button-calm" style="width:25%" ng-click="collectionDream()">+收藏</button>
                 </div>