// pages/fire/fire.js
const app = getApp();
const Dialog = require("../../components/dialog/dialog/dialog");
import {
$stopWuxRefresher
} from '../../components/wux/index.js'
import {
goodsTypeAll,
goodsGetByType,
goodsDoAction,
goodsGetOneEx,
wxOauth,
} from "../../utils/api.js"
Page({
/**
* 页面的初始数据
*/
data: {
imgUrls: [
'../../images/showDetail.png',
'../../images/showDetail.png',
'../../images/showDetail.png',
'../../images/showDetail.png'
],
currentSwiper: 0,
//样式展示
show_list_block: false,
show_pay: {
vis: false,
detail: false,
detail_data: ""
}, //是否显示支付模块
video_show: false,
menuList: [],
menuCurrent: "",
currentIndex: 0,
goods_detail: "",
goods_list: "",
currentItem: "",
stepper_value: 1,
tagCheckIdx: 0,
menuClass:"",
pullingText:"上一页",
menu_active:"",
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function(options) {
var self = this;
// if(options.active == 'true'){
// this.setData({
// menu_active:true,
// show_list_block:true,
// })
// }
wxOauth();
goodsTypeAll(function(res) {
self.setData({
menuList: res.data.data
})
if (!!options.menu) {
self.setData({
menu_active: true,
show_list_block: true,
menuCurrent: options.menu,
})
}else{
self.data.menuCurrent = res.data.data[0].name;
}
if (!options.weiguanwang) {
self.goodsGetBy();
}
}, "", "", 1)
this.getUser();
if (!!options.weiguanwang) {
this.goodsGetOneEx(JSON.parse(options.weiguanwang).goods_id)
}
},
swiperChange: function(e) {
this.setData({
currentSwiper: e.detail.current
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function() {
var self = this;
self.goodsGetBy();
},
goodsGetOneEx(id) {
var self = this;
let params = {
sessionId: wx.getStorageSync("ouath").sessionId,
goods_id: id
}
goodsGetOneEx(params, 1, function(res) {
if (res.data.state) {
res.data.data.map((str, idx) => {
if (str.size_price.length > 0) {
str.price = str.size_price[0].price;
} else {
str.price = str.base_price;
}
})
app.globalData.fireList.set(res.data.data[0].type_name, res.data.data);
self.data.currentIndex = 0;
self.data.menuCurrent = res.data.data[0].type_name;
self.getPrice();
self.setData({
currentItem: app.globalData.fireList.get(res.data.data[0].type_name)[0],
currentIndex: 0,
goods_list: app.globalData.fireList.get(res.data.data[0].type_name),
menuCurrent: res.data.data[0].type_name
})
}
})
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function() {
},
onShareAppMessage: function(res) {
var self = this;
if (res.from === 'menu') {
// 来自页面内转发按钮
}
return {
title: self.data.currentItem.goods_name,
path: 'pages/fire/fire?weiguanwang=' + JSON.stringify(self.data.currentItem)
}
},
//下拉加载
onRefresh() {
var self = this;
if (self.data.show_list_block == false) {
setTimeout(() => {
if (self.data.currentIndex - 1 >= 0) {
--self.data.currentIndex;
app.globalData.fireList.get(self.data.menuCurrent)[self.data.currentIndex].price = app.globalData.fireList.get(self.data.menuCurrent)[self.data.currentIndex].base_price;
self.setData({
currentItem: app.globalData.fireList.get(self.data.menuCurrent)[self.data.currentIndex],
video_show: false,
currentSwiper: 0,
stepper_value: 1,
})
} else {
if (!!app.globalData.fireList.get(self.data.menuCurrent) && app.globalData.fireList.get(self.data.menuCurrent).length == 1) {
wx.showToast({
title: "少侠此处只有一个商品,请到别处看看!",
icon: "none"
})
} else {
wx.showToast({
title: "没有更多了!",
icon: "none"
})
}
}
$stopWuxRefresher()
}, 100)
} else {
wx.showToast({
title: "此处已是全部商品!",
icon: "none"
})
$stopWuxRefresher()
}
},
goodsGetBy() {
var self = this;
console.log(app.globalData.fireList)
console.log(self.data.menuCurrent)
if (!!app.globalData.fireList.get(self.data.menuCurrent) && app.globalData.fireList.get(self.data.menuCurrent).length>0) {
this.getPrice();
self.setData({
currentItem: app.globalData.fireList.get(self.data.menuCurrent)[0],
currentIndex: 0,
goods_list: app.globalData.fireList.get(self.data.menuCurrent),
})
return;
}else{
self.data.currentIndex = 0;
self.setData({
currentItem: "",
currentIndex: 0,
goods_list: "",
})
}
var params = {
sessionId: wx.getStorageSync("ouath").sessionId,
type_name: this.data.menuCurrent
}
goodsGetByType(params, 1, function(res) {
if (res.data.state) {
if (res.data.data.length == 0){
app.globalData.fireList.set(self.data.menuCurrent, res.data.data);
self.data.currentIndex = 0;
self.setData({
currentItem: "",
currentIndex: 0,
goods_list: "",
})
}else{
res.data.data.map((str, idx) => {
if (str.size_price.length > 0) {
str.price = str.size_price[0].price;
} else {
str.price = str.base_price;
}
})
app.globalData.fireList.set(self.data.menuCurrent, res.data.data);
self.data.currentIndex = 0;
self.getPrice();
self.setData({
currentItem: app.globalData.fireList.get(self.data.menuCurrent)[0],
currentIndex: 0,
goods_list: app.globalData.fireList.get(self.data.menuCurrent),
})
}
}
})
},
goodsDoAction(e) {
var self = this;
var params = {
sessionId: wx.getStorageSync("ouath").sessionId,
goods_id: e.currentTarget.dataset.id,
type: parseInt(e.currentTarget.dataset.type)
}
goodsDoAction(params, 1, function(res) {
var glo_list = app.globalData.fireList.get(self.data.menuCurrent);
if (res.data.state == true) {
if (parseInt(e.currentTarget.dataset.type) == 1) {
glo_list[self.data.currentIndex].is_collect == 1 ? glo_list[self.data.currentIndex].is_collect = 0 : glo_list[self.data.currentIndex].is_collect = 1;
app.globalData.fireList.set(self.data.menuCurrent, glo_list);
if (glo_list[self.data.currentIndex].is_collect == 0) {
wx.showToast({
title: "取消收藏!",
icon: "none"
})
} else {
wx.showToast({
title: "收藏成功!",
icon: "none"
})
}
} else if (parseInt(e.currentTarget.dataset.type) == 2) {
glo_list[self.data.currentInde