<template>
  <div class="bill">
    <div class="bill-container">
      <cr-swipe class="bill-image" :show-indicators="false" @change="swipeChange">
        <cr-swipe-item v-for="(picItem, picIndex) in pictureUrlList" :key="picIndex">
          <cr-image lazy-load fit="contain" width="100%" height="100%" :src="picItem" />
        </cr-swipe-item>
      </cr-swipe>
    </div>
    <div class="bill-share" @click="shareClick" />
  </div>
</template>
<script>
import buttonEventMixin from '../mixins/buttonEvent.mixin';
export default {
  mixins: [buttonEventMixin],
  data() {
    const pictureUrl = this.$route.query.pictureUrl;
    return {
      swipeIndex: 0,
      pictureUrlList: pictureUrl.split(',')
    };
  },
  created() {
    if (this.pictureUrlList.length > 1) {
      this.swipeChange(0);
    }
  },
  methods: {
    shareClick() {
      const params = this.$route.query;
      const pictureUrl = this.pictureUrlList[this.swipeIndex];
      console.log({ ...params, pictureUrl });
      this.shareInvoice({ ...params, pictureUrl });
    },
    swipeChange(index) {
      this.$store.commit('CHANGE_TITLE', `${index + 1} / ${this.pictureUrlList.length}`); // 改变title
      this.swipeIndex = index;
    }
  }
};
</script>
<style lang="less" scoped>
.bill {
  height: 100%;
  display: flex;
  align-items: center;
  &-container {
    width: 100%;
  }
  &-image {
    width: 100%;
    height: 100%;
    @{deep} .cr-image {
      box-shadow: 0 2px 12px 0 rgba(100, 101, 102, 0.12);
    }
  }

  @{deep} .cr-swipe__track {
    align-items: center;
  }
  @{deep} .cr-swipe-item {
    padding: 12px;
    box-sizing: border-box;
  }
  &-share {
    position: fixed;
    bottom: 71px;
    right: 12px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    box-shadow: 0 2px 12px 0 rgba(100, 101, 102, 0.12);
    background: @white url(~@/assets/images/electronicInvoice/share.png) no-repeat center center;
    background-size: 50%;
  }
}
</style>
