index.js 1.67 KB
import Taro, { Component } from '@tarojs/taro';
import { View } from '@tarojs/components';
import { common as commonModel } from '../../models';
import Focus from '../resource-focus';
import HotSeries from '../resource-hot-series';
import Category from '../resource-category';
import './index.scss';
import getPrivateKey from '../../libs/request/getPrivateKey.js'

export default class Resources extends Component {
	constructor(props) {
		super(props);
		this.state = {
			floors: []
		};
	}

	static defaultProps = {
		floor: [],
		title: '热门系列',
		isShow: false
	}

	async componentDidMount() {
    const pk = await getPrivateKey();
    Taro.setStorage({ key: 'verifyKey', data: pk });
		commonModel.resource(this.props.code).then(res => {
			if (res && res.code === 200) {
				this.setState({
					floors: res.data
				});
			}
		});
	}

	render() {
		const { floors } = this.state;
		const { isShow } = this.props;

		return (
		<View className="resources">
			{
			floors.map(floor => {
				return (
					<View
						className={
							floor.template_name === 'tfGoodsList' ? 'resource-item no-right-padding' : 'resource-item'
						}
						key={floor.template_id}>
						{
							floor.template_name === 'focus' &&
							<Focus floor={floor.data}></Focus>
						}
						{
							floor.template_name === 'hotSeries' &&
							<HotSeries isShow={isShow} floor={floor.data} title={floor.template_intro}></HotSeries>
						}
						{
							
							floor.template_name === 'category' && floor.data.length > 0 &&
							floor.data.map((item, index) => {
								return (
									<Category floor={item} key={index}></Category>
								)
							})
						}
					</View>
				)
			})
			}
		</View>
		)
	}
}