import { ref } from 'vue';
import { defineStore } from 'pinia';
import '../../../api/shopAdmin/index.mjs';
import { tryOnMounted } from '@vueuse/core';
import { getPlatformLineApi } from '../../../api/shopAdmin/store/getPlatformLine.mjs';

const usePlatformLineListStore = defineStore("gmPlatformLineList", () => {
  const platformLineList = ref([]);
  const cascaderList = ref([]);
  const isLoading = ref(false);
  const getPlatformLineList = async (options) => {
    if (!options?.isReload && platformLineList.value.length !== 0) {
      isLoading.value = false;
      return;
    }
    if (isLoading.value) {
      return;
    }
    try {
      isLoading.value = true;
      const { data } = await getPlatformLineApi();
      isLoading.value = false;
      if (data.code !== 0) {
        return;
      }
      platformLineList.value = data.data;
      cascaderList.value = data.data.map((item) => {
        return {
          id: item.plat_id,
          name: item.platform,
          lineList: item.line_list.map((it) => {
            return {
              id: it.line_code,
              name: it.line_name
            };
          })
        };
      });
    } catch (e) {
      console.error(e);
      isLoading.value = false;
    }
  };
  tryOnMounted(() => {
    getPlatformLineList();
  });
  return {
    platformLineList,
    /**
     * 获取平台线路级联列表
     */
    cascaderList,
    isLoading,
    getPlatformLineList
  };
});

export { usePlatformLineListStore };
//# sourceMappingURL=index.mjs.map
