<template>
  <div>
    <el-row>
      <el-col :span="5" :xs="24" :offset="13">
        <label for="signature" class="labelclass">
          签名: <span class="auditor font-nomal"> {{ localSignature }}</span>
        </label>
      </el-col>
      <el-col :span="6">
        <label for="signTime" class="labelclass">
          日期：<span class="font-nomal"> {{ loaclSignTime }} </span>
        </label>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { parseTime } from "@/utils/ruoyi";
export default {
  props: {
    signature: {
      type: Number,
    },
    signTime: {
      type: String,
      default: ''
    },
    isCurrent: {
      type: Boolean,
      default: true
    }
  },
  data() {
    return {
      localSignature: '',
      loaclSignTime: '',
      localSignatureUserId: undefined
    }
  },
  watch: {
    signature(newval) {
      if (newval && !this.isCurrent) {
        this.localSignature = this.getUserName(newval);
        this.localSignatureUserId = newval;
      }
    },
    signTime(newval) {
      if (newval && !this.isCurrent) {
        this.loaclSignTime = newval;
      }
    },
    isCurrent(val) {
      this.syncDisplay(val);
    }
  },
  mounted() {
    this.syncDisplay(this.isCurrent);
  },
  methods: {
    syncDisplay(isCurrent) {
      if (isCurrent) {
        this.localSignature = this.$store.getters.name;
        this.localSignatureUserId = this.$store.getters.userId;
        this.loaclSignTime = parseTime(new Date(), '{y}-{m}-{d}');
      } else if (this.signature) {
        this.localSignature = this.getUserName(this.signature);
        this.localSignatureUserId = this.signature;
        this.loaclSignTime = this.signTime || '';
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.labelclass {
  text-align: right;
  vertical-align: middle;
  float: left;
  font-size: 14px;
  color: #606266;
  line-height: 40px;
  padding: 0 12px 0 0;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
}

.font-nomal {
  padding-left: 15px;
  font-weight: normal;
  color: #000;
}
</style>