高章伟
2022-03-18 a0bc3e3af59aed35334bdc38256a7a1dfe8aecf3
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
({
    setFormattedPrice: function(component, price) {
        var formattedPrice = Number(price).toLocaleString("en-US", {style: "currency", currency: 'USD', maximumFractionDigits: 0});
        component.set("v.formattedPrice", formattedPrice);
    },
 
    calculateDays: function(component, helper, price) {
        var property = component.get("v.property");
        var ellapsed = (new Date() - new Date(property.Date_Listed__c)) / 24 / 60 / 60 / 1000;
        var currentDays = component.get("v.days") || ellapsed;
        component.set("v.waiting", true);
        helper.predictDaysOnMarket(component, property, price, function(days) {
            if (component.isValid()) {
                component.set("v.waiting", false);
                var color = '#00716B';
                if (days > 60) {
                    color = '#C23934';
                } else if (days > 30) {
                    color = '#FFB75D';
                }
                component.set("v.color", color);
                var daysEl = component.find("days").getElement();
                var daysAnim = new CountUp(daysEl, currentDays, days, 0, 2);
                daysAnim.start();
                component.set("v.days", days);
            }
        });
    },
    
    predictDaysOnMarket: function(component, property, price, callback) {
        // Stubbed service call. Make call to PredictionIO here.
        // More info: http://www.dreamhouseapp.io/pio/
        window.setTimeout($A.getCallback(function() {
            if (component.isValid()) {
                var days;
                var assessedValue = property.Assessed_Value__c;
                if (price < assessedValue) {
                    days = 2;
                } else if (price < assessedValue * 1.1) {
                    days = price / assessedValue * 10;
                } else if (price < assessedValue * 1.2) {
                    days = price / assessedValue * 30;
                } else if (price < assessedValue * 1.3) {
                    days = price / assessedValue * 40;
                } else if (price < assessedValue * 1.4) {
                    days = price / assessedValue * 60;
                } else {
                    days = 90;
                }
                callback(days);
            }
        }), 300);
    }
 
})