index.vue 9.69 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485
<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, selected }">
					<view class="card" @click.stop="onCardClick(item)">
						<view class="card-header">
							<text class="title omit2">{{ item.deptName }}</text>
							<text :class="['status', `status_${item.status}`]">{{ filterStatus(item.status) }}</text>
						</view>
						<view class="info-row">
							<text>申请日期</text><text>{{ item.applyDate || '-' }}</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.status" @change="onStatusChange" :localdata="statusLocal" />
					</view>
					<view class="form-item">
						<view class="label">申请日期</view>
						<uni-datetime-picker type="daterange" v-model="model.dateRange" start="2023-01-01"
							@change="onDateChange($event, model)" />
					</view>
				</view>
			</template>
		</filter-modal>
	</view>
</template>

<script>
import CardList from '@/components/card/index.vue'
import FilterModal from '@/components/filter/index.vue'
import SingleSelectSheet from '@/components/single-select/index.vue'
import {
	queryApi
} from '@/api/delay_invoice.js'
import {
	getDicByCodes
} from '@/utils/dic'

export default {
	components: {
		CardList,
		FilterModal,
		SingleSelectSheet
	},
	data() {
		return {
			searchKeyword: '',
			searchKeywordDebounced: '',
			tabs: [],
			// 给到 card 的筛选值
			query: {
				status: '',
				dateRange: []
			},
			extraParams: {},

			// 批量选择
			rowKey: 'id',
			currentItems: [],

			// 筛选弹框
			filterVisible: false,
			filterForm: {
				status: '',
				dateRange: []
			},
			dicOptions: {
				AUDIT_STATUS: [],
			},
			statusLocal: [],
		}
	},
	computed: {
		extraCombined() {
			return {
				deptName: this.searchKeywordDebounced || undefined
			}
		}
	},
	watch: {
		extraCombined: {
			deep: true,
			handler(v) {
				this.extraParams = v
			},
			immediate: true
		},

	},
	created() {
		this.loadAllDicData()
	},
	onLoad() { },
	// 页面触底兜底:当页面自身滚动到底部时,转调卡片组件加载更多
	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'
			})
		},
		// 输入实时搜索:1200ms 防抖,仅在停止输入超过阈值后刷新
		onSearchInput(val) {
			if (this.searchDebounceTimer) clearTimeout(this.searchDebounceTimer)
			this.searchDebounceTimer = setTimeout(() => {
				this.searchKeywordDebounced = this.searchKeyword
				this.searchDebounceTimer = null
			}, 1200)
		},
		// uni-search-bar 确认搜索:更新关键字并触发 CardList 刷新
		search(e) {
			const val = e && e.value != null ? e.value : this.searchKeyword
			this.searchKeyword = val
			this.searchKeywordDebounced = val
		},
		onAdd() {
			uni.navigateTo({
				url: '/pages/replenishment_order/add'
			})
		},
		openFilter() {
			this.filterVisible = true
		},
		onFilterReset(payload) {
			this.filterForm = payload
		},
		onFilterConfirm(payload) {
			if ((payload.status === '' || payload.status == null) && this.filterForm.status !== '') {
				payload.status = this.filterForm.status
			}
			this.query = {
				...payload
			}
		},
		onStatusChange(e) {
			const raw = e && e.detail && e.detail.value !== undefined ?
				e.detail.value :
				(e && e.value !== undefined ? e.value : '')
			this.filterForm.status = raw
		},

		onDateChange(e, model) {
			// 确保同步更新 filterForm,避免数据不同步
			this.filterForm.dateRange = e
		},

		// 列表接口(真实请求)
		fetchList({
			pageIndex,
			pageSize,
			query,
			extra
		}) {
			const params = {
				pageIndex,
				pageSize,
				...extra,
				...query
			}
			if (Array.isArray(params.dateRange) && params.dateRange.length === 2) {
				params.applyDateStart = params.dateRange[0]
				params.applyDateEnd = params.dateRange[1]
				delete params.dateRange
			}
			if (this.searchKeywordDebounced) {
				params.deptName = this.searchKeywordDebounced
			}
			return queryApi(params)
				.then(res => {
					const _data = res.data || {};
					const records = _data.datas || [];
					const totalCount = _data.totalCount || 0;
					const hasNext = _data.hasNext || false
					return {
						records,
						totalCount,
						hasNext
					}
				})
				.catch(err => {
					console.error('fetchList error', err)
					this.onCardError()
					return {
						records: [],
						totalCount: 0,
						hasNext: false
					}
				})
		},
		loadAllDicData() {
			const dicCodes = ['AUDIT_STATUS']
			return getDicByCodes(dicCodes).then(results => {
				this.dicOptions.AUDIT_STATUS = results.AUDIT_STATUS.data || []
				this.statusLocal = (this.dicOptions.AUDIT_STATUS || []).map(it => ({
					value: it.code,
					text: it.name
				}))
			}).catch(() => {
				this.dicOptions = {
					AUDIT_STATUS: [],
				}
				this.statusLocal = []
			})
		},
		onCardClick(item) {
			const id = (item && (item.id || item.code)) || ''
			if (!id) return
			const query = '?id=' + encodeURIComponent(id)
			uni.navigateTo({
				url: '/pages/delay_invoice/detail' + query
			})
		},
		filterStatus(status) {
			return this.statusLocal.filter(item => item.value === status)[0].text || '';
		},
	}
}
</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;
			}
		}
	}

}

/* 仅当前页覆盖 uni-search-bar 盒子高度 */
::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;

	&.pad-batch {
		padding-bottom: 144rpx;
	}

	.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 {
			font-weight: 600;
			position: absolute;
			top: -32rpx;
			right: -12rpx;
			height: 48rpx;
			line-height: 48rpx;
			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.6);
			}

		}

	}

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

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

		text {
			width: 60%;
			line-height: 32rpx;

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

			&.category {
				display: inline-block;
				padding: 4rpx 12rpx;
				border-radius: 6rpx;
				font-size: 24rpx;
				width: auto;

				&.category_A {
					background: #FFF0ED;
					color: #D54941;
				}

				&.category_B {
					background: #FFF1E9;
					color: #E37318;
				}

				&.category_C {
					background: #F2F3FF;
					color: $theme-primary;
				}

				&.category_D {
					background: #E3F9E9;
					color: #2BA471;
				}
			}
		}

	}
}

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

}

/* 深度覆盖 uni-data-checkbox(mode=tag)内部的 tag 展示与间距 */
::v-deep .filter-form .uni-data-checklist .checklist-group {
	.checklist-box {
		&.is--tag {
			width: 212rpx;
			margin-top: 0;
			margin-bottom: 24rpx;
			margin-right: 24rpx;
			height: 80rpx;
			padding: 0;
			border-radius: 12rpx;
			background-color: #f3f3f3;
			border-color: #f3f3f3;

			&:nth-child(3n) {
				margin-right: 0;
			}

			.checklist-content {
				display: flex;
				justify-content: center;
			}

			.checklist-text {
				color: rgba(0, 0, 0, 0.9);
				font-size: 28rpx;
			}
		}

		&.is-checked {
			background-color: $theme-primary-plain-bg !important;
			border-color: $theme-primary-plain-bg !important;

			.checklist-text {
				color: $theme-primary !important;
			}
		}
	}

}
</style>