Files
陈誉午 994b267f5c feat: 电子药箱小程序 - 4Tab药品管理
- 电子药箱: 药品库存管理 + 手动录入 + 今日用药打卡
- 药品百科: 搜索 + 分类筛选 + 20种药品静态数据
- 惠教中心: 4条药品使用指南课程
- 我的: 家庭成员信息管理
- 自定义TabBar + navigation-bar组件
- SVG药品分类插图
2026-07-29 11:20:52 +08:00

161 lines
6.5 KiB
TypeScript

// @ts-nocheck
import { request } from '../../../utils/request'
import { locationItemType } from './location-item'
Component({
properties: {
item: {} as locationItemType,
selectLocation: {
type: Boolean,
value: true
}
},
data: {
locationStr: ''
},
observers: {
'item.location': function (location: string[]) {
if (location && Array.isArray(location)) {
this.setData({
locationStr: location.join(' ')
})
}
},
},
methods: {
handleEdit() {
console.log("this.data.item", this.data.item)
this.triggerEvent('edit', { item: this.data.item })
},
handleDelete() {
wx.showModal({
title: '地址设置',
content: '要将此收货地址删除吗?',
success: async (res) => {
if (res.confirm) {
wx.showLoading({ title: "加载中" })
try {
await request({
options: {
url: "/app/member-address/remove",
data: {
// mbuId: Number(wx.getStorageSync("mbuId")),
id: this.data.item.id
}
}
}).then(() => {
wx.showToast({ title: "删除成功" })
if (this.data.item.defaultStatus) {
wx.removeStorageSync("addressId");
wx.removeStorageSync("defualtAddress");
}
this.triggerEvent("refresh")
})
} catch {
}
}
}
})
},
handleSelect() {
// console.log(this.data.item)
if (this.data.selectLocation) {
wx.showModal({
title: '地址设置',
content: '要选择此收货地址吗?',
success: (res) => {
if (res.confirm) {
this.triggerEvent("select", {
id: this.data.item.id,
item: this.data.item
});
}
},
// success: async (res) => {
// if (res.confirm) {
// const value: any = {
// location: this.data.item.location,
// address: this.data.item.address,
// mobile: this.data.item.mobile,
// name: this.data.item.name,
// id: this.data.item.id,
// defaultStatus: 1,
// mbuId: wx.getStorageSync('mbuId')
// }
// try {
// await request<any[]>({
// options: {
// url: "/app/member-address/editor",
// data: value
// }, loadingTitle: "保存中"
// })
// .then(() => {
// // wx.showToast({ title: "设置地址成功!", duration: 1000 })
// wx.setStorage({ key: "addressId", data: this.data.item.id })
// if (this.data.item.location) wx.setStorage({ key: "defualtAddress", data: `${this.data.item.location.join("")}${this.data.item.address}` })
// this.triggerEvent("refresh")
// }).then(() => {
// wx.navigateBack()
// })
// } catch (e) {
// console.log(e, '出现错误')
// }
// } else if (res.cancel) {
// console.log('用户点击了取消')
// }
// },
fail: (e) => {
console.log(e, '错误')
}
})
}
},
stopTap() { },//阻止点击穿透
handleSwitch(e) {
const checked = e.detail;
if (!checked) {
wx.showToast({ title: "不能取消默认地址,请切换到其他默认地址~", icon: "none" });
return;
}
wx.showModal({
title: '地址设置',
content: '要将此地址设置为默认收货地址吗?',
success: async (res) => {
if (res.confirm) {
const value = {
location: this.data.item.location,
address: this.data.item.address,
mobile: this.data.item.mobile,
name: this.data.item.name,
id: this.data.item.id,
defaultStatus: 1,
mbuId: wx.getStorageSync('mbuId')
};
await request({
options: {
url: "/app/member-address/editor",
data: value
},
loadingTitle: "保存中"
});
wx.setStorageSync("addressId", this.data.item.id);
if (this.data.item.location) {
wx.setStorageSync(
"defualtAddress",
`${this.data.item.location.join("")}${this.data.item.address}`
);
}
this.triggerEvent("refresh");
}
}
});
},
}
})