123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- const pages = require('../../mixin/pages')
- const { getShopDetail } = require('../../api/common')
- const { postShopCollect } = require('./api/index')
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- ...pages.data(),
- listUrl: '/api/user/home/shop/product/list',
- searchForm: {
- shop_id: ''
- },
- nav: [
- {
- name: '详情',
- value: '1'
- },
- {
- name: '产品',
- value: '2'
- }
- ],
- active: '1',
- objShopDetail: { shop_address: {} },
- booLock: false
- },
- ...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.bindCallBack()
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {
- if (this.data.active === '2') {
- this.fetchOrderList()
- }
- },
- bindCallBack() {
- this.fetchShopDetail()
- this.refreshOrderList()
- },
- async fetchShopDetail() {
- try {
- const { status, data, msg } = await getShopDetail(this.data.searchForm.shop_id)
- if (status) {
- const { shop_address, collect_status } = data
- this.setData({
- objShopDetail: {
- ...data,
- shop_address: shop_address ? JSON.parse(shop_address) : {}
- },
- 'searchForm.type': collect_status === 0 ? 1 : 2 // 是否收藏(0否1是)
- })
- } else {
- wx.showToast({
- title: msg,
- icon: 'none'
- })
- }
- } catch (err) {}
- },
- async shopCollect() {
- const { type, shop_id } = this.data.searchForm
- if (this.data.booLock) {
- return
- }
- this.setData({
- booLock: true
- })
- try {
- const { status, msg } = await postShopCollect(shop_id, type)
- if (status) {
- this.setData({
- 'searchForm.type': type === 1 ? 2 : 1
- })
- } else {
- wx.showToast({
- title: msg,
- icon: 'none'
- })
- }
- } catch (err) {}
- this.setData({
- booLock: false
- })
- },
- handleNav(e) {
- const { value } = e.detail
- this.setData({
- active: value
- })
- }
- })
|