MetricModalAdd.tsx 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import { View, Text, CoverView } from '@tarojs/components'
  2. import './MetricModalAdd.scss'
  3. import { useTranslation } from 'react-i18next'
  4. import { alphaToHex } from '@/utils/tools'
  5. import SlidngScale from '@/components/input/SlidngScale'
  6. import { useEffect, useState } from 'react'
  7. export default function Component(props: { item: any, strTime: string, showPicker: Function, cancel: Function, confirm: Function }) {
  8. const [metricItem, setMetricItem] = useState(props.item)
  9. const [enable, setEnable] = useState(true)
  10. // const [disableCode,setDisableCode] = useState(0)
  11. const { t } = useTranslation()
  12. useEffect(() => {
  13. setMetricItem(props.item)
  14. }, [props.item])
  15. return <View>
  16. <View className='modal_content'>
  17. <Text className='modal_title' style={{ color: (metricItem as any).theme_color }}>{(metricItem as any).name ? (metricItem as any).name : ''}</Text>
  18. <View style={{ position: 'relative' }}>
  19. {
  20. (metricItem as any).schemas.map((item, index) => {
  21. return <View key={index}>
  22. {
  23. (metricItem as any).schemas.length > 1 && <Text style={{
  24. textAlign: 'center', width: '100%', display: 'flex',
  25. justifyContent: 'center', color: (metricItem as any).theme_color,
  26. // opacity:item.code==disableCode?0.4:1
  27. }}>{item.name}</Text>
  28. }
  29. <SlidngScale step={item.step} min={item.min} max={item.max}
  30. default_value={item.default_value}
  31. scale={item.scale}
  32. unit={item.default_unit}
  33. themeColor={(metricItem as any).theme_color}
  34. changed={(e) => { item.tempValue = e }}
  35. updateStatus={(isEnable) => {
  36. setEnable(isEnable)
  37. // if (isEnable){
  38. // setDisableCode(0)
  39. // }
  40. // else {
  41. // setDisableCode(item.code)
  42. // console.log(item.code)
  43. // }
  44. }} />
  45. </View>
  46. })
  47. }
  48. </View>
  49. <View className="change_time_bg" >
  50. <View className="gray1 time_bg"onClick={() => { props.showPicker(metricItem) }}>
  51. <Text className="time" >{props.strTime}</Text>
  52. </View>
  53. </View>
  54. <View className='modal_operate'>
  55. <View className='modal_btn' style={{ backgroundColor: (metricItem as any).theme_color + alphaToHex(0.4) }} onClick={() => props.cancel()}>
  56. <Text className='modal_cancel_text' style={{ color: (metricItem as any).theme_color,fontWeight:'bold' }}>{
  57. t('feature.common.picker_cancel_btn')
  58. }</Text>
  59. </View>
  60. <View className='btn_space' />
  61. <View className='modal_btn' style={{ backgroundColor: (metricItem as any).theme_color, opacity: enable ? 1 : 0.4 }} onClick={() => {
  62. if (enable) {
  63. props.confirm(metricItem)
  64. }
  65. }}>
  66. <Text className='modal_confirm_text' style={{ color: '#000',fontWeight:'bold' }}>{
  67. t('feature.common.picker_confirm_btn')
  68. }</Text>
  69. </View>
  70. </View>
  71. </View>
  72. </View>
  73. }