index.vue 9.59 KB
<template>
	<view class="page">
		<view class="dev-list-fixed">
			<view class="search-row">
				<uni-search-bar v-model="searchKeyword" radius="6" placeholder="请输入单位名称" clearButton="auto"
					cancelButton="none" bgColor="#F3F3F3" textColor="rgba(0,0,0,0.4)" @confirm="search"
					@input="onSearchInput" />
				<view class="tool-icons">
                    <image class="tool-icon" src="/static/images/dev_manage/add_icon.png" @click="onAdd" />
					<image class="tool-icon" src="/static/images/dev_manage/filter_icon.png" @click="openFilter" />
				</view>
			</view>
		</view>

		<view class="list-box">
			<card-list ref="cardRef" :fetch-fn="fetchList" :query="query" :extra="extraParams" row-key="id"
				:enable-refresh="true" :enable-load-more="true" @loaded="onCardLoaded" @error="onCardError">
				<template v-slot="{ item }">
					<view class="card" @click.stop="onCardClick(item)">
						<view class="card-header">
							<text class="title omit2">{{ item.companyName || '-' }}</text>
							<text :class="['status', `status_${item.auditStatus}`]">{{ getAuditStatusText(item.auditStatus) }}</text>
						</view>
						<view class="info-row">
							<text>公司性质</text><text>{{ item.companyNature || '-' }}</text>
						</view>
						<view class="info-row">
							<text>电话</text><text>{{ item.phone || '-' }}</text>
						</view>
						<view class="info-row">
						<text>业务负责人</text><text>{{ item.businessOwner || '-' }}</text>
					</view>
					<view class="info-row">
							<text>创建日期</text><text>{{ item.createDate || '-' }}</text>
						</view>
					</view>
				</template>
			</card-list>
		</view>

		<filter-modal :visible.sync="filterVisible" :value.sync="filterForm" title="筛选" @reset="onFilterReset"
			@confirm="onFilterConfirm">
			<template v-slot="{ model }">
				<view class="filter-form">
					<view class="form-item">
						<view class="label">审核状态</view>
						<uni-data-checkbox mode="tag" :multiple="false" :value-field="'value'" :text-field="'text'"
							v-model="model.auditStatus" @change="onAuditStatusChange" :localdata="auditStatusOptions" />
					</view>
					<view class="form-item">
						<view class="label">登记日期</view>
						<uni-datetime-picker type="daterange" v-model="model.dateRange" start="2023-01-01" />
					</view>
				</view>
			</template>
		</filter-modal>
	</view>
</template>

<script>
import CardList from '@/components/card/index.vue'
import FilterModal from '@/components/filter/index.vue'

