import React, { Component } from 'react'; import { connect } from 'react-redux'; import DocumentTitle from 'react-document-title'; import 'antd-mobile/dist/antd-mobile.less'; import styles from './index.less'; import router from 'umi/router'; import PlayMusic from '../components/playMusic/index'; import { onPlay, getPlayFlag, setImg } from '../common/common'; import { sysMobileNum } from '../../../utils/helper'; import icon03 from '../assets/detail/icon03.png'; import icon04 from '../assets/detail/icon04.png'; import * as Service from '../services/index'; import { Toast } from 'antd-mobile'; @connect(() => ({})) class Index extends Component { constructor(props) { super(props); this.state = { playFlag: getPlayFlag(), popFlag: false, numflag: true, number: null, numberT: null, catFoodList: [], schoolDetail: {}, votes: 0, //总的投票数 loading: false, //请求中 }; } componentWillMount = () => {}; componentDidMount = () => { this.getSchoolDetail(); }; //获取学校信息详情 getSchoolDetail = () => { const detailStr = window.sessionStorage.getItem('selectSchool'); const schoolDetail = JSON.parse(detailStr); this.setState({ schoolDetail, votes: schoolDetail && schoolDetail.votes ? schoolDetail.votes : '0', }); }; onClick = () => { const { number, loading } = this.state; if (number || loading) { return; } this.feed(); // this.feeding(); // this.raise(70); // this.popFlag(true); }; //喂养 feed = async () => { const { schoolDetail } = this.state; var openId = window.localStorage.getItem('openId'); //makeOpenId if (!openId) { openId = sysMobileNum; window.localStorage.setItem('openId', sysMobileNum); } if (!schoolDetail.schoolCode || !openId) { return; } const params = { id: schoolDetail.schoolCode, wxOpenId: openId, subscribe: 0, }; const { rc, data, msg } = await Service.feed(params); try { if (!rc) { // alert(JSON.stringify(data)); if (data && data.type === '1' && data.thisVotes === '0' && data.totalVotes === '100') { //弹出100内容提示框 this.popFlag(true, true); } else if (data && data.thisVotes) { //播放喂养动画 this.raise(data.thisVotes ? parseInt(data.thisVotes) : 10); this.feeding(); this.setState({ votes: data.votes, }); } } else { Toast.info(msg, 2); } } catch (e) {} //修改加载状态 this.setState({ loading: false, }); }; /**** * 猫数字和文案动画 */ raise = number => { const _this = this; _this.setState({ number, numberT: number, }); setTimeout(function() { _this.setState({ number: null, }); }, 2000); }; /**** * 撒猫粮动画 */ feeding = () => { const _this = this; const catFoodList = new Array(30); for (var i = 0; i < catFoodList.length; i++) { const x = 6.66 * Math.random().toFixed(2); const animationDuration = Math.random().toFixed(2) * 0.5 + 0.8; const animationDelay = Math.random().toFixed(2) * 0.6; const rotate = 360 * Math.random().toFixed(2); const scale = Math.random().toFixed(2) * 0.5 + 0.5; const style = { left: `${x}rem`, animationDuration: `${animationDuration}s`, animationDelay: `${animationDelay}s`, transform: `rotate(${rotate}deg) scale(${scale})`, }; catFoodList[i] = { style }; } _this.setState({ catFoodList, }); setTimeout(function() { _this.setState({ catFoodList: [], }); }, 2000); }; /**** * 弹窗提示 * flag 弹窗开启 * numflag true弹出100的内容框 false弹出150的内容框 */ popFlag = (flag, numflag) => { this.setState({ numflag: numflag, popFlag: flag, }); }; render() { const { popFlag, numflag, playFlag, number, numberT, catFoodList, schoolDetail, votes, } = this.state; return (
{ onPlay(playFlag, flag => { this.setState({ playFlag: flag, }); }); }} >
投喂总量:{votes ? votes : ''}
{schoolDetail && schoolDetail.catDescription ? schoolDetail.catDescription : ''}
{schoolDetail && schoolDetail.schoolName ? schoolDetail.schoolName : ''} {schoolDetail && schoolDetail.catName ? schoolDetail.catName : ''}
{/* icon */} 校宠美照
{catFoodList.map((food, i) => (
))}
{numflag ? 100 : 150}
{ router.push('share'); }} >
); } } export default Index;