226 lines
9.0 KiB
JavaScript
226 lines
9.0 KiB
JavaScript
"use strict";
|
|
const common_vendor = require("../../common/vendor.js");
|
|
const common_assets = require("../../common/assets.js");
|
|
const stores_price = require("../../stores/price.js");
|
|
const stores_region = require("../../stores/region.js");
|
|
const utils_price = require("../../utils/price.js");
|
|
const api_index = require("../../api/index.js");
|
|
if (!Array) {
|
|
const _easycom_uni_icons2 = common_vendor.resolveComponent("uni-icons");
|
|
_easycom_uni_icons2();
|
|
}
|
|
const _easycom_uni_icons = () => "../../node-modules/@dcloudio/uni-ui/lib/uni-icons/uni-icons.js";
|
|
if (!Math) {
|
|
_easycom_uni_icons();
|
|
}
|
|
const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
|
|
__name: "index",
|
|
setup(__props) {
|
|
const priceStore = stores_price.usePriceStore();
|
|
const regionStore = stores_region.useRegionStore();
|
|
const cities = common_vendor.ref([]);
|
|
const districts = common_vendor.ref([]);
|
|
const communities = common_vendor.ref([]);
|
|
const users = common_vendor.ref([]);
|
|
const showCityPicker = common_vendor.ref(false);
|
|
const showDistrictPicker = common_vendor.ref(false);
|
|
const showCommunityPicker = common_vendor.ref(false);
|
|
const showUserPicker = common_vendor.ref(false);
|
|
const goToPrice = () => {
|
|
common_vendor.index.navigateTo({ url: "/pages/price/price" });
|
|
};
|
|
const goToWeigh = (category) => {
|
|
common_vendor.index.navigateTo({ url: `/pages/weigh/weigh?category=${category}` });
|
|
};
|
|
const loadCities = async () => {
|
|
cities.value = await api_index.regionApi.getCities();
|
|
};
|
|
const loadDistricts = async (city) => {
|
|
const result = await api_index.regionApi.getDistricts(city);
|
|
districts.value = [...result, "其他"];
|
|
};
|
|
const loadCommunities = async (city, district) => {
|
|
const actualDistrict = district === "其他" ? "" : district;
|
|
const result = await api_index.regionApi.getStations(city, actualDistrict);
|
|
communities.value = [...result, "其他"];
|
|
};
|
|
const selectCity = async (city) => {
|
|
regionStore.setCity(city);
|
|
showCityPicker.value = false;
|
|
await loadDistricts(city);
|
|
};
|
|
const selectDistrict = async (district) => {
|
|
regionStore.setDistrict(district);
|
|
showDistrictPicker.value = false;
|
|
await loadCommunities(regionStore.selectedCity, district);
|
|
};
|
|
const loadUsers = async () => {
|
|
const stationName = regionStore.selectedCommunity;
|
|
if (stationName) {
|
|
const result = await api_index.regionApi.getSiteUsers(stationName);
|
|
if (result.length > 0) {
|
|
users.value = [...result];
|
|
} else {
|
|
users.value = ["新增商户", "新增个人"];
|
|
}
|
|
} else {
|
|
users.value = ["新增商户", "新增个人"];
|
|
}
|
|
};
|
|
const selectCommunity = async (community) => {
|
|
regionStore.setCommunity(community);
|
|
showCommunityPicker.value = false;
|
|
await loadUsers();
|
|
};
|
|
const selectUser = (user) => {
|
|
regionStore.setUser(user);
|
|
showUserPicker.value = false;
|
|
};
|
|
const onCustomDistrictInput = (e) => {
|
|
regionStore.setCustomDistrict(e.detail.value);
|
|
};
|
|
const onCustomCommunityInput = (e) => {
|
|
regionStore.setCustomCommunity(e.detail.value);
|
|
};
|
|
const onCustomUserInput = (e) => {
|
|
regionStore.setCustomUser(e.detail.value);
|
|
};
|
|
const closePickers = () => {
|
|
showCityPicker.value = false;
|
|
showDistrictPicker.value = false;
|
|
showCommunityPicker.value = false;
|
|
showUserPicker.value = false;
|
|
};
|
|
common_vendor.onMounted(async () => {
|
|
const isLoggedIn = common_vendor.index.getStorageSync("collector_login");
|
|
if (!isLoggedIn) {
|
|
common_vendor.index.redirectTo({ url: "/pages/user/login" });
|
|
return;
|
|
}
|
|
priceStore.loadPrices();
|
|
await loadCities();
|
|
if (regionStore.selectedCity) {
|
|
await loadDistricts(regionStore.selectedCity);
|
|
}
|
|
});
|
|
common_vendor.onShow(() => {
|
|
priceStore.loadPrices();
|
|
});
|
|
return (_ctx, _cache) => {
|
|
return common_vendor.e({
|
|
a: common_assets._imports_0$1,
|
|
b: common_vendor.o(goToPrice),
|
|
c: common_assets._imports_1,
|
|
d: common_vendor.t(common_vendor.unref(regionStore).selectedCity || "请选择城市"),
|
|
e: common_vendor.o(($event) => showCityPicker.value = true),
|
|
f: common_vendor.t(common_vendor.unref(regionStore).selectedDistrict || "请选择区"),
|
|
g: common_vendor.o(($event) => showDistrictPicker.value = true),
|
|
h: !common_vendor.unref(regionStore).selectedCity ? 1 : "",
|
|
i: common_vendor.unref(regionStore).selectedDistrict === "其他"
|
|
}, common_vendor.unref(regionStore).selectedDistrict === "其他" ? {
|
|
j: common_vendor.unref(regionStore).customDistrict,
|
|
k: common_vendor.o(onCustomDistrictInput)
|
|
} : {}, {
|
|
l: common_vendor.t(common_vendor.unref(regionStore).selectedCommunity || "请选择回收站点"),
|
|
m: common_vendor.o(($event) => showCommunityPicker.value = true),
|
|
n: !common_vendor.unref(regionStore).selectedDistrict ? 1 : "",
|
|
o: common_vendor.unref(regionStore).selectedCommunity === "其他"
|
|
}, common_vendor.unref(regionStore).selectedCommunity === "其他" ? {
|
|
p: common_vendor.unref(regionStore).customCommunity,
|
|
q: common_vendor.o(onCustomCommunityInput)
|
|
} : {}, {
|
|
r: common_vendor.t(common_vendor.unref(regionStore).selectedUser || "请选择用户"),
|
|
s: common_vendor.o(($event) => showUserPicker.value = true),
|
|
t: !common_vendor.unref(regionStore).selectedCommunity ? 1 : "",
|
|
v: common_vendor.unref(regionStore).selectedUser === "新增商户"
|
|
}, common_vendor.unref(regionStore).selectedUser === "新增商户" ? {
|
|
w: common_vendor.unref(regionStore).customUser,
|
|
x: common_vendor.o(onCustomUserInput)
|
|
} : {}, {
|
|
y: common_vendor.unref(regionStore).selectedUser === "新增个人"
|
|
}, common_vendor.unref(regionStore).selectedUser === "新增个人" ? {
|
|
z: common_vendor.unref(regionStore).customUser,
|
|
A: common_vendor.o(onCustomUserInput)
|
|
} : {}, {
|
|
B: common_assets._imports_2,
|
|
C: common_vendor.f(common_vendor.unref(priceStore).prices, (item, k0, i0) => {
|
|
return {
|
|
a: "83a5a03c-0-" + i0,
|
|
b: common_vendor.p({
|
|
type: common_vendor.unref(utils_price.getCategoryIcon)(item.category),
|
|
size: 64,
|
|
color: "#3366ff"
|
|
}),
|
|
c: common_vendor.t(item.name),
|
|
d: common_vendor.t(item.price),
|
|
e: common_vendor.t(item.unit === "kg" ? "kg" : "个"),
|
|
f: item.category,
|
|
g: common_vendor.o(($event) => goToWeigh(item.category), item.category)
|
|
};
|
|
}),
|
|
D: showCityPicker.value
|
|
}, showCityPicker.value ? {
|
|
E: common_vendor.o(closePickers),
|
|
F: common_vendor.f(cities.value, (city, k0, i0) => {
|
|
return {
|
|
a: common_vendor.t(city),
|
|
b: city,
|
|
c: common_vendor.unref(regionStore).selectedCity === city ? 1 : "",
|
|
d: common_vendor.o(($event) => selectCity(city), city)
|
|
};
|
|
}),
|
|
G: common_vendor.o(() => {
|
|
}),
|
|
H: common_vendor.o(closePickers)
|
|
} : {}, {
|
|
I: showDistrictPicker.value
|
|
}, showDistrictPicker.value ? {
|
|
J: common_vendor.o(closePickers),
|
|
K: common_vendor.f(districts.value, (district, k0, i0) => {
|
|
return {
|
|
a: common_vendor.t(district),
|
|
b: district,
|
|
c: common_vendor.unref(regionStore).selectedDistrict === district ? 1 : "",
|
|
d: common_vendor.o(($event) => selectDistrict(district), district)
|
|
};
|
|
}),
|
|
L: common_vendor.o(() => {
|
|
}),
|
|
M: common_vendor.o(closePickers)
|
|
} : {}, {
|
|
N: showCommunityPicker.value
|
|
}, showCommunityPicker.value ? {
|
|
O: common_vendor.o(closePickers),
|
|
P: common_vendor.f(communities.value, (community, k0, i0) => {
|
|
return {
|
|
a: common_vendor.t(community),
|
|
b: community,
|
|
c: common_vendor.unref(regionStore).selectedCommunity === community ? 1 : "",
|
|
d: common_vendor.o(($event) => selectCommunity(community), community)
|
|
};
|
|
}),
|
|
Q: common_vendor.o(() => {
|
|
}),
|
|
R: common_vendor.o(closePickers)
|
|
} : {}, {
|
|
S: showUserPicker.value
|
|
}, showUserPicker.value ? {
|
|
T: common_vendor.o(closePickers),
|
|
U: common_vendor.f(users.value, (user, k0, i0) => {
|
|
return {
|
|
a: common_vendor.t(user),
|
|
b: user,
|
|
c: common_vendor.unref(regionStore).selectedUser === user ? 1 : "",
|
|
d: common_vendor.o(($event) => selectUser(user), user)
|
|
};
|
|
}),
|
|
V: common_vendor.o(() => {
|
|
}),
|
|
W: common_vendor.o(closePickers)
|
|
} : {});
|
|
};
|
|
}
|
|
});
|
|
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-83a5a03c"]]);
|
|
wx.createPage(MiniProgramPage);
|