index.jsx 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. import React, { useEffect, useMemo, useState } from 'react'
  2. import Taro, { useDidShow, useRouter } from '@tarojs/taro'
  3. import { useSelector } from 'react-redux'
  4. import { View, ScrollView, Image } from '@tarojs/components'
  5. import Layout from '../../layout/index'
  6. import Tab from '../../compents/tab/index'
  7. import radio from '../../assets/radio.png'
  8. import './index.scss'
  9. import request from '../../util/request'
  10. const addimg = (props) => {
  11. const router = useRouter()
  12. const { houseId, tagIds } = router.params
  13. const user = useSelector(state => state.user)
  14. const [pageState, setPageState] = useState('2')
  15. const [list, setList] = useState([])
  16. const [choiceList, setChoicelist] = useState([])
  17. useEffect(() => {
  18. getImageList()
  19. }, [])
  20. const getImageList = () => {
  21. request({ url: '/taMetaImageTag', params: { tagIds: tagIds, pageSize: 999 } }).then((res) => {
  22. const { records, ...page } = res.data.data
  23. const r = records.reduce((all, next) => all.some((atom) => atom.imageId == next.imageId) ? all : [...all, next], []);
  24. setList(r)
  25. })
  26. }
  27. const choiceImg = (value) => {
  28. console.log(value, '111')
  29. const t = choiceList.find(x => x.imageId == value.imageId)
  30. if (t) {
  31. setChoicelist(choiceList.filter(x => x.imageId != value.imageId))
  32. } else {
  33. setChoicelist([
  34. ...choiceList,
  35. value
  36. ])
  37. }
  38. }
  39. const onAddimg = (e) => {
  40. console.log(e, '111')
  41. if (choiceList.length > 0) {
  42. const data = choiceList.map(x => {
  43. return {
  44. houseId,
  45. image: x.image,
  46. imageId:x.imageId,
  47. }
  48. })
  49. request({ url: '/taHouseSurround', method: 'post', data }).then((res)=>{
  50. Taro.showModal({
  51. title: '添加成功',
  52. content: '点击确认按钮,返回上级菜单',
  53. showCancel: false,
  54. success: function (res) {
  55. if (res.confirm) {
  56. console.log('用户点击确定')
  57. Taro.navigateBack({
  58. delta: 2
  59. })
  60. } else if (res.cancel) {
  61. console.log('用户点击取消')
  62. }
  63. }
  64. })
  65. })
  66. }
  67. }
  68. const handleImageClick = url => {
  69. Taro.previewImage({
  70. current: url,
  71. urls: [url]
  72. })
  73. }
  74. return <View className='addimg'>
  75. <View >
  76. <Layout>
  77. <View className='at-row at-row--wrap'>
  78. {list.map((x) => {
  79. return <View className='at-col at-col-3 addimg-view-card' key={x.imageId}>
  80. <View className='addimg-view-card-radio' onClick={() => choiceImg(x)}>
  81. {choiceList.find(y => y.imageId == x.imageId) && <Image src={radio} style={{ width: '30rpx', height: '20rpx' }}></Image>}
  82. </View>
  83. <Image src={x.image} mode='aspectFit' style={{ width: '100%', height: '200rpx' }} onClick={() => handleImageClick(x.image)} ></Image>
  84. </View>
  85. })}
  86. {/* {list.map((x) => {
  87. return <View className='at-col at-col-4'>A</View>
  88. })} */}
  89. </View>
  90. </Layout>
  91. <Tab value={['取消', `选择${choiceList.length}`]} pageState="3" onClick={[(e) => Taro.navigateBack({
  92. delta: 1
  93. }), (e) => onAddimg()]}></Tab>
  94. </View>
  95. </View>
  96. }
  97. export default addimg