
import Taro from '@tarojs/taro'
import useSave from "@/utils/hooks/useSave"
import msTip from '@/assets/icons/housemantj/foodtip.png'
import mjTip from '@/assets/icons/housemantj/mjtip.png'
import glTip from '@/assets/icons/housemantj/gltip.png'
import location from '@/assets/icons/housemantj/location.png'
import onlove from '@/assets/icons/housemantj/onlove.png'
import love from '@/assets/icons/housemantj/爱心.png'

export default (props) => {

  const { item } = props

  const [isSaved, toggleSave] = useSave(item.isSaved, item.targetType, item.targetId)
  const Detail=()=>{
    if (item.targetType=='tourist') {
      let location=item.lng+','+item.lat
      Taro.navigateTo({ url: `/pages/details/mjDetails/sceneryDetails?id=${item.targetId}&distance=${(item.distance/1000).toFixed(2)}&location=${location}` });
    }
    else{
      Taro.navigateTo({ url: `/pages/details/foodDetails/foodDetails?id=${item.targetId}` });
    }
  }
  return (
    <view className='contentCard'>
      <view className='cardTop'>
        <image mode='widthFix' onClick={Detail} src={item.poster} className='cCardimg' />
        <image className='lefttips' src={item.targetType==='tourist'?mjTip:msTip}/>
        <image onClick={toggleSave} src={isSaved> 0?onlove:love} className='loveharde'></image>
      </view>
      <view className='bContent' onClick={Detail}>
        <view className='cCword'>{(item.title).toString().length>35?(item.title).substring(0, 35)+'...':(item.title)}</view>
        <view className='cCleft'>
          <image src={location} className='cCicon'></image>
          <view className='distance'><text>{(item.distance/1000).toFixed(2)}</text>公里</view>
        </view>
        <view className='cCright'>          
          <view className='price'><text className='money'>￥</text><text>{item.averagePrice/100}</text>/人</view>
        </view>
      </view>
    </view>
  )

}
