'use strict';

var vue = require('vue');
var pinia = require('pinia');
require('../../../api/shopAdmin/index.js');
var core = require('@vueuse/core');
var getPlatformLine = require('../../../api/shopAdmin/store/getPlatformLine.js');

const usePlatformLineListStore = pinia.defineStore("gmPlatformLineList", () => {
  const platformLineList = vue.ref([]);
  const cascaderList = vue.ref([]);
  const isLoading = vue.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 getPlatformLine.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;
    }
  };
  core.tryOnMounted(() => {
    getPlatformLineList();
  });
  return {
    platformLineList,
    /**
     * 获取平台线路级联列表
     */
    cascaderList,
    isLoading,
    getPlatformLineList
  };
});

exports.usePlatformLineListStore = usePlatformLineListStore;
//# sourceMappingURL=index.js.map
