he wei
5 天以前 3c3576d5792bfabcef84979757ee344712e71cd3
src/hooks/useStationList.js
@@ -6,6 +6,7 @@
  getCountryByUid,
  getStationByUid,
  getPowerByUid,
  getBattByUid,
} from '@/api/station.js';
@@ -14,18 +15,29 @@
  const city = ref("");
  const country = ref("");
  const stationName = ref("");
  const stationId = ref("");
  const powerId = ref("");
  const lockName = ref("");
  const battId = ref("");
  const proviceList = ref([]);
  const cityList = ref([]);
  const countryList = ref([]);
  const stationList = ref([]);
  const powerList = ref([]);
  const battList = ref([]);
  onMounted(() => {
    getProviceList();
    getStationList();
    getPowerList();
  const isManual = ref(false);
  let loadPromise = null;
  onMounted(async () => {
    loadPromise = new Promise(async (resolve, reject) => {
      await getProviceList();
      await getStationList();
      await getPowerList();
      await getBattList();
      resolve();
    });
  });
  watch(
@@ -39,8 +51,9 @@
        city.value = "";
      }
      powerId.value = "";
      lockName.value = "";
      battId.value = "";
      getPowerList();
      getBattList();
    }
  );
@@ -55,8 +68,9 @@
        country.value = "";
      }
      powerId.value = "";
      lockName.value = "";
      battId.value = "";
      getPowerList();
      getBattList();
    }
  );
@@ -71,24 +85,31 @@
        stationName.value = "";
      }
      powerId.value = "";
      lockName.value = "";
      battId.value = "";
      getPowerList();
      getBattList();
    }
  );
  watch(
    () => stationName.value,
    (val) => {
      if (val) {
        powerId.value = "";
        getPowerList();
      } else {
        powerList.value = [];
        powerId.value = "";
    async (val) => {
      // if (val) {
      //   powerId.value = "";
      // } else {
      //   powerList.value = [];
      //   powerId.value = "";
      // }
      let station = stationList.value.find(v => v.stationName == val);
      if (station) {
        stationId.value = station.stationId;
      }
      powerId.value = "";
      lockName.value = "";
      getPowerList();
      if (!isManual.value) {
        powerId.value = "";
        battId.value = "";
        await getPowerList();
        await getBattList();
      }
    }
  );
@@ -113,6 +134,7 @@
      }
      cityList.value = _list;
      // city.value = "";
      return _list;
    });
  }
@@ -125,6 +147,7 @@
      }
      countryList.value = _list;
      // country.value = "";
      return _list;
    });
  }
@@ -142,6 +165,7 @@
      }
      stationList.value = _list;
      // stationName.value = "";
      return _list;
    });
  }
@@ -160,8 +184,31 @@
      }
      powerList.value = _list;
      // powerId.value = "";
      return _list;
    });
  }
  return { provice, city, country, stationName, powerId, proviceList, cityList, countryList, stationList, powerList, getProviceList, getCityList, getCountryList, getStationList, getPowerList };
  function getBattList() {
    let params = {
      provice: provice.value || undefined,
      city: city.value || undefined,
      country: country.value || undefined,
      stationName: stationName.value || undefined,
    };
    return getBattByUid(params).then((res) => {
      let { code, data, data2 } = res;
      let _list = [];
      if (code && data) {
        _list = data2;
      }
      battList.value = _list;
      // powerId.value = "";
      isManual.value = false;
      return _list;
    });
  }
  return { provice, city, country, stationName, stationId, powerId, battId, proviceList, cityList, countryList, stationList, powerList, battList, getProviceList, getCityList, getCountryList, getStationList, getPowerList, getBattList, isManual,
    whenLoaded: () => loadPromise,
  };
};