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' import { useSelector } from 'react-redux' export default function Component(props: { themeColor: string, cancel: Function, confirm: Function, array: any, limit: any, orders: any, newOrders: any }) { const color = props.themeColor ? props.themeColor : '#ff0000' const user = useSelector((state: any) => state.user); const [list, setList] = useState(props.array) const [oldList, setOldList] = useState(props.orders) const [newList, setNewList] = useState(props.newOrders) const min = props.limit.min const max = props.limit.max const { t } = useTranslation() var alpha = alphaToHex(0.4) function cancel() { props.cancel() } function confirm() { // props.confirm(orderList) var array: any = [] for (var i = 0; i < oldList.length; i++) { if (oldList[i].is_following) { array.push(oldList[i]) } } for (var i = 0; i < newList.length; i++) { array.push(newList[i]) } console.log(oldList,newList,array) debugger props.confirm(oldList,newList,array,list) } function tapItem(obj) { var check = !obj.is_following var count = 0; oldList.map(item => { if (item.is_following) { count++; } }) newList.map(item => { if (item.is_following) { count++; } }) if (check) { if (max == count) { Taro.showToast({ icon: 'none', title:`高级会员可选择${count}项以上` // title: t('feature.common.toast.max_metric_count',{count:count}), }) return } } else { if (min == count) { Taro.showToast({ icon: 'none', title: t('feature.common.toast.min_metric_count',{count:count}), }) return } } var isFind = false; oldList.map(item => { if (obj.code == item.code) { isFind = true; item.is_following = check } return item }) if (!isFind) { if (check) { obj.is_following = true newList.push(obj) } else { for (var i = 0; i < newList.length; i++) { if (newList[i].code == obj.code) { newList.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))) setOldList(JSON.parse(JSON.stringify(oldList))) setNewList(JSON.parse(JSON.stringify(newList))) } function codeIndex(code) { for (var i = 0; i < oldList.length; i++) { if (oldList[i].code == code) { return `序号:${i + 1}`; } } // for (var i = 0; i < newList.length; i++) { // if (newList[i].code == code) { // return i + 1 + oldList.length; // } // } return '' } function codeNewIndex(code){ for (var i = 0; i < newList.length; i++) { if (newList[i].code == code) { return `序号:${i + 1 + oldList.length}`; } } return '' } function codeOldIndex(code){ for (var i = 0; i < oldList.length; i++) { if (oldList[i].code == code) { return `序号:${i + 1}`; } } return '' } 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} { user.test_user && {obj.is_following ? codeIndex(obj.code) : ''} } { user.test_user && {obj.is_following ? codeNewIndex(obj.code) : ''} } { user.test_user && {!obj.is_following && codeOldIndex(obj.code)} } }) } }) } 取消 下一步 }