var util = require('../../utils/util.js'); // 确保你有这样一个文件


var e = getApp();

Component({
    data: {
        defaultDailyFreeParseNum: "--",
        totalParseNum: "--",
        userInfo: null,
        hasUserInfo: !1,
        uuid: null,
        isVip: !1,
        startTime: "--",
        endTime: "--",
        formattedEndTime: ""
    },
    methods: {
        onLoad: function() {
            wx.showShareMenu({
                withShareTicket: !0,
                menus: [ "shareAppMessage", "shareTimeline" ]
            });
        },
        onShow: function() {
            var t = this;
            e.getCurrentTabbar(3, this), e.checkUpdateVersion(), console.log("执行用户.jsonShow"), 
            e.getUserInfo().then(function() {
                console.log("获取用户信息开始"), console.log(wx.getStorageSync("defaultDailyFreeParseNum")), 
                t.setData({
                    hasUserInfo: !0,
                    uuid: wx.getStorageSync("uuid"),
                    defaultDailyFreeParseNum: wx.getStorageSync("defaultDailyFreeParseNum"),
                    totalParseNum: wx.getStorageSync("totalParseNum"),
                    isVip: wx.getStorageSync("isMember"),
                    startTime: wx.getStorageSync("startTime"),
                    endTime: wx.getStorageSync("endTime")
                }), t.formatEndTime(), console.log("获取用户信息结束");
            }).catch(function(e) {
                console.error("获取用户信息失败:", e);
            }).finally(function() {
                console.log("getUserInfo调用完成");
            });
        },
        formatEndTime: function() {
            var e = this.data.endTime;
              // 将秒时间戳转换为毫秒时间戳
              var date = new Date(e * 1000);

              // 格式化为“YYYY年MM月DD日”
              var year = date.getFullYear();
              var month = String(date.getMonth() + 1).padStart(2, "0"); // 月份从 0 开始，需要 +1
              var day = String(date.getDate()).padStart(2, "0");

              var formattedDate = `${year}-${month}-${day}`;

              // 更新到 data
              this.setData({
                  formattedEndTime: formattedDate
              });

        },
        getUserInfo: function(e) {},
        openvip: function(e) {
            wx.navigateTo({
                url: "../vip_recharge/vip_recharge?show=true"
            });
        },
        opennum: function(e) {
            wx.navigateTo({
                url: "../vip_recharge/vip_recharge?show=true"
            });
        },
        getTotalParseNum: function() {
            this.setData({
                defaultDailyFreeParseNum: wx.getStorageSync("defaultDailyFreeParseNum")
            });
        },
        showExchangeModal: function(t) {
            var o = this;
            wx.showLoading(), wx.showModal({
                title: "卡密兑换",
                content: "",
                editable: !0,
                placeholderText: "输入卡密",
                success: function(t) {
                    t.confirm ? (console.log("用户点击确定"), e.apiRequest({
                        url: "/myapp/redeem_card/",
                        method: "POST",
                        data: {
                            openid: wx.getStorageSync("openid"),
                            uuid: wx.getStorageSync("uuid"),
                            card_code: t.content
                        },
                        success: function(t) {
                            e.getUserInfo().then(function() {
                                o.getTotalParseNum(), console.log(wx.getStorageSync("defaultDailyFreeParseNum"));
                            }).catch(function(e) {
                                console.error("An error occurred:", e);
                            }), "success" == t.data.status ? wx.showToast({
                                title: t.data.message,
                                icon: "success",
                                duration: 1e3
                            }) : wx.showToast({
                                title: t.data.error,
                                icon: "error",
                                duration: 1e3
                            }), console.log("卡密兑换成功:", t.data);
                        },
                        fail: function(e) {
                            wx.showToast({
                                title: "请求网络失败",
                                icon: "none",
                                duration: 1e3
                            }), console.error("卡密兑换失败:", e);
                        }
                    })) : t.cancel && (console.log("用户点击取消"), wx.hideLoading());
                }
            });
        },
        onShareAppMessage: function() {
            return {
                title: "推荐一款免费又超好用的视频文案创作工具，分享给大家一起使用",
                path: "/pages/index/index?uuid=" + wx.getStorageSync("uuid"),
                imageUrl: "/images/share.jpg",
                success: function(e) {
                    wx.showToast({
                        title: "分享成功",
                        icon: "success",
                        duration: 2e3
                    });
                },
                fail: function(e) {
                    wx.showToast({
                        title: "分享失败",
                        icon: "none",
                        duration: 2e3
                    });
                }
            };
        }
    },
    onShareTimeline: function() {
        return {
            title: "推荐一款免费又超好用的视频文案创作工具，分享给大家一起使用",
            path: "/pages/index/index?uuid=" + wx.getStorageSync("uuid"),
            imageUrl: "/images/share.jpg",
            success: function(e) {
                wx.showToast({
                    title: "分享成功",
                    icon: "success",
                    duration: 2e3
                });
            },
            fail: function(e) {
                wx.showToast({
                    title: "分享失败",
                    icon: "none",
                    duration: 2e3
                });
            }
        };
    }
});