feat: add resident miniapp MVP

This commit is contained in:
王鹏
2026-07-07 16:38:13 +08:00
parent bb325151d6
commit 576c54ec9d
52 changed files with 17865 additions and 66 deletions

View File

@@ -1 +1,52 @@
Page({})
const { createSecondGoods } = require('../../api/secondGoodsApi')
const { setField } = require('../../utils/request')
Page({
data: {
submitting: false,
imageText: '',
form: {
title: '',
priceCent: 0,
description: '',
category: '',
contactPhone: '',
tradeMethod: 'FACE_TO_FACE',
imageUrls: []
}
},
onFieldInput(event) {
setField(this, event)
},
onPriceInput(event) {
this.setData({ 'form.priceCent': Math.round(Number(event.detail.value || 0) * 100) })
},
onTradeMethodChange(event) {
this.setData({ 'form.tradeMethod': event.detail.value })
},
onImageInput(event) {
const imageText = event.detail.value
this.setData({
imageText,
'form.imageUrls': imageText ? imageText.split(',').map((item) => item.trim()).filter(Boolean) : []
})
},
submit() {
if (this.data.submitting) {
return
}
this.setData({ submitting: true })
createSecondGoods(this.data.form)
.then(() => {
wx.showToast({ title: '待审核' })
wx.navigateBack()
})
.catch((error) => wx.showToast({ title: error.message, icon: 'none' }))
.finally(() => this.setData({ submitting: false }))
}
})

View File

@@ -1 +1,16 @@
<view class="page">发布闲置</view>
<view class="page">
<view class="section-title">发布闲置</view>
<view class="card">
<input class="input" placeholder="标题" data-field="title" bindinput="onFieldInput" />
<input class="input" placeholder="价格(元)" type="digit" bindinput="onPriceInput" />
<input class="input" placeholder="分类" data-field="category" bindinput="onFieldInput" />
<input class="input" placeholder="联系电话" data-field="contactPhone" bindinput="onFieldInput" />
<radio-group bindchange="onTradeMethodChange">
<label class="radio"><radio value="FACE_TO_FACE" checked="{{form.tradeMethod === 'FACE_TO_FACE'}}" />面交</label>
<label class="radio"><radio value="DELIVERY" checked="{{form.tradeMethod === 'DELIVERY'}}" />可配送</label>
</radio-group>
<input class="input" placeholder="图片 URL多个用英文逗号分隔" value="{{imageText}}" bindinput="onImageInput" />
<textarea class="textarea" placeholder="描述" data-field="description" bindinput="onFieldInput" />
<button class="primary" loading="{{submitting}}" bindtap="submit">提交审核</button>
</view>
</view>

View File

@@ -1,3 +1,5 @@
.page {
min-height: 100vh;
.radio {
display: block;
height: 60rpx;
line-height: 60rpx;
}

View File

@@ -1 +1,37 @@
Page({})
const { listSecondGoods } = require('../../api/secondGoodsApi')
Page({
data: {
loading: false,
goods: []
},
onLoad() {
this.load()
},
onShow() {
this.load()
},
load() {
this.setData({ loading: true })
listSecondGoods()
.then((goods) => this.setData({ goods: goods || [] }))
.catch((error) => wx.showToast({ title: error.message, icon: 'none' }))
.finally(() => this.setData({ loading: false }))
},
goCreate() {
wx.navigateTo({ url: '/pages/second-hand/create' })
},
callSeller(event) {
const phone = event.currentTarget.dataset.phone
if (!phone) {
wx.showToast({ title: '暂无电话', icon: 'none' })
return
}
wx.makePhoneCall({ phoneNumber: phone })
}
})

View File

@@ -1 +1,18 @@
<view class="page">二手闲置</view>
<view class="page">
<view class="row between section">
<view class="section-title">二手闲置</view>
<button size="mini" class="primary" bindtap="goCreate">发布</button>
</view>
<view wx:for="{{goods}}" wx:key="id" class="card">
<view class="row between">
<view>
<view>{{item.title}}</view>
<view class="muted">{{item.category}} / {{item.tradeMethod}}</view>
</view>
<view class="price">¥{{item.priceCent / 100}}</view>
</view>
<view class="muted">{{item.description}}</view>
<button size="mini" class="ghost" data-phone="{{item.contactPhone}}" bindtap="callSeller">联系卖家</button>
</view>
<view wx:if="{{!goods.length && !loading}}" class="card muted">暂无闲置</view>
</view>

View File

@@ -1,3 +1,3 @@
.page {
min-height: 100vh;
.ghost {
margin-top: 16rpx;
}