<template>
    <view
        :class="'custom-class ' + classPrefix + ' ' + (isImageName ? 'van-icon--image' : classPrefix + '-' + name)"
        :style="'color: ' + color + ';font-size: ' + utils.addUnit(size) + ';' + customStyle"
        @tap="onClick"
    >
        <van-info v-if="info !== null || dot" :dot="dot" :info="info" custom-class="van-icon__info" />
        <image v-if="isImageName" :src="name" mode="aspectFit" class="van-icon__image" />
    </view>
</template>
<script module="utils" lang="wxs" src="@/node_modules/@vant/weapp/dist/wxs/utils.wxs"></script>
<script>
import { VantComponent } from '../common/component';
export default {
    data() {
        return {
            isImageName: ''
        };
    },
    props: {
        dot: Boolean,
        info: null,
        size: null,
        color: String,
        customStyle: String,
        classPrefix: {
            type: String,
            default: 'van-icon'
        },
        name: {
            type: String
        }
    },
    methods: {
        onClick() {
            this.$emit('click');
        }
    },
    watch: {
        name: {
            handler: function (val) {
                this.setData({
                    isImageName: val.indexOf('/') !== -1
                });
            },

            immediate: true
        }
    }
};
</script>
<style>
@import './index.css';
</style>
