|
@@ -1,52 +1,34 @@
|
|
|
+const pages = require('../../mixin/pages')
|
|
|
+const { getProductCategoryList } = require('../../api/common')
|
|
|
+let leftHeight = 0
|
|
|
+let rightHeight = 0
|
|
|
+let query = null
|
|
|
+
|
|
|
Page({
|
|
|
|
|
|
/**
|
|
|
* 页面的初始数据
|
|
|
*/
|
|
|
data: {
|
|
|
- category: [
|
|
|
- {
|
|
|
- name: '全部',
|
|
|
- id: '1'
|
|
|
- },
|
|
|
- {
|
|
|
- name: '分类',
|
|
|
- id: '2'
|
|
|
- },
|
|
|
- {
|
|
|
- name: '分类',
|
|
|
- id: '3'
|
|
|
- },
|
|
|
- {
|
|
|
- name: '分类',
|
|
|
- id: '4'
|
|
|
- },
|
|
|
- {
|
|
|
- name: '分类',
|
|
|
- id: '5'
|
|
|
- },
|
|
|
- {
|
|
|
- name: '分类',
|
|
|
- id: '6'
|
|
|
- }
|
|
|
- ],
|
|
|
- currentCategory: '1',
|
|
|
+ ...pages.data(),
|
|
|
+ listUrl: '/api/user/caigou/product/list',
|
|
|
+ searchForm: {
|
|
|
+ key_words: '',
|
|
|
+ category_id: ''
|
|
|
+ },
|
|
|
+ categoryList: [],
|
|
|
navScrollLeft: -1,
|
|
|
- pagenum: 0,
|
|
|
- pagesize: 20,
|
|
|
- finished: false, // 所有数据是否加载完
|
|
|
- isRefresh: false, // 是否下拉刷新
|
|
|
- isFetchLock: false, // 接口调用加锁
|
|
|
- list: [1],
|
|
|
- booLock: false
|
|
|
+ leftList: [],
|
|
|
+ rightList: []
|
|
|
},
|
|
|
- freshing: false,
|
|
|
+ ...pages.methods,
|
|
|
|
|
|
/**
|
|
|
* 生命周期函数--监听页面加载
|
|
|
*/
|
|
|
- onLoad(options) {
|
|
|
-
|
|
|
+ async onLoad(options) {
|
|
|
+ await this.fetchProductCategoryList()
|
|
|
+ this.fetchOrderList()
|
|
|
},
|
|
|
|
|
|
/**
|
|
@@ -81,30 +63,91 @@ Page({
|
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
|
*/
|
|
|
onPullDownRefresh() {
|
|
|
-
|
|
|
+ if (this.data.freshing) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ this.setData({
|
|
|
+ freshing: true
|
|
|
+ })
|
|
|
+ this.bindCallBack()
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 页面上拉触底事件的处理函数
|
|
|
*/
|
|
|
onReachBottom() {
|
|
|
-
|
|
|
+ this.fetchOrderList()
|
|
|
},
|
|
|
-
|
|
|
- /**
|
|
|
- * 用户点击右上角分享
|
|
|
- */
|
|
|
- onShareAppMessage() {
|
|
|
-
|
|
|
+ bindCallBack() {
|
|
|
+ this.refreshOrderList()
|
|
|
+ },
|
|
|
+ async fetchProductCategoryList() {
|
|
|
+ try {
|
|
|
+ const { status, data, msg } = await getProductCategoryList()
|
|
|
+ if (status && Array.isArray(data) && data.length > 0) {
|
|
|
+ const temp = data.map(item => {
|
|
|
+ return {
|
|
|
+ ...item,
|
|
|
+ text: item.category_name
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ temp.unshift({
|
|
|
+ category_img_url: '',
|
|
|
+ category_name: '全部',
|
|
|
+ id: 0
|
|
|
+ })
|
|
|
+
|
|
|
+ this.setData({
|
|
|
+ categoryList: temp,
|
|
|
+ 'searchForm.category_id': temp[0].id
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ wx.showToast({
|
|
|
+ title: msg,
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
+ }
|
|
|
+ } catch (err) {}
|
|
|
},
|
|
|
handleNav(e) {
|
|
|
+ const { item } = e.currentTarget.dataset
|
|
|
+
|
|
|
+ if (this.data.searchForm.category_id !== item.id) {
|
|
|
+ this.setData({
|
|
|
+ 'searchForm.category_id': item.id,
|
|
|
+ navScrollLeft: 0
|
|
|
+ }, () => {
|
|
|
+ this.refreshOrderList()
|
|
|
+ })
|
|
|
+ }
|
|
|
+ },
|
|
|
+ async isLeft(list) {
|
|
|
const {
|
|
|
- item
|
|
|
- } = e.currentTarget.dataset
|
|
|
-
|
|
|
- this.setData({
|
|
|
- currentCategory: item.id,
|
|
|
- navScrollLeft: 0
|
|
|
+ leftList,
|
|
|
+ rightList
|
|
|
+ } = this.data
|
|
|
+ query = wx.createSelectorQuery()
|
|
|
+ for (const item of list) {
|
|
|
+ leftHeight <= rightHeight ? leftList.push(item) : rightList.push(item)
|
|
|
+
|
|
|
+ await this.getBoxHeight(leftList, rightList)
|
|
|
+ }
|
|
|
+ },
|
|
|
+ getBoxHeight(leftList, rightList) {
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ this.setData({
|
|
|
+ leftList,
|
|
|
+ rightList
|
|
|
+ }, () => {
|
|
|
+ query.select('.waterfall-left').boundingClientRect()
|
|
|
+ query.select('.waterfall-right').boundingClientRect()
|
|
|
+ query.exec((res) => {
|
|
|
+ leftHeight = res[0].height
|
|
|
+ rightHeight = res[1].height
|
|
|
+ resolve()
|
|
|
+ })
|
|
|
+ })
|
|
|
})
|
|
|
}
|
|
|
})
|