123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- const pages = require('../../mixin/pages')
- const { getShopDetail } = require('../../api/common')
- let leftHeight = 0
- let rightHeight = 0
- let query = null
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- ...pages.data(),
- listUrl: '/api/user/home/shop/product/list',
- searchForm: {
- shop_id: ''
- },
- background: ['demo-text-1', 'demo-text-2', 'demo-text-3'],
- nav: [
- {
- name: '详情',
- value: '1'
- },
- {
- name: '产品',
- value: '2'
- }
- ],
- active: '1',
- leftList: [],
- rightList: []
- },
- ...pages.methods,
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- const { shop_id } = options
- this.setData({
- 'searchForm.shop_id': shop_id
- }, () => {
- this.fetchShopDetail()
- this.fetchOrderList()
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady() {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide() {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {
- if (this.data.freshing) {
- return
- }
- this.setData({
- freshing: true
- })
- this.fetchShopDetail()
- this.bindCallBack()
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {
- this.fetchOrderList()
- },
- bindCallBack() {
- this.fetchShopDetail()
- this.refreshOrderList()
- },
- async fetchShopDetail() {
- try {
- const { status, data, msg } = await getShopDetail(this.data.searchForm.shop_id)
- if (status) {
- } else {
- wx.showToast({
- title: msg,
- icon: 'none'
- })
- }
- } catch (err) {}
- },
- async isLeft(list) {
- const {
- 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()
- })
- })
- })
- },
- handleNav(e) {
- const { value } = e.detail
- this.setData({
- active: value
- })
- }
- })
|