爱简收旧衣按件回收前端代码仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

412 lines
14 KiB

"use strict";
const common_vendor = require("../../common/vendor.js");
const pages_subcomponent_regionData = require("./region-data.js");
const pages_mixins_pullRefreshMixin = require("../mixins/pullRefreshMixin.js");
const _sfc_main = {
mixins: [pages_mixins_pullRefreshMixin.pullRefreshMixin],
data() {
return {
statusBarHeight: 0,
addressList: [
{
name: "郑文锦",
phone: "18108341643",
address: "海南省海口市秀英区秀英街道5单元183室",
defaultFlag: "Y"
},
{
name: "周俊",
phone: "13293992217",
address: "贵州省遵义市道真仡佬族苗族自治县洛龙镇5幢172室",
defaultFlag: "N"
},
{
name: "何炜",
phone: "18108341643",
address: "新疆维吾尔自治区乌鲁木齐市沙依巴克区仓房沟片区街道4单元50室",
defaultFlag: "N"
},
{
name: "赵晓艳",
phone: "15022123314",
address: "海南省海口市秀英区秀英街道5单元183室",
defaultFlag: "N"
},
{
name: "冯云",
phone: "15731435825",
address: "甘肃省兰州市城关区滑源路街道13幢199室",
defaultFlag: "N"
},
{
name: "钱皓皓",
phone: "18734717201",
address: "西藏自治区拉萨市堆龙德庆县东嘎镇7单元94室",
defaultFlag: "N"
}
],
batchMode: false,
selectedIndexes: [],
showAddressModal: false,
showRegionPicker: false,
form: {
name: "",
phone: "",
region: [],
address: "",
addressDetails: ""
},
provinces: pages_subcomponent_regionData.regionData,
cities: [],
districts: [],
regionIndex: [0, 0, 0],
mode: ""
};
},
watch: {
regionIndex: {
handler(val) {
var _a, _b, _c, _d;
let pIdx = val[0] < this.provinces.length ? val[0] : 0;
let cIdx = val[1] < (((_b = (_a = this.provinces[pIdx]) == null ? void 0 : _a.children) == null ? void 0 : _b.length) || 0) ? val[1] : 0;
this.cities = ((_c = this.provinces[pIdx]) == null ? void 0 : _c.children) || [];
this.districts = ((_d = this.cities[cIdx]) == null ? void 0 : _d.children) || [];
},
immediate: true
}
},
onPullDownRefresh() {
this.getAddressList(() => {
common_vendor.index.stopPullDownRefresh();
});
},
onLoad(options) {
var _a, _b;
this.statusBarHeight = common_vendor.index.getSystemInfoSync().statusBarHeight;
this.cities = ((_a = this.provinces[0]) == null ? void 0 : _a.children) || [];
this.districts = ((_b = this.cities[0]) == null ? void 0 : _b.children) || [];
this.regionIndex = [0, 0, 0];
this.getAddressList();
this.mode = options.mode || "";
},
methods: {
async onRefresh() {
await new Promise((resolve) => setTimeout(resolve, 1e3));
common_vendor.index.stopPullRefresh();
},
getAddressList(callback) {
this.$api("getAddressList", {}, (res) => {
if (res && res.result && res.result.records) {
this.addressList = res.result.records;
}
if (typeof callback === "function")
callback();
});
},
goBack() {
common_vendor.index.navigateBack();
},
startBatchDelete() {
this.batchMode = true;
this.selectedIndexes = [];
},
cancelBatchDelete() {
this.batchMode = false;
this.selectedIndexes = [];
},
selectItem(index) {
if (!this.batchMode)
return;
const idx = this.selectedIndexes.indexOf(index);
if (idx > -1) {
this.selectedIndexes.splice(idx, 1);
} else {
this.selectedIndexes.push(index);
}
},
confirmDelete() {
if (this.selectedIndexes.length === 0)
return;
common_vendor.index.showModal({
title: "提示",
content: "确定要删除选中的地址吗?",
success: (res) => {
if (res.confirm) {
this.selectedIndexes.sort((a, b) => b - a).forEach((index) => {
this.addressList.splice(index, 1);
});
this.batchMode = false;
this.selectedIndexes = [];
}
}
});
},
editAddress(item) {
var _a, _b;
this.showAddressModal = true;
this.form = {
id: item.id,
name: item.name,
phone: item.phone,
region: [],
address: item.address,
addressDetails: item.addressDetails,
defaultFlag: item.defaultFlag
};
this.regionIndex = [0, 0, 0];
this.cities = ((_a = this.provinces[0]) == null ? void 0 : _a.children) || [];
this.districts = ((_b = this.cities[0]) == null ? void 0 : _b.children) || [];
},
goToAddAddress() {
var _a, _b;
this.showAddressModal = true;
this.form = {
id: void 0,
name: "",
phone: "",
region: [],
address: "",
addressDetails: ""
};
this.regionIndex = [0, 0, 0];
this.cities = ((_a = this.provinces[0]) == null ? void 0 : _a.children) || [];
this.districts = ((_b = this.cities[0]) == null ? void 0 : _b.children) || [];
},
selectAddress(address) {
if (this.mode === "select") {
common_vendor.index.$emit("addressSelected", {
id: address.id,
name: address.name,
phone: address.phone,
address: address.address,
addressDetails: address.addressDetails
});
common_vendor.index.navigateBack();
}
},
closeAddressModal() {
this.showAddressModal = false;
},
saveAddress() {
if (!this.form.name)
return common_vendor.index.showToast({ title: "请输入联系人", icon: "none" });
if (!this.form.phone)
return common_vendor.index.showToast({ title: "请输入手机号", icon: "none" });
if (!this.form.address)
return common_vendor.index.showToast({ title: "请选择地区", icon: "none" });
if (!this.form.addressDetails)
return common_vendor.index.showToast({ title: "请输入详细地址", icon: "none" });
const params = {
name: this.form.name,
phone: this.form.phone,
address: this.form.address,
addressDetails: this.form.addressDetails,
defaultFlag: this.form.defaultFlag
};
if (this.form.id)
params.id = this.form.id;
this.$api("saveOrUpdateAddress", params, (res) => {
if (res.code == 200) {
common_vendor.index.showToast({ title: "保存成功", icon: "success" });
this.closeAddressModal();
this.getAddressList();
}
});
},
onRegionChange(e) {
let [pIdx, cIdx, dIdx] = e.detail.value;
if (pIdx !== this.regionIndex[0]) {
cIdx = 0;
dIdx = 0;
} else if (cIdx !== this.regionIndex[1]) {
dIdx = 0;
}
this.regionIndex = [pIdx, cIdx, dIdx];
},
confirmRegion() {
const province = this.provinces[this.regionIndex[0]];
const city = this.cities[this.regionIndex[1]];
const district = this.districts[this.regionIndex[2]];
this.form.region = [
(province == null ? void 0 : province.code) || "",
(city == null ? void 0 : city.code) || "",
(district == null ? void 0 : district.code) || ""
];
this.form.address = [
(province == null ? void 0 : province.name) || "",
(city == null ? void 0 : city.name) || "",
(district == null ? void 0 : district.name) || ""
].filter(Boolean).join(" ");
this.showRegionPicker = false;
},
setDefault(id) {
const address = this.addressList.find((item) => item.id === id);
const defaultFlag = address.defaultFlag === "Y" ? "N" : "Y";
this.$api("updateDefaultAddress", {
id
}, (res) => {
if (res.code == 200) {
common_vendor.index.showToast({
title: defaultFlag === "Y" ? "设置成功" : "已取消默认",
icon: "success"
});
this.getAddressList();
}
});
},
deleteAddress(id) {
common_vendor.index.showModal({
title: "提示",
content: "确定要删除该地址吗?",
success: (res) => {
if (res.confirm) {
this.$api("deleteAddress", { id }, (res2) => {
if (res2.code == 200) {
common_vendor.index.showToast({
title: "删除成功",
icon: "success"
});
this.getAddressList();
}
});
}
}
});
},
initRegionPicker() {
var _a, _b;
if (this.form.region.length > 0) {
const [provinceCode, cityCode, districtCode] = this.form.region;
const provinceIndex = this.provinces.findIndex((p) => p.code === provinceCode);
if (provinceIndex > -1) {
this.cities = this.provinces[provinceIndex].children || [];
if (this.cities.length === 0) {
this.cities = [{ code: "", name: "请选择" }];
}
const cityIndex = this.cities.findIndex((c) => c.code === cityCode);
if (cityIndex > -1) {
this.districts = this.cities[cityIndex].children || [];
if (this.districts.length === 0) {
this.districts = [{ code: "", name: "请选择" }];
}
const districtIndex = this.districts.findIndex((d) => d.code === districtCode);
this.regionIndex = [
provinceIndex,
cityIndex,
districtIndex > -1 ? districtIndex : 0
];
return;
}
}
}
this.cities = ((_a = this.provinces[0]) == null ? void 0 : _a.children) || [];
if (this.cities.length === 0) {
this.cities = [{ code: "", name: "请选择" }];
}
this.districts = ((_b = this.cities[0]) == null ? void 0 : _b.children) || [];
if (this.districts.length === 0) {
this.districts = [{ code: "", name: "请选择" }];
}
this.regionIndex = [0, 0, 0];
}
}
};
if (!Array) {
const _easycom_uni_icons2 = common_vendor.resolveComponent("uni-icons");
_easycom_uni_icons2();
}
const _easycom_uni_icons = () => "../../uni_modules/uni-icons/components/uni-icons/uni-icons.js";
if (!Math) {
_easycom_uni_icons();
}
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
return common_vendor.e({
a: common_vendor.p({
type: "left",
size: "20"
}),
b: common_vendor.o((...args) => $options.goBack && $options.goBack(...args)),
c: $data.statusBarHeight + 88 + "rpx",
d: $data.statusBarHeight + "px",
e: common_vendor.f($data.addressList, (item, index, i0) => {
return common_vendor.e({
a: common_vendor.t(item.name),
b: common_vendor.t(item.phone),
c: item.defaultFlag === "Y"
}, item.defaultFlag === "Y" ? {} : {}, {
d: common_vendor.t(item.address),
e: common_vendor.t(item.addressDetails),
f: item.defaultFlag === "Y"
}, item.defaultFlag === "Y" ? {} : {}, {
g: item.defaultFlag === "Y" ? 1 : "",
h: item.defaultFlag === "Y" ? 1 : "",
i: common_vendor.o(($event) => $options.setDefault(item.id), index),
j: "d2c808da-1-" + i0,
k: common_vendor.o(($event) => $options.editAddress(item), index),
l: "d2c808da-2-" + i0,
m: common_vendor.o(($event) => $options.deleteAddress(item.id), index),
n: common_vendor.o(($event) => $options.selectAddress(item), index),
o: index
});
}),
f: common_vendor.p({
type: "compose",
size: "22",
color: "#bbb"
}),
g: common_vendor.p({
type: "trash",
size: "22",
color: "#bbb"
}),
h: common_vendor.o((...args) => $options.goToAddAddress && $options.goToAddAddress(...args)),
i: $data.showAddressModal
}, $data.showAddressModal ? {
j: common_vendor.o((...args) => $options.closeAddressModal && $options.closeAddressModal(...args))
} : {}, {
k: $data.showAddressModal
}, $data.showAddressModal ? {
l: common_vendor.o((...args) => $options.closeAddressModal && $options.closeAddressModal(...args)),
m: common_vendor.t($data.form.id ? "编辑地址" : "新建地址"),
n: $data.form.name,
o: common_vendor.o(($event) => $data.form.name = $event.detail.value),
p: $data.form.phone,
q: common_vendor.o(($event) => $data.form.phone = $event.detail.value),
r: common_vendor.t($data.form.address || "选择省市区街道"),
s: !$data.form.address ? 1 : "",
t: common_vendor.o(($event) => $data.showRegionPicker = true),
v: $data.form.addressDetails,
w: common_vendor.o(($event) => $data.form.addressDetails = $event.detail.value),
x: common_vendor.o((...args) => $options.saveAddress && $options.saveAddress(...args))
} : {}, {
y: $data.showRegionPicker
}, $data.showRegionPicker ? {
z: common_vendor.o(($event) => $data.showRegionPicker = false),
A: common_vendor.f($data.provinces, (item, index, i0) => {
return {
a: common_vendor.t(item.name),
b: index
};
}),
B: common_vendor.f($data.cities, (item, index, i0) => {
return {
a: common_vendor.t(item.name),
b: index
};
}),
C: common_vendor.f($data.districts, (item, index, i0) => {
return {
a: common_vendor.t(item.name),
b: index
};
}),
D: $data.regionIndex,
E: common_vendor.o((...args) => $options.onRegionChange && $options.onRegionChange(...args)),
F: common_vendor.o((...args) => $options.confirmRegion && $options.confirmRegion(...args))
} : {}, {
G: $data.statusBarHeight + 88 + "rpx"
});
}
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-d2c808da"]]);
wx.createPage(MiniProgramPage);
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/subcomponent/select.js.map