feat: add resident miniapp MVP
This commit is contained in:
@@ -1 +1,64 @@
|
||||
Page({})
|
||||
const { listAddresses, createAddress, setDefaultAddress } = require('../../api/addressApi')
|
||||
const { setField } = require('../../utils/request')
|
||||
|
||||
Page({
|
||||
data: {
|
||||
addresses: [],
|
||||
submitting: false,
|
||||
form: {
|
||||
contactName: '',
|
||||
phone: '',
|
||||
building: '',
|
||||
room: '',
|
||||
detail: '',
|
||||
default: false
|
||||
}
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
this.load()
|
||||
},
|
||||
|
||||
load() {
|
||||
return listAddresses()
|
||||
.then((addresses) => this.setData({ addresses: addresses || [] }))
|
||||
.catch((error) => wx.showToast({ title: error.message, icon: 'none' }))
|
||||
},
|
||||
|
||||
onFieldInput(event) {
|
||||
setField(this, event)
|
||||
},
|
||||
|
||||
submit() {
|
||||
if (this.data.submitting) {
|
||||
return
|
||||
}
|
||||
this.setData({ submitting: true })
|
||||
createAddress(this.data.form)
|
||||
.then(() => {
|
||||
wx.showToast({ title: '已保存' })
|
||||
this.setData({
|
||||
form: {
|
||||
contactName: '',
|
||||
phone: '',
|
||||
building: '',
|
||||
room: '',
|
||||
detail: '',
|
||||
default: false
|
||||
}
|
||||
})
|
||||
return this.load()
|
||||
})
|
||||
.catch((error) => wx.showToast({ title: error.message, icon: 'none' }))
|
||||
.finally(() => this.setData({ submitting: false }))
|
||||
},
|
||||
|
||||
setDefault(event) {
|
||||
setDefaultAddress(event.currentTarget.dataset.id)
|
||||
.then(() => {
|
||||
wx.showToast({ title: '已设默认' })
|
||||
return this.load()
|
||||
})
|
||||
.catch((error) => wx.showToast({ title: error.message, icon: 'none' }))
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user