<div class="main" id="main" v-cloak>
    <div class="breadcrumb-box">
        <el-breadcrumb separator="/">
            <el-breadcrumb-item onclick="location.href=location.href"><i class="el-icon-s-home"></i>插件安装</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <el-form ref="form" label-width="130px" label-position="left">

        <el-form-item label="安装包上传">
            <ui-file-upload action="@Url.ActionUrl("Upload")" v-model="Package" return-type="string" :limit="1" :max-size="102400" :file-list='[]' accept=".zip" 
                            :data="{savePath:'upload/~temp',fileType:'file',deleteRepeat:true}"
                            v-validate="{data:Package,dataType:'*',nullMsg:'请先上传安装包'}">
            </ui-file-upload>
            <span class="help-block validate-tips-box">只能上传.zip格式的安装包,文件包中必须包含插件描述配置文件。</span>
        </el-form-item>
        <el-form-item v-show="disabled==true">
            <el-alert title="安装成功，请到插件管理界面开启插件！" type="success" v-show="result=='success'" show-icon> </el-alert>
            <el-alert :title="result" type="error" show-icon v-show="result!='success'"></el-alert>
        </el-form-item>

        <el-form-item>
            <el-button type="primary" size="small" v-on:click="postSubmit" :disabled="disabled">安装</el-button>
            <span class="help-block validate-tips-box"></span>
        </el-form-item>
    </el-form>
    <div class="alert alert-warning alert-dismissible" role="alert">
        <strong>说明：</strong>
        <p>插件安装包必须为zip格式，插件目录结构和规则请参考PageAdmin插件开发教程。</p>
    </div>

</div>
<script type="text/javascript">
    var formData = { Package: "", AppType: "plugin", Guid: "@Html.Guid()", disabled: false, result:""};
    var vue = new Vue({
        el: "#main",
        data:formData,
        methods: {
            postSubmit: function () {
                var _this = this;
                var validated = _this.validateForm({});//表单验证
                if (validated) {
                    _this.ajax({
                        type: "post", url: "@Url.ActionUrl()", data: formData, success: function (data) {
                            _this.disabled = true;
                            var state = data.State;
                            var msg = data.Msg;
                            if (state == 1) {
                                _this.result ="success"
                            }
                            else
                            {
                                _this.result = msg;
                            }
                        }
                    });
                }
            }
        }
    });
</script>