MetricModalAdd.tsx 4.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 [currentSel, setCurrentSel] = useState<any>({})
  11. // const [disableCode,setDisableCode] = useState(0)
  12. const { t } = useTranslation()
  13. useEffect(() => {
  14. setMetricItem(props.item)
  15. }, [props.item])
  16. return <View>
  17. <View className='modal_content'>
  18. <Text className='modal_title' style={{ color: (metricItem as any).theme_color }}>{(metricItem as any).name ? (metricItem as any).name : ''}</Text>
  19. <View style={{ position: 'relative' }}>
  20. {
  21. (metricItem as any).schemas.map((item, index) => {
  22. var obj = item;
  23. const { unit_options, chosen_unit } = item;
  24. if (unit_options && unit_options.length > 0) {
  25. unit_options.map((temp, i) => {
  26. if (temp.unit == chosen_unit) {
  27. obj = temp
  28. var tempMap = JSON.parse(JSON.stringify(currentSel))
  29. tempMap[index] = i;
  30. }
  31. })
  32. }
  33. return <View key={index} style={{position:'relative'}}>
  34. {
  35. (metricItem as any).schemas.length > 1 && <Text style={{
  36. textAlign: 'center', width: '100%', display: 'flex',
  37. justifyContent: 'center', color: (metricItem as any).theme_color,
  38. // opacity:item.code==disableCode?0.4:1
  39. }}>{item.name}</Text>
  40. }
  41. {
  42. unit_options && unit_options.length > 1 && <View style={{position:'absolute',right:20,}}>
  43. <Text style={{color:'#fff'}}>切换</Text>
  44. </View>
  45. }
  46. <SlidngScale step={obj.step} min={obj.min} max={obj.max}
  47. default_value={obj.default_value}
  48. scale={obj.scale}
  49. unit={obj.unit ? obj.unit : item.default_unit}
  50. special={obj.special ?? null}
  51. themeColor={(metricItem as any).theme_color}
  52. changed={(e) => {
  53. item.tempValue = e;
  54. item.tempUnit = obj.unit ? obj.unit : item.default_unit
  55. debugger
  56. }}
  57. updateStatus={(isEnable) => {
  58. setEnable(isEnable)
  59. }} />
  60. </View>
  61. })
  62. }
  63. </View>
  64. <View className="change_time_bg" >
  65. <View className="gray1 time_bg" onClick={() => { props.showPicker(metricItem) }}>
  66. <Text className="time" >{props.strTime}</Text>
  67. </View>
  68. </View>
  69. <View className='modal_operate'>
  70. <View className='modal_btn' style={{ backgroundColor: (metricItem as any).theme_color + alphaToHex(0.4) }} onClick={() => props.cancel()}>
  71. <Text className='modal_cancel_text' style={{ color: (metricItem as any).theme_color, fontWeight: 'bold' }}>{
  72. t('feature.common.picker_cancel_btn')
  73. }</Text>
  74. </View>
  75. <View className='btn_space' />
  76. <View className='modal_btn' style={{ backgroundColor: (metricItem as any).theme_color, opacity: enable ? 1 : 0.4 }} onClick={() => {
  77. if (enable) {
  78. props.confirm(metricItem)
  79. }
  80. }}>
  81. <Text className='modal_confirm_text' style={{ color: '#000', fontWeight: 'bold' }}>{
  82. t('feature.common.picker_confirm_btn')
  83. }</Text>
  84. </View>
  85. </View>
  86. </View>
  87. </View>
  88. }