ToolBox.vue 6.64 KB
<template>
  <view class="tool-box" :style="toolStyle">
    <view :class="['btn', { hideIcon: !show }]" @click="open">
      <view class="icon sprite-icon icon-tool-file"></view>
      {{ folderName }}
    </view> 
    <view :class="['list', { showList: !show }]">
      <view class="title" @click="close">{{ folderName }}</view>
      <view class="list-body">
        <template v-for="(i, index) in data">
          <view :class="['item', { active: i[idKey] == id }]" :key="index" @click="jump(i)" :style="{'--i': index}">
            <template v-if="i.shortTitleUrl">
              <image class="icon" :src="i.shortTitleUrl" mode="scaleToFill" />
            </template>
            <template v-else>
              <view class="icon">
                <view class="sprite-icon icon-tool-file"></view>
              </view>
            </template>
            {{ i.shortTitle }}
          </view>
        </template>
      </view>
      <template v-if="showPayBtn">
        <view class="item" @click="toPay" :style="{'--i': data.length}">
          <view class="icon">
            <view class="sprite-icon icon-tool-pay"></view>
          </view>
          付款方式
        </view>
      </template>
      <template v-if="type != 'preview'">
        <view class="item" @click="finish" :style="{'--i': data.length + (showPayBtn ? 1 : 0)}">
          <view class="icon">
            <view class="sprite-icon icon-tool-finish"></view>
          </view>
          完成接待
        </view>
      </template>
    </view>
  </view>
</template>

<script type="text/ecmascript-6">
export default {
  name: 'ToolBox',
  props: {
    type: String,
    data: Array,
    id: [String, Number],
    showPayBtn: Boolean,
    idKey: {
      type: String,
      default: 'id'
    },
    toolStyle:String,
    folderName: {
      type: String,
      default: '文件夹'
    }
  },
  data () {
    return {
      show: true
    }
  },
  computed: {
    watchStatus () {
      return this.$store.state.user.historyStatus
    },
  },
  watch: {
    watchStatus: {
      immediate: true,
      handler (newval) {
        this.show = true
      }
    },
  },
  methods: {
    hide () {
      this.show = true
    },
    open () {
      this.show = false
      this.$emit('open')
    },
    close () {
      this.show = true
      this.$emit('close')
    },
    jump (item) {
      this.show = true
      this.$emit('choose', item)
    },
    finish () {
      this.$emit('finish')
    },
    // 选择付款方式
    toPay () {
      this.$emit('toPay')
    },

  }
}
</script>

<style scoped lang="scss">
.tool-box {
  position: fixed;
  right: toRpx(40);
  top: calc(5% + #{toRpx(140)});
  z-index: 998;
  width: toRpx(120);

  /* 基础变量定义 */
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);

  .btn {
    width: 100%;
    height: toRpx(120);
    background: #ffffff;
    /* 玻璃拟态背景,增加现代感 */
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(10px);
    border: toRpx(2) solid #ffffff;
    box-shadow: 0 toRpx(8) toRpx(24) 0 rgba(0, 0, 0, 0.12);
    border-radius: toRpx(24); /* 更圆润的角 */
    font-size: toRpx(24);
    color: #292d33;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: all 0.4s var(--ease-out);
    opacity: 1;
    transform: scale(1);
    overflow: hidden;
    position: relative;
    z-index: 2;

    .icon {
      width: toRpx(60);
      height: toRpx(60);
      margin-bottom: toRpx(8);
      transition: transform 0.3s ease;
    }

    &:active {
        transform: scale(0.96);
    }
  }

  .hideIcon {
    opacity: 0;
    transform: scale(0.8);
    pointer-events: none;
    transition: all 0.3s ease;
  }

  .list {
    width: 100%;
    /* 手风琴效果核心:通过 max-height 进行高度动画 */
    max-height: 0;
    border: toRpx(2) solid #ffffff;
    box-shadow: 0 toRpx(12) toRpx(32) 0 rgba(0, 0, 0, 0.15);
    border-radius: toRpx(24);
    display: flex;
    flex-direction: column;
    align-items: center;
    overflow: hidden;
    
    /* 定位与初始状态 */
    position: absolute;
    top: 0;
    left: 0;
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(20px);
    
    opacity: 0;
    visibility: hidden;
    
    z-index: 1;
    /* 干净利落的快速展开 */
    transition: 
      opacity 0.2s ease,
      visibility 0.2s ease,
      max-height 0.3s cubic-bezier(0.19, 1, 0.22, 1); /* Expo Out: 极快冲刺,迅速到位 */

    .title {
      width: 100%;
      height: toRpx(72); 
      background: rgba(248, 249, 251, 0.8);
      border-bottom: toRpx(1) solid rgba(0,0,0,0.03);
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: toRpx(26);
      font-weight: 600;
      color: #333;
      flex-shrink: 0;
      
      &:active {
        background: rgba(0,0,0,0.02);
      }
    }

    .list-body {
      width: 100%;
      /* 移除 max-height 限制,由父容器 max-height 控制 */
      /* max-height: 60vh; */
      overflow-y: auto;
      display: flex;
      flex-direction: column;
      align-items: center;
      padding-bottom: toRpx(16);
      
      /* 滚动条隐藏但可滚动 */
      &::-webkit-scrollbar {
        width: 0;
        height: 0;
        background-color: transparent;
      }
    }

    .item {
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      font-size: toRpx(22);
      color: #555;
      width: 100%;
      padding-top: toRpx(20);
      padding-bottom: toRpx(12);
      position: relative;
      
      /* 列表项快速复位 */
      opacity: 0;
      transform: translateY(5rpx); /* 减少位移距离,更紧凑 */
      transition: all 0.2s ease;
      
      .icon {
        width: toRpx(64); 
        height: toRpx(64);
        margin-bottom: toRpx(8);
        transition: transform 0.2s;
      }
      
      &:active {
        .icon {
            transform: scale(0.9);
        }
      }
      
      /* 选中态指示器 */
      &.active {
        color: #2c66f7;
        font-weight: 500;
        
        &::after {
            content: '';
            position: absolute;
            right: toRpx(10);
            top: 50%;
            width: toRpx(6);
            height: toRpx(6);
            background: #2c66f7;
            border-radius: 50%;
        }
      }
    }
  }

  .showList {
    opacity: 1;
    visibility: visible;
    max-height: toRpx(1000); 
    z-index: 3;

    .item {
      opacity: 1;
      transform: translateY(0);
      /* 极微小的延迟,保持整体性,减少拖沓感 */
      transition-delay: calc(0.05s + var(--i) * 0.02s);
    }
  }
}
</style>