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

Component({
	/**
	 * 组件的属性列表
	 */
	properties: {
		currentHasUserInfo: {
			type: Boolean,
			type: false
		},
		picNav: {
			type: Array,
			value: [],
		},
	},
	attached() {
		this.setData({
			baseImgUrl: app.globalData.imageUrl
		})
		const { picNav } = this.data
		picNav.forEach(item => {
			// 存在 row 处理数据 8 商品 9 分类
			let newRow = null
			if (item.link) { 
				if(item.link.type == 2){
					// 父组件 更新
					const urls = getCurrentPages()
					const currentPath = urls[0]
					const pageId = item.link.url
					console.log('currentPath', currentPath.route,item.link.url)
					item.link.newPath = `/${currentPath.route}`
			}
				return 
			}	else if (item.row) {
				newRow = JSON.parse(item.row)
				if (newRow.type == 8) {
					newRow.newPath = '/pages/productDetail/productDetail'
				} else if (newRow.type == 9) {
					newRow.newPath = '/subPackage/page/pages/categoryPro/categoryPro'
				} else {
					newRow.newPath = ''
				}
				// item.row = JSON.stringify(newRow)
				item.row = newRow
			}
		})

		this.setData({ picNav }, () => {
		
		})
	},
	/**
	 * 组件的初始数据
	 */
	data: {
		imagewidth: 0,//缩放后的宽 
		imageheight: 0,//缩放后的高 
		isAuthorization: false,
		isAuthorizationActiveText: '',
		isAuthorizationType: 2,
		baseImgUrl: ''
	},
	/**
	 * 组件的方法列表
	 */
	methods: {
		_getUserInfo(res = {}) {
			wxService.nextTick(() => {
				this.triggerEvent('getAuth', res);
			})
		},
		imageLoad(e) {
			let imageSize = utils.imageUtil(e)
			this.setData({
				imagewidth: imageSize.imageWidth,
				imageheight: imageSize.imageHeight
			})
		},
		preview(event) {
			const ev = event.currentTarget.dataset;
			let curItemType = ev.item
			// 获取当前帐号信息
			const userInfo = wx.getStorageSync('_baseUserInfo')

			// link row
			if (curItemType.link) {
				let currentClickType = app.globalData.commonFunc.getLink(curItemType.link.type, curItemType)
				if (curItemType.link.type == 1) {

				} else if (curItemType.link.type == 2) {
					// 触发父组件更新页面
					wxService.nextTick(() => {
						this.triggerEvent('updatePage', { pageId: currentClickType.url })
					})
				} else if (curItemType.link.type == 3) {
					// 预览
					wx.previewImage({
						current: `${app.globalData.imageUrl}/${currentClickType.imageUrl}`, // 当前显示图片的http链接
						urls: [`${app.globalData.imageUrl}/${currentClickType.link.url}`]  // 需要预览的图片http链接列表
					})
				} else if (curItemType.link.type == 4) {
					wxService.router(`${currentClickType}`)
				} else if (curItemType.link.type == 5) {
					if (currentClickType == 1) {
						wxService.openCard()
					} else if (currentClickType == 2) {
						wxService.openCard()
					}
				} else if (curItemType.link.type == 6) {
					wxService.router(`/${currentClickType}`)
				} else if (curItemType.link.type == 7) {
					// 集点详情
					wxService.router(`${currentClickType}`)
				}
			} else if (curItemType.row) {
				// let rowObj = JSON.parse(curItemType.row)
				let rowObj = curItemType.row
				let currentClickRow = app.globalData.commonFunc.getLinkRow(rowObj.type, rowObj)

				if (rowObj.type == 1) { }
				else if (rowObj.type == 2) { }
				else if (rowObj.type == 3) { }
				else if (rowObj.type == 4) { }
				else if (rowObj.type == 5) { }
				else if (rowObj.type == 6) { }
				else if (rowObj.type == 7) { }
				else if (rowObj.type == 8) {
					// 商品
					wxService.router(`/pages/productDetail/productDetail?id=${currentClickRow}`)
				}
				else if (rowObj.type == 9) {
					// 分类
					wxService.router(`/subPackage/page/pages/categoryPro/categoryPro?${currentClickRow}`)
				}
			}
		},
		activeTocard(e) {
			if (e.detail) {
				wxService.openCard()
			}
		}
	}
})
