index.jsx 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. import { useState, useEffect } 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 Popup from '@/components/Popup'
  11. import { saveTravel, newTravelMine } from '@/services/travel'
  12. import './style.less'
  13. const CouponMedia = CouponCard.Media
  14. const Action = CouponCard.Action
  15. //套餐卡片
  16. export default (props) => {
  17. const { item, st, editable, setScroll, goshop, travelMine, resourceList, det, handelNoteList } = props
  18. console.log("🚀 ~ file: index.jsx ~ line 24 ~ resourceList", resourceList)
  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. const [traveCoumun, setTraveCoumun] = useState()
  28. useEffect(() => {
  29. setValueList(travelMine?.records)
  30. setTraveCoumun(travelMine?.records[0].dayNum)
  31. }, [travelMine?.records, item])
  32. const onClose = () => {
  33. //关闭当前套餐详情弹窗
  34. setShowCutover(false)
  35. //使父组件恢复滚动
  36. setScroll(true)
  37. }
  38. //列改变
  39. const numberTrave = (new Array(traveCoumun).fill()).map((_, index) => ({ id: index + 1, title: `第 ${index + 1} 天` }))
  40. const array = [valueList, travelMine?.records == '' ? [] : numberTrave]
  41. const handleColumn = e => {
  42. console.log("🚀 ~ file: index.jsx ~ line 63 ~ e", e)
  43. // console.log(e.detail.column);
  44. const { column, value } = e.detail
  45. if (column == 0) {
  46. const firstValue = valueList[value] || ''
  47. setTraveCoumun(firstValue.dayNum)
  48. }
  49. }
  50. const day = new Date();
  51. const y = day.getFullYear();
  52. const m = day.getMonth() + 1;
  53. const d = day.getDate();
  54. let number = 0
  55. const hanleChange = (e) => {
  56. console.log("🚀 ~ file: index.jsx ~ line 63 ~ e", e)
  57. if (travelMine?.records == '') {
  58. // newTravelMine({ title: `我的行程 ${y}-${m}-${d}` }).then(res => {
  59. // handelNoteList()
  60. // // 首先创建一个行程,然后才能拿到下面的这些数据
  61. // const [firstInx, secondInx] = e.detail?.value
  62. // const firstValue = valueList[firstInx] || ''
  63. // const secondValue = numberTrave[secondInx] || ''
  64. // const { travelId } = firstValue
  65. // //行程内容
  66. // const { id } = secondValue//天数
  67. // // saveTravel({})
  68. // saveTravel(res.travelId, { dayOrder: id, targetId: targetId, targetType: targetType }).then((val) => {
  69. // Taro.showToast({
  70. // title: '添加成功',
  71. // icon: 'none',
  72. // duration: 1000
  73. // })
  74. // resourceList(travelId)
  75. // })
  76. // })
  77. return;
  78. } else {
  79. const [firstInx, secondInx] = e.detail.value
  80. const firstValue = valueList[firstInx]
  81. const secondValue = numberTrave[secondInx]
  82. const { travelId } = firstValue
  83. //行程内容
  84. const { id } = secondValue//天数
  85. saveTravel(travelId, { dayOrder: id, targetId: targetId, targetType: targetType }).then((res) => {
  86. Taro.showToast({
  87. title: '添加成功',
  88. icon: 'none',
  89. duration: 1000
  90. })
  91. resourceList(travelId)
  92. // setGrowGrass(grassNO)
  93. })
  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={hanleChange}
  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 / 100 : 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. }