<template>
  <div style="display: block">
    <slot name="pre"></slot>
    <div class="user-audit">
      <div class="circle-user">
        <Tooltip v-if="userName" :content="userName" placement="bottom-start" width="45px"/>
        <Tooltip v-else :content="user.name" placement="bottom-start" width="45px"/>
        <!--        :style="{-->
        <!--        backgroundColor: '#fff'-->
        <!--        }">-->
        <div v-if="user.icon"
             class="el-timeline-item__node">
          <div v-if="user.isAgent&&!showIcon">
          </div>
          <el-icon v-else 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
  },
  showIcon: {
    type: Boolean,
    default: false
  },
  user: {
    type: Object,
    default: {}
  },
  userName: {
    type: String,
    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' || state === 'ROLLBACK') {
    // user["icon"] = 'Close'
    // user["color"] = "#f56c6c"
    user["icon"] = 'CircleCloseFilled'
    user["color"] = "#f56c6c"
  }
  if (state === 'PASS') {
    user["icon"] = 'MoreFilled'
    user["color"] = "#c0c4cc"
  }
  // if (state === 'ROLLBACK') {
  //   // user["icon"] = 'RefreshLeft'
  //   // user["color"] = "#f78f5f"
  //   user["icon"] = 'CircleCloseFilled'
  //   user["color"] = "#f56c6c"
  // }
  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>
