index.jsx 6.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. import { useState, useEffect, useRef } from 'react'
  2. import Taro from '@tarojs/taro'
  3. import { View, Picker, Image, ScrollView, Text } from '@tarojs/components'
  4. import CouponCard from '@/components/CouponCard'
  5. import { compressImage } from '@/utils'
  6. import SaveIcon from '@/components/SaveIcon'
  7. import Location from '@/components/Location'
  8. import grassOFF from '@/assets/icons/housemantj/grassOFF.png'
  9. import grassNO from '@/assets/icons/housemantj/grassNO.png'
  10. import VideoStart from '@/assets/icons/housemantj/VideoStart.png'
  11. import Popup from '@/components/Popup'
  12. import { saveTravel, newTravelMine, getTravelMine } from '@/services/travel'
  13. import './style.less'
  14. const CouponMedia = CouponCard.Media
  15. const Action = CouponCard.Action
  16. //套餐卡片
  17. export default (props) => {
  18. const { item, st, editable, setScroll, goshop, travelMine, resourceList, det, handelNoteList } = props
  19. // const travelId = travelMineContent?.records[0]?.travelId
  20. const targetId = props.item?.targetId
  21. const targetType = props.item?.targetType
  22. const goFood = () => {
  23. Taro.navigateTo({ url: `/pages/details/foodDetails/foodDetails?id=${targetId}` })
  24. }
  25. const [showCutover, setShowCutover] = useState(false)
  26. const [valueList, setValueList] = useState([])
  27. useEffect(() => {
  28. if (item == []) {
  29. }
  30. setValueList(travelMine?.records)
  31. }, [travelMine?.records, item])
  32. const onClose = () => {
  33. //关闭当前套餐详情弹窗
  34. setShowCutover(false)
  35. //使父组件恢复滚动
  36. setScroll(true)
  37. }
  38. //列改变
  39. const [traveCoumun, setTraveCoumun] = useState()
  40. const numberTrave = (new Array(traveCoumun).fill()).map((_, index) => ({ id: index + 1, title: `第 ${index + 1} 天` }))
  41. const array = [valueList, travelMine?.records == '' ? [] : numberTrave]
  42. const handleColumn = e => {
  43. // console.log(e.detail.column);
  44. const { column, value } = e.detail
  45. const firstValue = valueList[value]
  46. setTraveCoumun(firstValue.dayNum)
  47. }
  48. const day = new Date();
  49. const y = day.getFullYear();
  50. const m = day.getMonth() + 1;
  51. const d = day.getDate();
  52. let number = 0
  53. const onChange = (e) => {
  54. if (travelMine?.records == '') {
  55. console.log('没有行程');
  56. newTravelMine({ title: `我的行程 ${y}-${m}-${d}` }).then(res => {
  57. handelNoteList()
  58. // 首先创建一个行程,然后才能拿到下面的这些数据
  59. const [firstInx, secondInx] = e.detail?.value
  60. const firstValue = valueList[firstInx] || ''
  61. console.log("🚀 ~ file: index.jsx ~ line 89 ~ newTravelMine ~ e.detail", firstValue)
  62. const secondValue = numberTrave[secondInx] || ''
  63. const { travelId } = firstValue
  64. //行程内容
  65. const { i } = secondValue//天数
  66. // saveTravel({})
  67. saveTravel(res.travelId, { dayOrder: i, targetId: targetId, targetType: targetType }).then((val) => {
  68. Taro.showToast({
  69. title: '添加成功',
  70. icon: 'none',
  71. duration: 1000
  72. })
  73. resourceList(travelId)
  74. })
  75. })
  76. } else {
  77. console.log('有行程', e);
  78. const [firstInx, secondInx] = e.detail.value
  79. const firstValue = valueList[firstInx]
  80. const secondValue = numberTrave[secondInx]
  81. const { travelId } = firstValue
  82. //行程内容
  83. const { i } = secondValue//天数
  84. saveTravel(travelId, { dayOrder: i, targetId: targetId, targetType: targetType }).then((res) => {
  85. Taro.showToast({
  86. title: '添加成功',
  87. icon: 'none',
  88. duration: 1000
  89. })
  90. resourceList(travelId)
  91. // setGrowGrass(grassNO)
  92. })
  93. // console.log('else');
  94. }
  95. }
  96. const handlePayClick = () => {
  97. if (travelMine?.records == '') {
  98. Taro.showToast({
  99. title: '暂无行程,已自动创建',
  100. icon: 'none',
  101. duration: 3000
  102. })
  103. newTravelMine({ title: `我的行程 ${y}-${m}-${d}` }).then(res => {
  104. handelNoteList()
  105. // 首先创建一个行程,然后才能拿到下面的这些数据
  106. })
  107. }
  108. // Taro.navigateTo({ url: `/pages/PayOrder/index?packageId=${item.packageId}&scene=${scene || ''}&subOrderId=${subOrderId}&id=${id}` })
  109. }
  110. const PayAction = travelMine.total >= 1 ?
  111. <View className='view-picker'>
  112. <Picker
  113. className='picker-box'
  114. mode='multiSelector'
  115. range={array}
  116. range-key='title'
  117. onColumnChange={handleColumn}
  118. onChange={onChange}
  119. scrollType='link'
  120. // value={}
  121. >
  122. <Action.Icon icon={item.isVisited < 1 ? grassOFF : grassNO} text={item.isVisited < 1 ? '种草' : '已种草'} onClick={handlePayClick} />
  123. </Picker>
  124. </View>
  125. :
  126. <Action.Icon icon={item.isVisited < 1 ? grassOFF : grassNO} text={item.isVisited < 1 ? '种草' : '已种草'} onClick={handlePayClick} />
  127. return (
  128. <View style={{ margin: '15px 5px' }} >
  129. <View className='packageDetail' style={{ display: goshop ? '' : 'none' }}>
  130. <Popup show={showCutover} maskClosable={showCutover} onClose={onClose}>
  131. <ScrollView
  132. scrollY
  133. style={{ maxHeight: '60vh' }}
  134. >
  135. <Image mode='widthFix' src={item.details ? item.details : item.poster} />
  136. </ScrollView>
  137. </Popup >
  138. </View>
  139. <CouponCard action={PayAction}>
  140. <CouponMedia onClick={goFood}>
  141. <CouponMedia.Header
  142. cashback={item.cashback}
  143. image={compressImage(item.poster)}
  144. badge='note'
  145. />
  146. <CouponMedia.Body star={st}>
  147. <View className='foodCard'>
  148. <View className='cpn-card-text'>
  149. {(item.title).toString().length > 25 ? (item.title).substring(0, 25) + '...' : (item.title)}
  150. </View>
  151. <View className='cpn-card-text' style={{ marginTop: '10rpx' }}>
  152. <Text className='cpn-card-text_mn'>¥{`${(item.averagePrice == '' ? '0.00' : item.averagePrice / 100)?.toFixed(2)}元`}</Text>
  153. {/* <Text className='cpn-card-text_rm'>{`门市价${(item.standardPrice / 100)?.toFixed(2)}元`}</Text> */}
  154. </View>
  155. <View className='cpn-md-act'>
  156. <Location {...det} />
  157. <SaveIcon saved={item.isSaved > 0} targetType='shop_package' editable={editable} targetId={item.targetId} />
  158. </View>
  159. </View>
  160. </CouponMedia.Body>
  161. </CouponMedia>
  162. </CouponCard>
  163. </View>
  164. )
  165. }