import classnames from "classnames"; import { Component, PropsWithChildren, useEffect, useState } from "react"; // import { InstrumentInfo } from "../../utils/Interface"; import Taro from "@tarojs/taro"; // 引入 Swiper, SwiperItem 组件 import { Block, View, Text, Image, Input, // Button, Video, ScrollView, Canvas, } from "@tarojs/components"; import { InstrumentInfo } from "../../utils/Interface"; import { go, back, loading, msg, showModal } from "../../utils/traoAPI"; import { isVideo } from "../../utils/util"; import utilHtml from "../../utils/utilhtml"; import { getImgInfo, contraction } from "../../utils/compressImage"; /* 自定义组件 */ import Navbar from "../../components/navbar/navbar"; import PopupAlert from "../../components/popup/popup-alert"; /* 组件 */ import "./instrument.less"; export default class Instrument extends Component { constructor(props) { super(props); this.state = { name: "instrument", isBindingError: false, isBindingCheckError: false, style: "font-size: 28rpx; color: #ccc;", succeedShow: false, tipShow: false, loading: true, channelList: [], channelInfo: { id: "", image: "", serial: "", bind_intro_Video: "", }, equipmentList: [ { id: 1, banner: "", titile: "测试", }, ], isVideo: false, inputType: 1, //1.手写 2.扫码绑定 bindCode: "", bindCodeInfo: null, bindPopup: "", userinfo: null, showLoginPopup: "", fromUrl: "", }; } async onLoad() { this.unbindingInstrumentInfoList(); } componentDidMount() {} componentWillUnmount() {} componentDidShow() {} componentDidHide() {} async initData() {} onSerial = (event) => { const { value } = event.detail; let { channelInfo } = this.state; channelInfo.serial = value; this.setState({ channelInfo }); }; onScanCode() { Taro.scanCode({ scanType: ["qrCode"], success: (res) => { let { channelInfo } = this.state; channelInfo.serial = res.result; this.setState({ channelInfo }); }, }); } onTipShow = () => { this.setState({ tipShow: true }); }; onTabTap = (type) => { this.setState({ inputType: type, }); }; onScanTap = () => { /* // 本地测试 const result = decodeURIComponent('https%3A%2F%2Fi.flossom.com%2Fa%3Ffr200test12'); const bindCode = result.split('?')[1]; that.setData({ bindCode }) that.getBindCodeInfo(); return*/ Taro.scanCode({ scanType: ["barCode", "qrCode"], success: (res) => { const result = decodeURIComponent(res.result); if (result.indexOf("?") > -1) { const bindCode = result.split("?")[1]; console.log("bindCode", bindCode); this.setState({ bindCode, }); } this.bindingInstrument(); // this.getBindCodeInfo(); }, fail(err) {}, complete(res) {}, }); }; // getBindCodeInfo = async () => { // const { bindCode, instrumentList, channelInfo } = this.state; // // // 1.查询资料 // // try { // // const { data } = await InstrumentCodeCheck({ // // code: bindCode, // // }); // // const bindCodeInfo = { ...data.data.bindCodeInfo }; // // // 2.判断是否是选中的仪器, 如果不是, 直接弹出scanErrorPopup // // if (channelInfo.id != bindCodeInfo.instrument_id) { // // this.setState({ // // bindPopup: "scanErrorPopup", // // }); // // return; // // } // // const match = instrumentList.find((item) => { // // if (item.id == bindCodeInfo.instrument_id && item.serial) { // // // 找到同一个仪器 // // bindCodeInfo.hadBindSame = true; // // if (item.serial == bindCodeInfo.antifakeCode) { // // // 找到同一个序列号 // // bindCodeInfo.hadBindSameCode = true; // // } else { // // bindCodeInfo.hadBindSameCode = false; // // } // // return item; // // } // // if (item.id == bindCodeInfo.instrument_id) { // // const { channelInfo } = this.state; // // if (channelInfo.id === item.id) return; // // this.setState({ // // channelInfo: item, // // isVideo: isVideo(item.bind_intro_video), // // }); // // } // // }); // // if (match) { // // bindCodeInfo.hadBind = true; // // } else { // // bindCodeInfo.hadBindSame = false; // // } // // this.setState({ // // bindCodeInfo, // // }); // // this.judgeBindCode(); // // } catch (e) { // // this.judgeBindCode(); // // } // }; // judgeBindCode = () => { // const { bindCode, bindCodeInfo } = this.state; // const opts: any = {}; // if (bindCode && !bindCodeInfo) { // // 有仪器码, 但是没有找到信息时 // opts.bindPopup = "noFoundPopup"; // } else if (bindCode && bindCodeInfo && bindCodeInfo.isLabelCode) { // opts.bindPopup = "labelPopup"; // } else if ( // bindCode && // bindCodeInfo.hadBindSame && // bindCodeInfo.hadBindSameCode // ) { // // 有仪器码, 如果有登录, 判断是绑定了同样的仪器和仪器的序列号是一致 -- 不弹弹窗, 回到首页 // opts.bindCode = ""; // 重置bindCode // opts.bindPopup = ""; // 隐藏bindPopup // } else if ( // bindCode && // bindCodeInfo.hadBindSame && // !bindCodeInfo.hadBindSameCode // ) { // // 有仪器码, 如果有登录, 判断是绑定了同样的仪器, 但仪器的序列号不一致 -- 判断换绑 // opts.bindPopup = "switchBindCodePopup"; // } else if (bindCode && !bindCodeInfo.hadBindSame) { // // 有仪器码, 如果有登录, 判断不是绑定了同样的仪器 -- 绑定 // opts.bindPopup = "toBindPopup"; // } // if (Object.keys(opts).length) { // this.setState(opts); // } // }; onCustomerTap = () => { this.onCancelBind2Tap(); go("/pages/consultant/consultant"); }; onCancelBind2Tap = () => { this.setState({ bindPopup: "", bindCode: "", }); }; onChangeImg = async () => { Taro.chooseMedia({ count: 1, mediaType: ["image"], success: async (res) => { const tempFilePath = res.tempFiles[0].tempFilePath; let img = await getImgInfo(tempFilePath); let compressImage = await contraction(img, "compressImage"); // 压缩后文件地址 let compressTempFilePath = compressImage.tempFilePath; let { channelInfo } = this.state; channelInfo.image = compressTempFilePath; this.setState({ channelInfo }); }, }); }; onSubmit = () => { const that = this; const { serial, image, buy_id, id } = this.state.channelInfo; if (!serial?.trim()) return msg("请输入设备序列号"); if (!image) return msg("请上传序列号照片"); // if (!buy_id) return msg('请选择购买渠道'); // loading("绑定中"); // InstrumentBindingAdd({ serial, image, buy_id, instrument_id: id }) // .then((res) => { // this.setState({ succeedShow: true }); // }) // .catch((err) => { // if (err.data.code != 400) { // that.setState({ // errorMsg: err.data.msg, // bindPopup: "errorMsg", // }); // } // }); }; onSelectChange(item) { const { channelInfo } = this.state; if (channelInfo.id === item.id) return; this.setState({ channelInfo: item, isVideo: isVideo(item.bind_intro_video), }); } public back = () => { back(); }; closeDev = () => { // go("/pages/user/user"); let isInstrumentJump = Taro.getStorageSync("isInstrumentJump"); if (isInstrumentJump === "true") { Taro.reLaunch({ url: "/pages/user/user", }); } }; // 未绑定列表 unbindingInstrumentInfoList = async () => { let { data } = await InstrumentInfo.unbindingInstrumentInfoList(); if (data.code === 200) { console.log("data", data); if (data.data.length) { this.setState({ equipmentList: data.data, channelInfo: data.data[0] }); } } }; // 绑定仪器 bindingInstrument = async () => { Taro.showLoading({ title: "请求中...", mask: true, }); let { instrumentInfo } = this.state; let { data } = await InstrumentInfo.binding({ serial: instrumentInfo.serial, }); console.log("bindingInstrument", data); Taro.hideLoading(); if (data.code === 200) { // this.setState({ isVisibleBinding: false }); msg("绑定成功"); } else { this.setState({ isBindingError: true }); } }; onBindErrorClose = () => { this.setState({ isBindingError: false }); }; onBindErrorConfirm = () => { this.onBindErrorClose(); go("/pages/consultant/consultant"); }; onBindCheckErrorClose = () => { this.setState({ isBindingCheckError: false }); }; render() { let { isBindingError, isBindingCheckError, isVideo, channelInfo, inputType, style, equipmentList, } = this.state; return ( 仪器绑定 请参考图片指引,扫描或输入产品序列号 完成花至美容仪绑定 {isVideo && channelInfo.bind_intro_Video ? ( 需要绑定的仪器 {equipmentList.map((item, index) => { return ( {item.name} ); })} 手写输入绑定 扫码绑定 {inputType == 1 && ( 填写序列号 查看序列号位置 上传序列号照片 {channelInfo.image && ( )} {!channelInfo.image && ( )} )} {inputType == 1 && ( 确认绑定 )} {inputType == 2 && ( 扫码绑定 )} ); } }