var t = getApp(), a = require("../../../wxParse/wxParse.js"), e = 0;

Page({
    data: {
        article: {},
        copyright: "",
        id: 0,
        blist: {},
        tcolor: "",
        hide_time: "0",
        hide_title: "0",
        hide_tabbar: "0",
        isshow: 0,
        stars: [ 0, 1, 2, 3, 4 ],
        normalSrc: "../../resource/images/no-star.png",
        selectedSrc: "../../resource/images/full-star.png",
        halfSrc: "../../resource/images/half-star.png",
        key: 5,
        content: "",
        oid: "",
        commentList: {},
        voteArr: [],
        showVoteHoverImg: 0
    },
    onLoad: function(e) {
        this.setData({
            copyright: t.globalData.copyright
        });
        var i = e.id, r = this, n = t.siteInfo.uniacid;
        this.setData({
            id: i
        });
        var o = new Array();
        (o = wx.getStorageSync("voteArr")) && -1 != o.indexOf(i) && this.setData({
            showVoteHoverImg: 1
        }), t.util.request({
            url: "?action=news_details",//entry/wxapp/content
            data: {
                m: "yyf_company",
                action:"news_details",
                id: i,
                uniacid: n
            },
            cachetime: 0,
            success: function(t) {
                t.data.errno || (r.setTabBar(i), a.wxParse("article1", "html", t.data.data.content, r, 10), 
                r.setData({
                    article: t.data.data,
                    hide_time: t.data.data.hide_time,
                    hide_title: t.data.data.hide_title
                }), wx.setNavigationBarTitle({
                    title: t.data.data.title
                }));
            }
        }), t.util.request({
            url: "entry/wxapp/TabBar",
            data: {
                m: "yyf_company",
                uniacid: n
            },
            cachetime: 0,
            success: function(t) {
                if (!t.data.errno) {
                    var a = wx.getStorageSync("barlist");
                    "" != a && a.uptime == t.data.data.uptime || (wx.setStorageSync("barlist", t.data.data), 
                    r.setTabBar());
                }
            }
        }), t.util.request({
            url: "entry/wxapp/Comment",
            data: {
                m: "yyf_company",
                uniacid: n,
                aid: i,
                op: "list"
            },
            cachetime: 0,
            success: function(t) {
                t.data.errno || r.setData({
                    commentList: t.data.data
                });
            }
        });
    },
    startRating: function(a) {
        var e = this, i = t.siteInfo.uniacid, r = wx.getStorageSync("comment_sendtime");
        if ("" == r && (r = 0), "" == e.data.content) return e.notice("评论内容您还没有填写"), !1;
        t.util.request({
            url: "entry/wxapp/Comment",
            data: {
                m: "yyf_company",
                uniacid: i,
                score: e.data.key,
                content: e.data.content,
                op: "add",
                aid: e.data.id,
                sendtime: r
            },
            cachetime: 0,
            success: function(t) {
                if (!t.data.errno) {
                    var a = Date.parse(new Date());
                    a /= 1e3, wx.setStorageSync("comment_sendtime", a), "1" == t.data.data.check_comment ? (e.notice("提交成功，请等待管理员审核"), 
                    e.setData({
                        isshow: 0
                    })) : (e.setData({
                        commentList: t.data.data.commentList
                    }), wx.showModal({
                        title: "提交成功",
                        content: "",
                        success: function(t) {
                            e.setData({
                                isshow: 0
                            });
                        }
                    }));
                }
            }
        });
    },
    upvoteAction: function(t) {
        var a = new Array();
        (a = wx.getStorageSync("voteArr")) ? -1 == a.indexOf(this.data.id) ? this.submitUpvote() : this.UpvoteNotice() : this.submitUpvote();
    },
    submitUpvote: function() {
        var a = this, e = t.siteInfo.uniacid;
        t.util.request({
            url: "entry/wxapp/Upvote",
            data: {
                m: "yyf_company",
                uniacid: e,
                aid: a.data.id
            },
            cachetime: 0,
            success: function(t) {
                if (!t.data.errno) {
                    var e = a.data.article;
                    if (e.vote_num = t.data.data, a.setData({
                        article: e,
                        showVoteHoverImg: 1
                    }), i = new Array(), !(i = wx.getStorageSync("voteArr"))) var i = new Array();
                    i.push(a.data.id), wx.setStorageSync("voteArr", i);
                }
            }
        });
    },
    UpvoteNotice: function() {
        wx.showToast({
            title: "您已经点赞过了哦！"
        });
    },
    notice: function(t) {
        wx.showModal({
            title: t,
            content: "",
            success: function(t) {}
        });
    },
    onShareAppMessage: function(t) {
        return {
            title: this.data.article.title,
            path: "/yyf_company/pages/content/content?id=" + this.data.id
        };
    },
    setTabBar: function(t) {
        if (!(n = wx.getStorageSync("barlist"))) return !1;
        this.setData({
            blist: n,
            tcolor: n.tcolor,
            hide_tabbar: n.hide_tabbar
        });
        var a, e;
        a = "" != n.font_color ? n.font_color : "#ffffff", e = "" != n.head_color ? n.head_color : n.tcolor, 
        wx.setNavigationBarColor({
            frontColor: a,
            backgroundColor: e
        });
        var i = getCurrentPages(), r = i[i.length - 1], n = this.data.blist;
        r.options.id == t && (n.isCurrentPage = !0);
        var o = new Array(n.m1_path, n.m2_path, n.m3_path, n.m4_path), s = 0;
        for (var c in o) o[c] == "a" + t && (s = parseInt(c) + 1);
        n.currentNum = s, this.setData({
            blist: n
        });
    },
    tel: function() {
        var t = this.data.blist.phone;
        wx.makePhoneCall({
            phoneNumber: t
        });
    },
    driver: function() {
        wx.openLocation({
            latitude: Number(this.data.blist.jing),
            longitude: Number(this.data.blist.wei),
            address: this.data.blist.address
        });
    },
    tabNav: function(t) {
        var a = t.currentTarget.dataset.url, e = t.currentTarget.dataset.tab;
        "-1" != a.indexOf("https") ? (wx.setStorageSync("navurl", a), a = "../webview/webview?op=" + e, 
        wx.navigateTo({
            url: a
        })) : wx.redirectTo({
            url: a
        });
    },
    copy_action: function() {
        var t = this.data.blist.copyright;
        if ("1" == t.copy_kind) {
            var a = t.copy_phone;
            wx.makePhoneCall({
                phoneNumber: a
            });
        }
        if ("2" == t.copy_kind) {
            var e = t.copy_appid, i = t.copy_ddress;
            wx.navigateToMiniProgram({
                appId: e,
                path: i,
                success: function(t) {}
            });
        }
    },
    selectLeft: function(t) {
        var a = t.currentTarget.dataset.key;
        .5 == this.data.key && .5 == t.currentTarget.dataset.key && (a = 0), e = a, this.setData({
            key: a
        });
    },
    selectRight: function(t) {
        var a = t.currentTarget.dataset.key;
        e = a, this.setData({
            key: a
        });
    },
    hideComment: function() {
        this.setData({
            isshow: 0
        });
    },
    showComment: function() {
        this.setData({
            isshow: 1
        });
    },
    textareaBlur: function(t) {
        this.setData({
            content: t.detail.value
        });
    }
});