Commit d5e089f8 by 高淑倩

点击分类

parent af4a7549
......@@ -2,6 +2,7 @@
var app = getApp()
const wxService = require('../../utils/wxService')
const utils = require('../../utils/util')
const utilLink = require('../../utils/currentLinkRouter')
const envInfo = require('../../config/index').envInfo
Component({
......@@ -19,7 +20,47 @@ Component({
}
},
attached() {
const { categoryType } = this.data
let currentTab = categoryType.categorys
currentTab.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
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'
}
item.row = newRow
}
})
// 当前匹配路径是否需要授权 true 需要 false 不需要
currentTab.forEach(item => {
let checkUrl = ''
if (item.link) {
checkUrl = item.link.newPath ? item.link.newPath : item.link.url
} else if (item.row) {
checkUrl = item.row.newPath ? item.row.newPath : item.row.url
}
wxService.NoLoginPage(checkUrl).then(res => {
if(checkUrl) item.needAuth = res.needAuth
this.setData({ categoryList: currentTab },()=>{
console.log('categoryList', this.data.categoryList)
})
})
})
},
/**
* 组件的初始数据
......@@ -28,6 +69,7 @@ Component({
// currentTab: 0,
currentTab: 99,
isAuthorization: false, // false 不显示 true 显示
categoryList:[]
},
/*组件所在页面的生命周期 */
pageLifetimes: {
......@@ -62,84 +104,7 @@ Component({
},
// 设置tab active
switchNav(event) {
const ev = event.currentTarget.dataset;
let cur = ev.current
let curItemType = ev.item
const userInfo = wx.getStorageSync('_baseUserInfo')
const {currentTab} = this.data
// 切换 active
if (currentTab == cur) {
return false
} else {
this.setData({
currentTab: cur
})
}
// link row
if (curItemType.link) {
let currentClickType = app.globalData.commonFunc.getLink(curItemType.link.type, curItemType)
if (curItemType.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 (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 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}`)
}
}
utilLink.currentLinkRouter(event, this)
},
switchTab(event) {
var cur = event.detail.current
......
<!--component/tabSort/tabSort.wxml-->
<view class="tab-sort" wx:if="{{categoryType.categorys}}">
<view class="tab-sort" wx:if="{{categoryList}}">
<scroll-view scroll-x class="scroll-view_H" scroll-with-animation="{{true}}">
<block
wx:for="{{categoryType.categorys}}"
wx:for="{{categoryList}}"
wx:for-index="idx"
wx:for-item="navItem"
wx:key="idx"
>
<view
class="scroll-view-item {{currentTab == idx ?'active':''}}"
style="width:{{navItemWidth}}%"
data-current="{{idx}}"
data-redirectId="{{navItem.redirectId}}"
data-item="{{navItem}}"
bindtap="switchNav"
>
<view>{{navItem.title}}</view>
<view wx:if="{{navItem.needAuth}}" class="scroll-view-item {{currentTab == idx ?'active':''}}" style="width:{{navItemWidth}}%">
<view wx:if="{{!currentHasUserInfo}}" class="scroll-view-item {{currentTab == idx ?'active':''}}" style="width: {{navItemWidth}}%;height: 80rpx;display: flex;">
<button
bindgetuserinfo="_getUserInfo"
data-jflag="false"
open-type='getUserInfo'
class="scroll-view-item {{currentTab == idx ?'active':''}}"
hover-class="btn-hover"
>
{{navItem.title}}
</button>
</view>
<view wx:else class="scroll-view-item {{currentTab == idx ?'active':''}}" style="width:{{navItemWidth}}%">
<view
data-current="{{idx}}"
data-redirectId="{{navItem.redirectId}}"
data-item="{{navItem}}"
bindtap="switchNav"
>{{navItem.title}}
</view>
</view>
</view>
<view wx:else class="scroll-view-item {{currentTab == idx ?'active':''}}" style="width:{{navItemWidth}}%">
<view
data-current="{{idx}}"
data-redirectId="{{navItem.redirectId}}"
data-item="{{navItem}}"
bindtap="switchNav"
>{{navItem.title}}
</view>
</view>
</block>
</scroll-view>
<!-- showQrcode 2 购物车 1 会员码 0 隐藏 -->
......
......@@ -40,3 +40,14 @@
display: flex;
align-items: center;
}
button {
background-color: transparent;
border-radius:0;
padding: 0;
}
button::after{
border:none;
}
.button-hover, .button-active{
background-color:transparent;
}
\ No newline at end of file
......@@ -38,8 +38,7 @@ function currentLinkRouter(event, _this) {
wxService.router(`${currentClickType}`)
}
} else if (curItemType.row) {
// let rowObj = JSON.parse(curItemType.row)
let rowObj = curItemType.row
let rowObj = typeof(curItemType.row) == "string" ? JSON.parse(curItemType.row) : curItemType.row
let currentClickRow = app.globalData.commonFunc.getLinkRow(rowObj.type, rowObj)
if (rowObj.type == 1) { }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment