index.vue 7.7 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.peerName || '-' }}</text>
						</view>
						<view class="info-row">
							<text>同行品种</text><text>{{ item.peerProductName || '-' }}</text>
						</view>
						<view class="info-row">
							<text>同行报价</text><text>{{ item.peerPrice != null ? item.peerPrice : '-' }}</text>
						</view>
						<view class="info-row">
							<text>创建人</text><text>{{ item.createBy || '-' }}</text>
						</view>
						<view class="info-row">
							<text>创建时间</text><text>{{ formatDateTime(item.createTime) }}</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-easyinput v-model="model.peerName" placeholder="请输入同行名称" :inputBorder="false"
							placeholderStyle="font-size:14px" @input="onPeerNameInput" />
					</view>
					<view class="form-item">
						<view class="label">同行品种名称</view>
						<uni-easyinput v-model="model.peerProductName" placeholder="请输入同行品种名称" :inputBorder="false"
							placeholderStyle="font-size:14px" @input="onPeerProductNameInput" />
					</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'
import { salesmanQuotationPeerQueryApi } from '@/api/procure-manage/salesmanQuotationPeer.js'

export default {
	name: 'PeerInfoList',
	components: { CardList, FilterModal },
	data() {
		return {
			searchKeyword: '',
			searchKeywordDebounced: '',
			searchDebounceTimer: null,
			query: {
				peerName: '',
				peerProductName: '',
				dateRange: []
			},
			extraParams: {},
			currentItems: [],
			filterVisible: false,
			filterForm: {
				peerName: '',
				peerProductName: '',
				dateRange: []
			}
		}
	},
	watch: {
		searchKeywordDebounced(v) {
			this.query = { ...this.query, peerName: v || '' }
		}
	},
	onShow() {
		let needRefresh = ''
		try { needRefresh = uni.getStorageSync('PEER_INFO_LIST_NEED_REFRESH') } catch (e) {}
		if (!needRefresh) return
		try { uni.removeStorageSync('PEER_INFO_LIST_NEED_REFRESH') } catch (e) {}
		if (this.$refs && this.$refs.cardRef && this.$refs.cardRef.reload) {
			this.$refs.cardRef.reload()
		}
	},
	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: {
		formatDateTime(v) {
			const s = v == null ? '' : String(v).trim()
			if (!s) return '-'
			if (s.length >= 16) return s.slice(0, 16)
			if (s.length >= 10) return s.slice(0, 10)
			return s
		},
		onAdd() {
			uni.navigateTo({ url: '/pages/peer-info/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 = {
				peerName: this.query.peerName || '',
				peerProductName: this.query.peerProductName || '',
				dateRange: Array.isArray(this.query.dateRange) ? this.query.dateRange.slice(0) : []
			}
			this.filterVisible = true
		},
		onFilterReset(payload) {
			this.filterForm = payload
		},
		onFilterConfirm(payload) {
			this.query = {
				peerName: this.searchKeywordDebounced || payload.peerName || '',
				peerProductName: payload.peerProductName || '',
				dateRange: Array.isArray(payload.dateRange) ? payload.dateRange : []
			}
		},
		onPeerNameInput(val) {
			this.filterForm.peerName = val
		},
		onPeerProductNameInput(val) {
			this.filterForm.peerProductName = val
		},
		fetchList({ pageIndex, pageSize, query }) {
			const q = query || {}
			const range = Array.isArray(q.dateRange) ? q.dateRange : []
			const params = {
				pageIndex,
				pageSize,
				peerName: q.peerName || '',
				peerProductName: q.peerProductName || '',
				createDateStart: (range && range.length === 2) ? range[0] : '',
				createDateEnd: (range && range.length === 2) ? range[1] : ''
			}
			return salesmanQuotationPeerQueryApi(params).then(res => {
				const _data = res && res.data ? res.data : {}
				let records = _data.datas || _data.list || _data.records || []
				const totalCount = _data.totalCount || _data.count || 0
				const hasNext = _data.hasNext || false
				records = records.map(it => ({ ...it }))
				return { records, totalCount, hasNext }
			}).catch(() => {
				this.onCardError()
				return { records: [], totalCount: 0, hasNext: false }
			})
		},
		onCardClick(item) {
			uni.navigateTo({ url: '/pages/peer-info/detail?id=' + item.id })
		}
	}
}
</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: 100%;
		}
	}

	.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;
	}

	.uni-easyinput {
		border: 1rpx solid #f3f3f3;
	}
}
</style>