83 lines
1.9 KiB
JavaScript
83 lines
1.9 KiB
JavaScript
|
|
/**
|
|
* Web唐明明
|
|
* 匆匆数载恍如梦,岁月迢迢华发增。
|
|
* 碌碌无为枉半生,一朝惊醒万事空。
|
|
*/
|
|
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
companyList: [], //企业广场列表
|
|
pages : {}, //企业广场分页
|
|
record : [], //浏览记录
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad(options) {
|
|
wx.$api.company.lists({}, "").then(res=>{
|
|
this.setData({
|
|
companyList: res.data,
|
|
pages : res.page
|
|
})
|
|
})
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
onShow() {
|
|
wx.hideHomeButton()
|
|
wx.getStorage({
|
|
key : "companyRecord",
|
|
success : res=>{
|
|
this.setData({record: res.data})
|
|
}
|
|
})
|
|
},
|
|
|
|
/**
|
|
* 点击企业
|
|
*/
|
|
onCompany(e){
|
|
let company = e.currentTarget.dataset.item,
|
|
newRecord = [...[company], ...this.data.record],
|
|
newobj = {}
|
|
|
|
let record = newRecord.reduce((preVal, curVal)=>{
|
|
newobj[curVal.company_id] ? '' : newobj[curVal.company_id] = preVal.push(curVal);
|
|
return preVal
|
|
}, [])
|
|
|
|
// 去重后的数组长度
|
|
if(record.length > 10){
|
|
record = record.slice(0, 10)
|
|
}
|
|
|
|
// 更新页面数据
|
|
this.setData({
|
|
record: record
|
|
})
|
|
|
|
// 存储浏览记录
|
|
wx.setStorageSync('companyRecord', record)
|
|
|
|
// 存储店铺ID
|
|
wx.setStorage({
|
|
data : company.store_id,
|
|
key : "storeId",
|
|
success : res=>{
|
|
if(res.errMsg == "setStorage:ok"){
|
|
wx.navigateTo({
|
|
url: "/pages/shortVideo/index",
|
|
})
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}) |