import React, { Component } from "react";
import { View, Icon } from '@tarojs/components'
import { AtButton } from "taro-ui";
import './index.less';
import Taro from "@tarojs/taro";

class Result extends Component {
  constructor(props) {
    super(props);
    this.determine = this.determine.bind(this);
    this.punchClock = this.punchClock.bind(this);
  }

  determine() {
    Taro.eventCenter.trigger('result')
  }

  punchClock(e) {
    e.stopPropagation();
    Taro.eventCenter.trigger('GoPunchIn', this.props.punchClockInfor)
    Taro.switchTab({
      url: '/pages/punchClock/index',
    })

  }

  render() {
    return (
      <View className='result'>
        <View className='resultIcon'>
          {
            this.props.isShow
              ? <Icon size='80' type='warn' color='#ff9900' />
              : <Icon size='80' type='success' />
          }
        </View>
        <View className='resultTitle'>
          <View>申请成功{!this.props.isShow && ",可以打卡了！"}</View>
          {
            !this.props.isShow &&
            <View className='resultError'>
              {
                this.props.resultState === 0 ?
                  '' :
                  this.props.resultState === 43101 || this.props.resultState === 2 || this.props.resultState === 40003 ?
                    ('您可以联系上级审核' + '(' + this.props.resultState + ')') :
                    this.props.resultState === 41030 || this.props.resultState === 47003 || this.props.resultState === 40037 ?
                      ('您可以联系上级审核' + '(' + this.props.resultState + ')') :
                      ('您可以联系上级审核' + '(' + this.props.resultState + ')')
              }
            </View>
          }
        </View>
        {
          this.props.isShow && this.props.type != 1 &&
          <View className="resultTips">公出他人企业，需跟单人员“
            {this.props.tipList.toString()}
            ”审核同意，才可以打卡！！!</View>
        }
        {/* {
          this.props.isShow && this.props.type == 1 &&
          <View className="resultTips">已发出公出申请！待“
            {this.props.tipList.toString()}
            ”审核通过，方可打卡！</View>
        } */}
        <View className='resultOperation'>
          <AtButton circle onClick={this.determine}>
            再次发起
          </AtButton>
          {
            (!this.props.isShow || this.props.type == 1) &&
            <AtButton circle type='primary' onClick={this.punchClock}>
              前往打卡
            </AtButton>
          }
          <AtButton type='secondary' circle onClick={() => {
            Taro.navigateTo({
              url: '/pages/egressDetails/index?id=' + this.props.resultId
            })
          }}>
            前往分享
          </AtButton>
        </View>
      </View>
    )
  }
}

export default Result;
