const app = getApp();
Page({
    data: {
        showSetMoney: false,
        currentMoney: 0.00,
        currentMoneyText: "8754.09",
        priceError: false,
        visible : false,
        dateRangeText : '请选择日期区间',
        dateRange : [new Date().getTime()- 24 * 60 * 60 * 1000,new Date().getTime()],
        minDate: new Date().getTime() - 365 * 24 * 60 * 60 * 1000,
        maxDate: new Date().getTime(),
        incomeList : [
            {"title":"电脑","type":"income","dateTime":"01-06","from":"银行卡","money":"4500.00"}
        ],
        payList : [
            {"title":"狗粮","type":"expend","dateTime":"01-06","from":"支付宝","money":"35.00"},
            {"title":"狗粮","type":"expend","dateTime":"01-06","from":"支付宝","money":"35.00"},
            {"title":"狗粮","type":"expend","dateTime":"01-06","from":"支付宝","money":"35.00"},
            {"title":"狗粮","type":"expend","dateTime":"01-06","from":"支付宝","money":"35.00"},
            {"title":"狗粮","type":"expend","dateTime":"01-06","from":"支付宝","money":"35.00"},
            {"title":"狗粮","type":"expend","dateTime":"01-06","from":"支付宝","money":"35.00"}
        ]
    },
    onLoad: function (options) {
    },
    handleCalendar() {
        this.setData({ visible: true });
    },
    handleConfirm(e) {
        const { value } = e.detail;
        console.log(value);
        let valueText = app.$utils.formatDate(new Date(value[0])) + '至' +
            (value[1] ? app.$utils.formatDate(new Date(value[1])) : app.$utils.formatDate(new Date()));
        this.setData({
            visible: false,
            dateRange: value,
            dateRangeText: valueText
        });
    },

    showDialog() {
        this.setData({
            showSetMoney: true,
            currentMoney: this.data.currentMoneyText
        })
    },
    onPriceInput(e) {
        this.setData({
            currentMoney: e.detail.value
        })
    },
    onConfirm () {
        const isNumber = /^\d+(\.\d+)?$/.test(this.data.currentMoney);
        if (!isNumber) {
            this.setData({
                priceError: true
            })
            return;
        }
        this.setData({
            currentMoneyText: this.data.currentMoney,
            priceError: false
        })
        this.closeDialog()
    },
    closeDialog() {
        this.setData({
            showSetMoney: false
        })
    }
});
