MetricModalChoose.tsx 4.0 KB

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