import { Component, PropsWithChildren, useEffect, useState } from "react";
import Taro from "@tarojs/taro";
import { Block, View, Text, Image, Input, Button } from "@tarojs/components";

import Navbar from "../../components/navbar/navbar";

import "./consultant.less";

import { getContactWorker } from "../../utils/Interface";
import { back } from "@/utils/traoAPI";

export default class Consultant extends Component<any, any> {
  constructor(props) {
    super(props);
    this.state = {
      name: "consultant",
      pictureUrl: "",
    };
  }
  $instance = Taro.getCurrentInstance();

  async onLoad() {
    this.initData();
  }
  componentDidMount() {}

  componentWillUnmount() {}

  componentDidShow() {}

  componentDidHide() {}

  async initData() {
    let res = await getContactWorker();
    console.log("initData", res);
    if (res.data.code === 200) {
      this.setState({ pictureUrl: res.data.data.pictureUrl });
    }
  }

  customBack = () => {
    let customBack = this.$instance.router?.params?.customBack;
    if (customBack) {
      Taro.switchTab({ url: "/pages/index/index" });
      return;
    }
    back();
  };

  render() {
    const { pictureUrl } = this.state;
    return (
      <Block>
        <Navbar
          titleSlot="联系客服"
          isBack={true}
          isCustomBack
          customBack={this.customBack}
        />
        <View className="img">
          <Image
            src={pictureUrl}
            show-menu-by-longpress
            // mode="widthFix"
            mode="aspectFill"
          ></Image>
        </View>
      </Block>
    );
  }
}
