// custom-tab-bar/index.js
const app = getApp()
const urlMap = {
	'coupon': '/pages/activityDetail/activityDetail',
	'y': '/scanGroup/index/index', // /pages/ywymReward/index /scanGroup/jyScan/index/index /middlePage/pages/privacyGps/privacyGps /scanGroup/index/index /scanGroup/dahaoda/index/index
	'jys': '/scanGroup/index/index',
	'costa': '/pages/costa/index/index',
	'x': '/scanGroup/index/index',
	'h': '/scanGroup/index/index', // 吉士丁扫码
	'jyo':'/scanGroup/index/index',
	'singleProduct': '/pages/index/index',
	'delivery-sxh': '/delivery/index/index',
	't': '/subPackages/tickets/index/index'
}

const urls = {
	'HTTPS://M.HH66.CN/': '/pages/qptest/index',
	'https://test-utc-paltform.bzh001.com': '/subPackages/scan/middle/middle'
}
Component({
    /**
     * 组件的属性列表
     */
    properties: {

    },

    /**
     * 组件的初始数据
     */
    data: {
         // tabbar 的列表 
        tabbarLists:[
            {
                pagePath: "/custom-pages/custom-index/index",
                text: "首页",
                type:'page',
                iconPath: "/images/icon_index.png",
                selectedIconPath: "/images/icon_index_act.png"
            },
            {
                pagePath: "/custom-pages/custom-scan/index",
                text: "扫一扫",
                type:'scan',
                // iconPath: "/images/icon-pack.png",
                selectedIconPath: "/images/tab_scan.png"
            },
            {
                pagePath: "/custom-pages/custom-product/index",
                text: "产品介绍",
                // type:'page_pro',
                type:'page',
                iconPath: "/images/icon_pro.png",
                selectedIconPath: "/images/icon_pro_act.png"
            }
        ],
        active:null, //设为数字,会产生tabbar闪烁
        isShow:true //控制显示隐藏tabbar 
    },
    

    /**
     * 组件的方法列表
     */
    methods: {
        switchTab(e){
            const { index,url,item } = e.currentTarget.dataset;
            if(item.type!=='scan'){
                // if(item.type=='page_pro'){
                //     wx.showModal({
                //       title: '提示',
                //       content: '暂未开放,敬请期待',
                //       showCancel:false,
                //       confirmText:'知道了',
                //       confirmColor:'#00478b',
                //       complete: (res) => {
                //         if (res.cancel) {
                          
                //         }
                    
                //         if (res.confirm) {
                          
                //         }
                //       }
                //     })
                //     return
                // }
                wx.switchTab({url})
            }else{
                console.log('扫码');
                this.showScan()
            }
        },
        showScan() {
            wx.scanCode({
                success(res) {
					console.log(res,"res");
                    // success
                    var url = res.result
					url = "HTTPS://AAX6.CN/JYS/:QD3T8+4:F-ZS19GIG,8DDHPVIT"
                    url = url.trim()
                    url = url.replace(/[\r\n]/g, '')
                    let type = app.GetUrlParh(url)
                    console.log(type,"--------");
					// url = "HTTP://JY.AAX6.CN/Y/NZU-NWL.2BDJ8F$:IA,0000003101"
                    if (urlMap.hasOwnProperty(type)) {
                        wx.navigateTo({
                            url: `${urlMap[type]}?q=${encodeURIComponent(url)}`
                        })
                        return
                    }
                    for (const i in urls) {
                        if (url.indexOf(i) > -1) {
                            wx.navigateTo({
                                url: `${urls[i]}?q=${encodeURIComponent(url)}`
                            })
                            return
                        }
                    }
                    wx.showToast({
                        icon: 'none',
                        title: '无法找到页面资源'
                    })
                }
            })
        },
    
    }
})