Files
gxtyzx-uniapp/dist/dev/mp-weixin/package/user/address.js
T

440 lines
14 KiB
JavaScript

"use strict";
const common_vendor = require("../../common/vendor.js");
const api_shop_userAddress_index = require("../../api/shop/userAddress/index.js");
require("../../utils/request.js");
const regionsData = require("../../regions-data.js");
const utils_common = require("../../utils/common.js");
const store_modules_user = require("../../store/modules/user.js");
const store_modules_car = require("../../store/modules/car.js");
const userStore = store_modules_user.useUserStore();
const carStore = store_modules_car.useCarStore();
const _sfc_main = {
data() {
return {
list: [],
statusBarHeight: 104,
isLogin: false,
form: {
name: "",
phone: ""
},
// 表单数据
formData: {},
fields: {},
logo: "",
bookingUser: {},
server: [],
order: [],
defaultData: [{
text: "默认收货地址",
value: true
}],
typeData: [
{
text: "家",
value: "家"
},
{
text: "公司",
value: "公司"
},
{
text: "学校",
value: "学校"
}
],
regions: regionsData.regions,
dataTree: [
{
text: "一年级",
value: "1-0",
children: [
{
text: "1.1班",
value: "1-1"
},
{
text: "1.2班",
value: "1-2"
}
]
},
{
text: "二年级",
value: "2-0",
children: [
{
text: "2.1班",
value: "2-1"
},
{
text: "2.2班",
value: "2-2"
}
]
},
{
text: "三年级",
value: "3-0",
disable: true
}
],
rules: {
// 对name字段进行必填验证
name: {
rules: [{
required: true,
errorMessage: "请输入收件人名称"
}]
},
phone: {
rules: [{
required: true,
format: "number",
errorMessage: "请输入正确的手机号码"
}]
},
address: {
rules: [{
required: true,
errorMessage: "请输入详情地址"
}]
},
region: {
rules: [{
required: true,
errorMessage: "请选择所在地区"
}, {
validateFunction: function(rule, value, data, callback) {
console.log("value: ", value);
if (value.length < 2) {
callback("请至少勾选两个兴趣爱好");
}
return true;
}
}]
}
}
};
},
onLoad() {
this.reload();
},
methods: {
async reload(e) {
const app = this;
const userInfo = await userStore.fetchUserInfo();
if (Object.keys(userInfo).length > 0) {
app.isLogin = true;
app.userInfo = userInfo;
} else {
app.isLogin = false;
}
api_shop_userAddress_index.pageUserAddress({
userId: userInfo.userId
}).then((res) => {
app.list = res.list;
});
},
navTo(item) {
if (!this.isLogin) {
this.$refs.login.open("bottom");
return false;
}
utils_common.openUrl(item);
},
// 弹出登录提示框
openLogin() {
if (!this.isLogin) {
this.$refs.login.open("bottom");
return false;
}
},
onType(e) {
this.formData.type = e.detail.value;
},
onIsDefault() {
this.formData.isDefault = !this.formData.isDefault;
},
// 选用该地址
onAddres(item) {
carStore.setAddress(item);
common_vendor.index.navigateBack();
},
add() {
this.formData = {};
this.$refs.addForm.open("center");
},
openEdit(item) {
this.formData = item;
this.$refs.addForm.open("center");
},
remove(item) {
const app = this;
common_vendor.index.showModal({
title: "确定要删除吗?",
success(o) {
if (o.confirm) {
common_vendor.index.showLoading({
title: "请求中."
});
api_shop_userAddress_index.removeUserAddress(item.id).then((res) => {
common_vendor.index.showToast({
title: "操作成功",
icon: "none"
});
app.$refs.addForm.close();
app.reload();
});
app.reload();
}
}
});
},
// 触发提交表单
submit() {
this.$refs.form.validate().then((res) => {
const saveOrUpdate = this.formData.id ? api_shop_userAddress_index.updateUserAddress : api_shop_userAddress_index.addUserAddress;
saveOrUpdate(this.formData).then((message) => {
common_vendor.index.showToast({
title: "保存成功",
icon: "success"
});
this.$refs.addForm.close();
this.reload();
}).catch((err) => {
console.log(err);
});
console.log("表单数据信息:", res);
}).catch((err) => {
console.log("表单错误信息:", err);
});
},
save() {
api_shop_userAddress_index.addUserAddress(this.form).then((msg) => {
common_vendor.index.showToast({
title: msg,
icon: "none"
});
this.$refs.addForm.close();
this.reload();
}).catch(() => {
common_vendor.index.showToast({
title: "请检查您的网络.",
icon: "none"
});
common_vendor.index.hideLoading();
this.$refs.addForm.close();
this.reload();
});
}
}
};
if (!Array) {
const _easycom_uv_avatar2 = common_vendor.resolveComponent("uv-avatar");
const _easycom_uni_tag2 = common_vendor.resolveComponent("uni-tag");
const _easycom_uni_icons2 = common_vendor.resolveComponent("uni-icons");
const _easycom_uv_cell2 = common_vendor.resolveComponent("uv-cell");
const _easycom_uv_cell_group2 = common_vendor.resolveComponent("uv-cell-group");
const _easycom_uni_card2 = common_vendor.resolveComponent("uni-card");
const _easycom_uv_button2 = common_vendor.resolveComponent("uv-button");
const _easycom_ws_login2 = common_vendor.resolveComponent("ws-login");
const _easycom_uv_input2 = common_vendor.resolveComponent("uv-input");
const _easycom_uni_forms_item2 = common_vendor.resolveComponent("uni-forms-item");
const _easycom_uni_data_picker2 = common_vendor.resolveComponent("uni-data-picker");
const _easycom_uni_data_checkbox2 = common_vendor.resolveComponent("uni-data-checkbox");
const _easycom_uni_forms2 = common_vendor.resolveComponent("uni-forms");
const _easycom_uni_popup2 = common_vendor.resolveComponent("uni-popup");
(_easycom_uv_avatar2 + _easycom_uni_tag2 + _easycom_uni_icons2 + _easycom_uv_cell2 + _easycom_uv_cell_group2 + _easycom_uni_card2 + _easycom_uv_button2 + _easycom_ws_login2 + _easycom_uv_input2 + _easycom_uni_forms_item2 + _easycom_uni_data_picker2 + _easycom_uni_data_checkbox2 + _easycom_uni_forms2 + _easycom_uni_popup2)();
}
const _easycom_uv_avatar = () => "../../uni_modules/uv-avatar/components/uv-avatar/uv-avatar.js";
const _easycom_uni_tag = () => "../../uni_modules/uni-tag/components/uni-tag/uni-tag.js";
const _easycom_uni_icons = () => "../../uni_modules/uni-icons/components/uni-icons/uni-icons.js";
const _easycom_uv_cell = () => "../../uni_modules/uv-cell/components/uv-cell/uv-cell.js";
const _easycom_uv_cell_group = () => "../../uni_modules/uv-cell/components/uv-cell-group/uv-cell-group.js";
const _easycom_uni_card = () => "../../uni_modules/uni-card/components/uni-card/uni-card.js";
const _easycom_uv_button = () => "../../uni_modules/uv-button/components/uv-button/uv-button.js";
const _easycom_ws_login = () => "../../uni_modules/ws-login/components/ws-login/ws-login.js";
const _easycom_uv_input = () => "../../uni_modules/uv-input/components/uv-input/uv-input.js";
const _easycom_uni_forms_item = () => "../../uni_modules/uni-forms/components/uni-forms-item/uni-forms-item.js";
const _easycom_uni_data_picker = () => "../../uni_modules/uni-data-picker/components/uni-data-picker/uni-data-picker.js";
const _easycom_uni_data_checkbox = () => "../../uni_modules/uni-data-checkbox/components/uni-data-checkbox/uni-data-checkbox.js";
const _easycom_uni_forms = () => "../../uni_modules/uni-forms/components/uni-forms/uni-forms.js";
const _easycom_uni_popup = () => "../../uni_modules/uni-popup/components/uni-popup/uni-popup.js";
if (!Math) {
(_easycom_uv_avatar + _easycom_uni_tag + _easycom_uni_icons + _easycom_uv_cell + _easycom_uv_cell_group + _easycom_uni_card + _easycom_uv_button + _easycom_ws_login + _easycom_uv_input + _easycom_uni_forms_item + _easycom_uni_data_picker + _easycom_uni_data_checkbox + _easycom_uni_forms + _easycom_uni_popup)();
}
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
return common_vendor.e({
a: common_vendor.f($data.list, (item, index, i0) => {
return common_vendor.e({
a: "c55c4c84-3-" + i0 + "," + ("c55c4c84-2-" + i0),
b: common_vendor.p({
text: item.type,
fontSize: "12",
size: "32",
randomBgColor: true
}),
c: common_vendor.t(item.name),
d: common_vendor.t(item.phone),
e: item.isDefault
}, item.isDefault ? {
f: "c55c4c84-4-" + i0 + "," + ("c55c4c84-2-" + i0),
g: common_vendor.p({
text: "默认",
size: "mini",
inverted: true,
type: "success"
})
} : {}, {
h: common_vendor.o(($event) => $options.openEdit(item), index),
i: "c55c4c84-5-" + i0 + "," + ("c55c4c84-2-" + i0),
j: "c55c4c84-2-" + i0 + ",c55c4c84-1",
k: common_vendor.p({
cellStyle: {
padding: "10px 0"
},
label: item.address
}),
l: index
});
}),
b: common_vendor.p({
type: "compose",
size: "18"
}),
c: common_vendor.p({
customStyle: {
backgroundColor: "#ffffff"
},
border: false
}),
d: common_vendor.p({
border: false,
["is-shadow"]: false,
padding: 0
}),
e: common_vendor.o($options.add),
f: common_vendor.p({
customStyle: {
background: "linear-gradient(to right, #70b915, #008e04)",
borderRadius: "30px",
color: "#ffffff"
},
text: "添加收货地址"
}),
g: common_vendor.sr("login", "c55c4c84-7"),
h: common_vendor.o($options.reload),
i: common_vendor.p({
logo: $data.logo
}),
j: common_vendor.o(($event) => $data.formData.name = $event),
k: common_vendor.p({
placeholder: "收件人姓名",
maxlength: "5",
modelValue: $data.formData.name
}),
l: common_vendor.p({
label: "收件人",
name: "name",
required: true
}),
m: common_vendor.o(($event) => $data.formData.phone = $event),
n: common_vendor.p({
placeholder: "收件人手机号码",
maxlength: "11",
modelValue: $data.formData.phone
}),
o: common_vendor.p({
label: "手机号码",
name: "phone",
required: true
}),
p: common_vendor.o(_ctx.onchange),
q: common_vendor.o(_ctx.onnodeclick),
r: common_vendor.o(_ctx.onpopupopened),
s: common_vendor.o(_ctx.onpopupclosed),
t: common_vendor.o(($event) => $data.formData.region = $event),
v: common_vendor.p({
placeholder: "省、市、区、街道",
["popup-title"]: "请选择所在地区",
localdata: $data.regions,
map: {
text: "label",
value: "value"
},
modelValue: $data.formData.region
}),
w: common_vendor.p({
label: "所在地区",
name: "region",
required: true
}),
x: common_vendor.o(($event) => $data.formData.address = $event),
y: common_vendor.p({
placeholder: "小区、写字楼、门牌号等",
modelValue: $data.formData.address
}),
z: common_vendor.p({
label: "详细地址",
name: "address",
required: true
}),
A: common_vendor.o($options.onType),
B: common_vendor.o(($event) => $data.formData.type = $event),
C: common_vendor.p({
mode: "tag",
localdata: $data.typeData,
modelValue: $data.formData.type
}),
D: common_vendor.p({
label: "标签",
name: "type"
}),
E: common_vendor.o($options.onIsDefault),
F: common_vendor.o(($event) => $data.formData.isDefault = $event),
G: common_vendor.p({
localdata: $data.defaultData,
modelValue: $data.formData.isDefault
}),
H: $data.formData.id
}, $data.formData.id ? {
I: common_vendor.p({
type: "trash"
}),
J: common_vendor.o(($event) => $options.remove($data.formData))
} : {}, {
K: common_vendor.p({
name: "isDefault"
}),
L: common_vendor.o($options.submit),
M: common_vendor.p({
customStyle: {
background: "linear-gradient(to right, #70b915, #008e04)",
borderRadius: "30px",
color: "#ffffff"
},
text: "保存"
}),
N: common_vendor.sr("form", "c55c4c84-10,c55c4c84-9"),
O: common_vendor.p({
modelValue: $data.formData,
rules: $data.rules,
["label-width"]: 80
}),
P: common_vendor.p({
title: "添加收货地址",
border: false,
["is-shadow"]: false,
padding: "10px 6px"
}),
Q: common_vendor.sr("addForm", "c55c4c84-8"),
R: common_vendor.p({
type: "center",
["border-radius"]: "10px 10px 0 0"
})
});
}
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__file", "/Users/gxwebsoft/APP/gxtyzx-uniapp-cli/src/package/user/address.vue"]]);
wx.createPage(MiniProgramPage);