<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Update</title>
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" name="viewport">
    <script src="assets/lib/vue/vue.min.js"></script>
    <link rel="stylesheet" href="assets/css/common.css" type="text/css"/>
    <link rel="stylesheet" href="assets/css/header.css" type="text/css"/>
    <link rel="stylesheet" href="assets/css/piece.css" type="text/css"/>
    <style>
        .actions{
            width: 100%;
        }
        .actions .container{
            min-height: 100px;
            margin: 12px;
            border-radius: 8px;
            background-color: white;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            padding-top: 16px;
            padding-bottom: 16px;
        }
        .actions .container .tip{
            color: #666666;
            margin-bottom: 16px;
        }
        .actions .container .btn{
            min-width: 160px;
            padding: 10px 16px;
            border-radius: 8px;
            display: flex;
            align-items: center;
            justify-content: center;
            cursor: pointer;
            color: white;
            background-color: #61affe;
        }
        .actions .container .btn.disable{
            color: black;
            background-color: #aeaeae;
        }
    </style>
</head>
<body>
<div id="app" v-cloak>
    <div class="header">
        <div class="btn" @click="onClickBack"><img class="icon" src="assets/icons/left.svg"></div>
        <div class="text">{{ lang.title }}</div>
        <div class="btn"></div>
    </div>
    <div class="content">
        <div class="settings">
            <div class="piece">
                <div class="piece-items">
                    <a class="piece-item">
                        <div class="piece-item-content">
                            <div class="piece-item-key">{{ lang.product }}</div>
                            <div class="piece-item-val">{{ package.product }}</div>
                        </div>
                    </a>
                    <a class="piece-item">
                        <div class="piece-item-content">
                            <div class="piece-item-key">{{ lang.version }}</div>
                            <div class="piece-item-val">{{ package.version }}</div>
                        </div>
                    </a>
                    <a class="piece-item">
                        <div class="piece-item-content">
                            <div class="piece-item-key">{{ lang.date }}</div>
                            <div class="piece-item-val">{{ package.date }}</div>
                        </div>
                    </a>
                </div>
            </div>
        </div>
        <div class="actions">
            <div class="container">
                <div class="tip" v-if="package.latest">{{ lang.tips_latest_version }}</div>
                <div class="btn" :class="{'disable': !package.allow}" @click="onClickUpgrade">{{ lang.update_start }}</div>
            </div>
        </div>
    </div>
</div>
</body>
</html>

<script>
    var app = new Vue({
        "el": "#app",
        "data": {
            lang: {
                title				: "固件升级",
                product             : "型号",
                version             : "版本",
                date                : "日期",
                tips_latest_version : "已是最新版本",
                update_start        : "开始更新",
            },
            package: {
                product             : "",
                version             : "",
                date                : "",
                latest              : false,
                allow               : false,
            }
        },
        "created": function(){
            if (typeof ($android) !== "undefined") {
                //加载语言
                this.lang = Object.assign(this.lang, JSON.parse($android.onGetLang()));
                //加载升级包
                $android.onLoadPackage();
            }
        },
        "methods": {
            onLoadPackage: function(data){
                this.package.latest     = data.latest;
                this.package.allow      = data.allow;
                this.package.product    = data.product;
                this.package.version    = data.version;
                this.package.date       = data.date;
            },
            onClickBack: function () {
                if(typeof($android) == "undefined"){
                    location.href = "index.html"
                    return;
                }
                $android.onClickBack();
            },
            onClickUpgrade: function(){
                if(!this.package.allow)
                    return false;
                if(typeof($android) == "undefined")
                    return false;
                $android.onClickUpgrade();
            },
        }
    })
</script>