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;
|
||||
}
|
||||
|
||||
@@ -1 +1,71 @@
|
||||
Page({})
|
||||
const { calculateExpressFeeCent, createExpressOrder } = require('../../api/expressApi')
|
||||
const { listAddresses } = require('../../api/addressApi')
|
||||
const { setField } = require('../../utils/request')
|
||||
|
||||
Page({
|
||||
data: {
|
||||
addresses: [],
|
||||
addressIndex: 0,
|
||||
feeCent: 300,
|
||||
submitting: false,
|
||||
form: {
|
||||
expressCompany: '',
|
||||
pickupCode: '',
|
||||
pickupAddress: '',
|
||||
receiverPhone: '',
|
||||
addressId: null,
|
||||
packageCount: 1,
|
||||
remark: ''
|
||||
}
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
listAddresses()
|
||||
.then((addresses) => {
|
||||
this.setData({
|
||||
addresses: addresses || [],
|
||||
'form.addressId': addresses && addresses[0] ? addresses[0].id : null
|
||||
})
|
||||
})
|
||||
.catch(() => {})
|
||||
},
|
||||
|
||||
onFieldInput(event) {
|
||||
setField(this, event)
|
||||
},
|
||||
|
||||
onAddressChange(event) {
|
||||
const index = Number(event.detail.value)
|
||||
const address = this.data.addresses[index]
|
||||
this.setData({
|
||||
addressIndex: index,
|
||||
'form.addressId': address ? address.id : null
|
||||
})
|
||||
},
|
||||
|
||||
onPackageCountChange(event) {
|
||||
const packageCount = Number(event.detail.value || 1)
|
||||
this.setData({
|
||||
'form.packageCount': packageCount,
|
||||
feeCent: calculateExpressFeeCent(packageCount)
|
||||
})
|
||||
},
|
||||
|
||||
submit() {
|
||||
if (this.data.submitting) {
|
||||
return
|
||||
}
|
||||
if (!this.data.form.addressId) {
|
||||
wx.showToast({ title: '请先添加地址', icon: 'none' })
|
||||
return
|
||||
}
|
||||
this.setData({ submitting: true })
|
||||
createExpressOrder(this.data.form)
|
||||
.then(() => {
|
||||
wx.showToast({ title: '已提交' })
|
||||
wx.navigateTo({ url: '/pages/orders/index' })
|
||||
})
|
||||
.catch((error) => wx.showToast({ title: error.message, icon: 'none' }))
|
||||
.finally(() => this.setData({ submitting: false }))
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1 +1,23 @@
|
||||
<view class="page">代取快递</view>
|
||||
<view class="page">
|
||||
<view class="section-title">代取快递</view>
|
||||
<view class="card">
|
||||
<input class="input" placeholder="快递公司" data-field="expressCompany" bindinput="onFieldInput" />
|
||||
<input class="input" placeholder="取件码" data-field="pickupCode" bindinput="onFieldInput" />
|
||||
<input class="input" placeholder="快递站地址" data-field="pickupAddress" bindinput="onFieldInput" />
|
||||
<input class="input" placeholder="手机号" data-field="receiverPhone" bindinput="onFieldInput" />
|
||||
<view class="muted">送达地址</view>
|
||||
<picker mode="selector" range="{{addresses}}" range-key="detail" value="{{addressIndex}}" bindchange="onAddressChange">
|
||||
<view class="picker">{{addresses[addressIndex] ? addresses[addressIndex].building + ' ' + addresses[addressIndex].room + ' ' + addresses[addressIndex].detail : '请选择地址'}}</view>
|
||||
</picker>
|
||||
<input class="input" type="number" value="{{form.packageCount}}" bindinput="onPackageCountChange" />
|
||||
<view class="card">
|
||||
<view class="row between">
|
||||
<text>预估服务费</text>
|
||||
<text class="price">¥{{feeCent / 100}}</text>
|
||||
</view>
|
||||
<view class="muted">首件 3 元,续件每件 1 元</view>
|
||||
</view>
|
||||
<textarea class="textarea" placeholder="备注" data-field="remark" bindinput="onFieldInput" />
|
||||
<button class="primary" loading="{{submitting}}" bindtap="submit">提交代取</button>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
.page {
|
||||
min-height: 100vh;
|
||||
.card .card {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
@@ -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 }))
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1 +1,25 @@
|
||||
<view class="page">团购详情</view>
|
||||
<view class="page" wx:if="{{groupBuy}}">
|
||||
<view class="card">
|
||||
<view class="section-title">{{groupBuy.title}}</view>
|
||||
<view class="price">¥{{groupBuy.priceCent / 100}}</view>
|
||||
<view class="muted">{{groupBuy.description || '社区团购'}}</view>
|
||||
<view class="muted">自提点:{{groupBuy.pickupAddress}}</view>
|
||||
</view>
|
||||
<view class="card">
|
||||
<view class="muted">数量</view>
|
||||
<input class="input" type="number" value="{{form.quantity}}" bindinput="onQuantityChange" />
|
||||
<view class="muted">提货方式</view>
|
||||
<radio-group bindchange="onMethodChange">
|
||||
<label class="radio"><radio value="SELF_PICKUP" checked="{{form.deliveryMethod === 'SELF_PICKUP'}}" />自提</label>
|
||||
<label class="radio"><radio value="IMMEDIATE" checked="{{form.deliveryMethod === 'IMMEDIATE'}}" />配送</label>
|
||||
</radio-group>
|
||||
<view wx:if="{{form.deliveryMethod !== 'SELF_PICKUP'}}">
|
||||
<view class="muted">收货地址</view>
|
||||
<picker mode="selector" range="{{addresses}}" range-key="detail" value="{{addressIndex}}" bindchange="onAddressChange">
|
||||
<view class="picker">{{addresses[addressIndex] ? addresses[addressIndex].building + ' ' + addresses[addressIndex].room + ' ' + addresses[addressIndex].detail : '请选择地址'}}</view>
|
||||
</picker>
|
||||
</view>
|
||||
<textarea class="textarea" placeholder="备注" bindinput="onRemarkInput" />
|
||||
<button class="primary" loading="{{submitting}}" bindtap="submit">提交团购订单</button>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
.page {
|
||||
min-height: 100vh;
|
||||
.radio {
|
||||
display: block;
|
||||
height: 60rpx;
|
||||
line-height: 60rpx;
|
||||
}
|
||||
|
||||
@@ -1 +1,28 @@
|
||||
Page({})
|
||||
const { listGroupBuys } = require('../../api/groupBuyApi')
|
||||
|
||||
Page({
|
||||
data: {
|
||||
loading: false,
|
||||
groupBuys: []
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
this.load()
|
||||
},
|
||||
|
||||
onShow() {
|
||||
this.load()
|
||||
},
|
||||
|
||||
load() {
|
||||
this.setData({ loading: true })
|
||||
listGroupBuys()
|
||||
.then((groupBuys) => this.setData({ groupBuys: groupBuys || [] }))
|
||||
.catch((error) => wx.showToast({ title: error.message, icon: 'none' }))
|
||||
.finally(() => this.setData({ loading: false }))
|
||||
},
|
||||
|
||||
goDetail(event) {
|
||||
wx.navigateTo({ url: '/pages/group-buy/detail?id=' + event.currentTarget.dataset.id })
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1 +1,14 @@
|
||||
<view class="page">今日团购</view>
|
||||
<view class="page">
|
||||
<view class="section-title">今日团购</view>
|
||||
<view wx:for="{{groupBuys}}" wx:key="id" class="card" bindtap="goDetail" data-id="{{item.id}}">
|
||||
<view class="row between">
|
||||
<view>
|
||||
<view>{{item.title}}</view>
|
||||
<view class="muted">截单 {{item.endTime}}</view>
|
||||
</view>
|
||||
<view class="price">¥{{item.priceCent / 100}}</view>
|
||||
</view>
|
||||
<view class="muted">库存 {{item.stock}} / 已售 {{item.soldCount}}</view>
|
||||
</view>
|
||||
<view wx:if="{{!groupBuys.length && !loading}}" class="card muted">暂无团购</view>
|
||||
</view>
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
.page {
|
||||
min-height: 100vh;
|
||||
.price {
|
||||
min-width: 120rpx;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
@@ -1 +1,49 @@
|
||||
Page({})
|
||||
const { getHomeData } = require('../../api/homeApi')
|
||||
const { yuan } = require('../../utils/request')
|
||||
|
||||
Page({
|
||||
data: {
|
||||
loading: false,
|
||||
banners: [],
|
||||
notices: [],
|
||||
products: [],
|
||||
groupBuys: [],
|
||||
secondGoods: []
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
this.load()
|
||||
},
|
||||
|
||||
onPullDownRefresh() {
|
||||
this.load().finally(() => wx.stopPullDownRefresh())
|
||||
},
|
||||
|
||||
load() {
|
||||
this.setData({ loading: true })
|
||||
return getHomeData()
|
||||
.then((data) => {
|
||||
this.setData({
|
||||
banners: data.banners || [],
|
||||
notices: (data.notices || []).slice(0, 3),
|
||||
products: (data.products || []).slice(0, 6),
|
||||
groupBuys: (data.groupBuys || []).slice(0, 3),
|
||||
secondGoods: (data.secondGoods || []).slice(0, 3)
|
||||
})
|
||||
})
|
||||
.catch((error) => wx.showToast({ title: error.message, icon: 'none' }))
|
||||
.finally(() => this.setData({ loading: false }))
|
||||
},
|
||||
|
||||
go(event) {
|
||||
wx.navigateTo({ url: event.currentTarget.dataset.url })
|
||||
},
|
||||
|
||||
goTab(event) {
|
||||
wx.switchTab({ url: event.currentTarget.dataset.url })
|
||||
},
|
||||
|
||||
yuan(cent) {
|
||||
return yuan(cent)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1 +1,57 @@
|
||||
<view class="page">邻小帮</view>
|
||||
<view class="page">
|
||||
<view class="section">
|
||||
<view class="section-title">邻小帮</view>
|
||||
<view class="muted">社区服务 30 分钟到家</view>
|
||||
</view>
|
||||
|
||||
<view class="grid section">
|
||||
<view class="shortcut" bindtap="go" data-url="/pages/products/index">商品预定</view>
|
||||
<view class="shortcut" bindtap="go" data-url="/pages/express/create">代取快递</view>
|
||||
<view class="shortcut" bindtap="goTab" data-url="/pages/group-buy/index">今日团购</view>
|
||||
<view class="shortcut" bindtap="goTab" data-url="/pages/second-hand/index">二手闲置</view>
|
||||
<view class="shortcut" bindtap="go" data-url="/pages/notices/index">社区公告</view>
|
||||
<view class="shortcut" bindtap="go" data-url="/pages/orders/index">我的订单</view>
|
||||
</view>
|
||||
|
||||
<view class="section">
|
||||
<view class="section-title">公告</view>
|
||||
<view wx:for="{{notices}}" wx:key="id" class="card" bindtap="go" data-url="/pages/notices/index">
|
||||
<view>{{item.title}}</view>
|
||||
<view class="muted">{{item.category}}</view>
|
||||
</view>
|
||||
<view wx:if="{{!notices.length}}" class="card muted">暂无公告</view>
|
||||
</view>
|
||||
|
||||
<view class="section">
|
||||
<view class="section-title">热门商品</view>
|
||||
<view wx:for="{{products}}" wx:key="id" class="card" bindtap="go" data-url="/pages/products/detail?id={{item.id}}">
|
||||
<view class="row between">
|
||||
<view>{{item.name}}</view>
|
||||
<view class="tag">{{item.status}}</view>
|
||||
</view>
|
||||
<view class="muted">{{item.description || '社区商品'}}</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="section">
|
||||
<view class="section-title">今日团购</view>
|
||||
<view wx:for="{{groupBuys}}" wx:key="id" class="card" bindtap="go" data-url="/pages/group-buy/detail?id={{item.id}}">
|
||||
<view class="row between">
|
||||
<view>{{item.title}}</view>
|
||||
<view class="price">¥{{item.priceCent / 100}}</view>
|
||||
</view>
|
||||
<view class="muted">已售 {{item.soldCount}} / 库存 {{item.stock}}</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="section">
|
||||
<view class="section-title">最新闲置</view>
|
||||
<view wx:for="{{secondGoods}}" wx:key="id" class="card">
|
||||
<view class="row between">
|
||||
<view>{{item.title}}</view>
|
||||
<view class="price">¥{{item.priceCent / 100}}</view>
|
||||
</view>
|
||||
<view class="muted">{{item.category}}</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
.page {
|
||||
min-height: 100vh;
|
||||
padding-bottom: 40rpx;
|
||||
}
|
||||
|
||||
@@ -1 +1,20 @@
|
||||
Page({})
|
||||
const { listNotices } = require('../../api/noticeApi')
|
||||
|
||||
Page({
|
||||
data: {
|
||||
loading: false,
|
||||
notices: []
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
this.load()
|
||||
},
|
||||
|
||||
load() {
|
||||
this.setData({ loading: true })
|
||||
listNotices()
|
||||
.then((notices) => this.setData({ notices: notices || [] }))
|
||||
.catch((error) => wx.showToast({ title: error.message, icon: 'none' }))
|
||||
.finally(() => this.setData({ loading: false }))
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1 +1,12 @@
|
||||
<view class="page">社区公告</view>
|
||||
<view class="page">
|
||||
<view class="section-title">社区公告</view>
|
||||
<view wx:for="{{notices}}" wx:key="id" class="card">
|
||||
<view class="row between">
|
||||
<view>{{item.title}}</view>
|
||||
<view wx:if="{{item.pinned}}" class="tag">置顶</view>
|
||||
</view>
|
||||
<view class="muted">{{item.category}} {{item.publishedAt}}</view>
|
||||
<view>{{item.content}}</view>
|
||||
</view>
|
||||
<view wx:if="{{!notices.length && !loading}}" class="card muted">暂无公告</view>
|
||||
</view>
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
.page {
|
||||
min-height: 100vh;
|
||||
.card > view:last-child {
|
||||
margin-top: 12rpx;
|
||||
line-height: 44rpx;
|
||||
}
|
||||
|
||||
@@ -1 +1,56 @@
|
||||
Page({})
|
||||
const { getGoodsOrderDetail, cancelGoodsOrder } = require('../../api/orderApi')
|
||||
const { getExpressOrderDetail, cancelExpressOrder, completeExpressOrder } = require('../../api/expressApi')
|
||||
const { getGroupBuyOrderDetail, cancelGroupBuyOrder } = require('../../api/groupBuyApi')
|
||||
const { statusText } = require('../../utils/request')
|
||||
|
||||
Page({
|
||||
data: {
|
||||
type: '',
|
||||
order: null
|
||||
},
|
||||
|
||||
onLoad(options) {
|
||||
this.type = options.type
|
||||
this.id = Number(options.id)
|
||||
this.setData({ type: this.type })
|
||||
this.load()
|
||||
},
|
||||
|
||||
load() {
|
||||
const loaders = {
|
||||
goods: getGoodsOrderDetail,
|
||||
express: getExpressOrderDetail,
|
||||
group: getGroupBuyOrderDetail
|
||||
}
|
||||
loaders[this.type](this.id)
|
||||
.then((order) => this.setData({ order }))
|
||||
.catch((error) => wx.showToast({ title: error.message, icon: 'none' }))
|
||||
},
|
||||
|
||||
cancel() {
|
||||
const actions = {
|
||||
goods: () => cancelGoodsOrder(this.id),
|
||||
express: () => cancelExpressOrder(this.id, '用户取消'),
|
||||
group: () => cancelGroupBuyOrder(this.id)
|
||||
}
|
||||
actions[this.type]()
|
||||
.then(() => {
|
||||
wx.showToast({ title: '已取消' })
|
||||
this.load()
|
||||
})
|
||||
.catch((error) => wx.showToast({ title: error.message, icon: 'none' }))
|
||||
},
|
||||
|
||||
completeExpress() {
|
||||
completeExpressOrder(this.id)
|
||||
.then(() => {
|
||||
wx.showToast({ title: '已完成' })
|
||||
this.load()
|
||||
})
|
||||
.catch((error) => wx.showToast({ title: error.message, icon: 'none' }))
|
||||
},
|
||||
|
||||
statusText(status) {
|
||||
return statusText(status)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1 +1,29 @@
|
||||
<view class="page">订单详情</view>
|
||||
<view class="page" wx:if="{{order}}">
|
||||
<view class="card">
|
||||
<view class="section-title">{{order.orderNo}}</view>
|
||||
<view class="tag">{{order.status}}</view>
|
||||
<view class="muted">类型:{{type}}</view>
|
||||
</view>
|
||||
<view class="card">
|
||||
<view wx:if="{{type === 'goods'}}">
|
||||
<view>商品金额:¥{{order.totalAmountCent / 100}}</view>
|
||||
<view>配送费:¥{{order.deliveryFeeCent / 100}}</view>
|
||||
<view class="price">应收:¥{{order.payableAmountCent / 100}}</view>
|
||||
<view class="muted">{{order.deliveryMethod}}</view>
|
||||
</view>
|
||||
<view wx:if="{{type === 'express'}}">
|
||||
<view>{{order.expressCompany}} / {{order.pickupCode}}</view>
|
||||
<view class="muted">{{order.pickupAddress}}</view>
|
||||
<view class="price">服务费:¥{{order.feeCent / 100}}</view>
|
||||
</view>
|
||||
<view wx:if="{{type === 'group'}}">
|
||||
<view>{{order.groupBuyTitle}}</view>
|
||||
<view>数量:{{order.quantity}}</view>
|
||||
<view class="price">金额:¥{{order.amountCent / 100}}</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="button-row">
|
||||
<button class="ghost" bindtap="cancel">取消订单</button>
|
||||
<button wx:if="{{type === 'express'}}" class="primary" bindtap="completeExpress">确认完成</button>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
.page {
|
||||
min-height: 100vh;
|
||||
.button-row button {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
@@ -1 +1,70 @@
|
||||
Page({})
|
||||
const { listGoodsOrders } = require('../../api/orderApi')
|
||||
const { listExpressOrders } = require('../../api/expressApi')
|
||||
const { listGroupBuyOrders } = require('../../api/groupBuyApi')
|
||||
const { statusText } = require('../../utils/request')
|
||||
|
||||
Page({
|
||||
data: {
|
||||
loading: false,
|
||||
orders: []
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
this.load()
|
||||
},
|
||||
|
||||
onShow() {
|
||||
this.load()
|
||||
},
|
||||
|
||||
load() {
|
||||
this.setData({ loading: true })
|
||||
Promise.all([
|
||||
listGoodsOrders().catch(() => []),
|
||||
listExpressOrders().catch(() => []),
|
||||
listGroupBuyOrders().catch(() => [])
|
||||
])
|
||||
.then(([goodsOrders, expressOrders, groupBuyOrders]) => {
|
||||
const orders = []
|
||||
;(goodsOrders || []).forEach((item) => orders.push({
|
||||
id: item.id,
|
||||
type: 'goods',
|
||||
typeText: '商品订单',
|
||||
orderNo: item.orderNo,
|
||||
title: item.orderNo,
|
||||
amountCent: item.payableAmountCent,
|
||||
status: item.status
|
||||
}))
|
||||
;(expressOrders || []).forEach((item) => orders.push({
|
||||
id: item.id,
|
||||
type: 'express',
|
||||
typeText: '快递代取',
|
||||
orderNo: item.orderNo,
|
||||
title: item.expressCompany + ' ' + item.pickupCode,
|
||||
amountCent: item.feeCent,
|
||||
status: item.status
|
||||
}))
|
||||
;(groupBuyOrders || []).forEach((item) => orders.push({
|
||||
id: item.id,
|
||||
type: 'group',
|
||||
typeText: '团购订单',
|
||||
orderNo: item.orderNo,
|
||||
title: item.groupBuyTitle,
|
||||
amountCent: item.amountCent,
|
||||
status: item.status
|
||||
}))
|
||||
this.setData({ orders })
|
||||
})
|
||||
.catch((error) => wx.showToast({ title: error.message, icon: 'none' }))
|
||||
.finally(() => this.setData({ loading: false }))
|
||||
},
|
||||
|
||||
goDetail(event) {
|
||||
const { type, id } = event.currentTarget.dataset
|
||||
wx.navigateTo({ url: '/pages/orders/detail?type=' + type + '&id=' + id })
|
||||
},
|
||||
|
||||
statusText(status) {
|
||||
return statusText(status)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1 +1,17 @@
|
||||
<view class="page">我的订单</view>
|
||||
<view class="page">
|
||||
<view class="section-title">我的订单</view>
|
||||
<view wx:for="{{orders}}" wx:key="id" class="card" bindtap="goDetail" data-type="{{item.type}}" data-id="{{item.id}}">
|
||||
<view class="row between">
|
||||
<view>
|
||||
<view>{{item.title}}</view>
|
||||
<view class="muted">{{item.typeText}} {{item.orderNo}}</view>
|
||||
</view>
|
||||
<view class="tag">{{item.status}}</view>
|
||||
</view>
|
||||
<view class="row between">
|
||||
<view class="muted">状态:{{item.status}}</view>
|
||||
<view class="price">¥{{item.amountCent / 100}}</view>
|
||||
</view>
|
||||
</view>
|
||||
<view wx:if="{{!orders.length && !loading}}" class="card muted">暂无订单</view>
|
||||
</view>
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
.page {
|
||||
min-height: 100vh;
|
||||
.tag {
|
||||
min-width: 120rpx;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
@@ -1 +1,93 @@
|
||||
Page({})
|
||||
const { getProductDetail, createGoodsOrder } = require('../../api/productApi')
|
||||
const { listAddresses } = require('../../api/addressApi')
|
||||
|
||||
Page({
|
||||
data: {
|
||||
product: null,
|
||||
addresses: [],
|
||||
addressIndex: 0,
|
||||
skuIndex: 0,
|
||||
submitting: false,
|
||||
form: {
|
||||
quantity: 1,
|
||||
deliveryMethod: 'IMMEDIATE',
|
||||
scheduledTime: '',
|
||||
remark: ''
|
||||
}
|
||||
},
|
||||
|
||||
onLoad(options) {
|
||||
this.productId = Number(options.id)
|
||||
this.load()
|
||||
},
|
||||
|
||||
load() {
|
||||
Promise.all([getProductDetail(this.productId), listAddresses().catch(() => [])])
|
||||
.then(([product, addresses]) => {
|
||||
this.setData({
|
||||
product,
|
||||
addresses: addresses || []
|
||||
})
|
||||
})
|
||||
.catch((error) => wx.showToast({ title: error.message, icon: 'none' }))
|
||||
},
|
||||
|
||||
onSkuChange(event) {
|
||||
this.setData({ skuIndex: Number(event.detail.value) })
|
||||
},
|
||||
|
||||
onAddressChange(event) {
|
||||
this.setData({ addressIndex: Number(event.detail.value) })
|
||||
},
|
||||
|
||||
onQuantityChange(event) {
|
||||
this.setData({ 'form.quantity': Number(event.detail.value || 1) })
|
||||
},
|
||||
|
||||
onMethodChange(event) {
|
||||
this.setData({ 'form.deliveryMethod': event.detail.value })
|
||||
},
|
||||
|
||||
onScheduledTimeChange(event) {
|
||||
this.setData({ 'form.scheduledTime': event.detail.value })
|
||||
},
|
||||
|
||||
onRemarkInput(event) {
|
||||
this.setData({ 'form.remark': event.detail.value })
|
||||
},
|
||||
|
||||
submit() {
|
||||
if (!this.data.product || this.data.submitting) {
|
||||
return
|
||||
}
|
||||
const sku = this.data.product.skus[this.data.skuIndex]
|
||||
if (!sku) {
|
||||
wx.showToast({ title: '请选择规格', icon: 'none' })
|
||||
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 })
|
||||
createGoodsOrder({
|
||||
merchantId: this.data.product.merchantId,
|
||||
addressId: address ? address.id : null,
|
||||
deliveryMethod: this.data.form.deliveryMethod,
|
||||
scheduledTime: this.data.form.scheduledTime || null,
|
||||
remark: this.data.form.remark,
|
||||
items: [{
|
||||
productId: this.data.product.id,
|
||||
skuId: sku.id,
|
||||
quantity: this.data.form.quantity
|
||||
}]
|
||||
})
|
||||
.then(() => {
|
||||
wx.showToast({ title: '已提交' })
|
||||
wx.navigateTo({ url: '/pages/orders/index' })
|
||||
})
|
||||
.catch((error) => wx.showToast({ title: error.message, icon: 'none' }))
|
||||
.finally(() => this.setData({ submitting: false }))
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1 +1,34 @@
|
||||
<view class="page">商品详情</view>
|
||||
<view class="page" wx:if="{{product}}">
|
||||
<view class="card">
|
||||
<view class="section-title">{{product.name}}</view>
|
||||
<view class="muted">{{product.description || '社区商品'}}</view>
|
||||
</view>
|
||||
|
||||
<view class="card">
|
||||
<view class="muted">规格</view>
|
||||
<picker mode="selector" range="{{product.skus}}" range-key="skuName" value="{{skuIndex}}" bindchange="onSkuChange">
|
||||
<view class="picker">{{product.skus[skuIndex].skuName}} / ¥{{product.skus[skuIndex].priceCent / 100}} / 库存 {{product.skus[skuIndex].stock}}</view>
|
||||
</picker>
|
||||
<view class="muted">数量</view>
|
||||
<input class="input" type="number" value="{{form.quantity}}" bindinput="onQuantityChange" />
|
||||
<view class="muted">配送方式</view>
|
||||
<radio-group bindchange="onMethodChange">
|
||||
<label class="radio"><radio value="IMMEDIATE" checked="{{form.deliveryMethod === 'IMMEDIATE'}}" />立即配送</label>
|
||||
<label class="radio"><radio value="SCHEDULED" checked="{{form.deliveryMethod === 'SCHEDULED'}}" />预约配送</label>
|
||||
<label class="radio"><radio value="SELF_PICKUP" checked="{{form.deliveryMethod === 'SELF_PICKUP'}}" />自提</label>
|
||||
</radio-group>
|
||||
<view wx:if="{{form.deliveryMethod !== 'SELF_PICKUP'}}">
|
||||
<view class="muted">收货地址</view>
|
||||
<picker mode="selector" range="{{addresses}}" range-key="detail" value="{{addressIndex}}" bindchange="onAddressChange">
|
||||
<view class="picker">{{addresses[addressIndex] ? addresses[addressIndex].building + ' ' + addresses[addressIndex].room + ' ' + addresses[addressIndex].detail : '请选择地址'}}</view>
|
||||
</picker>
|
||||
</view>
|
||||
<view wx:if="{{form.deliveryMethod === 'SCHEDULED'}}">
|
||||
<view class="muted">预约时间</view>
|
||||
<input class="input" placeholder="2026-07-07T18:30:00" bindinput="onScheduledTimeChange" />
|
||||
</view>
|
||||
<view class="muted">备注</view>
|
||||
<textarea class="textarea" bindinput="onRemarkInput" />
|
||||
<button class="primary" loading="{{submitting}}" bindtap="submit">提交订单</button>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
.page {
|
||||
min-height: 100vh;
|
||||
.radio {
|
||||
display: block;
|
||||
height: 60rpx;
|
||||
line-height: 60rpx;
|
||||
}
|
||||
|
||||
@@ -1 +1,46 @@
|
||||
Page({})
|
||||
const { listCategories, listProducts } = require('../../api/productApi')
|
||||
|
||||
Page({
|
||||
data: {
|
||||
loading: false,
|
||||
categories: [],
|
||||
activeCategoryId: null,
|
||||
products: []
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
this.load()
|
||||
},
|
||||
|
||||
load() {
|
||||
this.setData({ loading: true })
|
||||
Promise.all([listCategories(), listProducts()])
|
||||
.then(([categories, products]) => {
|
||||
this.setData({
|
||||
categories: categories || [],
|
||||
products: products || []
|
||||
})
|
||||
})
|
||||
.catch((error) => wx.showToast({ title: error.message, icon: 'none' }))
|
||||
.finally(() => this.setData({ loading: false }))
|
||||
},
|
||||
|
||||
chooseCategory(event) {
|
||||
const categoryId = event.currentTarget.dataset.id
|
||||
this.setData({ activeCategoryId: categoryId })
|
||||
listProducts(categoryId)
|
||||
.then((products) => this.setData({ products: products || [] }))
|
||||
.catch((error) => wx.showToast({ title: error.message, icon: 'none' }))
|
||||
},
|
||||
|
||||
clearCategory() {
|
||||
this.setData({ activeCategoryId: null })
|
||||
listProducts()
|
||||
.then((products) => this.setData({ products: products || [] }))
|
||||
.catch((error) => wx.showToast({ title: error.message, icon: 'none' }))
|
||||
},
|
||||
|
||||
goDetail(event) {
|
||||
wx.navigateTo({ url: '/pages/products/detail?id=' + event.currentTarget.dataset.id })
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1 +1,28 @@
|
||||
<view class="page">商品预定</view>
|
||||
<view class="page">
|
||||
<view class="section-title">商品预定</view>
|
||||
<scroll-view scroll-x class="category-scroll">
|
||||
<view class="category-item {{!activeCategoryId ? 'active' : ''}}" bindtap="clearCategory">全部</view>
|
||||
<view
|
||||
wx:for="{{categories}}"
|
||||
wx:key="id"
|
||||
class="category-item {{activeCategoryId === item.id ? 'active' : ''}}"
|
||||
bindtap="chooseCategory"
|
||||
data-id="{{item.id}}"
|
||||
>
|
||||
{{item.name}}
|
||||
</view>
|
||||
</scroll-view>
|
||||
|
||||
<view wx:for="{{products}}" wx:key="id" class="card" bindtap="goDetail" data-id="{{item.id}}">
|
||||
<view class="row between">
|
||||
<view>
|
||||
<view>{{item.name}}</view>
|
||||
<view class="muted">{{item.description || '社区精选商品'}}</view>
|
||||
</view>
|
||||
<view class="tag">{{item.status}}</view>
|
||||
</view>
|
||||
<view wx:if="{{item.skus.length}}" class="price">¥{{item.skus[0].priceCent / 100}} 起</view>
|
||||
</view>
|
||||
|
||||
<view wx:if="{{!products.length && !loading}}" class="card muted">暂无商品</view>
|
||||
</view>
|
||||
|
||||
@@ -1,3 +1,23 @@
|
||||
.page {
|
||||
min-height: 100vh;
|
||||
.category-scroll {
|
||||
white-space: nowrap;
|
||||
margin-bottom: 20rpx;
|
||||
}
|
||||
|
||||
.category-item {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-width: 120rpx;
|
||||
height: 64rpx;
|
||||
padding: 0 20rpx;
|
||||
margin-right: 12rpx;
|
||||
background: #ffffff;
|
||||
border: 1rpx solid #d9e0e8;
|
||||
border-radius: 6rpx;
|
||||
}
|
||||
|
||||
.category-item.active {
|
||||
color: #ffffff;
|
||||
background: #0f766e;
|
||||
border-color: #0f766e;
|
||||
}
|
||||
|
||||
@@ -1 +1,19 @@
|
||||
Page({})
|
||||
Page({
|
||||
data: {
|
||||
user: null
|
||||
},
|
||||
|
||||
onShow() {
|
||||
const app = getApp()
|
||||
this.setData({ user: app.globalData.user || null })
|
||||
},
|
||||
|
||||
go(event) {
|
||||
const url = event.currentTarget.dataset.url
|
||||
if (event.currentTarget.dataset.tab) {
|
||||
wx.switchTab({ url })
|
||||
return
|
||||
}
|
||||
wx.navigateTo({ url })
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1 +1,11 @@
|
||||
<view class="page">我的</view>
|
||||
<view class="page">
|
||||
<view class="card">
|
||||
<view class="section-title">我的</view>
|
||||
<view class="muted">邻小帮居民端</view>
|
||||
</view>
|
||||
<view class="card menu" bindtap="go" data-url="/pages/orders/index">我的订单</view>
|
||||
<view class="card menu" bindtap="go" data-url="/pages/address/index">地址管理</view>
|
||||
<view class="card menu" bindtap="go" data-url="/pages/express/create">代取快递</view>
|
||||
<view class="card menu" bindtap="go" data-url="/pages/products/index">商品预定</view>
|
||||
<view class="card menu" bindtap="go" data-url="/pages/notices/index">社区公告</view>
|
||||
</view>
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
.page {
|
||||
min-height: 100vh;
|
||||
.menu {
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
@@ -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 }))
|
||||
}
|
||||
})
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
.page {
|
||||
min-height: 100vh;
|
||||
.radio {
|
||||
display: block;
|
||||
height: 60rpx;
|
||||
line-height: 60rpx;
|
||||
}
|
||||
|
||||
@@ -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 })
|
||||
}
|
||||
})
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
.page {
|
||||
min-height: 100vh;
|
||||
.ghost {
|
||||
margin-top: 16rpx;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user