|
@@ -3,7 +3,7 @@ import './Metric.scss'
|
|
|
import { useDispatch, useSelector } from "react-redux";
|
|
import { useDispatch, useSelector } from "react-redux";
|
|
|
import { useEffect, useRef, useState } from "react";
|
|
import { useEffect, useRef, useState } from "react";
|
|
|
import Taro from "@tarojs/taro";
|
|
import Taro from "@tarojs/taro";
|
|
|
-import { metricCards, metricGroups, uploadMetric, uploadSteps } from "@/services/trackSomething";
|
|
|
|
|
|
|
+import { metricCards, metricFollows, metricGroups, uploadMetric, uploadSteps } from "@/services/trackSomething";
|
|
|
import { TimeFormatter } from "@/utils/time_format";
|
|
import { TimeFormatter } from "@/utils/time_format";
|
|
|
import MetricItem from "./MetricItem";
|
|
import MetricItem from "./MetricItem";
|
|
|
import Modal from "@/components/layout/Modal";
|
|
import Modal from "@/components/layout/Modal";
|
|
@@ -12,17 +12,21 @@ import SlidngScale from "@/components/input/SlidngScale";
|
|
|
import NoData from "@/components/view/NoData";
|
|
import NoData from "@/components/view/NoData";
|
|
|
import { alphaToHex } from "@/utils/tools";
|
|
import { alphaToHex } from "@/utils/tools";
|
|
|
import Layout from "@/components/layout/layout";
|
|
import Layout from "@/components/layout/layout";
|
|
|
-import { NaviBarTitleShowType, TemplateType } from "@/utils/types";
|
|
|
|
|
|
|
+import { MetricModalType, ModalType, NaviBarTitleShowType, TemplateType } from "@/utils/types";
|
|
|
import { useTranslation } from "react-i18next";
|
|
import { useTranslation } from "react-i18next";
|
|
|
import { jumpPage } from "@/features/trackTimeDuration/hooks/Common";
|
|
import { jumpPage } from "@/features/trackTimeDuration/hooks/Common";
|
|
|
import TitleView from "@/features/trackTimeDuration/components/TitleView";
|
|
import TitleView from "@/features/trackTimeDuration/components/TitleView";
|
|
|
import { setTabbarStatus } from "@/store/common";
|
|
import { setTabbarStatus } from "@/store/common";
|
|
|
|
|
+import MetricModalChoose from "./MetricModalChoose";
|
|
|
|
|
+import MetricModalOrder from './MetricModalOrder';
|
|
|
|
|
|
|
|
let useNavigation;
|
|
let useNavigation;
|
|
|
if (process.env.TARO_ENV == 'rn') {
|
|
if (process.env.TARO_ENV == 'rn') {
|
|
|
useNavigation = require("@react-navigation/native").useNavigation
|
|
useNavigation = require("@react-navigation/native").useNavigation
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
export default function Component(props: any) {
|
|
export default function Component(props: any) {
|
|
|
const { t } = useTranslation()
|
|
const { t } = useTranslation()
|
|
|
const user = useSelector((state: any) => state.user);
|
|
const user = useSelector((state: any) => state.user);
|
|
@@ -46,6 +50,11 @@ export default function Component(props: any) {
|
|
|
const limitPickerRef = useRef<any>(null);
|
|
const limitPickerRef = useRef<any>(null);
|
|
|
const [count, setCount] = useState(0)
|
|
const [count, setCount] = useState(0)
|
|
|
const [showPageContainer, setShowPageContainer] = useState(false)
|
|
const [showPageContainer, setShowPageContainer] = useState(false)
|
|
|
|
|
+ const [modalType, setModalType] = useState(MetricModalType.none)
|
|
|
|
|
+ const [themeColor, setThemeColor] = useState('#00ffff')
|
|
|
|
|
+ const [groups, setGroups] = useState([])
|
|
|
|
|
+ const [limits, setLimits] = useState(null)
|
|
|
|
|
+ const [orders, setOrders] = useState([])
|
|
|
const dispatch = useDispatch();
|
|
const dispatch = useDispatch();
|
|
|
let navigation;
|
|
let navigation;
|
|
|
if (useNavigation) {
|
|
if (useNavigation) {
|
|
@@ -86,6 +95,19 @@ export default function Component(props: any) {
|
|
|
setErrorPage(false)
|
|
setErrorPage(false)
|
|
|
setList((res as any).cards)
|
|
setList((res as any).cards)
|
|
|
setTriggered(false)
|
|
setTriggered(false)
|
|
|
|
|
+ if ((res as any).cards.length > 0) {
|
|
|
|
|
+ var obj = (res as any).cards[0]
|
|
|
|
|
+ setThemeColor(obj.theme_color)
|
|
|
|
|
+ }
|
|
|
|
|
+ var list: any = [];
|
|
|
|
|
+ (res as any).cards.map(item => {
|
|
|
|
|
+ list.push({
|
|
|
|
|
+ name: item.name,
|
|
|
|
|
+ code: item.code
|
|
|
|
|
+ })
|
|
|
|
|
+ })
|
|
|
|
|
+ setOrders(list)
|
|
|
|
|
+
|
|
|
}).catch(e => {
|
|
}).catch(e => {
|
|
|
Taro.stopPullDownRefresh()
|
|
Taro.stopPullDownRefresh()
|
|
|
if (list.length == 0) {
|
|
if (list.length == 0) {
|
|
@@ -95,9 +117,10 @@ export default function Component(props: any) {
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- function getGroups(){
|
|
|
|
|
- metricGroups().then(res=>{
|
|
|
|
|
-
|
|
|
|
|
|
|
+ function getGroups() {
|
|
|
|
|
+ metricGroups().then(res => {
|
|
|
|
|
+ setGroups((res as any).groups)
|
|
|
|
|
+ setLimits((res as any).num_options_limit)
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -143,106 +166,8 @@ export default function Component(props: any) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- function pointPicker(item: any) {
|
|
|
|
|
- var min = item.min
|
|
|
|
|
- var max = item.max
|
|
|
|
|
- var step = item.step
|
|
|
|
|
- var value = item.default_value
|
|
|
|
|
- var items: number[] = []
|
|
|
|
|
- var items2: number[] = []
|
|
|
|
|
-
|
|
|
|
|
- var value0Index = 0
|
|
|
|
|
- var value1Index = 0
|
|
|
|
|
-
|
|
|
|
|
- for (var i = min; i <= max; i++) {
|
|
|
|
|
- if (i == Math.floor(value)) {
|
|
|
|
|
- value0Index = i - min
|
|
|
|
|
- }
|
|
|
|
|
- items.push(i)
|
|
|
|
|
- // items2.push(i)
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- for (var i = 0; i <= 9; i++) {
|
|
|
|
|
- items2.push(i)
|
|
|
|
|
- }
|
|
|
|
|
- value1Index = Math.round(10 * (value - Math.floor(value)));
|
|
|
|
|
-
|
|
|
|
|
- setPickerValue([value0Index, value1Index] as any)
|
|
|
|
|
- setPickerItems([items, items2] as any)
|
|
|
|
|
- setIsPoint(true)
|
|
|
|
|
-
|
|
|
|
|
- openModal()
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- function singlePicker(item: any) {
|
|
|
|
|
- var min = item.min
|
|
|
|
|
- var max = item.max
|
|
|
|
|
- var step = 1//item.step
|
|
|
|
|
- var value = item.default_value
|
|
|
|
|
-
|
|
|
|
|
- var items: number[] = []
|
|
|
|
|
- for (var i = min; i <= max; i += step) {
|
|
|
|
|
- if (i == value) {
|
|
|
|
|
- setPickerValue([i - min] as any)
|
|
|
|
|
- }
|
|
|
|
|
- items.push(i)
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- setPickerItems([items] as any)
|
|
|
|
|
- setIsPoint(false)
|
|
|
|
|
-
|
|
|
|
|
- openModal()
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- function pickerChanged(e) {
|
|
|
|
|
- closeModal();
|
|
|
|
|
- var params = {}
|
|
|
|
|
- var date = new Date(time)
|
|
|
|
|
- var strDate = (date.getFullYear() + '') + (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : (date.getMonth() + 1)) + (date.getDate() < 10 ? '0' + date.getDate() : date.getDate());
|
|
|
|
|
-
|
|
|
|
|
- if ((metricItem as any).schemas[0].type == 'DECIMAL') {
|
|
|
|
|
- var array = pickerItems;
|
|
|
|
|
- var value = array[0][e[0]] + '.' + array[1][e[1]]
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- params = {
|
|
|
|
|
- code: (metricItem as any).code,
|
|
|
|
|
- timestamp: time,
|
|
|
|
|
- date: strDate,
|
|
|
|
|
- items: [{ code: (metricItem as any).schemas[0].code, value: value }]
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- else if ((metricItem as any).schemas.length > 1) {
|
|
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
- else {
|
|
|
|
|
- var array = pickerItems;
|
|
|
|
|
- var value = array[0][e[0]] + ''
|
|
|
|
|
- params = {
|
|
|
|
|
- code: (metricItem as any).code,
|
|
|
|
|
- timestamp: time,
|
|
|
|
|
- date: strDate,
|
|
|
|
|
- items: [{ code: (metricItem as any).schemas[0].code, value: value }]
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- uploadMetric(params).then(res => {
|
|
|
|
|
- list.map((item, index) => {
|
|
|
|
|
- if ((item as any).code == (res as any).code) {
|
|
|
|
|
- (item as any).latest_record = (res as any).latest_record
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
- setList(list)
|
|
|
|
|
-
|
|
|
|
|
- setTimeout(() => {
|
|
|
|
|
- setCount(count + 1)
|
|
|
|
|
- }, 31000)
|
|
|
|
|
- // getCards();
|
|
|
|
|
- })
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
function showTimePicker() {
|
|
function showTimePicker() {
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
setIsTimePickerOpen(true)
|
|
setIsTimePickerOpen(true)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -364,8 +289,31 @@ export default function Component(props: any) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function addBtnClick() {
|
|
function addBtnClick() {
|
|
|
- dispatch(setTabbarStatus(false))
|
|
|
|
|
- setShowPageContainer(true)
|
|
|
|
|
|
|
+ Taro.showActionSheet({
|
|
|
|
|
+ itemList: [t('feature.track_something.metric.choose_metric'),
|
|
|
|
|
+ t('feature.track_something.metric.order')]
|
|
|
|
|
+ })
|
|
|
|
|
+ .then(res => {
|
|
|
|
|
+ switch (res.tapIndex) {
|
|
|
|
|
+ case 0:
|
|
|
|
|
+ global.metricAdd = true
|
|
|
|
|
+ setModalType(MetricModalType.choose)
|
|
|
|
|
+ dispatch(setTabbarStatus(false))
|
|
|
|
|
+ setShowPageContainer(true)
|
|
|
|
|
+
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 1:
|
|
|
|
|
+ global.metricAdd = false
|
|
|
|
|
+ setModalType(MetricModalType.order)
|
|
|
|
|
+ dispatch(setTabbarStatus(false))
|
|
|
|
|
+ setShowPageContainer(true)
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ .catch(err => {
|
|
|
|
|
+ console.log(err.errMsg)
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function headerView() {
|
|
function headerView() {
|
|
@@ -373,6 +321,64 @@ export default function Component(props: any) {
|
|
|
</TitleView>
|
|
</TitleView>
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ function metricModalContent() {
|
|
|
|
|
+ switch (modalType) {
|
|
|
|
|
+ case MetricModalType.choose:
|
|
|
|
|
+ return <MetricModalChoose
|
|
|
|
|
+ themeColor={themeColor}
|
|
|
|
|
+ cancel={modalCancel}
|
|
|
|
|
+ confirm={modalConfirm}
|
|
|
|
|
+ array={groups}
|
|
|
|
|
+ orders={orders}
|
|
|
|
|
+ limit={limits}
|
|
|
|
|
+ />
|
|
|
|
|
+ case MetricModalType.order:
|
|
|
|
|
+ return <MetricModalOrder themeColor={themeColor} cancel={modalOrderCancel} confirm={modalOrderConfirm} array={orders} />
|
|
|
|
|
+ }
|
|
|
|
|
+ return <View />
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function modalCancel() {
|
|
|
|
|
+ setShowPageContainer(false)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function modalConfirm(datas) {
|
|
|
|
|
+ var array: any = []
|
|
|
|
|
+ datas.map(item => {
|
|
|
|
|
+ array.push(item.code)
|
|
|
|
|
+ })
|
|
|
|
|
+ metricFollows({ codes: array }).then(res => {
|
|
|
|
|
+ getCards()
|
|
|
|
|
+ getGroups()
|
|
|
|
|
+ })
|
|
|
|
|
+ setShowPageContainer(false)
|
|
|
|
|
+
|
|
|
|
|
+ setTimeout(() => {
|
|
|
|
|
+ dispatch(setTabbarStatus(false))
|
|
|
|
|
+ setModalType(MetricModalType.order)
|
|
|
|
|
+ setShowPageContainer(true)
|
|
|
|
|
+ }, 500)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function modalOrderCancel() {
|
|
|
|
|
+ global.metricAdd ? modalCancel() : modalCancel()
|
|
|
|
|
+ if (global.metricAdd) {
|
|
|
|
|
+ setShowPageContainer(false)
|
|
|
|
|
+ setTimeout(() => {
|
|
|
|
|
+ dispatch(setTabbarStatus(false))
|
|
|
|
|
+ setModalType(MetricModalType.choose)
|
|
|
|
|
+ setShowPageContainer(true)
|
|
|
|
|
+ }, 500)
|
|
|
|
|
+ }
|
|
|
|
|
+ else {
|
|
|
|
|
+ setShowPageContainer(false)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function modalOrderConfirm() {
|
|
|
|
|
+ setShowPageContainer(false)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
return <View style={{ position: 'relative' }}>
|
|
return <View style={{ position: 'relative' }}>
|
|
|
<Layout children={showErrorPage ? <NoData refresh={() => { getCards() }} /> : detailContent()}
|
|
<Layout children={showErrorPage ? <NoData refresh={() => { getCards() }} /> : detailContent()}
|
|
|
title={t('page.metric.title')}
|
|
title={t('page.metric.title')}
|
|
@@ -385,10 +391,13 @@ export default function Component(props: any) {
|
|
|
<PageContainer style={{ backgroundColor: '#1c1c1c' }}
|
|
<PageContainer style={{ backgroundColor: '#1c1c1c' }}
|
|
|
overlayStyle='background-color:rgba(0,0,0,0.9)'
|
|
overlayStyle='background-color:rgba(0,0,0,0.9)'
|
|
|
custom-style='background-color:#1c1c1c'
|
|
custom-style='background-color:#1c1c1c'
|
|
|
- show={showPageContainer} round={true} overlay={true} position='bottom' onAfterLeave={() => {setShowPageContainer(false);dispatch(setTabbarStatus(true))}}>
|
|
|
|
|
- <Text style={{color:'#000'}} onClick={()=>{console.log('ssss')}}>1111</Text>
|
|
|
|
|
- <View style={{ width: 200, height: 200, backgroundColor: 'pink', margin: 50 }} />
|
|
|
|
|
- <Text style={{color:'#000'}} onClick={()=>{console.log('ssss')}}>1111</Text>
|
|
|
|
|
|
|
+ closeOnSlideDown={false}
|
|
|
|
|
+ show={showPageContainer} round={true} overlay={true} position='bottom'
|
|
|
|
|
+ onBeforeLeave={() => { dispatch(setTabbarStatus(true)) }}
|
|
|
|
|
+ onAfterLeave={() => { setShowPageContainer(false); }}>
|
|
|
|
|
+ {
|
|
|
|
|
+ metricModalContent()
|
|
|
|
|
+ }
|
|
|
</PageContainer>
|
|
</PageContainer>
|
|
|
{
|
|
{
|
|
|
isModalOpen && <Modal dismiss={closeModal} title={(metricItem as any).name}
|
|
isModalOpen && <Modal dismiss={closeModal} title={(metricItem as any).name}
|