9.18/2
This commit is contained in:
59
frontend/pages/customer/form.vue
Normal file
59
frontend/pages/customer/form.vue
Normal file
@@ -0,0 +1,59 @@
|
||||
<template>
|
||||
<view class="page">
|
||||
<view class="field"><text class="label">客户名称</text><input class="value" v-model="form.name" placeholder="必填" /></view>
|
||||
<view class="field"><text class="label">客户等级</text><input class="value" v-model="form.level" placeholder="可选,如 VIP/A/B" /></view>
|
||||
<view class="field">
|
||||
<text class="label">售价档位</text>
|
||||
<picker :range="priceLevels" :value="priceIdx" @change="onPriceChange">
|
||||
<view class="value">{{ priceLevels[priceIdx] }}</view>
|
||||
</picker>
|
||||
</view>
|
||||
<view class="field"><text class="label">联系人</text><input class="value" v-model="form.contactName" placeholder="可选" /></view>
|
||||
<view class="field"><text class="label">手机</text><input class="value" v-model="form.mobile" placeholder="可选" /></view>
|
||||
<view class="field"><text class="label">电话</text><input class="value" v-model="form.phone" placeholder="可选(座机)" /></view>
|
||||
<view class="field"><text class="label">送货地址</text><input class="value" v-model="form.address" placeholder="可选" /></view>
|
||||
<view class="field"><text class="label">初始应收</text><input class="value" type="digit" v-model.number="form.arOpening" placeholder="默认 0.00" /></view>
|
||||
<view class="textarea"><textarea v-model="form.remark" maxlength="200" placeholder="备注(最多200字)"></textarea></view>
|
||||
|
||||
<view class="bottom"><button class="primary" @click="save">保存</button></view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { post, put } from '../../common/http.js'
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
id: null,
|
||||
form: { name:'', level:'', priceLevel:'retail', contactName:'', mobile:'', phone:'', address:'', arOpening:0, remark:'' },
|
||||
priceLevels: ['retail','distribution','wholesale','big_client'],
|
||||
priceIdx: 0
|
||||
}
|
||||
},
|
||||
onLoad(query) { if (query && query.id) { this.id = Number(query.id) } },
|
||||
methods: {
|
||||
onPriceChange(e){ this.priceIdx = Number(e.detail.value); this.form.priceLevel = this.priceLevels[this.priceIdx] },
|
||||
async save() {
|
||||
if (!this.form.name) return uni.showToast({ title:'请填写客户名称', icon:'none' })
|
||||
try {
|
||||
if (this.id) await put(`/api/customers/${this.id}`, this.form)
|
||||
else await post('/api/customers', this.form)
|
||||
uni.showToast({ title:'保存成功', icon:'success' })
|
||||
setTimeout(() => uni.navigateBack(), 500)
|
||||
} catch(e) { uni.showToast({ title: e?.message || '保存失败', icon:'none' }) }
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.page { padding-bottom: 140rpx; }
|
||||
.field { display:flex; justify-content: space-between; padding: 22rpx 24rpx; background:#fff; border-bottom:1rpx solid #eee; }
|
||||
.label { color:#666; }
|
||||
.value { color:#333; text-align: right; flex: 1; }
|
||||
.textarea { padding: 16rpx 24rpx; background:#fff; margin-top: 12rpx; }
|
||||
.bottom { position: fixed; left:0; right:0; bottom:0; background:#fff; padding: 16rpx 24rpx calc(env(safe-area-inset-bottom) + 16rpx); box-shadow: 0 -4rpx 12rpx rgba(0,0,0,0.06); }
|
||||
.primary { width: 100%; background: linear-gradient(135deg, #A0E4FF 0%, #17A2C4 100%); color:#fff; border-radius: 999rpx; padding: 20rpx 0; }
|
||||
</style>
|
||||
|
||||
|
||||
@@ -3,28 +3,37 @@
|
||||
<view class="search">
|
||||
<input v-model="kw" placeholder="搜索客户名称/电话" @confirm="search" />
|
||||
<button size="mini" @click="search">搜索</button>
|
||||
<button size="mini" :type="debtOnly ? 'primary' : 'default'" @click="toggleDebtOnly">只看欠款</button>
|
||||
</view>
|
||||
<scroll-view scroll-y class="list">
|
||||
<view class="item" v-for="c in customers" :key="c.id" @click="select(c)">
|
||||
<view class="name">{{ c.name }}</view>
|
||||
<view class="meta">{{ c.mobile || '—' }}</view>
|
||||
<view class="meta">
|
||||
{{ c.mobile || '—' }}
|
||||
<text v-if="typeof c.receivable === 'number'">|应收:¥ {{ Number(c.receivable).toFixed(2) }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</scroll-view>
|
||||
<view class="bottom">
|
||||
<button class="primary" @click="createCustomer">新增客户</button>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { get } from '../../common/http.js'
|
||||
export default {
|
||||
data() { return { kw: '', customers: [] } },
|
||||
data() { return { kw: '', debtOnly: false, customers: [] } },
|
||||
onLoad() { this.search() },
|
||||
methods: {
|
||||
toggleDebtOnly() { this.debtOnly = !this.debtOnly; this.search() },
|
||||
async search() {
|
||||
try {
|
||||
const res = await get('/api/customers', { kw: this.kw, page: 1, size: 50 })
|
||||
const res = await get('/api/customers', { kw: this.kw, debtOnly: this.debtOnly, page: 1, size: 50 })
|
||||
this.customers = Array.isArray(res?.list) ? res.list : (Array.isArray(res) ? res : [])
|
||||
} catch(e) { uni.showToast({ title: '加载失败', icon: 'none' }) }
|
||||
},
|
||||
createCustomer() { uni.navigateTo({ url: '/pages/customer/form' }) },
|
||||
select(c) {
|
||||
const opener = getCurrentPages()[getCurrentPages().length-2]
|
||||
if (opener && opener.$vm) {
|
||||
@@ -39,12 +48,14 @@
|
||||
|
||||
<style>
|
||||
.page { display:flex; flex-direction: column; height: 100vh; }
|
||||
.search { display:flex; gap: 12rpx; padding: 16rpx; background:#fff; }
|
||||
.search { display:flex; gap: 12rpx; padding: 16rpx; background:#fff; align-items:center; }
|
||||
.search input { flex:1; background:#f6f6f6; border-radius: 12rpx; padding: 12rpx; }
|
||||
.list { flex:1; }
|
||||
.item { padding: 20rpx 24rpx; background:#fff; border-bottom: 1rpx solid #f1f1f1; }
|
||||
.name { color:#333; margin-bottom: 6rpx; }
|
||||
.meta { color:#888; font-size: 24rpx; }
|
||||
.bottom { position: fixed; left:0; right:0; bottom:0; background:#fff; padding: 16rpx 24rpx calc(env(safe-area-inset-bottom) + 16rpx); box-shadow: 0 -4rpx 12rpx rgba(0,0,0,0.06); }
|
||||
.primary { width: 100%; background: linear-gradient(135deg, #A0E4FF 0%, #17A2C4 100%); color:#fff; border-radius: 999rpx; padding: 20rpx 0; }
|
||||
</style>
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user