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' }))
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1 +1,19 @@
|
||||
<view class="page">地址管理</view>
|
||||
<view class="page">
|
||||
<view class="section-title">地址管理</view>
|
||||
<view class="card">
|
||||
<input class="input" placeholder="联系人" data-field="contactName" value="{{form.contactName}}" bindinput="onFieldInput" />
|
||||
<input class="input" placeholder="手机号" data-field="phone" value="{{form.phone}}" bindinput="onFieldInput" />
|
||||
<input class="input" placeholder="楼栋" data-field="building" value="{{form.building}}" bindinput="onFieldInput" />
|
||||
<input class="input" placeholder="房号" data-field="room" value="{{form.room}}" bindinput="onFieldInput" />
|
||||
<input class="input" placeholder="详细地址" data-field="detail" value="{{form.detail}}" bindinput="onFieldInput" />
|
||||
<button class="primary" loading="{{submitting}}" bindtap="submit">保存地址</button>
|
||||
</view>
|
||||
<view wx:for="{{addresses}}" wx:key="id" class="card">
|
||||
<view class="row between">
|
||||
<view>{{item.contactName}} {{item.phone}}</view>
|
||||
<view wx:if="{{item.default}}" class="tag">默认</view>
|
||||
</view>
|
||||
<view class="muted">{{item.building}} {{item.room}} {{item.detail}}</view>
|
||||
<button wx:if="{{!item.default}}" size="mini" class="ghost" data-id="{{item.id}}" bindtap="setDefault">设为默认</button>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
.page {
|
||||
min-height: 100vh;
|
||||
.ghost {
|
||||
margin-top: 16rpx;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user