import React, { useEffect, useRef } from "react" import { useImmer } from "use-immer" import Taro, { getCurrentInstance } from "@tarojs/taro" import api from "@/api" import { SpPage, SpImage } from '@/components' import { View, Text, Picker, Input } from "@tarojs/components" import './goods.scss' const initState = { loading: false, shopList: [] } function goods () { const [state, setState] = useImmer(initState) const { loading } = state const { windowHeight, windowWidth } = Taro.getSystemInfoSync() const width = windowWidth * 2 const goods_1774 = [1, 2, 3, 4, 5, 6, 7] const { shopList } = state const handleBackToIndex = () => { Taro.redirectTo({ url: '/pages/index' }) } const handleGoBuy = (item, index) => { if (index === 3) { Taro.navigateTo({ url: `/pages/item/espier-detail?id=${shopList[0]?.itemId}` }) } if (index === 5) { Taro.navigateTo({ url: `/pages/item/espier-detail?id=${shopList[1]?.itemId}` }) } } useEffect(() => { getShop() setTimeout(() => { setState((draft) => { draft.loading = false }) }, 300) }, []) const getShop = async () => { let params = { page: 1, pageSize: 10, keywords: '', approve_status: 'onsale,only_show,offline_sale', item_type: 'normal', is_point: 'false', goodsSort: 6 } const { list: BK_075List = [] } = await api.item.search({ ...params, keywords: 'BK075' }) const { list: BK_074List = [] } = await api.item.search({ ...params, keywords: 'BK074' }) setState((draft) => { draft.shopList = [...BK_075List, ...BK_074List] }) } return ( {goods_1774.map((item, index) => {(index === 3 || index === 5) && handleGoBuy(item, index)} >} )} 返回首页 ) } export default goods