export default {
	name: 'DomesticTradeList',
	components: { CardList, FilterModal },
	data() {
		return {
			searchKeyword: '',
			searchKeywordDebounced: '',
			searchDebounceTimer: null,
			query: {
				companyName: '',
				auditStatus: '',
				dateRange: []
			},
			extraParams: {},
			currentItems: [],
			filterVisible: false,
			filterForm: {
				auditStatus: '',
				dateRange: []
			},
			auditStatusOptions: [
				{ value: '', text: '全部' },
				{ value: 'AUDIT', text: '审核中' },
				{ value: 'PASS', text: '通过' },
				{ value: 'REFUSE', text: '驳回' },
				{ value: 'CANCEL', text: '已取消' }
			],
			mockAll: []
		}
	},
	watch: {
		searchKeywordDebounced(v) {
			this.query = { ...this.query, companyName: v || '' }
		}
	},
	created() {
		this.mockAll = this.buildMockList(60)
	},
	onReachBottom() {
		if (this.$refs && this.$refs.cardRef && this.$refs.cardRef.onLoadMore) {
			this.$refs.cardRef.onLoadMore()
		}
	},
	beforeDestroy() {
		if (this.searchDebounceTimer) {
			clearTimeout(this.searchDebounceTimer)
			this.searchDebounceTimer = null
		}
	},
	methods: {
        onAdd() {
            uni.navigateTo({ url: '/pages/domestic_trade/add' })
        },
		onCardLoaded({ items }) {
			this.currentItems = items
		},
		onCardError() {
			uni.showToast({ title: '列表加载失败', icon: 'none' })
		},
		onSearchInput() {
			if (this.searchDebounceTimer) clearTimeout(this.searchDebounceTimer)
			this.searchDebounceTimer = setTimeout(() => {
				this.searchKeywordDebounced = this.searchKeyword
				this.searchDebounceTimer = null
			}, 1200)
		},
		search(e) {
			const val = e && e.value != null ? e.value : this.searchKeyword
			this.searchKeyword = val
			this.searchKeywordDebounced = val
		},
		openFilter() {
			this.filterForm = {
				auditStatus: this.query.auditStatus || '',
				dateRange: Array.isArray(this.query.dateRange) ? this.query.dateRange.slice(0) : []
			}
			this.filterVisible = true
		},
		onFilterReset(payload) {
			this.filterForm = payload
		},
		onFilterConfirm(payload) {
			this.query = {
				companyName: this.query.companyName || '',
				auditStatus: payload.auditStatus || '',
				dateRange: Array.isArray(payload.dateRange) ? payload.dateRange : []
			}
		},
		onAuditStatusChange(e) {
			const raw = e && e.detail && e.detail.value !== undefined ? e.detail.value : (e && e.value !== undefined ? e.value : '')
			this.filterForm.auditStatus = raw
		},
		getAuditStatusText(status) {
			const found = (this.auditStatusOptions || []).find(it => it.value === status)
			return found ? found.text : (status || '-')
		},
		fetchList({ pageIndex, pageSize, query }) {
			const listAll = Array.isArray(this.mockAll) ? this.mockAll : []
			const q = query || {}
			const name = (q.companyName || '').trim()
			const status = q.auditStatus || ''
			const range = Array.isArray(q.dateRange) ? q.dateRange : []
			const start = range && range.length === 2 ? range[0] : ''
			const end = range && range.length === 2 ? range[1] : ''

			let filtered = listAll.slice(0)
			if (name) {
				const kw = name.toLowerCase()
				filtered = filtered.filter(it => String(it.companyName || '').toLowerCase().includes(kw))
			}
			if (status) {
				filtered = filtered.filter(it => it.auditStatus === status)
			}
			if (start && end) {
				const s = String(start)
				const ed = String(end)
				filtered = filtered.filter(it => {
					const d = String(it.registerDate || it.createDate || '')
					return d >= s && d <= ed
				})
			}

			const totalCount = filtered.length
			const begin = (Number(pageIndex || 1) - 1) * Number(pageSize || 10)
			const endIdx = begin + Number(pageSize || 10)
			const records = filtered.slice(begin, endIdx)
			const hasNext = endIdx < totalCount

			return new Promise(resolve => {
				setTimeout(() => resolve({ records, totalCount, hasNext }), 220)
			})
		},
		onCardClick(item) {
            uni.navigateTo({ url: '/pages/domestic_trade/detail?id=' + item.id })
		},
		buildMockList(count) {
			const n = Number(count || 0)
			const natures = ['民营', '国企', '外资', '合资', '其他']
			const statusPool = ['AUDIT', 'PASS', 'REFUSE', 'CANCEL']
			const baseNames = ['华东', '华南', '华北', '西南', '中原', '海纳', '启航', '远成', '融盛', '天泽']
			const owners = ['张三', '李四', '王五', '赵六', '周七', '吴八', '郑九', '钱十']
			const list = []
			for (let i = 0; i < n; i++) {
				const idx = i + 1
				const companyName = `${baseNames[i % baseNames.length]}商贸有限公司${idx}`
				const auditStatus = statusPool[i % statusPool.length]
				const companyNature = natures[i % natures.length]
				const businessOwner = owners[i % owners.length]
				const phone = this.mockPhone(i)
				const daysAgo = i % 40
				const date = this.formatDate(this.addDays(new Date(), -daysAgo))
				list.push({
					id: String(idx),
					companyName,
					companyNature,
					phone,
					businessOwner,
					auditStatus,
					registerDate: date,
					createDate: date
				})
			}
			return list
		},
		mockPhone(i) {
			const s = String(13000000000 + (i % 900000000))
			return s.slice(0, 11)
		},
		addDays(d, days) {
			const dt = new Date(d.getTime())
			dt.setDate(dt.getDate() + Number(days || 0))
			return dt
		},
		formatDate(d) {
			const y = d.getFullYear()
			const m = String(d.getMonth() + 1).padStart(2, '0')
			const da = String(d.getDate()).padStart(2, '0')
			return `${y}-${m}-${da}`
		}
	}
}
</script>

<style lang="scss" scoped>
.page {
	display: flex;
	flex-direction: column;
	height: 100vh;
}

.dev-list-fixed {
	position: fixed;
	top: 96rpx;
	left: 0;
	right: 0;
	z-index: 2;
	background: #fff;

	.search-row {
		display: flex;
		align-items: center;
		padding: 16rpx 32rpx;

		.uni-searchbar {
			padding: 0;
			flex: 1;
		}

		.tool-icons {
			display: flex;

			.tool-icon {
				width: 48rpx;
				height: 48rpx;
				display: block;
				margin-left: 32rpx;
			}
		}
	}
}

::v-deep .uni-searchbar__box {
	height: 80rpx !important;
	justify-content: start;

	.uni-searchbar__box-search-input {
		font-size: 32rpx !important;
	}
}

.list-box {
	flex: 1;
	padding-top: 140rpx;

	.card {
		position: relative;
	}

	.card-header {
		margin-bottom: 28rpx;
		position: relative;

		.title {
			font-size: 36rpx;
			font-weight: 600;
			line-height: 50rpx;
			color: rgba(0, 0, 0, 0.9);
			width: 578rpx;
		}

		.status {
			position: absolute;
			top: -32rpx;
			right: -12rpx;
			height: 48rpx;
			line-height: 48rpx;
			font-weight: 600;
			color: #fff;
			font-size: 24rpx;
			padding: 0 14rpx;
			border-radius: 6rpx;

			&.status_AUDIT {
				background: $theme-primary;
			}

			&.status_PASS {
				background: #2BA471;
			}

			&.status_REFUSE {
				background: #D54941;
			}

			&.status_CANCEL {
				background: #E7E7E7;
				color: rgba(0, 0, 0, 0.9);
			}
		}
	}

	.info-row {
		display: flex;
		align-items: center;
		color: rgba(0, 0, 0, 0.6);
		font-size: 28rpx;
		margin-bottom: 24rpx;
		height: 32rpx;

		&:last-child {
			margin-bottom: 0;
		}

		text {
			width: 50%;

			&:last-child {
				color: rgba(0, 0, 0, 0.9);
				width: 50%;
			}
		}
	}
}

.filter-form {
	.form-item {
		margin-bottom: 24rpx;
	}

	.label {
		margin-bottom: 20rpx;
		color: rgba(0, 0, 0, 0.9);
		height: 44rpx;
		line-height: 44rpx;
		font-size: 30rpx;
	}
}
</style>