import { View, Text, ScrollView } from '@tarojs/components' import './MetricModalChoose.scss' import { alphaToHex } from '@/utils/tools' import { useTranslation } from 'react-i18next' import { useEffect, useState } from 'react' import { IconRadio, IconRadioCheck } from '@/components/basic/Icons' import Taro from '@tarojs/taro' export default function Component(props: { themeColor: string, cancel: Function, confirm: Function, array: any, limit: any, orders: any }) { const color = props.themeColor ? props.themeColor : '#ff0000' const [list, setList] = useState(props.array) const [orderList, setOrderList] = useState(props.orders) const min = props.limit.min const max = props.limit.max const { t } = useTranslation() var alpha = alphaToHex(0.4) useEffect(()=>{ setList(props.array) setOrderList(props.orders) },[props.array,props.orders]) function cancel() { props.cancel() } function confirm() { // var datas: any = [] // list.map(item => { // item.items.map(data => { // if (data.is_following) { // datas.push(data as any) // } // }) // }) if (min > orderList.length) { Taro.showToast({ icon: 'none', title: t('feature.common.toast.min_value'), }) return } if (max < orderList.length) { Taro.showToast({ icon: 'none', title: t('feature.common.toast.max_value'), }) return } props.confirm(orderList) } function tapItem(obj) { var check = !obj.is_following if (check) { orderList.push({ name: obj.name, code: obj.code }) } else { for (var i = 0; i < orderList.length; i++) { if (orderList[i].code == obj.code) { orderList.splice(i, 1) } } } for (var i = 0; i < list.length; i++) { for (var j = 0; j < list[i].items.length; j++) { var temp = list[i].items[j] if (obj.code == temp.code) { temp.is_following = check } } } setList(JSON.parse(JSON.stringify(list))) setOrderList(JSON.parse(JSON.stringify(orderList))) } return {t('feature.track_something.metric.choose_metric')} 按需选择自己常用的指标 { list.map((item, index) => { return {item.name} { item.items.map((obj, i) => { return tapItem(obj)}> { obj.is_following ? : } {obj.name} }) } }) } 取消 下一步 }