<template>
  <div style="display: block">
    <slot name="pre"></slot>
    <div class="user-audit">
      <div class="circle-user">
        <Tooltip :content="user.name" placement="bottom-start" width="45px"/>
        <div v-if="user.icon"
             class="el-timeline-item__node" :style="{
                      backgroundColor: '#fff'
                    }">
          <el-icon v-if="user.icon" size="15" :color="user.color" :class="user.class">
            <component :is="user.icon"/>
          </el-icon>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>

const props = defineProps({
  row: {
    type: Number,
    default: 1
  },
  hoverTip: {
    type: Boolean,
    default: false
  },
  user: {
    type: Object,
    default: {}
  },
  mode: {
    type: String,
    default: 'design'
  },
  type: {
    type: String,
    default: ''
  },
})

const init = () => {
  // for (let user of props.userInfo) {
  initUser(props.user)
  // }
}

const initUser = (user) => {
  let state = user.state
  //创建节点
  if (state === 'CREATE') {
    user["icon"] = 'CircleCheckFilled'
    user["color"] = "#0bbd87"
  }
  //审批通过
  if (state === 'AGREE' || state === 'AUTO_PASS') {
    user["icon"] = 'CircleCheckFilled'
    user["color"] = "#0bbd87"
  }
  if (props.type === "CC") {
    user["icon"] = "Promotion"
    user["color"] = "#3395f8"
  }
  //审批处理中
  if (state === 'RUNNING') {
    user["icon"] = 'Loading'
    user["color"] = "#f78f5f"
    user["class"] = 'is-loading'
  }
  //拒绝后评论
  if (state === 'REFUSE') {
    user["icon"] = 'Close'
    user["color"] = "#f56c6c"
  }
  if (state === 'PASS') {
    user["icon"] = 'MoreFilled'
    user["color"] = "#c0c4cc"
  }
  if (state === 'ROLLBACK') {
    user["icon"] = 'RefreshLeft'
    user["color"] = "#f78f5f"
  }
  return user;
}

init()
</script>

<style scoped lang="scss">
.user-audit {
  display: flex;
  flex-direction: column;
  align-items: center;

  .circle-user {
    width: 46px;
    height: 46px;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 50%;
    border: 1px solid #ACACAC;
    position: relative;
    background-color: #8a7243;
    color: #fff;

    .el-timeline-item__node {
      position: absolute;
      bottom: 0;
      right: 1px;
    }
  }
}
</style>
