<template>
    <div class="app-container">
        <div class="title">应用中心</div>
        <div class="list">
            <div class="item" @click="upPop">
                <img src="./kp.png" class="icon">
                <div class="info">
                    <div class="name">开票</div>
                    <div class="intro">

                    </div>
                </div>
            </div>
            <div class="item" v-for="item in list" :key="item.id" @click="to(item)">
                <img :src="item.coverImg" class="icon">
                <div class="info">
                    <div class="name">{{ item.name }}</div>
                    <div class="intro">
                        {{ item.value }}
                    </div>
                </div>
            </div>
        </div>
        <!-- 弹窗 -->
        <el-dialog :title="title" :visible.sync="dialogVisible" width="30%" >
            <el-form :model="forms">
                <el-form-item label="账号：" label-width="60px">
                    <el-input v-model="forms.account" :disabled="title != '绑定数点票账号'" autocomplete="off"></el-input>
                </el-form-item>
                <!-- <el-form-item label="密码/验证码" label-width="120px">
                    <el-input v-model="forms.name" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="开票项目:" label-width="120px">
                    <el-input v-model="forms.name" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="开票类型:" label-width="120px">
                    <el-input v-model="forms.name" autocomplete="off"></el-input>
                </el-form-item> -->
                <div style="text-align: right;" v-if="title == '绑定数点票账号'">联系区域经理开通</div>
                <div style="text-align: center;" v-else @click="title = '绑定数点票账号'">更换绑定</div>
                <!-- <el-form-item label="活动区域" label-width="120px">
                    <el-select v-model="form.region" placeholder="请选择活动区域">
                        <el-option label="区域一" value="shanghai"></el-option>
                        <el-option label="区域二" value="beijing"></el-option>
                    </el-select>
                </el-form-item> -->
            </el-form>
            <span slot="footer" class="dialog-footer" v-if="title == '绑定数点票账号'">
                <el-button @click="dialogVisible = false">取 消</el-button>
                <el-button type="primary" @click="sumbitEvent">确 定</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
import { appCenterGet, getbinding } from "@/api/application";
export default {
    data() {
        return {
            list: [],
            dialogVisible: false,
            forms: {},
            title: '绑定数点票账号',

        }
    },
    mounted() {
        this.appCenterGet()
        this.getbinding()
    },
    methods: {
        upPop() {
            this.dialogVisible = true
        },
        sumbitEvent() {
            if (this.forms.account) {
                this.dialogVisible = false
                this.getbinding(this.forms)
            }
        },
        // 跳转
        to(item) {
            localStorage.setItem('applocation', JSON.stringify(item))
            this.$router.push({
                name: item.absUrl
            })
        },
        // 获取应用列表
        async appCenterGet() {
            try {
                const res = await appCenterGet()
                this.list = res
            } catch (error) {
                console.log(error);
            }
        },

        // 开票
        async getbinding(d = "") {
            try {
                const res = await getbinding(d)
                if (res) {
                    this.forms = res.store
                    this.title = '数电票账号已绑定'
                } else {
                    this.title = '绑定数点票账号'
                    this.forms = {}
                }
            } catch (error) {
                console.log(error);
            }
        }

    }
}
</script>

<style scoped lang="scss">
.title {
    font-size: 24px;
    font-weight: bold;
    padding-top: 10px;
}

.list {
    padding: 20px 0;
    display: flex;
    flex-wrap: wrap;
    gap: 14px;

    .item {
        width: 400px;
        background-color: #f5f5f5;
        display: flex;
        align-items: center;
        padding: 14px;

        &:hover {
            cursor: pointer;

            .info {
                .name {
                    color: #39D47A;
                }

                .intro {
                    color: #39D47A;
                }
            }
        }

        .icon {
            width: 40px;
            height: 40px;
            object-fit: cover;
        }

        .info {
            flex: 1;
            padding-left: 10px;

            .name {
                font-weight: bold;
            }

            .intro {
                color: #999;
                margin-top: 4px;
            }
        }
    }
}
</style>