index.js 1.41 KB

Component({
    properties: {
      data: {
        type: Array,
        value: [],
      },
    },
    data: {
      swiperCurrent: 0,
      ticketCode: ''
    },
    ready: function() {
      let swiperCurrent = this.data.swiperCurrent;
      if (swiperCurrent < this.properties.data.length) {
        let ticket = this.properties.data[swiperCurrent].ticks[0];
        let ticketCode = ticket.ticket_code || '';
        this.setData({
          ticketCode
        });
      }
    },
    methods: {
      swiperChange: function (e) {
        this.setData({
            swiperCurrent: e.detail.current
        });
      },

      rightSlide() {
        let swiperCurrent = this.data.swiperCurrent;
        swiperCurrent += 1;

        let ticketCode = this.data.ticketCode;
        if (swiperCurrent < this.properties.data.length) {
          let ticket = this.properties.data[swiperCurrent].ticks[0];
          let ticketCode = ticket.ticket_code || '';
          this.setData({
            swiperCurrent,
            ticketCode
          });
        }
      },

      leftSlide() {
        let swiperCurrent = this.data.swiperCurrent;
        if (swiperCurrent > 0) {
          swiperCurrent -= 1;

          let ticket = this.properties.data[swiperCurrent].ticks[0];
          let ticketCode = ticket.ticket_code || '';
          this.setData({
            swiperCurrent,
            ticketCode
          });
        }
      },
    }
});