You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
93 lines
2.7 KiB
93 lines
2.7 KiB
Page({
|
|
data: {
|
|
list:[],
|
|
children:[]
|
|
},
|
|
toggleExpand(e) {
|
|
const id = e.currentTarget.dataset.id;
|
|
const list = this.data.list.map(item => {
|
|
if (item.id === id) {
|
|
return { ...item, haveChildren: !item.haveChildren };
|
|
} else {
|
|
return { ...item, haveChildren: false };
|
|
}
|
|
});
|
|
this.setData({ list });
|
|
if(!e.currentTarget.dataset.have){
|
|
wx.navigateTo({
|
|
url: '/pages/newdetail/newdetail?name='+id // 支持参数传递
|
|
// url: '/pages/detail/detail?name='+id // 支持参数传递
|
|
})
|
|
}
|
|
},
|
|
// 在生命周期函数中加载数据
|
|
onLoad(options) {
|
|
// wx.showToast({
|
|
// title: `点击了子项 ${options.name}`,
|
|
// icon: 'none'
|
|
// });
|
|
const s = options.name;
|
|
wx.request({
|
|
url: 'https://keytest.aik518.com/prod-api/work_key/obd/zk_key/type_blue?blueName='+"BYD_OBD",
|
|
|
|
// url: 'https://keytest.aik518.com/prod-api/work_key/obd/zk_key/type_blue?blueName='+s,
|
|
method: 'GET', // 请求方法
|
|
success: res => {
|
|
console.log(res);
|
|
wx.setNavigationBarTitle({ title: res.data.data[0].name })
|
|
this.setData({
|
|
list:res.data.data,
|
|
children:res.data.data[0].children
|
|
// list: res.data.map(item => ({
|
|
// ...item,
|
|
// isExpanded: false,
|
|
// bgColor: '#fff'
|
|
// }))
|
|
})
|
|
}
|
|
})
|
|
},
|
|
refresh: function(e) {
|
|
|
|
wx.navigateTo({
|
|
url: '/pages/detail/detail?id=1&name=example'
|
|
});
|
|
},
|
|
// 点击事件处理函数
|
|
handleItemClick: function (e) {
|
|
// const index = e.currentTarget.dataset.index; // 主列表索引
|
|
// const subIndex = e.currentTarget.dataset.subIndex; // 子列表索引
|
|
// const subItem = this.data.list[index].sublist[subIndex];
|
|
// wx.showToast({ title: `点击了 ${subItem.name}`, icon: 'none' });
|
|
const childIndex = e.currentTarget.dataset.childIndex;
|
|
// const {parentIndex, childIndex} = e.currentTarget.dataset
|
|
// const childData = this.data.list[parentIndex].children[childIndex]
|
|
if(childIndex.haveChildren){
|
|
// this.setData({list:childIndex.children});
|
|
|
|
wx.navigateTo({
|
|
|
|
url: '/pages/elselist/elselist?name='+childIndex.name, // 支持参数传递
|
|
// url: '/pages/detail/detail?name='+childIndex.id // 支持参数传递
|
|
success (res) {
|
|
// 通过eventChannel向被打开页面传送数据
|
|
res.eventChannel.emit('getCartDatalist', childIndex) //触发事件
|
|
}
|
|
})
|
|
|
|
|
|
}else{
|
|
wx.navigateTo({
|
|
|
|
url: '/pages/newdetail/newdetail?name='+childIndex.id // 支持参数传递
|
|
// url: '/pages/detail/detail?name='+childIndex.id // 支持参数传递
|
|
})
|
|
}
|
|
// wx.showToast({
|
|
// title: `点击了子项 ${childIndex.id}`,
|
|
// icon: 'none'
|
|
// });
|
|
},
|
|
|
|
|
|
})
|