|
@@ -6,11 +6,7 @@ import Taro from "@tarojs/taro";
|
|
|
import { metricCards, metricFollows, 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 LimitPickers from "@/components/input/LimitPickers";
|
|
|
|
|
-import SlidngScale from "@/components/input/SlidngScale";
|
|
|
|
|
import NoData from "@/components/view/NoData";
|
|
import NoData from "@/components/view/NoData";
|
|
|
-import { alphaToHex } from "@/utils/tools";
|
|
|
|
|
import Layout from "@/components/layout/layout";
|
|
import Layout from "@/components/layout/layout";
|
|
|
import { MetricModalType, ModalType, NaviBarTitleShowType, TemplateType } from "@/utils/types";
|
|
import { MetricModalType, ModalType, NaviBarTitleShowType, TemplateType } from "@/utils/types";
|
|
|
import { useTranslation } from "react-i18next";
|
|
import { useTranslation } from "react-i18next";
|
|
@@ -20,6 +16,7 @@ import { setTabbarStatus } from "@/store/common";
|
|
|
import MetricModalChoose from "./MetricModalChoose";
|
|
import MetricModalChoose from "./MetricModalChoose";
|
|
|
import MetricModalOrder from './MetricModalOrder';
|
|
import MetricModalOrder from './MetricModalOrder';
|
|
|
import MetricModalAdd from "./MetricModalAdd";
|
|
import MetricModalAdd from "./MetricModalAdd";
|
|
|
|
|
+import MetricModalTime from "./MetricModalTime";
|
|
|
|
|
|
|
|
let useNavigation;
|
|
let useNavigation;
|
|
|
if (process.env.TARO_ENV == 'rn') {
|
|
if (process.env.TARO_ENV == 'rn') {
|
|
@@ -32,13 +29,6 @@ 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);
|
|
|
const [list, setList] = useState([])
|
|
const [list, setList] = useState([])
|
|
|
-
|
|
|
|
|
- const [isModalOpen, setIsModalOpen] = useState(false);
|
|
|
|
|
- const [isTimePickerOpen, setIsTimePickerOpen] = useState(false);
|
|
|
|
|
- const [pickerValue, setPickerValue] = useState([]);
|
|
|
|
|
- const [pickerItems, setPickerItems] = useState([]);
|
|
|
|
|
- const [isPoint, setIsPoint] = useState(false)
|
|
|
|
|
-
|
|
|
|
|
const [metricItem, setMetricItem] = useState({})
|
|
const [metricItem, setMetricItem] = useState({})
|
|
|
|
|
|
|
|
const [strTime, setStrTime] = useState('')
|
|
const [strTime, setStrTime] = useState('')
|
|
@@ -48,7 +38,6 @@ export default function Component(props: any) {
|
|
|
|
|
|
|
|
const [setupTime, setSetupTime] = useState(0)
|
|
const [setupTime, setSetupTime] = useState(0)
|
|
|
const [triggered, setTriggered] = useState(true)
|
|
const [triggered, setTriggered] = useState(true)
|
|
|
- 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 [modalType, setModalType] = useState(MetricModalType.none)
|
|
@@ -57,6 +46,7 @@ export default function Component(props: any) {
|
|
|
const [orignalGroups, setOrignalGroups] = useState([])
|
|
const [orignalGroups, setOrignalGroups] = useState([])
|
|
|
const [limits, setLimits] = useState(null)
|
|
const [limits, setLimits] = useState(null)
|
|
|
const [orders, setOrders] = useState([])
|
|
const [orders, setOrders] = useState([])
|
|
|
|
|
+ const [tempMetricItem, setTempMetricItem] = useState(null)
|
|
|
const dispatch = useDispatch();
|
|
const dispatch = useDispatch();
|
|
|
let navigation;
|
|
let navigation;
|
|
|
if (useNavigation) {
|
|
if (useNavigation) {
|
|
@@ -83,11 +73,6 @@ export default function Component(props: any) {
|
|
|
dispatch(setTabbarStatus(false))
|
|
dispatch(setTabbarStatus(false))
|
|
|
setModalType(MetricModalType.add)
|
|
setModalType(MetricModalType.add)
|
|
|
setShowPageContainer(true)
|
|
setShowPageContainer(true)
|
|
|
- // setIsModalOpen(true);
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
- const closeModal = () => {
|
|
|
|
|
- setIsModalOpen(false);
|
|
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
global.refreshMetric = () => {
|
|
global.refreshMetric = () => {
|
|
@@ -174,72 +159,12 @@ export default function Component(props: any) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- function showTimePicker() {
|
|
|
|
|
-
|
|
|
|
|
- setIsTimePickerOpen(true)
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
function chooseTime(e) {
|
|
function chooseTime(e) {
|
|
|
setTime(e);
|
|
setTime(e);
|
|
|
setStrTime(TimeFormatter.dateTimeFormate(e))
|
|
setStrTime(TimeFormatter.dateTimeFormate(e))
|
|
|
- setIsTimePickerOpen(false)
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- function cancelModal() {
|
|
|
|
|
- (metricItem as any).schemas.map((item, index) => {
|
|
|
|
|
- item.tempValue = ''
|
|
|
|
|
- })
|
|
|
|
|
- closeModal()
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- function confirmModal() {
|
|
|
|
|
- closeModal()
|
|
|
|
|
- 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());
|
|
|
|
|
-
|
|
|
|
|
- var array: any[] = [];
|
|
|
|
|
- (metricItem as any).schemas.map((item, index) => {
|
|
|
|
|
- array.push({
|
|
|
|
|
- code: item.code,
|
|
|
|
|
- value: item.tempValue && item.tempValue > 0 ? item.tempValue : item.default_value
|
|
|
|
|
- })
|
|
|
|
|
- })
|
|
|
|
|
- var params = {
|
|
|
|
|
- code: (metricItem as any).code,
|
|
|
|
|
- timestamp: time,
|
|
|
|
|
- date: strDate,
|
|
|
|
|
- items: array,
|
|
|
|
|
- extra: {
|
|
|
|
|
- set_time: setupTime,
|
|
|
|
|
- confirm_time: new Date().getTime()
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- global.postBtnUpdateStatus('normal');
|
|
|
|
|
- uploadMetric(params).then(res => {
|
|
|
|
|
- // getCards();
|
|
|
|
|
- (metricItem as any).schemas.map((item, index) => {
|
|
|
|
|
- item.tempValue = ''
|
|
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
- list.map((item, index) => {
|
|
|
|
|
- if ((item as any).code == (res as any).code) {
|
|
|
|
|
- (item as any).latest_record = (res as any).latest_record;
|
|
|
|
|
- (item as any).schemas = (res as any).schemas;
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
- setList(JSON.parse(JSON.stringify(list)))
|
|
|
|
|
-
|
|
|
|
|
- global.postBtnUpdateStatus('idle');
|
|
|
|
|
- setTimeout(() => {
|
|
|
|
|
- setCount(count + 1)
|
|
|
|
|
- }, 31000)
|
|
|
|
|
-
|
|
|
|
|
- })
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const limitDay = 500
|
|
const limitDay = 500
|
|
|
-
|
|
|
|
|
const limit = new Date().getTime() - limitDay * 3600 * 1000 * 24;
|
|
const limit = new Date().getTime() - limitDay * 3600 * 1000 * 24;
|
|
|
|
|
|
|
|
function detail() {
|
|
function detail() {
|
|
@@ -284,18 +209,6 @@ export default function Component(props: any) {
|
|
|
</View>
|
|
</View>
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- function detailContent() {
|
|
|
|
|
- // if (process.env.TARO_ENV=='rn'){
|
|
|
|
|
- // return <ScrollView>
|
|
|
|
|
- // {
|
|
|
|
|
- // detail()
|
|
|
|
|
- // }
|
|
|
|
|
- // <View style={{height:150}}/>
|
|
|
|
|
- // </ScrollView>
|
|
|
|
|
- // }
|
|
|
|
|
- return detail()
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
function addBtnClick() {
|
|
function addBtnClick() {
|
|
|
Taro.showActionSheet({
|
|
Taro.showActionSheet({
|
|
|
itemList: [t('feature.track_something.metric.choose_metric'),
|
|
itemList: [t('feature.track_something.metric.choose_metric'),
|
|
@@ -349,11 +262,34 @@ export default function Component(props: any) {
|
|
|
array={orders} />
|
|
array={orders} />
|
|
|
case MetricModalType.add:
|
|
case MetricModalType.add:
|
|
|
return <MetricModalAdd
|
|
return <MetricModalAdd
|
|
|
- item={metricItem}
|
|
|
|
|
|
|
+ item={tempMetricItem ? tempMetricItem : metricItem}
|
|
|
strTime={strTime}
|
|
strTime={strTime}
|
|
|
- showPicker={() => { }}
|
|
|
|
|
- cancel={() => { }}
|
|
|
|
|
- confirm={() => { }} />
|
|
|
|
|
|
|
+ showPicker={(tempItem) => {
|
|
|
|
|
+ var temp = JSON.parse(JSON.stringify(tempItem))
|
|
|
|
|
+ temp.schemas.map(item => {
|
|
|
|
|
+ if (item.tempValue) {
|
|
|
|
|
+ item.default_value = item.tempValue
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ setTempMetricItem(temp)
|
|
|
|
|
+ setModalType(MetricModalType.time)
|
|
|
|
|
+ }}
|
|
|
|
|
+ cancel={modalAddCancel}
|
|
|
|
|
+ confirm={modalAddConfirm} />
|
|
|
|
|
+ case MetricModalType.time:
|
|
|
|
|
+ return <MetricModalTime
|
|
|
|
|
+ item={metricItem}
|
|
|
|
|
+ time={time}
|
|
|
|
|
+ limit={limit}
|
|
|
|
|
+ limitDay={limitDay}
|
|
|
|
|
+ cancel={() => {
|
|
|
|
|
+ setModalType(MetricModalType.add)
|
|
|
|
|
+ }}
|
|
|
|
|
+ confirm={(e) => {
|
|
|
|
|
+ chooseTime(e)
|
|
|
|
|
+ setModalType(MetricModalType.add)
|
|
|
|
|
+ }}
|
|
|
|
|
+ />
|
|
|
}
|
|
}
|
|
|
return <View />
|
|
return <View />
|
|
|
}
|
|
}
|
|
@@ -395,6 +331,60 @@ export default function Component(props: any) {
|
|
|
setShowPageContainer(false)
|
|
setShowPageContainer(false)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ function modalAddCancel() {
|
|
|
|
|
+ dispatch(setTabbarStatus(true))
|
|
|
|
|
+ setShowPageContainer(false)
|
|
|
|
|
+ onPageContainerCancel()
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function modalAddConfirm(result) {
|
|
|
|
|
+ dispatch(setTabbarStatus(true))
|
|
|
|
|
+ setShowPageContainer(false)
|
|
|
|
|
+
|
|
|
|
|
+ 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());
|
|
|
|
|
+
|
|
|
|
|
+ var array: any[] = [];
|
|
|
|
|
+ result.schemas.map((item, index) => {
|
|
|
|
|
+ array.push({
|
|
|
|
|
+ code: item.code,
|
|
|
|
|
+ value: item.tempValue && item.tempValue > 0 ? item.tempValue : item.default_value
|
|
|
|
|
+ })
|
|
|
|
|
+ })
|
|
|
|
|
+ var params = {
|
|
|
|
|
+ code: result.code,
|
|
|
|
|
+ timestamp: time,
|
|
|
|
|
+ date: strDate,
|
|
|
|
|
+ items: array,
|
|
|
|
|
+ extra: {
|
|
|
|
|
+ set_time: setupTime,
|
|
|
|
|
+ confirm_time: new Date().getTime()
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ global.postBtnUpdateStatus('normal');
|
|
|
|
|
+ uploadMetric(params).then(res => {
|
|
|
|
|
+ // getCards();
|
|
|
|
|
+ result.schemas.map((item, index) => {
|
|
|
|
|
+ item.tempValue = ''
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ list.map((item, index) => {
|
|
|
|
|
+ if ((item as any).code == (res as any).code) {
|
|
|
|
|
+ (item as any).latest_record = (res as any).latest_record;
|
|
|
|
|
+ (item as any).schemas = (res as any).schemas;
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ setList(JSON.parse(JSON.stringify(list)))
|
|
|
|
|
+
|
|
|
|
|
+ global.postBtnUpdateStatus('idle');
|
|
|
|
|
+ setTimeout(() => {
|
|
|
|
|
+ setCount(count + 1)
|
|
|
|
|
+ }, 31000)
|
|
|
|
|
+
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
function onPageContainerCancel() {
|
|
function onPageContainerCancel() {
|
|
|
if (modalType == MetricModalType.choose || modalType == MetricModalType.order) {
|
|
if (modalType == MetricModalType.choose || modalType == MetricModalType.order) {
|
|
|
var array: any = [];
|
|
var array: any = [];
|
|
@@ -409,10 +399,13 @@ export default function Component(props: any) {
|
|
|
setGroups(JSON.parse(JSON.stringify(orignalGroups)))
|
|
setGroups(JSON.parse(JSON.stringify(orignalGroups)))
|
|
|
// setGroups(orignalGroups)
|
|
// setGroups(orignalGroups)
|
|
|
}
|
|
}
|
|
|
|
|
+ else {
|
|
|
|
|
+ setTempMetricItem(null)
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return <View style={{ position: 'relative' }}>
|
|
return <View style={{ position: 'relative' }}>
|
|
|
- <Layout children={showErrorPage ? <NoData refresh={() => { getCards() }} /> : detailContent()}
|
|
|
|
|
|
|
+ <Layout children={showErrorPage ? <NoData refresh={() => { getCards() }} /> : detail()}
|
|
|
title={t('page.metric.title')}
|
|
title={t('page.metric.title')}
|
|
|
type={TemplateType.customHeader}
|
|
type={TemplateType.customHeader}
|
|
|
header={headerView()}
|
|
header={headerView()}
|
|
@@ -433,34 +426,6 @@ export default function Component(props: any) {
|
|
|
metricModalContent()
|
|
metricModalContent()
|
|
|
}
|
|
}
|
|
|
</PageContainer>
|
|
</PageContainer>
|
|
|
- {
|
|
|
|
|
- isModalOpen && <Modal dismiss={closeModal} title={(metricItem as any).name}
|
|
|
|
|
- themeColor={(metricItem as any).theme_color}
|
|
|
|
|
- confirm={confirmModal}>
|
|
|
|
|
-
|
|
|
|
|
- </Modal>
|
|
|
|
|
- }
|
|
|
|
|
- {
|
|
|
|
|
-
|
|
|
|
|
- isTimePickerOpen && <Modal
|
|
|
|
|
- themeColor={(metricItem as any).theme_color}
|
|
|
|
|
- dismiss={() => setIsTimePickerOpen(false)} confirm={() => {
|
|
|
|
|
- var picker = limitPickerRef.current;
|
|
|
|
|
- chooseTime((picker as any).getConfirmData());
|
|
|
|
|
- setIsTimePickerOpen(false);
|
|
|
|
|
- }}>
|
|
|
|
|
- <LimitPickers ref={limitPickerRef}
|
|
|
|
|
- isRealTime={true} time={time} limit={limit}
|
|
|
|
|
- title={t('feature.track_something.picker_datetime')}
|
|
|
|
|
- themeColor={(metricItem as any).theme_color}
|
|
|
|
|
- limitDay={limitDay} onCancel={() => { setIsTimePickerOpen(false) }}
|
|
|
|
|
- onChange={(e) => {
|
|
|
|
|
- chooseTime(e)
|
|
|
|
|
- // pickerConfirm(e)
|
|
|
|
|
- // hidePicker()
|
|
|
|
|
- }} />
|
|
|
|
|
- </Modal>
|
|
|
|
|
- }
|
|
|
|
|
</View>
|
|
</View>
|
|
|
|
|
|
|
|
}
|
|
}
|