123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import React, { useEffect, useState } from 'react'
  2. import Taro from "@tarojs/taro";
  3. import { useSelector } from 'react-redux'
  4. import { View, Button, Image } from '@tarojs/components'
  5. import uploadicon from '../../assets/uploadicon.png'
  6. import roleList from '../../util/userRole'
  7. import './index.scss'
  8. const getColor = (role) => {
  9. switch (role) {
  10. case roleList.landlord: return '#274291'
  11. case roleList.adminuser: return '#274291'
  12. // landlord: 'landlord',
  13. case roleList.customer: return '#fed12f'
  14. }
  15. }
  16. const tab = (props) => {
  17. const user = useSelector(state => state.user)
  18. const { value, openType, pageState, formType, color, styleType='', ...prop } = props
  19. const [state, setState] = useState(1)
  20. console.log(props, openType, 'formType')
  21. useEffect(() => {
  22. }, [])
  23. // &-on{
  24. // color: #fed12f;
  25. // }${props.className}
  26. return <View className='tab'>
  27. {
  28. value.length == 1 &&
  29. <>
  30. {openType && <button openType="share" className={`tab,tab1,${props.className}`} style={{ backgroundColor: getColor(user.role), color }} onClick={() => props.onClick('2')}>{value[0]}</button>}
  31. {!openType && <View className={`tab,tab1,${props.className}`} style={{ backgroundColor: getColor(user.role), color }} onClick={() => props.onClick('2')}>{value[0]}</View>}
  32. </>
  33. }
  34. {
  35. value.length == 2 && <View className={`tab,tab2,${props.className}`} style={{ display: 'flex', }}>
  36. <View style={{ width: '50%' }} style={pageState == '2'&&styleType!='tab' ? { color: getColor(user.role), width: '50%' } : { color:pageState != '2'&&styleType=='tab'?getColor(user.role):undefined, width: '50%' }} onClick={props.onClick[0]}>{value[0]}</View>
  37. {formType &&
  38. <Button className='tab-btn'
  39. formType="submit"
  40. plain={true}
  41. style={pageState == '3' &&styleType!='tab'? { color: getColor(user.role), width: '50%', border: 'none' } : { width: '50%', border: 'none' }}
  42. >{value[1]}
  43. </Button>}
  44. {openType &&
  45. <button className='tab-btn'
  46. openType="share" plain={true} style={pageState == '3'&&styleType!='tab' ? { color: getColor(user.role), width: '50%', border: 'none' } : { width: '50%', border: 'none' }}>{value[1]}</button>}
  47. {!formType&&!openType &&
  48. <View style={{ width: '50%' }}
  49. style={pageState == '3'&&styleType!='tab' ? { color: getColor(user.role), width: '50%' } : { color:pageState != '3'&&styleType=='tab'?getColor(user.role):undefined, width: '50%' }}
  50. onClick={props.onClick[1]}
  51. >{value[1]}</View>
  52. }
  53. </View>
  54. }
  55. </View>
  56. };
  57. export default tab
  58. // import React, { useEffect, useState } from 'react'
  59. // import Taro from "@tarojs/taro";
  60. // import { Button, View } from '@tarojs/components'
  61. // import './index.scss'
  62. // const getColor = (role) => {
  63. // switch (role) {
  64. // case roleList.landlord: return '#274291'
  65. // case roleList.adminuser: return '#274291'
  66. // // landlord: 'landlord',
  67. // case roleList.customer: return '#fed12f'
  68. // }
  69. // }
  70. // const tab = (props) => {
  71. // // formType="submit"
  72. // const { value, pageState, formType, color, ...prop } = props
  73. // const [state, setState] = useState(1)
  74. // // console.log(props)
  75. // useEffect(() => {
  76. // }, [])
  77. // // &-on{
  78. // // color: #fed12f; style={{ backgroundColor:'#274291' ,color}}
  79. // // }${props.className}
  80. // return <View className='tab'>
  81. // {value.length == 1 && <View className={`tab tab1 ${props.className}`} onClick={() => props.onClick('2')}>{value[0]}
  82. // </View>}
  83. // {value.length == 2 && <View className={`tab tab2 ${props.className}`} style={{ display: 'flex', }}>
  84. // <View style={{ width: '50%' }} style={pageState == '2' ? { color: '#274291', width: '50%' } : { width: '50%' }} onClick={props.onClick[0]}>{value[0]}</View>
  85. // { !formType?
  86. // <View formType={formType} style={{ width: '50%' }} style={pageState == '3' ? { color: '#274291', width: '50%' } : { width: '50%' }} onClick={props.onClick[1]}>{value[1]}</View>
  87. // :<Button className='tab-btn' formType={formType} plain={true} style={{ width: '50%' }} style={pageState == '3' ? { color: '#274291', width: '50%',border:'none' } : { width: '50%',border:'none' }} onClick={props.onClick[1]}>{value[1]}</Button>}
  88. // </View>}
  89. // </View>
  90. // };
  91. // export default tab