import Taro, { setStorageSync } from "@tarojs/taro"; import classnames from "classnames"; import { Component, PropsWithChildren, useEffect, useState } from "react"; import { Block, View, Text, Image, Input, Button, ScrollView, Picker, Textarea, } from "@tarojs/components"; import { go } from "@/utils/traoAPI"; import { Tab, Tabs, Dialog, Popup } from "@antmjs/vantui"; /** 自定义组件 **/ import Navbar from "@/components/navbar/navbar"; import PopupClock from "@/components/popup/popup-clock"; /** 自定义组件 **/ import { InstrumentInfo } from "@/utils/Interface"; import { date, getdates, previewImage } from "@/utils/util"; import { showModal } from "@/utils/traoAPI.js"; import "./recording.less"; export default class Recording extends Component { constructor(props) { super(props); this.state = { name: "护理历程", current: 0, ViewAddInstrument: false, //用来记录有没有添加设备 array: [1, 2, 3, 4, 5], recordList: [], bindingInstrumentList: [], clockShow: false, curIndex: null, clockStatistics: [], statistics: [], year: new Date().getFullYear(), today: new Date(), monthTime: [ { month: 1, time: 0 }, { month: 2, time: 0 }, { month: 3, time: 0 }, { month: 4, time: 0 }, { month: 5, time: 0 }, { month: 6, time: 0 }, { month: 7, time: 0 }, { month: 8, time: 0 }, { month: 9, time: 0 }, { month: 10, time: 0 }, { month: 11, time: 0 }, { month: 12, time: 0 }, ], show: false, punchInInfo: { clockImageList: [], clockContent: "", }, navigationBarHeight: "", statusBarHeight: "", }; } componentDidMount() {} componentWillUnmount() {} // 格式化时间 getTime(time) { const hour = time.slice(0, 2); const minute = time.slice(3, 5); const second = time.slice(6, 8); if (hour > 0) { return hour + "时" + minute + "分" + second + "秒"; } else { return minute + "分" + second + "秒"; } } // 获取仪器列表 async getBindingInstrumentList() { let res = await InstrumentInfo.bindingInstrumentList(); if (res.data.code === 200) { this.setState({ bindingInstrumentList: res.data.data }); } } // 获取护理历程 async getRecord(id) { let data = {}; if (id != null) { data["instrumentId"] = id; } let res = await InstrumentInfo.apiNursingLog.getRecord(data); console.log(res, "查看你获取护理历程"); if (res.data.code === 200) { res.data.rows.map((item) => { item.nursingTime = this.getTime(item.nursingTime); let createTime = getdates(item.createTime); item.createTime = createTime && createTime.replace(/-/g, "."); }); this.setState({ recordList: res.data.rows }); } } // 查询用户当天最新的一条打卡记录 async getLatestClockRecord() { let res = await InstrumentInfo.apiClock.getLatestClockRecord(); if (res.data.code === 200) { if (!res.data.data) { // this.setShow(true); } else { let punchInInfo = { clockImageList: res.data.data.clockImg, clockContent: res.data.data.clockContent, }; this.setState({ punchInInfo }); } } } // 添加打卡记录(测试用) async addLog() { let data = { instrumentId: 57, instrumentName: "0130验收FR100", online: 1, modeId: 100, modeName: "护理记录测试", nursingTime: "00:15:00", }; let res = await InstrumentInfo.apiNursingLog.addLog(data); if (res.data.code === 200) { } } /**分页获取用户的打卡记录 page size*/ async getClockStatistics(year = this.state.year) { let res = await InstrumentInfo.apiClock.getClockStatistics({ year }); if (res.data.code === 200) { res.data.data.reverse(); if (res.data.data.length > 0) { res.data.data.map((item, index) => { item.isMore = false; item.detail = []; if (index === 0) { item.isMore = true; this.getList(item.id, item.year, item.month); } this.state.monthTime.map((monthItem) => { if (monthItem.month == item.month) { monthItem.time = item.clockNum; } }); }); this.setState({ monthTime: this.state.monthTime }); } else { let monthTime = [ { month: 1, time: 0 }, { month: 2, time: 0 }, { month: 3, time: 0 }, { month: 4, time: 0 }, { month: 5, time: 0 }, { month: 6, time: 0 }, { month: 7, time: 0 }, { month: 8, time: 0 }, { month: 9, time: 0 }, { month: 10, time: 0 }, { month: 11, time: 0 }, { month: 12, time: 0 }, ]; this.setState({ monthTime }); } this.setState({ clockStatistics: res.data.data }); } } // 文本框输入文字 handleTextareaInput = (e) => { const punchInInfo = this.state.punchInInfo; this.setState({ punchInInfo: { ...punchInInfo, clockContent: e.detail.value }, }); }; // 打开/关闭弹窗 setShow(show: boolean) { this.setState({ show }); } // 选择仪器 onChangeProduct(id) { this.setState({ curIndex: id }); this.getRecord(id); // this.addLog(); } // 展开收起 onChangeMore(id, year, month) { this.state.clockStatistics.map((item) => { if (item.id === id) { item.isMore = !item.isMore; if (item.isMore && item.detail.length === 0) { this.getList(id, year, month); } } }); this.setState({ clockStatistics: this.state.clockStatistics }); } // 获取当月打卡记录 async getList(id, year, month) { let data = { year, month, }; let res = await InstrumentInfo.apiClock.getList(data); if (res.data.code === 200) { console.log(res, 88888, this.state.clockStatistics, id); this.state.clockStatistics.map((item) => { if (item.id === id) { item.detail = res.data.data; item.detail.map((obj) => { let updateTime = obj.updateTime ? getdates(obj.updateTime) : getdates(obj.createTime); obj.updateTime = updateTime && updateTime.replace(/-/g, "."); }); } }); this.setState({ clockStatistics: this.state.clockStatistics }); } } async DayTime() { let storedData = Taro.getStorageSync("DayTime"); const day = new Date(); if (storedData === undefined || storedData === "") { this.setState({ clockShow: false, }); } else { const storedDate = new Date(storedData); const currentDate = new Date(day.toISOString()); const isSameDate = storedDate.toDateString() === currentDate.toDateString(); if (isSameDate) { this.setState({ clockShow: true, }); } else { this.setState({ clockShow: false, }); } } } async onLoad(options) { const ViewAddInstrument = options.param; this.setState({ ViewAddInstrument: ViewAddInstrument, }); this.getRecord(null); this.getBindingInstrumentList(); this.getLatestClockRecord(); this.getClockStatistics(); this.DayTime(); this.setStatusBar(); } componentDidShow() {} componentDidHide() {} async initData() {} // 选择年份 onChangeYear(event) { this.setState({ year: event.detail.value }); this.getClockStatistics(event.detail.value); } // 点击tab栏 onTab = async (event) => { const { current } = event.currentTarget.dataset; this.setState({ current }); if (current === 1) { this.getClockStatistics(); } }; // 跳转到护理报告 toReport(id, recordId, item) { this.state.bindingInstrumentList.map((instrument) => { if (instrument.id == id) { setStorageSync("instrument_detail", instrument); } }); console.log(item, "查看"); if ([1, 2, 3, 4, 5].includes(item.jumpType)) { this.One(item); } else if (item.jumpType === 0) { this.two(item); } else if (item.jumpType === 6) { this.three(item); } else { this.AllDevice(item); } // let report =false // go("/recording/pages/face_report/face_report?id=" + id + "&recordId=" + recordId+ "&report=" + report ); } // 打开第一种类型 One = async (item) => { let ids = Number(item.id); // 获取echarts数据 这个是获取接口更新echarts页面 let res2 = await InstrumentInfo.apiNursingLog.getStatiCDE(ids); let nursingData = JSON.parse(res2.data.data.nursingData); let obj = { modeName: res2.data.data.modeName, data: nursingData, }; let report = false; go( "/recoding/pages/face_report_one/face_report_one?id=" + item.id + "&report=" + report + "&obj=" + JSON.stringify(obj) ); }; // 打开第二种类型 two = async (item) => { console.log("打开第二种类型", item); let report = false; go( "/recoding/pages/face_report/face_report?id=" + item.id + "&recordId=" + item.instrumentId + "&report=" + report ); }; // 打开第三种类型 three = async (item) => { this.moistureTest(item); }; async moistureTest(allData) { let data = { queryDate: allData.createTime, instrumentId: allData.instrumentId, }; let res = await InstrumentInfo.fr200.moistureTest(data); let echartsData = res.data.rows; for (let i = 0; i < echartsData.length; i++) { for (let j = i + 1; j < echartsData.length; j++) { if ( echartsData[i].createTime.split(" ")[0] == echartsData[j].createTime.split(" ")[0] ) { let result = Date.parse(echartsData[i].createTime) - Date.parse(echartsData[j].createTime); if (result < 0) { echartsData.splice(i, 1); } else { echartsData.splice(j, 1); } } } } let gears: any = []; let eDate: any = []; echartsData.map((item) => { const result = item.createTime.split(" ")[0].substring(5); eDate.push(result); item.nursingData = JSON.parse(item.nursingData); let level: any = 0; item.nursingData?.GearData?.map((gear) => { level = level + gear.forehead; }); level = Math.floor(level / 3); gears.push(level); }); echartsData = { gears, eDate } setStorageSync('moistureEachtsData', JSON.stringify(echartsData)) let report =false go(`/recoding/pages/moisture_test_report/moisture_test_report?data=${allData.nursingData}&date=${allData.createTime}&modeId=${allData.modeId}&id=${allData.instrumentId}&echartsData=${JSON.stringify(echartsData)}&report=${report }`); } // 打开其他类型 AllDevice = async (item) => { console.log("打开其他类型", item); go("/pages/face_report_AllDevice/face_report_AllDevice"); }; // 上传图片 handleChooseImage() { Taro.chooseMedia({ count: 1, mediaType: ["image"], sourceType: ["album", "camera"], success: (res) => { const tempFilePaths = res.tempFiles.map((item) => item.tempFilePath); tempFilePaths?.forEach((item) => { // eslint-disable-next-line @typescript-eslint/no-shadow InstrumentInfo.apiClock .clockFileUpload({ clockImg: item }) .then((res) => { const currentImage = res.data.url; const newImageList = this.state.punchInInfo.clockImageList.length >= 3 ? this.state.punchInInfo.clockImageList : [...this.state.punchInInfo.clockImageList, currentImage]; const punchInInfo = this.state.punchInInfo; punchInInfo.clockImageList = newImageList; this.setState({ punchInInfo }); }); }); }, fail: (err) => { console.info("err", err); }, }); } // 删除打卡图片 delImg(i) { const punchInInfo = this.state.punchInInfo; punchInInfo.clockImageList.splice(i, 1); this.setState({ punchInInfo }); } async submit() { let punchInInfo = this.state.punchInInfo || {}; if (!punchInInfo.clockImageList.length) { Taro.showToast({ title: "请上传图片", icon: "none", }); return; } if (!punchInInfo.clockContent) { Taro.showToast({ title: "请输入打卡心得", icon: "none", }); return; } InstrumentInfo.apiClock.postInsertClockLog(punchInInfo).then((res) => { showModal({ t2: "您已完成今日打卡", btn1show: false, }).then(() => { let data = new Date(); Taro.setStorageSync("DayTime", data.toISOString()); this.setState({ clockShow: true, }); this.getClockStatistics(); this.setShow(false); }); }); } back() { Taro.navigateBack({ delta: 1, }); } setStatusBar() { Taro.getSystemInfoAsync({ success: (res) => { const statusBarHeight = res.statusBarHeight || 0; // 获取微信胶囊的位置信息 width,height,top,right,left,bottom const custom = Taro.getMenuButtonBoundingClientRect(); // 导航栏高度(标题栏高度) = 胶囊高度 + (顶部距离 - 状态栏高度) * 2 const navigationBarHeight = custom.height + (custom.top - statusBarHeight) * 2; this.setState({ statusBarHeight, navigationBarHeight, }); }, }); } render() { let { current, array, name, recordList, ViewAddInstrument, bindingInstrumentList, clockShow, curIndex, clockStatistics, statistics, year, today, monthTime, show, punchInInfo, navigationBarHeight, statusBarHeight, } = this.state; const statusBarHeightRpx = statusBarHeight * 2; const navigationBarHeightRpx = navigationBarHeight * 2; const height = statusBarHeightRpx + navigationBarHeightRpx; return ( 护理历程 打卡统计 {current === 0 && ( 全部 {bindingInstrumentList.map((item: any, index: any) => ( {item.name} ))} )} {current === 0 && recordList.length === 0 && ( 暂无数据 )} {current === 0 && ( {/* 2024.1.23 在线 回看报告 小子弹智能射频仪 模式:基础场景版 护理时间:15分00秒 */} {recordList.map((item: any, index: any) => ( {item.createTime} {item.online === 1 ? "在线" : "离线"} {item.instrumentType === 2 && ( 回看报告 )} {item.instrumentName} 模式:{item.modeName} {item.instrumentType === 2 && ( 护理时间:{item.nursingTime} )} ))} )} {current === 1 && ( {/* 暂无数据 */} 年度打卡统计 {year}年 {monthTime.map((item) => ( {item.time > 0 && ( {item.time}天 )} {item.month} ))} {clockStatistics.map((item) => ( {item.year}年{item.month}月 {" "} {!item.isMore ? "展开更多" : "收起更多"} {item.clockNum} 本月打卡天数 {(item.percentage * 100).toFixed(2)}% 超越花至用户 {item.isMore && item.detail && ( {item.detail.map((obj) => ( {obj.updateTime} {obj.clockImg.map((img) => ( ))} {/* 小紫弹智能射频仪、花至抗老射频仪PRO{" "} */} {obj.instrumentName === null ? "" : obj.instrumentName} {obj.clockContent} ))} )} ))} )} {!clockShow && ViewAddInstrument === "true" && ( 前往打卡 {/* 跳过 > */} )} this.setState({ show: false })}> 今日打卡 本月您已打卡 {clockStatistics[0]?.clockNum}{" "} 天,超越 {(clockStatistics[0]?.percentage * 100).toFixed(1)}% 花至用户 {punchInInfo.clockImageList.map((item, index) => ( ))} {punchInInfo.clockImageList.length < 3 && ( )} {"(" + (punchInInfo.clockContent.length || 0) + "/120)"} 确认提交 ); } }