import React, { Component } from "react";
import { AtModal, AtModalAction, AtModalContent, AtIcon } from "taro-ui";
import { Button, Image, View } from "@tarojs/components";
import Taro from "@tarojs/taro";
import './index.less';
import { listRecordLog } from '../../utils/servers/servers';
import "taro-ui/dist/style/components/icon.scss";
import { getClockState } from "../../utils/tools";


class HistoricalClock extends Component {
  constructor(props) {
    super(props);
    this.state = {
      publicReleaseLog: []
    }
    this.listRecordLog = this.listRecordLog.bind(this);
  }

  componentDidMount() {
    this.listRecordLog();
  }

  listRecordLog() {
    Taro.showLoading({
      title: '加载中...'
    })
    listRecordLog({
      psrId: this.props.id
    }).then(v => {
      Taro.hideLoading();
      if (v.code === 200) {
        this.setState({
          publicReleaseLog: v.data,
        })
      } else {
        Taro.showToast({ title: v.msg, icon: 'none' })
      }
    }).catch(err => {
      Taro.hideLoading();
      Taro.showToast({ title: '系统错误.请稍后重试', icon: 'none' })
      //console.log(err)
    })
  }

  render() {
    return (
      <AtModal
        width="90%"
        isOpened={this.props.isOpened}
        onClose={this.props.onClose}
        onCancel={this.props.onClose}>
        <AtModalContent>
          <View className='historicalClock'>
            {
              this.state.publicReleaseLog.map((v, k) => (
                <View key={k} className='item'>
                  <View className='head'>
                    <View className='spot' />
                    <View className='clockTime' style={{
                      color: getClockState(v.processStatus).color
                    }}>
                      {getClockState(v.processStatus).title}
                    </View>
                  </View>
                  <View className='clockContent'>
                    <View className='verticalLine' style={{
                      visibility: this.state.publicReleaseLog[k + 1] ? 'visible' : 'hidden'
                    }} />
                    <View className='rightContent' style={{
                      paddingBottom: this.state.publicReleaseLog[k + 1] ? '30px' : 0
                    }}>
                      <View className='contentItem'>
                        <AtIcon className='atIcon' value='user' size='15' color='#999999' />
                        操作人:{v.name}
                      </View>
                      <View className='contentItem'>
                        <AtIcon className='atIcon' value='clock' size='15' color='#999999' />
                        操作时间:{v.createTime}
                      </View>
                      {v.content ? <View className='contentItem'>
                        <AtIcon className='atIcon' value='message' size='15' color='#999999' />
                        备注:{v.content}
                      </View> : null}
                    </View>
                  </View>
                </View>
              ))
            }
          </View>
        </AtModalContent>
        <AtModalAction>
          <Button onClick={this.props.onClose}>确定</Button>
        </AtModalAction>
      </AtModal>
    )
  }
}

export default HistoricalClock;
