bk-shop/src/pages/other/goods.js

76 lines
2.2 KiB
JavaScript

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 (
<SpPage loading={loading} title={''} className='page-other-goods has-navbar' showNavSearchIcon showNavLogo>
<View className="" style={{ minHeight: windowHeight * 2, background: '#000' }} >
{goods_1774.map((item, index) => <SpImage src={`1774/${item}.jpg`} width={width} isNew >
{(index === 3 || index === 5) && <View className="go-buy" onClick={() => handleGoBuy(item, index)} ></View>}
</SpImage>)}
</View>
<View className="content-btn" onClick={handleBackToIndex} >
返回首页
</View>
</SpPage>
)
}
export default goods