index.vue 6.4 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/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">
						<view class="card-header">
							<text class="title omit2">{{ item.projectName || '-' }}</text>
						</view>
						<view class="info-row">
							<text>项目编号</text><text>{{ item.projectCode || '-' }}</text>
						</view>
						<view class="info-row">
							<text>品种</text><text>{{ item.productName || '-' }}</text>
						</view>
						<view class="info-row">
							<text>供应商名称</text><text>{{ item.supplierName || '-' }}</text>
						</view>
						<view class="info-row">
							<text>价格</text><text>{{ item.price != null ? item.price : '-' }}</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.projectCode" placeholder="请输入项目编号" :inputBorder="true" />
					</view>
					<view class="form-item">
						<view class="label">供应商名称</view>
						<uni-easyinput v-model="model.supplierName" placeholder="请输入供应商名称" :inputBorder="true" />
					</view>
				</view>
			</template>
		</filter-modal>
	</view>
</template>

<script>
import CardList from '@/components/card/index.vue'
import FilterModal from '@/components/filter/index.vue'
import { supplierQuotationDealQueryApi } from '@/api/procure-manage/supplierQuotationDeal.js'

export default {
	name: 'QuoteManageList',
	components: { CardList, FilterModal },
	data() {
		return {
			searchKeyword: '',
			searchKeywordDebounced: '',
			searchDebounceTimer: null,
			query: {
				projectName: '',
				projectCode: '',
				supplierName: ''
			},
			extraParams: {},
			currentItems: [],
			filterVisible: false,
			filterForm: {
				projectCode: '',
				supplierName: ''
			}
		}
	},
	watch: {
		searchKeywordDebounced(v) {
			this.query = { ...this.query, projectName: v || '' }
		}
	},
	onShow() {
		let needRefresh = ''
		try { needRefresh = uni.getStorageSync('QUOTE_MANAGE_LIST_NEED_REFRESH') } catch (e) {}
		if (!needRefresh) return
		try { uni.removeStorageSync('QUOTE_MANAGE_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: {
		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 = {
				projectCode: this.query.projectCode || '',
				supplierName: this.query.supplierName || ''
			}
			this.filterVisible = true
		},
		onFilterReset(payload) {
			this.filterForm = payload
		},
		onFilterConfirm(payload) {
			this.query = {
				projectName: this.query.projectName || '',
				projectCode: payload.projectCode || '',
				supplierName: payload.supplierName || ''
			}
		},
		fetchList({ pageIndex, pageSize, query }) {
			const q = query || {}
			const params = {
				pageIndex,
				pageSize,
				projectName: q.projectName || '',
				projectCode: q.projectCode || '',
				supplierName: q.supplierName || ''
			}
			return supplierQuotationDealQueryApi(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 }
			})
		}
	}
}
</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;
		}
	}

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