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

141 lines
4.3 KiB
Vue

<script setup>
import { ref } from 'vue'
import { onShow, onReachBottom } from '@dcloudio/uni-app'
import { listContract } from '@/api/crm'
import { labelOf, dash, formatMoney } from '@/utils/crmLabels'
import { PAGE_PATHS } from '@/config/api'
const tabs = [
{ key: 'all', label: '全部' },
{ key: 'draft', label: '草稿', status: 'draft' },
{ key: 'pending', label: '待审批', status: 'pending' },
{ key: 'approved', label: '已生效', status: 'approved' },
{ key: 'executing', label: '执行中', status: 'executing' }
]
const activeTab = ref('all')
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.crmContractDetail}?id=${row.id}` })
}
const statusLabel = (s) => labelOf('contractStatus', 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 tab = tabs.find((t) => t.key === activeTab.value)
const query = {
pageNum: page.value,
pageSize,
contractName: keyword.value.trim() || undefined,
customerName: keyword.value.trim() || undefined
}
if (tab?.status) query.status = tab.status
const res = await listContract(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.contractName) }}</text>
<text class="mp-card__sub">{{ dash(row.contractNo) }} · {{ dash(row.customerName) }}</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">{{ formatMoney(row.totalAmount ?? row.amount) }}</text>
</view>
<view class="mp-card__row">
<text>负责人</text>
<text class="mp-card__row-val">{{ dash(row.ownerUserName) }}</text>
</view>
<view class="mp-card__row">
<text>签订日期</text>
<text class="mp-card__row-val">{{ dash(row.signDate) }}</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>