orderList.vue 3.61 KB
<template>
  <div class="layout">
    <div class="title">左右滑动查看核销凭证</div>
    <div class="content" @touchend="end">
      <van-swipe :class="['img-box', { one: orderList.length == 1 }]" :key="updata" indicator-color="#FFFFFF" :loop="false" @change="change" :style="swipeStyle" :show-indicators="false" ref="swipe" duration="200">
        <template v-for="(i, index) in orderList">
          <van-swipe-item :key="index">
            <create-order-img :orderInfo="i" :canvasId="`order-${index}`" :ref="`order-${index}`" />
            <van-image :src="imgList[index]" class="img">
              <template v-slot:loading>
                <van-loading type="spinner" size="20" />
              </template>
            </van-image>
          </van-swipe-item>
        </template>
      </van-swipe>
      <template v-if="orderList.length > 1">
        <div class="dots x-center text-center">
          <template v-for="(i, index) in orderList">
            <div :class="['dots-item', { active: itemIndex == index }]" :key="index"></div>
          </template>
        </div>
      </template>
    </div>
    <div class="tips text-center">长按保存图片</div>
  </div>
</template>

<script type="text/ecmascript-6">
import { shopmallApi } from '@/api'
const swipeStyle = 'padding-left: 9px;'
export default {
  name: 'orderList',
  data () {
    return {
      orderList: [],
      imgList: [],
      updata: Date.now(),
      itemIndex: 0,
      swipeStyle
    }
  },
  activated () {
    this.getOrderList()
  },
  deactivated () {
    this.imgList = []
  },
  methods: {
    end () {
      let { swipe } = this.$refs
      let { track } = swipe.$refs,
        { itemIndex } = this,
        { offsetWidth } = swipe.$children[0].$el
      this.$nextTick(() => {
        if (itemIndex == 0) this.swipeStyle = swipeStyle
        else {
          let width = track.style.cssText.split('width:')[1]
          let num = offsetWidth * itemIndex - 9
          track.style.cssText = `transition-duration: 200; transform: translateX(-${num}px); width:${width}`
          this.swipeStyle = ''
        }
      })
    },
    change (e) {
      this.itemIndex = e
    },
    getOrderList () {
      let { id } = this.getLocalStorage('wx_scrm_link_params')
      shopmallApi.getOrderList(id).then(data => {
        console.table(data)
        data && data.length && data.map(e => {
          e.createdDate = new Date(this.iosTimeFormat(e.payDate))
        })
        this.orderList = data || []
        this.$nextTick(() => {
          this.orderList.map((e, index) => {
            this.$refs[`order-${index}`][0].drawOrderImg(url => {
              this.imgList[index] = url
              this.updata = Date.now()
            })
          })
        })
      })
    }
  }
}
</script>

<style scoped lang="scss">
.layout {
  user-select: none;
  .title {
    font-size: 12px;
    color: #999999;
    padding: 16px 0 8px 20px;
  }
  .content {
    position: relative;
    height: 561px;
    .dots {
      bottom: 15px;
      &-item {
        width: 5px;
        height: 5px;
        background: rgba(255, 255, 255, 0.5);
        border-radius: 100%;
        margin: 0 4px;
      }
      .active {
        background: #ffffff;
      }
    }
  }
  .img-box {
    width: 100%;
    height: 561px;
    /deep/.van-swipe-item {
      width: 347px !important;
    }
    .img {
      width: 337px;
      height: 561px;
      object-fit: contain;
      margin-left: 10px;
    }
  }
  .one {
    box-sizing: border-box;
  }
  .tips {
    width: 219px;
    height: 28px;
    background: #f6f6f6;
    border-radius: 4px;
    font-size: 14px;
    color: #656566;
    margin: 14px auto 0;
  }
}
</style>