<!--
 * @Title: 
 * @Description: 
 * @Author: swp
 * @Date: 2022-08-24 10:49:21
 * @LastEditors: 
 * @LastEditTime: 2022-08-24 10:49:21
-->
<template>
    <el-row>
        <el-col :span="24">
            <basic-container>
                <el-button-group>
                    <el-button type="primary" size="small" icon="el-icon-upload2" @click="handleImport">上传APK
                    </el-button>
                </el-button-group>
            </basic-container>
            <basic-container>
                <avue-crud :option="option" :table-loading="loading" :data="data" :page.sync="page"
                    :before-open="beforeOpen" ref="crud" v-model="form" :permission="permissionList"
                    @search-change="searchChange" @search-reset="searchReset" @selection-change="selectionChange"
                    @current-change="currentChange" @size-change="sizeChange" @refresh-change="refreshChange"
                    @on-load="onLoad">
                </avue-crud>
            </basic-container>
        </el-col>
        <el-dialog title="APK上传向导" :visible.sync="versionuploadDialog" width="60%" height="60%"
            :close-on-click-modal="false" append-to-body :v-loading="importLoading" v-if="versionuploadDialog">
            <versionupload :importLoading="importLoading" :visible.sync="versionuploadDialog" ref="rtuImportProcess">
            </versionupload>
        </el-dialog>
    </el-row>
</template>

<script>
import { getPage } from "@/api/versionmanage/version.js";

import versionupload from "./versionupload.vue";
export default {
    components: {
        versionupload,
    },
    data() {
        return {
            importLoading: false,
            loading: false,
            versionuploadDialog: false,
            infoDialog: false,
            orgId: 0,
            orgName: '',
            id: "",
            editForm: {},
            editDialog: false,
            form: {},
            selectionList: [],
            query: {},
            page: {
                pageSize: 10,
                currentPage: 1,
                total: 0,
            },
            option: {
                labelWidth: 120,
                viewLabelWidth: 100,
                searchlabelWidth: 100,
                height: "auto",
                calcHeight: 80,
                align: "center",
                headerAlign: "center",
                lazy: false,
                tip: false,
                simplePage: true,
                searchShow: true,
                searchMenuSpan: 6,
                tree: true,
                border: true,
                index: true,
                selection: false,
                viewBtn: false,
                viewTitle: "版本管理",
                editBtn: false,
                delBtn: false,
                addBtn: false,
                menu: false,
                menuWidth: 220,
                dialogType: "drawer",
                dialogClickModal: false,
                column: [
                    {
                        label: "版本ID",
                        prop: "appId",
                        span: 24,
                        hide: true,
                        viewDisplay: false,
                        type: "tree",
                        addDisabled: false,
                    },
                    {
                        label: "版本号",
                        prop: "version",
                        span: 24,
                        editDisplay: false,
                        addDisplay: false,
                    },
                    {
                        label: "APK名称",
                        prop: "appName",
                        span: 24,
                        editDisplay: false,
                        addDisplay: false,
                    },
                    {
                        label: "升级提示",
                        prop: "versionNote",
                        span: 24,
                        editDisplay: false,
                        addDisplay: false,
                    },
                    {
                        label: "上传时间",
                        prop: "createTime",
                        span: 24,

                    },
                    {
                        label: "是否可用",
                        prop: "isDeleted",
                        span: 24,
                        dicData: [{
                            label: '发布中',
                            value: 0,
                        }, {
                            label: '停用',
                            value: 1,
                        }],
                    },
                ],
            },
            data: [],
        };
    },
    computed: {
        // ...mapGetters(["userInfo", "permission"]),
        permissionList() {
            return {
                // addBtn: this.vaildData(this.permission.docCategory_add, false),
                // viewBtn: this.vaildData(this.permission.docCategory_view, false),
                // delBtn: this.vaildData(this.permission.docCategory_delete, false),
                // editBtn: this.vaildData(this.permission.docCategory_edit, false),
            };
        },
        ids() {
            let ids = [];
            this.selectionList.forEach((ele) => {
                ids.push(ele.id);
            });
            return ids.join(",");
        },
    },
    mounted() { },
    created() {

    },
    methods: {
        handleImport() {
            this.versionuploadDialog = true;
        },
        searchReset() {
            this.query = {};
            this.onLoad(this.page);
        },
        searchChange(params, done) {
            this.query = params;
            this.page.currentPage = 1;
            this.onLoad(this.page, params);
            done();
        },
        selectionChange(list) {
            this.selectionList = list;
        },
        selectionClear() {
            this.selectionList = [];
            this.$refs.crud.toggleSelection();
        },
        currentChange(currentPage) {
            this.page.currentPage = currentPage;
        },
        sizeChange(pageSize) {
            this.page.pageSize = pageSize;
        },
        refreshChange() {
            this.onLoad(this.page, this.query);
        },
        onLoad(page, params = {}) {
            this.loading = true;
            getPage(
                page.currentPage,
                page.pageSize,
                Object.assign(params, this.query)
            ).then((res) => {
                const data = res.data.data;
                this.page.total = data.total;
                this.data = data.records;
                this.loading = false;
                this.selectionClear();
            });
        },
    },
};
</script>
