import { api_getUserReceiveAddressPage, api_userReceiveAddressRemove } from "../../api/login"; Page({ data: { id: "", //当前选中的id popupShow: false, selectedId: "", addressList: [], addAddressPopupShow: false, editId: "" }, onShow() { this.getPageList() }, onLoad(options: any) { const { id } = options; this.setData({ id }) }, async getPageList() { try { const resData = await api_getUserReceiveAddressPage() const pageRows = resData?.data?.data?.rows || [] this.setData({ addressList: pageRows }) } catch (e) { console.log(e, 'e') } }, onDialogClose() { this.setData({ popupShow: false }) }, async onDialogOk() { try { const { data } = await api_userReceiveAddressRemove(this.data.selectedId) if (data.code === 200) { this.setData({ popupShow: false }) await this.getPageList() // 当删的是当前选中的 if (this.data.selectedId === this.data.id) { let item: any if (this.data.addressList.length) { item = this.data.addressList[0] this.setData({ id: item.id }) } this.setPagesData(item) } } } catch (e: any) { } }, onDel(e: any) { const { dataset } = e.currentTarget this.setData({ selectedId: dataset.id }) this.setData({ popupShow: true }) }, onEdit(e: any) { const { dataset } = e.currentTarget this.setData({ editId: dataset.id, addAddressPopupShow: true }) }, onAdd() { this.setData({ editId: "", addAddressPopupShow: true }) }, onSelect(e: any) { const { dataset } = e.currentTarget const item = dataset.item; this.setPagesData(item) wx.navigateBack() }, async onAddAddress() { // 编辑 if (this.data.editId) { await this.getPageList() if (this.data.editId === this.data.id) { // 编辑 完了之后刷新上一页的数据 const item = this.data.addressList.find(((item: any) => { return item.id === this.data.id })) this.setPagesData(item) } } else { // 新增 this.getPageList() } }, setPagesData(item: any) { console.log(item,233339999) const pages = getCurrentPages(); const prevPage = pages[pages.length - 2]; // 获取上一个页面实例 prevPage.setData({ addressInfo: item ? { id: item.id, name: item.name, phoneNumber: item.phoneNumber, addressDes: item.provinceName + item.cityName + (item.regionName || "") + item.detailAddress } : {} }); } })