<template>
  <view class="modal-mask" v-if="show" @click="closeModal">
    <view class="modal-content" @click.stop>
      <view class="staff-code-modal">
        <view class="title">员工验证码</view>
        <view class="code-container">
          <view class="code">{{ code }}</view>
        </view>
        <view class="expire-container">
          <view class="expire-label">
            将于 {{ expireTime}} 过期
            <br/>若生成新的验证码该验证码将立即失效
          </view>
        </view>
        <view class="tips">请将验证码提供给新员工，用于绑定账号</view>
        <button
          class="share-btn"
          open-type="share"
        >
          <u-icon name="share" size="32" color="#2979ff"></u-icon>
          <text>分享给好友</text>
        </button>
        <view class="close-btn" @click="closeModal">
          <text class="close-icon">×</text>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  name: 'StaffCodeModal',
  props: {
    value: {
      type: Boolean,
      default: false
    },
    code: {
      type: String,
      default: ''
    },
    expireTime: {
      type: String,
      default: ''
    },
    mchId: {
      type: [String, Number],
      default: ''
    }
  },
  computed: {
    show: {
      get() {
        return this.value
      },
      set(val) {
        this.$emit('input', val)
      }
    }
  },
  methods: {
    closeModal() {
      this.show = false
    }
  },
}
</script>

<style lang="scss" scoped>
.modal-mask {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
}

.modal-content {
  width: 600rpx;
  animation: modalShow 0.3s ease;
}

@keyframes modalShow {
  from {
    transform: scale(0.8);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

.staff-code-modal {
  position: relative;
  padding: 40rpx;
  background: #fff;
  border-radius: 20rpx;

  .title {
    font-size: 36rpx;
    font-weight: bold;
    text-align: center;
    margin-bottom: 40rpx;
    color: #333;
  }

  .code-container, .expire-container {
    margin-bottom: 30rpx;

    .code-label, .expire-label {
      font-size: 28rpx;
      color: #666;
      margin-bottom: 10rpx;
      text-align: center;
    }

    .code {
      font-size: 48rpx;
      font-weight: bold;
      color: #2979ff;
      text-align: center;
      letter-spacing: 4rpx;
      background: #f5f7fa;
      padding: 20rpx;
      border-radius: 10rpx;
    }

    .expire-time {
      font-size: 32rpx;
      color: #333;
      text-align: center;
    }
  }

  .tips {
    font-size: 24rpx;
    color: #999;
    text-align: center;
    margin-top: 20rpx;
    margin-bottom: 30rpx;
  }

  .share-btn {
    width: 80%;
    margin: 0 auto;
    background: #fff;
    border-radius: 50rpx;
    padding: 20rpx 20rpx;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.1);
    border: 2rpx solid #2979ff;

    text {
      margin-left: 10rpx;
      font-size: 28rpx;
      color: #2979ff;
    }
  }

  .close-btn {
    position: absolute;
    top: 20rpx;
    right: 20rpx;
    width: 40rpx;
    height: 40rpx;
    display: flex;
    align-items: center;
    justify-content: center;

    .close-icon {
      font-size: 40rpx;
      color: #999;
      line-height: 1;
    }
  }
}
</style>