import React, { useState } from "react";
import { history } from "umi";
import { Tabs } from "antd-mobile";
import commonConfig from "@/utils/config";
import * as commonServices from "@/services/services";
import * as commonFunc from "@/components/Common/commonFunc";
import { useEffect } from "react";
import styles from "./quotationDetail.less";
import SelectInput from "../components/SelectInput";
const QuotationAllprogressDetail = props => {
  // const {state} = props.location

  // console.log(JSON.parse(state), "QuotationAllprogressDetail");
  console.log(props, "QuotationAllprogressDetail props");

  return (
    <div className={styles.quotationDetailBox}>
      <QuotationDetail {...props} />
    </div>
  );
};

const QuotationDetail = props => {
  const { location, app } = props;
  const { token } = app;
  const [state, setState] = useState(null);

  // 初始化状态
  const { formData = [] } = state || {};
  const { quotationData } = JSON.parse(location.state) || {};
  const [masterConfig, setMasterConfig] = useState(null);
  useEffect(() => {
    // 安全地解析 state
    let parsedState = {};
    try {
      parsedState = JSON.parse(location.state || "{}");
    } catch (error) {
      console.error("Error parsing state:", error);
    }
    const { sModelsId } = parsedState;
    // 构造请求 URL
    const configUrl = `${commonConfig.server_host}business/getModelBysId/${"172129113112117428019179600"}?sModelsId=${"172129113112117428019179600"}`;
    // 调用服务获取数据
    commonServices
      .getService(token, configUrl)
      .then(({ data: configReturn }) => {
        if (configReturn.code === 1) {
          const formData = configReturn.dataset.rows[0]?.formData;
          setMasterConfig(formData[0]);
          setState(pre => ({ ...pre, formData }));
        }
      })
      .catch(error => {
        console.error("Error fetching data:", error);
      });
  }, [location, app]);

  // 主表
  const list = masterConfig?.gdsconfigformslave.filter(item => item.sName && item.bVisible);
  console.log("🚀 ~ list:", list);
  // 客户
  const customer = list?.find(x => x.showName === "客户名称") || {};
  // console.log("🚀 ~ ableConfigs:", masterConfig);
  console.log("🚀 ~ customer:", customer);
  return (
    <div>
      <div>{quotationData?.showName || "Loading..."}</div>
      {/* {list&& list.length
        ? list.map((item, index) => {
            return (
              <div key={index} className={styles.customer}>
                <div className={styles.quotationDetailTitle}>{item.showName}</div>
                <SelectInput {...props} detailData={item}/>
              </div>
            );
          })
        : ""} */}
      <div className={styles.customer}>
        <div>客户名称</div>
        <SelectInput {...props} />
      </div>
    </div>
  );
};

export default QuotationAllprogressDetail;
