
// component/imageSwiper/imageSwiper.js
var app = getApp()
const wxService = require('../../utils/wxService')
const utils = require('../../utils/util')
const envInfo = require('../../config/index').envInfo

Component({
	/**
	 * 组件的属性列表
	 */
  properties: {
    imageData: {
      type: Array,
      value: [],
    },
  },
  attached() {
    this.setData({
      baseImgUrl: app.globalData.imageUrl
    })
  },
	/**
	 * 组件的初始数据
	 */
  data: {
    imgUrls: [],
    indicatorDots: false,
    autoplay: false,
    circular: true,
    interval: 3000,
    duration: 1000,
    isAuthorization: false, // false 不显示 true 显示
    baseImgUrl: '',
    swiperCurrent:0
  },
	/**
	 * 组件的方法列表
	 */
  methods: {
    preview(e) {
      const { appid, path, link, item } = e.currentTarget.dataset
      // 获取当前帐号信息
      const userInfo = wx.getStorageSync('_baseUserInfo')
      let currentClickType = app.globalData.commonFunc.getLink(item.link.type, item)
      if (link.type == 1) {
        // 触发父组件更新页面 外部小程序
        this.setData({
          isAuthorization: false
        })
        return false
      } else if (!userInfo) {
        this.setData({
          isAuthorization: true
        })
        return false
      } else if (userInfo && userInfo.member && !userInfo.member.mobile) {
        wxService.openCard()
        return false
      }

      if (link.type == 2) {
        // 触发父组件更新页面
        wxService.nextTick(() => {
          this.triggerEvent('updatePage', { pageId: currentClickType.url })
        })
      } else if (link.type == 3) {
        // 预览
        wx.previewImage({
          current: `${app.globalData.imageUrl}/${currentClickType.imageUrl}`, // 当前显示图片的http链接
          urls: [`${app.globalData.imageUrl}/${currentClickType.link.url}`]  // 需要预览的图片http链接列表
        })
      } else if (link.type == 4) {
        wxService.router(`${currentClickType}`)
      } else if (link.type == 5) {
        if (currentClickType == 1) {
          // wxService.openCardList()
          wxService.openCard()
        } else if (currentClickType == 2) {
          wxService.openCard()
        }
      } else if (link.type == 6) {
        wxService.router(`${currentClickType}`)
      }
    },
    swiperChange(e){
      this.setData({
        swiperCurrent: e.detail.current
      })  
    }
  }
})
