import Taro from "@tarojs/taro"; import classnames from "classnames"; import { Component, PropsWithChildren, useEffect, useState } from "react"; import { Block, View, Text, Image, Input, Button, ScrollView, Swiper, SwiperItem, } from "@tarojs/components"; import "./index.less"; import Navbar from "../../components/navbar/navbar"; import { InstrumentInfo } from "../../utils/Interface"; import { go, msg, setStorageSync } from "../../utils/traoAPI"; export default class InstrumentManage extends Component { constructor(props) { super(props); this.state = { name: "InstrumentManage", userinfo: {}, imgUrl: "", imgUrl2: "", list: [], bindList: [], unBindList: [], page: 1, isback: false, //全局参数 appdata: {}, tipshow: false, FR200LIST: [], devinfo: {}, current: 0, }; } async onLoad() { this.initData(); } componentDidMount() {} componentWillUnmount() {} componentDidShow() {} componentDidHide() {} async initData() { this.bindingInstrumentList(); this.unbindingInstrumentInfoList(); } // 获取已绑定仪器列表 bindingInstrumentList = async () => { Taro.showLoading({ title: "请求中...", mask: true, }); let { data: res } = await InstrumentInfo.bindingInstrumentList(); Taro.hideLoading(); if (res.code === 200) { this.setState({ bindList: res.data }); } else { // 仪器列表失败todo } }; // 获取未绑定仪器列表 unbindingInstrumentInfoList = async () => { Taro.showLoading({ title: "请求中...", mask: true, }); let { data: res } = await InstrumentInfo.unbindingInstrumentInfoList(); Taro.hideLoading(); if (res.code === 200) { this.setState({ unBindList: res.data }); } else { // 仪器列表失败todo } }; goIntro = (item) => { console.log("item", item); setStorageSync("instrument_detail", item); let bindid = item.id; go("/pages/instrument/intro?id=" + bindid); }; goBind = (item) => { let bindid = item.id; go("/pages/instrument/instrument?isOnly=true&id=" + bindid); // 只显示当前仪器内容 }; goBindInfo = (item) => { // let bindid = item.id; setStorageSync("instrument_detail", item); go("/pages/instrument_detail/index"); }; lesgobuy = (item) => { console.log(item); if (item.isPurchase === 1) { if (item.programs_json) { item.programs_json = JSON.parse(item.programs_json); // console.log(item.programs_json) Taro.navigateToMiniProgram({ appId: item.programs_json.buylink, path: item.programs_json.buypath, envVersion: "release", success(res) { // 打开成功 }, fail() {}, }); } else { msg("暂无购买链接"); } } else { msg("暂无购买链接"); } }; customBack = () => { Taro.switchTab({ url: "/pages/user/user" }); }; render() { let { bindList, unBindList, current } = this.state; return ( {bindList.length > 0 && ( 我的设备 {bindList.length > 0 && ( {bindList.map((item: any, index: number) => { return ( 已绑定 仪器介绍 {item.name} 查看绑定信息 ); })} )} )} {/* 当且仅当未绑定仪器存在时显示 */} {unBindList.length > 0 && ( 未绑定的仪器 {unBindList.map((item, index) => { if (item.status === 0) { return ( {item.name} {item.isPurchase === 1 && ( 立即购买 )} 前往绑定 ); } })} )} ); } }