feat: add resident miniapp MVP
This commit is contained in:
@@ -1 +1,69 @@
|
||||
Page({})
|
||||
const { getGroupBuyDetail, createGroupBuyOrder } = require('../../api/groupBuyApi')
|
||||
const { listAddresses } = require('../../api/addressApi')
|
||||
|
||||
Page({
|
||||
data: {
|
||||
groupBuy: null,
|
||||
addresses: [],
|
||||
addressIndex: 0,
|
||||
submitting: false,
|
||||
form: {
|
||||
quantity: 1,
|
||||
deliveryMethod: 'SELF_PICKUP',
|
||||
remark: ''
|
||||
}
|
||||
},
|
||||
|
||||
onLoad(options) {
|
||||
this.groupBuyId = Number(options.id)
|
||||
Promise.all([getGroupBuyDetail(this.groupBuyId), listAddresses().catch(() => [])])
|
||||
.then(([groupBuy, addresses]) => {
|
||||
this.setData({
|
||||
groupBuy,
|
||||
addresses: addresses || []
|
||||
})
|
||||
})
|
||||
.catch((error) => wx.showToast({ title: error.message, icon: 'none' }))
|
||||
},
|
||||
|
||||
onQuantityChange(event) {
|
||||
this.setData({ 'form.quantity': Number(event.detail.value || 1) })
|
||||
},
|
||||
|
||||
onMethodChange(event) {
|
||||
this.setData({ 'form.deliveryMethod': event.detail.value })
|
||||
},
|
||||
|
||||
onAddressChange(event) {
|
||||
this.setData({ addressIndex: Number(event.detail.value) })
|
||||
},
|
||||
|
||||
onRemarkInput(event) {
|
||||
this.setData({ 'form.remark': event.detail.value })
|
||||
},
|
||||
|
||||
submit() {
|
||||
if (!this.data.groupBuy || this.data.submitting) {
|
||||
return
|
||||
}
|
||||
const address = this.data.addresses[this.data.addressIndex]
|
||||
if (this.data.form.deliveryMethod !== 'SELF_PICKUP' && !address) {
|
||||
wx.showToast({ title: '请先添加地址', icon: 'none' })
|
||||
return
|
||||
}
|
||||
this.setData({ submitting: true })
|
||||
createGroupBuyOrder({
|
||||
groupBuyId: this.data.groupBuy.id,
|
||||
addressId: address ? address.id : null,
|
||||
quantity: this.data.form.quantity,
|
||||
deliveryMethod: this.data.form.deliveryMethod,
|
||||
remark: this.data.form.remark
|
||||
})
|
||||
.then(() => {
|
||||
wx.showToast({ title: '已提交' })
|
||||
wx.navigateTo({ url: '/pages/orders/index' })
|
||||
})
|
||||
.catch((error) => wx.showToast({ title: error.message, icon: 'none' }))
|
||||
.finally(() => this.setData({ submitting: false }))
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user