import Taro, { Component } from '@tarojs/taro';
import { Image } from '@tarojs/components';
import defaultStoreIcon from './../assets/images/common/headimg.jpg'
import defaultGoodsIcon from './../assets/images/common/icon_default.png'
import defaultPersonIcon from './../assets/images/common/person_zhanweitu@2x.png'
interface IProps {
className: string;
src: string;
type: string;
key: string;
}
const iconEnum = {
'store': defaultStoreIcon,
'person': defaultPersonIcon,
'goods': defaultGoodsIcon
}
export default class BackTop extends Component<IProps> {
state = {};
handleError = key => {
const { type } = this.props
this.setState({
[`imgError${key}`]: iconEnum[type]
})
}
render() {
const { className, src, type, key } = this.props
return (
<Image {...this.props}
src={this.state[`imgError${key}`] || src}
onError={this.handleError.bind(this, key)}
/>
);
}
}