// pages/index/sw/index.js
const imgurl = require("../../utils/imgurl");
const app = getApp()

Component({
  /**
   * 组件的属性列表
   */
  properties: {
    list: {
      value: [],
      type: Array
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    bannerUrl: imgurl.banner.url,
    currentIndex: 0,
    mouldType: 0,
  },

  /**
   * 组件的方法列表
   */
  methods: {
    gotobannerdetail: function(e) {
      console.log(this.data.list)
      if (e.currentTarget.dataset.data.type == 3) {
        // 小程序路径
        let indexOf = (e.currentTarget.dataset.data.pagePath).indexOf("=");
        console.log(indexOf, "123")
        let id = (e.currentTarget.dataset.data.pagePath).substring(indexOf);
        let type = (e.currentTarget.dataset.data.pagePath).substr(indexOf + 1, 2) // 2020/7/22 变量获取pagePath中的type
        console.log(indexOf, id, type);
        console.log(e.currentTarget.dataset.data.pagePath)
        if (type == 'cd' || type == 'sd') {
          wx.navigateTo({
            url: `/${e.currentTarget.dataset.data.pagePath}`,
          })
        } else if (type == "wj") {
          wx.navigateTo({
            url: `/pages/questionnaire/questionnaire?id=${id}`,
          })
        } else if (type == 'ra') {
          wx.navigateTo({
            url: `/pages/radetail/index?id=${id}`,
          })
        }
      } else if (e.currentTarget.dataset.data.type == 2) {
        // 自由图文
        wx.navigateTo({
          url: `/pages/freeBannerDetail/index?id=${e.currentTarget.dataset.id}`
        });
      } else if (e.currentTarget.dataset.data.type == 4) {
        let tempObj = {

          appId: e.currentTarget.dataset.data.goAppid,
          // path: 'page/index/index?id=123',
          // extraData: {
          //   foo: 'bar'
          // },
          // envVersion: 'develop',
          success(res) {
            // 打开成功
          }

        }
        if (e.currentTarget.dataset.data.pagePath){
          tempObj.path = e.currentTarget.dataset.data.pagePath
        }
        wx.navigateToMiniProgram(tempObj)
      } else {
        // 固定格式
        wx.navigateTo({
          url: `/pages/bannerdetail/index?id=${e.currentTarget.dataset.id}`
        });
      }
    },
    handleChange: function(e) {
      this.setData({
        currentIndex: e.detail.current
      })
    },
  },
  attached: function() {
    // 在组件实例进入页面节点树时执行
    if (app.globalData.mouldType) {
      this.setData({
        mouldType: app.globalData.mouldType
      })
    }
  },
});