import { computed, shallowRef } from "vue";
import { FormConfig } from "/@/components/PageSearch";

interface IQueryOptions {
  sourceConfig: FormConfig;
  queryField?: string;
}

export function useSupplierQuery(options: IQueryOptions) {
  const { sourceConfig, queryField = "relaComNo" } = options;
  const searchConfig = JSON.parse(JSON.stringify(sourceConfig));

  const companyNo = shallowRef("");
  const isHasCompany = computed(() => companyNo.value === "");

  searchConfig.formItems = [
    ...searchConfig.formItems,
    {
      noRest: true,
      trigger: "change",
      field: queryField,
      placeholder: "供应商",
      type: "supplier-permission",
      onChange: (value: string) => (companyNo.value = value)
    }
  ];

  return {
    searchConfig,
    isHasCompany,
    companyNo
  };
}
