Files
shanxia2.0/miniprogram/pages/crm/customer/list.vue
T
2026-07-18 09:14:02 +08:00

138 lines
4.1 KiB
Vue

<script setup>
import { ref } from 'vue'
import { onShow, onReachBottom } from '@dcloudio/uni-app'
import { listCustomer, listMyCustomer } from '@/api/crm'
import { labelOf, dash } from '@/utils/crmLabels'
import { PAGE_PATHS } from '@/config/api'
const tabs = [
{ key: 'mine', label: '我的' },
{ key: 'all', label: '全部' }
]
const activeTab = ref('mine')
const keyword = ref('')
const list = ref([])
const page = ref(1)
const total = ref(0)
const loading = ref(false)
const finished = ref(false)
const pageSize = 20
const goBack = () => {
uni.navigateBack({
fail: () => uni.switchTab({ url: PAGE_PATHS.workbench })
})
}
const goDetail = (row) => {
uni.navigateTo({ url: `${PAGE_PATHS.crmCustomerDetail}?id=${row.id}` })
}
const statusLabel = (s) => labelOf('customerStatus', s)
const levelLabel = (s) => labelOf('level', s)
const loadList = async (reset = false) => {
if (loading.value) return
if (reset) {
page.value = 1
finished.value = false
list.value = []
}
if (finished.value) return
loading.value = true
try {
const query = {
pageNum: page.value,
pageSize,
keyword: keyword.value.trim() || undefined,
customerName: keyword.value.trim() || undefined
}
const res =
activeTab.value === 'mine' ? await listMyCustomer(query) : await listCustomer(query)
const rows = res.rows || []
list.value = reset ? rows : list.value.concat(rows)
total.value = res.total || 0
if (list.value.length >= total.value || rows.length < pageSize) finished.value = true
else page.value += 1
} catch (e) {
uni.showToast({ title: e.message || '加载失败', icon: 'none' })
} finally {
loading.value = false
}
}
const switchTab = (key) => {
if (activeTab.value === key) return
activeTab.value = key
loadList(true)
}
onShow(() => loadList(true))
onReachBottom(() => loadList(false))
</script>
<template>
<view class="mp-page mp-page--sub">
<view class="mp-header">
<text class="mp-subpage-back" @click="goBack">← 工作台</text>
<text class="mp-header__title" style="margin-top: 16rpx">客户管理</text>
<view class="mp-header__search">
<view class="mp-header__search-dot" />
<input
v-model="keyword"
class="mp-header__search-input"
placeholder="搜索客户名称"
confirm-type="search"
@confirm="loadList(true)"
/>
</view>
</view>
<view class="mp-section" style="padding-bottom: 0">
<scroll-view scroll-x class="mp-tabs">
<view
v-for="t in tabs"
:key="t.key"
class="mp-tab"
:class="{ 'mp-tab--active': activeTab === t.key }"
@click="switchTab(t.key)"
>
{{ t.label }}
</view>
</scroll-view>
</view>
<view class="mp-section">
<mp-empty v-if="!list.length && !loading" title="暂无客户" />
<view v-else class="mp-list">
<view v-for="row in list" :key="row.id" class="mp-card" @click="goDetail(row)">
<view class="mp-card__head">
<view>
<text class="mp-card__title">{{ dash(row.customerName) }}</text>
<text class="mp-card__sub">{{ dash(row.customerNo) }}</text>
</view>
<text class="mp-tag" :class="'mp-tag--' + statusLabel(row.status).tag">
{{ statusLabel(row.status).text }}
</text>
</view>
<view class="mp-card__row">
<text>级别</text>
<text class="mp-card__row-val">{{ levelLabel(row.level).text }}</text>
</view>
<view class="mp-card__row">
<text>联系人</text>
<text class="mp-card__row-val">{{ dash(row.contactName || row.mobile) }}</text>
</view>
<view class="mp-card__row">
<text>负责人</text>
<text class="mp-card__row-val">{{ dash(row.ownerUserName) }}</text>
</view>
</view>
</view>
<view v-if="loading" class="mp-list-loading">加载中…</view>
<view v-else-if="finished && list.length" class="mp-list-end">已加载全部</view>
</view>
</view>
</template>