ToolBox.vue 5.52 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);
  .btn {
    width: 100%;
    height: toRpx(120);
    background-image: linear-gradient(180deg, #ffffff 0%, #f8f9fb 100%);
    border: toRpx(2) solid #ffffff;
    box-shadow: 0 toRpx(8) toRpx(24) 0 #00000033;
    border-radius: toRpx(16);
    font-size: toRpx(24);
    color: #292d33;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: all 0.2s cubic-bezier(0.19, 1, 0.22, 1);
    opacity: 1;
    transform: scale(1);
    overflow: hidden;
    position: relative;
    z-index: 2;

    .icon {
      width: toRpx(60);
      height: toRpx(60);
      margin-bottom: toRpx(8);
      transition: all 0.2s;
    }
  }
  .hideIcon {
    opacity: 0;
    transform: translateY(toRpx(10)) scale(0.95);
    pointer-events: none;
  }
  .list {
    width: 100%;
    border: toRpx(2) solid #ffffff;
    box-shadow: 0 toRpx(8) toRpx(22) 0 #0000001a;
    border-radius: toRpx(16);
    display: flex;
    flex-direction: column;
    align-items: center;
    transition: all 0.25s cubic-bezier(0.19, 1, 0.22, 1);
    overflow: hidden;
    opacity: 0;
    position: absolute;
    top: 0;
    left: 0;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    visibility: hidden;
    max-height: toRpx(120); /* Same as button height initially */
    transform: scale(0.98);
    transform-origin: top center;
    z-index: 1;

    .title {
      width: 100%;
      height: toRpx(56);
      background: #f8f9fb;
      border-bottom: toRpx(1) solid rgba(0,0,0,0.05);
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: toRpx(24);
      font-weight: 500;
      color: #333;
      flex-shrink: 0;
    }
    .list-body {
      width: 100%;
      max-height: 60vh;
      overflow-y: auto;
      display: flex;
      flex-direction: column;
      align-items: center;
      padding-bottom: toRpx(10);
    }
    .item {
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      font-size: toRpx(20);
      color: #666666;
      width: 100%;
      padding-top: toRpx(16);
      padding-bottom: toRpx(8);
      
      /* Animation Setup */
      opacity: 0;
      transform: translateY(toRpx(-20));
      transition: all 0.25s cubic-bezier(0.25, 1, 0.5, 1); /* Smooth ease-out, no bounce */
      
      .icon {
        width: toRpx(60);
        height: toRpx(60);
        margin-bottom: toRpx(8);
      }
      
      &:active {
        transform: scale(0.95) !important;
        transition: transform 0.1s;
      }
    }
    .active {
      color: #2c66f7;
    }
  }
  .showList {
    opacity: 1;
    visibility: visible;
    max-height: 80vh;
    transform: scale(1);
    z-index: 3;
    padding-bottom: toRpx(16);

    .item {
      opacity: 1;
      transform: translateY(0);
      transition-delay: calc(0.02s + var(--i) * 0.025s); /* Staggered delay */
    }
  }
}
</style>