
// 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: [
      'https://images.unsplash.com/photo-1551334787-21e6bd3ab135?w=640',
      'https://images.unsplash.com/photo-1551214012-84f95e060dee?w=640',
      'https://images.unsplash.com/photo-1551446591-142875a901a1?w=640'
    ],
    indicatorDots: true,
    autoplay: true,
    circular: true,
    interval: 5000,
    duration: 1000,
    isAuthorization: false, // false 不显示 true 显示
    baseImgUrl: ''
  },
	/**
	 * 组件的方法列表
	 */
  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}`)
      }
    }
  }
})
