<template>
    <div class="teachingschool">
        <m-header :backUrl="backUrl">
            <template slot="right">
                <router-link :to="{ path: '/teachingset?type=create' }">添加</router-link>
            </template>
        </m-header>

        <div v-if="schoolList.length > 0">
            <van-cell-group v-for="(item, index) in schoolList" :key="index">
                <van-cell title-class="cell-title" label-class="cell-label" :border="false">
                    <template slot="title">{{ item.name }}</template>
                    <template slot="label">{{ item.address }}</template>
                </van-cell>
                <div class="operation-btn">
                    <span class="edit" @click="onOperation('update', item)"><i></i>编辑</span>
                    <span class="delete" @click="onSchoolDel(item)"><i></i>删除</span>
                </div>
            </van-cell-group>
        </div>
        <m-empty v-else msg="暂无教学点"></m-empty>
    </div>
</template>
<script>
/* eslint-disable */
import MHeader from '@/components/MHeader'
import MEmpty from '@/components/MEmpty'
import { findVipSchoolByTeacher, schoolDel } from '@/api/teacher'
import { browser }  from '@/common/common'
import setLoading from '@/utils/loading'
export default {
    name: 'teachingschool',
    components: { MHeader, MEmpty },
    data() {
        let self = this
        return {
            schoolList: [],
            backUrl: {
                callBack: function() {
                    if(browser().iPhone) {
                        window.webkit.messageHandlers.DAYA.postMessage(JSON.stringify({api: 'back'}))
                    } else if(browser().android) {
                        DAYA.postMessage(JSON.stringify({api: 'back'}))
                    } else {
                        self.$router.push('/business')
                    }
                }
            }
        }
    },
    created() {
        let params = this.$route.query
        if(params.Authorization) {
            localStorage.setItem('Authorization', decodeURI(params.Authorization))
            localStorage.setItem('userInfo', decodeURI(params.Authorization))
        }
        this.getSchoolList()
    },
    mounted() {

    },
    methods: {
        async getSchoolList() {
            setLoading(true)
            await findVipSchoolByTeacher({ isDefault: 1 }).then(res => {
                let result = res.data
                if(result.code == 200) {
                    this.schoolList = result.data
                }
            })
            setLoading(false)
        },
        onSchoolDel(item) {
            this.$dialog.confirm({
                title: '提示',
                message: '您确认删除吗?'
            }).then(async () => {
                // on confirm
                setLoading(true)
                await schoolDel({ id: item.id }).then(res => {
                    let result = res.data
                    setLoading(false)
                    if(result.code == 200) {
                        this.$toast('删除成功')
                        this.getSchoolList()
                    } else {
                        this.$toast(result.msg)
                    }
                }).catch(() => {
                    setLoading(false)
                })
            })
        },
        onOperation(type, item) {
            this.$router.push({
                path: '/teachingset',
                query: {
                    type: type,
                    id: item.id,
                    name: item.name,
                    address: item.address,
                    longitudeLatitude: item.longitudeLatitude
                }
            })
        }
    }
}
</script>
<style lang='less' scoped>
@import url("../../assets/commonLess/variable.less");
.teachingschool {
    min-height: 100vh;
}
.cell-title, .cell-label {
    font-size: .14rem;
    line-height: .18rem;
}
/deep/.van-cell-group {
    margin-bottom: .02rem;
}
.operation-btn {
    text-align: center;
    font-size: .14rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: row;
    padding: .1rem 0;
    i {
        width: .18rem;
        height: .18rem;
        display: inline-block;
        margin-right: .08rem;
    }
    span {
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 0 .16rem;
    }
    .edit {
        color: @mColor;
        border-right: .02rem solid #D8D8D8;
        i {
            background: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACQAAAAkCAYAAADhAJiYAAADRklEQVRYR82YT0gUURzHv783u2paiToLXbsFQVFQ1KGDu2oZdOjQpUMdigrUSTNXkcKVQnPXhB37g10CD0FGQQRhaPcoKIqiKKKSRNZ1k1VJs935xWyupa7NjM5u+w67zLz5/b6f93u/997MjzDXXEH/PibUA9gJYH3yfpr/JwA8Jcbl8Glvv65F+o/cHWgB0ALmxHXGGxEDaB2raWilRGQEPfxvMMnREzFpvJ9k1T8AoCzjUUktOEiyGogCnKmcMRg3TegR0ucva1pagRiIEOEuGCfMjjidQGEBrXxUaXrpUv3nGLhgBipdQCGJqSx0uuF1EqJE7WgkEu1GqzkNQDzCUo4nUlX3dnFE5GDgDIg7k/tfqojZC8QYhiS5x6rr3y83Pa6gv4YJweWgbANiYEgC3KOK96NRrsjdHafAdBWAWPysLUAMfI4RuaM1DZ+MYJL9ctB/HIJuLM4pO4A+xjXNPV7bNGQWJnF+Bv1dINTZHaEPGtj9TWn8agGGXGpAZXC13Un9DnGne6yubsQ0DDPJ3YHrAE4uZ7OyKSO8EfEcz2htbcg0jM8n5JICPWeO/ctmJUCvZhArm1Kaw1ZgXMX5Nxk4YmRjEYhe/hA/PZPVzREjx/P9fX2SHPrSC+bDZmysATGPsAOeSFXjkl04pZjP55CL828BOGQGRn/GGlDCK4ckFgvOqZRiPT1O12z0NjMOmoWxAhQFoK+mTXPO50/ylGKqmitj5g6AA1ZgLABRn9CciibNPgZjcyJO+ruOQMVYtff5AlGfL08uLrgHcKVVGNNADByNKN7etWqbKw+OQQBb5qDGIYm9kaqzzxLiXV1rSpyx+8QoXwmMWSBtBnkbphQlsczXXWkrydWkAYC2zYlGhaBKmsareC4/AFC6UhhTQAQ8CSve3X+LFF5rL3LGHI8A3vE7zzEJonfz16sgMlxlBJwPK96LizWKLl0qdOSLfgZ2rUJ/iakJIGl7WKl/kbRc19kpO3O1UsHwAKgAsDFzQIRhEgWboE3vYdY8ALkB3prqxcouKIMI8XcGOQjIsUvQyI/hlBk5sLtfB9J34Sz5lEbiUzq7ig1ZV47RcyCrClbJpPxT0qOdmSvP0ATAC0p6vwCaV1oD5lfavQAAAABJRU5ErkJggg==') no-repeat center;
            background-size: contain;
        }
    }
    .delete {
        color: #EF5A50;
        i {
            background: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACIAAAAkCAYAAADsHujfAAACyElEQVRYR+1XS2gTURQ9Z2JSlNRMLGpBEVvEhYqI4ErRrgQXbZPWWpJYEBQEF34W7gS7EFeCFHFhRBS0Q6GlTbsSwc9GLAVx0UJBLCoVC5ZkhkbTaJO5MkkrmVDaTMhGmLeYxdx7zzvvcd975xDrjJ+RzoM55h8KcBjAhvXyy+IZCCZA5VxQG/66Vi3XCkovFONj6BOAJocEbOkkNLU/EauaiBHtaBaYM0UAviZl2gkhEZyyFkFiWu1P7KuaSDLSul+hZ6pAA7igaolHTojokfAoKG0EZlQtsef/IZKMdewk5IYi0gJAlcIGFD4eARqWV/IdoO5kRwDZBaCewJIAVrP+ASiAmATmIXweqNPv8cmbLI2e1ibkPe8E2O5sktpkExwP6NkWGtHQgADdtYGtFoVXqEdDSQBbqoWoRR2BYYtIGoC/FoDVY8hbpmJtRynwAcpxAL2lYASSJnmz0LimnAZhNXPpeCnkSCEucstqdFs9+cAEJgHZTMHtcqIUnhTmc4Ci/7tZjUioU4ihsuQvQS1RuFX1aHsfwMt2oryjaiPXC/FI+BsoO2z1itkefDY29qOrq9HrXZorJ6L6t/kYjy8tn9Bi2CXi7khJo7g94p4auPeIe7PCfWvc1xeuHilXaLNBLWF5Exix0H0RXCp7L/qCWuJqUViF54TSaJeK0qX2jw5ZvkkRc7bqt8YyRj4qzRtTi/NGsG4cwKEyTfshk84fC9Z7t2aLHtljj8tAJm2e99d7zuSBxxUR0c92tME0R1dR4otFh4bAaiqdkCxAyxF6nap41T/rY/y9XbOme8IHcnmZdApWbT7BlKqNrNjZosddGUY0PCGQI9WCO6kjEFe1xMWVGhuRhe7w3rxivgJptwVOZqgkVzCl5LwnAoODqVWJWD8XwuEGc5N5TURpJWS3AHWVYFeQ8xvEZwiGVE/mLp+++FVa8xfMsJNPkke/EgAAAABJRU5ErkJggg==') no-repeat center;
            background-size: contain;
        }
    }
}
.m-nav-bar__right a {
    color: @whiteColor;
}
</style>