
import { useState } from 'react'
import CustomCard from '@/components/foodCards/CustomCard/index'

import Taro from '@tarojs/taro'
import { getTravelMine, deleteTravelItem } from '@/services/travel'
import openUp from './ico/openUp.png'
import packUp from './ico/packUp.png'
import './style.less'



export default (props) => {
  const { item, handleDelete } = props
  const { travelItemList, travelId, dayNum } = item




  const [unfold, setUnfold] = useState(false)
  const onUnfold = () => {
    setUnfold(!unfold)

  }
  const onDelete = (e) => {

    const itemId = e
    Taro.showModal({
      title: '提示',
      content: '确定要删除吗',
      success: function (res) {
        if (res.confirm) {
          handleDelete()

          deleteTravelItem(travelId, itemId).then(val => {
            Taro.showToast({
              title: '删除成功',
              icon: 'none',
              duration: 1000
            })
          })
        } else if (res.cancel) {


        }
      }
    })

  }


  return (
    <view style='height:100%'>
      {

        travelItemList == '' ? '' : <view onClick={onUnfold} className='cssUnfold' >
          <image className='unfoldIcoCss' src={unfold === true ? packUp : openUp} />
          展开</view>
      }


      <scroll-view scrollY style={unfold === false ? 'height:100%;' : ' height:0em;'} >
        {

          travelItemList.map((ite, index) =>
            item == '' ? <view></view> :

              <CustomCard item={ite} det={ite} travelId={travelId} onDelete={onDelete} />

          )

        }

      </scroll-view>
    </view>


  )
}
