|
@@ -3,163 +3,161 @@ var goodsUtil = require('../../utils/goods.js');
|
|
|
var api = require('../../config/api.js');
|
|
|
|
|
|
Page({
|
|
|
- data: {
|
|
|
- // text:"这是一个页面"
|
|
|
- navList: [],
|
|
|
- goodsList: [],
|
|
|
- id: 0,
|
|
|
- goodsBizType: '00',
|
|
|
- currentTab: 0,
|
|
|
- navIndex: 0,
|
|
|
- currentCategory: {},
|
|
|
- scrollLeft: 0,
|
|
|
- scrollTop: 0,
|
|
|
- scrollHeight: 0,
|
|
|
- page: 1,
|
|
|
- size: 10,
|
|
|
- showNavList: false,
|
|
|
- footCart: {},
|
|
|
- openAttr: false,
|
|
|
- productList: {},
|
|
|
- specificationList: {},
|
|
|
- checkedSpecText: '请选择规格数量',
|
|
|
- number: 1
|
|
|
- },
|
|
|
- toggleNav() {
|
|
|
- this.setData({
|
|
|
- showNavList: !this.data.showNavList
|
|
|
- })
|
|
|
- },
|
|
|
- // 滚动切换标签样式
|
|
|
- switchTab: function (e) {
|
|
|
- let that = this;
|
|
|
- that.setData({
|
|
|
- goodsList: []
|
|
|
+ data: {
|
|
|
+ // text:"这是一个页面"
|
|
|
+ navList: [],
|
|
|
+ goodsList: [],
|
|
|
+ id: 0,
|
|
|
+ goodsBizType: '00',
|
|
|
+ currentTab: 0,
|
|
|
+ navIndex: 0,
|
|
|
+ currentCategory: {},
|
|
|
+ scrollLeft: 0,
|
|
|
+ scrollTop: 0,
|
|
|
+ scrollHeight: 0,
|
|
|
+ page: 1,
|
|
|
+ size: 10,
|
|
|
+ showNavList: false,
|
|
|
+ footCart: {},
|
|
|
+ openAttr: false,
|
|
|
+ productList: {},
|
|
|
+ specificationList: {},
|
|
|
+ checkedSpecText: '请选择规格数量',
|
|
|
+ number: 1
|
|
|
+ },
|
|
|
+ toggleNav() {
|
|
|
+ this.setData({
|
|
|
+ showNavList: !this.data.showNavList
|
|
|
+ })
|
|
|
+ },
|
|
|
+ // 滚动切换标签样式
|
|
|
+ switchTab: function (e) {
|
|
|
+ let that = this;
|
|
|
+ //当页面改变是会触发
|
|
|
+ console.log("e.detail.current:" + e.detail.current);
|
|
|
+ this.setData({
|
|
|
+ currentTab: e.detail.current
|
|
|
+ });
|
|
|
+ // console.log("currentTab:" + that.data.currentTab);
|
|
|
+ if (that.data.navIndex == e.detail.current) {
|
|
|
+ this.setData({
|
|
|
+ navIndex: -1
|
|
|
});
|
|
|
- //当页面改变是会触发
|
|
|
- console.log("e.detail.current:" + e.detail.current);
|
|
|
- this.setData({
|
|
|
- currentTab: e.detail.current
|
|
|
- });
|
|
|
- // console.log("currentTab:" + that.data.currentTab);
|
|
|
- if (that.data.navIndex == e.detail.current) {
|
|
|
- this.setData({
|
|
|
- navIndex: -1
|
|
|
- });
|
|
|
- return;
|
|
|
- }
|
|
|
- let navListCount = that.data.navList.length;
|
|
|
- for (let i = 0; i < navListCount; i++) {
|
|
|
- if (i == e.detail.current) {
|
|
|
- that.setData({
|
|
|
- id: that.data.navList[i].id
|
|
|
- });
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- that.setData({
|
|
|
- scrollLeft: (e.detail.current - 1) * 60
|
|
|
- });
|
|
|
- that.refreshCategoryInfo();
|
|
|
- },
|
|
|
- switchNav(event) {
|
|
|
- let name = event.currentTarget.dataset.name;
|
|
|
- wx.switchTab({
|
|
|
- url: `/pages/${name}/${name}`,
|
|
|
- });
|
|
|
- },
|
|
|
- onLoad: function (options) {
|
|
|
- // 页面初始化 options为页面跳转所带来的参数
|
|
|
- var that = this;
|
|
|
- if (options.id) {
|
|
|
- that.setData({
|
|
|
- id: parseInt(options.id)
|
|
|
- });
|
|
|
- } else {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ let navListCount = that.data.navList.length;
|
|
|
+ for (let i = 0; i < navListCount; i++) {
|
|
|
+ if (i == e.detail.current) {
|
|
|
that.setData({
|
|
|
- id: 0,
|
|
|
- currentCategory: {}
|
|
|
+ id: that.data.navList[i].id
|
|
|
});
|
|
|
+ break;
|
|
|
}
|
|
|
- if (options.goodsBizType) {
|
|
|
+ }
|
|
|
+ that.setData({
|
|
|
+ scrollLeft: (e.detail.current - 1) * 60
|
|
|
+ });
|
|
|
+ that.refreshCategoryInfo();
|
|
|
+ },
|
|
|
+ switchNav(event) {
|
|
|
+ let name = event.currentTarget.dataset.name;
|
|
|
+ wx.switchTab({
|
|
|
+ url: `/pages/${name}/${name}`,
|
|
|
+ });
|
|
|
+ },
|
|
|
+ onLoad: function (options) {
|
|
|
+ // 页面初始化 options为页面跳转所带来的参数
|
|
|
+ var that = this;
|
|
|
+ if (options.id) {
|
|
|
+ that.setData({
|
|
|
+ id: parseInt(options.id)
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ that.setData({
|
|
|
+ id: 0,
|
|
|
+ currentCategory: {}
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (options.goodsBizType) {
|
|
|
+ that.setData({
|
|
|
+ goodsBizType: options.goodsBizType
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (options.currentIndex) {
|
|
|
+ that.setData({
|
|
|
+ currentTab: options.currentIndex
|
|
|
+ });
|
|
|
+ }
|
|
|
+ wx.getSystemInfo({
|
|
|
+ success: function (res) {
|
|
|
+ var clientHeight = res.windowHeight,
|
|
|
+ clientWidth = res.windowWidth,
|
|
|
+ rpxR = 750 / clientWidth;
|
|
|
+ var calc = clientHeight * rpxR - 180;
|
|
|
that.setData({
|
|
|
- goodsBizType: options.goodsBizType
|
|
|
+ scrollHeight: calc
|
|
|
});
|
|
|
}
|
|
|
- if (options.currentIndex) {
|
|
|
+ });
|
|
|
+ this.getCategoryInfo();
|
|
|
+ },
|
|
|
+ getFootCart: function () {
|
|
|
+ let that = this;
|
|
|
+ util.request(api.GetFootCart).then(function (res) {
|
|
|
+ if (res.errno === 0) {
|
|
|
that.setData({
|
|
|
- currentTab: options.currentIndex
|
|
|
+ footCart: res.data,
|
|
|
});
|
|
|
}
|
|
|
- wx.getSystemInfo({
|
|
|
- success: function (res) {
|
|
|
- var clientHeight = res.windowHeight,
|
|
|
- clientWidth = res.windowWidth,
|
|
|
- rpxR = 750 / clientWidth;
|
|
|
- var calc = clientHeight * rpxR - 180;
|
|
|
+ });
|
|
|
+ },
|
|
|
+ getCategoryInfo: function () {
|
|
|
+ let that = this;
|
|
|
+ util.request(api.GoodsCategory, { id: that.data.id, goodsBizType: that.data.goodsBizType })
|
|
|
+ .then(function (res) {
|
|
|
+ if (res.errno == 0) {
|
|
|
that.setData({
|
|
|
- scrollHeight: calc
|
|
|
+ navList: res.data.brotherCategory,
|
|
|
+ currentCategory: res.data.currentCategory
|
|
|
});
|
|
|
- }
|
|
|
- });
|
|
|
- this.getCategoryInfo();
|
|
|
- },
|
|
|
- getFootCart: function () {
|
|
|
- let that = this;
|
|
|
- util.request(api.GetFootCart).then(function (res) {
|
|
|
- if (res.errno === 0) {
|
|
|
- that.setData({
|
|
|
- footCart: res.data,
|
|
|
- });
|
|
|
- }
|
|
|
- });
|
|
|
- },
|
|
|
- getCategoryInfo: function () {
|
|
|
- let that = this;
|
|
|
- util.request(api.GoodsCategory, { id: that.data.id, goodsBizType: that.data.goodsBizType})
|
|
|
- .then(function (res) {
|
|
|
- if (res.errno == 0) {
|
|
|
- that.setData({
|
|
|
- navList: res.data.brotherCategory,
|
|
|
- currentCategory: res.data.currentCategory
|
|
|
- });
|
|
|
- //nav位置
|
|
|
- let currentIndex = that.data.currentTab;
|
|
|
- let navListCount = that.data.navList.length;
|
|
|
- for (let i = 0; i < navListCount; i++) {
|
|
|
- if (that.data.navList[i].id == that.data.id) {
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- if (currentIndex > navListCount / 2 && navListCount > 5) {
|
|
|
- that.setData({
|
|
|
- scrollLeft: currentIndex * 60
|
|
|
- });
|
|
|
+ //nav位置
|
|
|
+ let currentIndex = that.data.currentTab;
|
|
|
+ let navListCount = that.data.navList.length;
|
|
|
+ for (let i = 0; i < navListCount; i++) {
|
|
|
+ if (that.data.navList[i].id == that.data.id) {
|
|
|
+ break;
|
|
|
}
|
|
|
+ }
|
|
|
+ if (currentIndex > navListCount / 2 && navListCount > 5) {
|
|
|
that.setData({
|
|
|
- currentTab: currentIndex,
|
|
|
- navIndex: currentIndex
|
|
|
+ scrollLeft: currentIndex * 60
|
|
|
});
|
|
|
- that.getGoodsList();
|
|
|
- } else {
|
|
|
- //显示错误信息
|
|
|
}
|
|
|
- });
|
|
|
- },
|
|
|
- refreshCategoryInfo: function () {
|
|
|
- let that = this;
|
|
|
- util.request(api.GoodsCategory, {id: this.data.id})
|
|
|
- .then(function (res) {
|
|
|
- if (res.errno == 0) {
|
|
|
- that.setData({
|
|
|
- navList: res.data.brotherCategory,
|
|
|
- currentCategory: res.data.currentCategory
|
|
|
- });
|
|
|
- that.getGoodsList();
|
|
|
- } else {
|
|
|
- //显示错误信息
|
|
|
- }
|
|
|
- });
|
|
|
+ that.setData({
|
|
|
+ currentTab: currentIndex,
|
|
|
+ navIndex: currentIndex
|
|
|
+ });
|
|
|
+ that.getGoodsList();
|
|
|
+ } else {
|
|
|
+ //显示错误信息
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ refreshCategoryInfo: function () {
|
|
|
+ let that = this;
|
|
|
+ util.request(api.GoodsCategory, { id: this.data.id })
|
|
|
+ .then(function (res) {
|
|
|
+ if (res.errno == 0) {
|
|
|
+ that.setData({
|
|
|
+ navList: res.data.brotherCategory,
|
|
|
+ currentCategory: res.data.currentCategory,
|
|
|
+ goodsList: []
|
|
|
+ });
|
|
|
+ that.getGoodsList();
|
|
|
+ } else {
|
|
|
+ //显示错误信息
|
|
|
+ }
|
|
|
+ });
|
|
|
},
|
|
|
onReady: function () {
|
|
|
// 页面渲染完成
|
|
@@ -171,19 +169,19 @@ Page({
|
|
|
onHide: function () {
|
|
|
// 页面隐藏
|
|
|
},
|
|
|
- getGoodsList: function () {
|
|
|
- wx.showLoading({
|
|
|
- title: '加载中...',
|
|
|
- });
|
|
|
- var that = this;
|
|
|
- util.request(api.GoodsList, { categoryId: that.data.id, goodsBizType: that.data.goodsBizType, page: that.data.page, size: that.data.size })
|
|
|
- .then(function (res) {
|
|
|
- let goodsList = that.data.goodsList.concat(res.data.data);
|
|
|
- that.setData({
|
|
|
- goodsList: goodsList,
|
|
|
- });
|
|
|
- wx.hideLoading();
|
|
|
+ getGoodsList: function () {
|
|
|
+ var that = this;
|
|
|
+ wx.showLoading({
|
|
|
+ title: '加载中...',
|
|
|
+ });
|
|
|
+ util.request(api.GoodsList, { categoryId: that.data.id, goodsBizType: that.data.goodsBizType, page: that.data.page, size: that.data.size })
|
|
|
+ .then(function (res) {
|
|
|
+ let goodsList = that.data.goodsList.concat(res.data.data);
|
|
|
+ that.setData({
|
|
|
+ goodsList: goodsList,
|
|
|
});
|
|
|
+ wx.hideLoading();
|
|
|
+ });
|
|
|
},
|
|
|
onUnload: function () {
|
|
|
// 页面关闭
|
|
@@ -302,41 +300,41 @@ Page({
|
|
|
util.showErrorToast(res.errmsg)
|
|
|
}
|
|
|
});
|
|
|
- }
|
|
|
- ,
|
|
|
- switchCate: function (event) {
|
|
|
- if (this.data.id == event.currentTarget.dataset.id) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- var that = this;
|
|
|
- that.setData({
|
|
|
- goodsList: [],
|
|
|
- page: 1,
|
|
|
- currentTab: event.currentTarget.dataset.current
|
|
|
- });
|
|
|
- console.log("currentIndex:" + that.data.currentTab);
|
|
|
- var clientX = event.detail.x;
|
|
|
- var currentTarget = event.currentTarget;
|
|
|
- if (clientX < 60) {
|
|
|
- that.setData({
|
|
|
- scrollLeft: currentTarget.offsetLeft - 60
|
|
|
- });
|
|
|
- } else if (clientX > 330) {
|
|
|
- that.setData({
|
|
|
- scrollLeft: currentTarget.offsetLeft
|
|
|
- });
|
|
|
- }
|
|
|
- this.setData({
|
|
|
- id: event.currentTarget.dataset.id,
|
|
|
- goodsBizType: that.data.goodsBizType
|
|
|
- });
|
|
|
- this.getCategoryInfo();
|
|
|
},
|
|
|
- onReachBottom() {
|
|
|
- var that = this;
|
|
|
- that.setData({
|
|
|
- page: that.data.page + 1,
|
|
|
- });
|
|
|
- that.getGoodsList();
|
|
|
+ switchCate: function (event) {
|
|
|
+ console.log(this.data.scrollLeft);
|
|
|
+ if (this.data.id == event.currentTarget.dataset.id) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ var that = this;
|
|
|
+ that.setData({
|
|
|
+ goodsList: [],
|
|
|
+ page: 1,
|
|
|
+ currentTab: event.currentTarget.dataset.current
|
|
|
+ });
|
|
|
+ console.log("currentIndex:" + that.data.currentTab);
|
|
|
+ var clientX = event.detail.x;
|
|
|
+ var currentTarget = event.currentTarget;
|
|
|
+ if (clientX < 60) {
|
|
|
+ that.setData({
|
|
|
+ scrollLeft: currentTarget.offsetLeft - 60
|
|
|
+ });
|
|
|
+ } else if (clientX > 330) {
|
|
|
+ that.setData({
|
|
|
+ scrollLeft: currentTarget.offsetLeft
|
|
|
+ });
|
|
|
}
|
|
|
+ this.setData({
|
|
|
+ id: event.currentTarget.dataset.id,
|
|
|
+ goodsBizType: that.data.goodsBizType
|
|
|
+ });
|
|
|
+ this.getCategoryInfo();
|
|
|
+ },
|
|
|
+ onReachBottom() {
|
|
|
+ var that = this;
|
|
|
+ that.setData({
|
|
|
+ page: that.data.page + 1,
|
|
|
+ });
|
|
|
+ that.getGoodsList();
|
|
|
+ }
|
|
|
})
|