MetricModalChoose.tsx 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. import { View, Text, ScrollView } from '@tarojs/components'
  2. import './MetricModalChoose.scss'
  3. import { alphaToHex } from '@/utils/tools'
  4. import { useTranslation } from 'react-i18next'
  5. import { useEffect, useState } from 'react'
  6. import { IconRadio, IconRadioCheck } from '@/components/basic/Icons'
  7. import Taro from '@tarojs/taro'
  8. export default function Component(props: { themeColor: string, cancel: Function, confirm: Function, array: any, limit: any, orders: any }) {
  9. const color = props.themeColor ? props.themeColor : '#ff0000'
  10. const [list, setList] = useState(props.array)
  11. const [orderList, setOrderList] = useState(props.orders)
  12. const min = props.limit.min
  13. const max = props.limit.max
  14. const { t } = useTranslation()
  15. var alpha = alphaToHex(0.4)
  16. useEffect(()=>{
  17. setList(props.array)
  18. setOrderList(props.orders)
  19. },[props.array,props.orders])
  20. function cancel() {
  21. props.cancel()
  22. }
  23. function confirm() {
  24. // var datas: any = []
  25. // list.map(item => {
  26. // item.items.map(data => {
  27. // if (data.is_following) {
  28. // datas.push(data as any)
  29. // }
  30. // })
  31. // })
  32. if (min > orderList.length) {
  33. Taro.showToast({
  34. icon: 'none',
  35. title: t('feature.common.toast.min_value'),
  36. })
  37. return
  38. }
  39. if (max < orderList.length) {
  40. Taro.showToast({
  41. icon: 'none',
  42. title: t('feature.common.toast.max_value'),
  43. })
  44. return
  45. }
  46. props.confirm(orderList)
  47. }
  48. function tapItem(obj) {
  49. var check = !obj.is_following
  50. if (check) {
  51. orderList.push({
  52. name: obj.name,
  53. code: obj.code
  54. })
  55. }
  56. else {
  57. for (var i = 0; i < orderList.length; i++) {
  58. if (orderList[i].code == obj.code) {
  59. orderList.splice(i, 1)
  60. }
  61. }
  62. }
  63. for (var i = 0; i < list.length; i++) {
  64. for (var j = 0; j < list[i].items.length; j++) {
  65. var temp = list[i].items[j]
  66. if (obj.code == temp.code) {
  67. temp.is_following = check
  68. }
  69. }
  70. }
  71. setList(JSON.parse(JSON.stringify(list)))
  72. setOrderList(JSON.parse(JSON.stringify(orderList)))
  73. }
  74. return <View className='modal_content'>
  75. <View className='modal_title_view'>
  76. <Text className='modal_title1'>{t('feature.track_something.metric.choose_metric')}</Text>
  77. <Text className='modal_subtitle'>按需选择自己常用的指标</Text>
  78. </View>
  79. <ScrollView className='modal_detail' scrollY>
  80. <View>
  81. {
  82. list.map((item, index) => {
  83. return <View className='modal_group' key={index}>
  84. <Text className='modal_group_title'>{item.name}</Text>
  85. {
  86. item.items.map((obj, i) => {
  87. return <View className='modal_item' onClick={() => tapItem(obj)}>
  88. {
  89. obj.is_following ? <IconRadioCheck width={16} color='#fff' /> : <IconRadio width={16} color='#fff' />
  90. }
  91. <Text className='modal_item_text' style={{ color: color, marginLeft: 10 }}>{obj.name}</Text>
  92. </View>
  93. })
  94. }
  95. </View>
  96. })
  97. }
  98. </View>
  99. </ScrollView>
  100. <View className='modal_operate'>
  101. <View className='modal_btn' style={{ backgroundColor: color + alpha }} onClick={cancel}>
  102. <Text className='modal_cancel_text' style={{ color: color }}>取消</Text>
  103. </View>
  104. <View className='btn_space' />
  105. <View className='modal_btn' style={{ backgroundColor: color }} onClick={confirm}>
  106. <Text className='modal_confirm_text' style={{ color: '#000' }}>下一步</Text>
  107. </View>
  108. </View>
  109. </View>
  110. }