inventory.vue 9.41 KB
<template>
	<view>
		<view class="search">
			<uni-search-bar @confirm="handleSearch" @clear="handleClear" @input="searchInput" placeholder="输入物料编号"></uni-search-bar>
		</view>
		<view class='inventory-list'>
			<view class="item" v-for="(item,index) in inventoryList" :key="index">
				<view class="u-f u-f-jcsb">
					<view class="name">
						[XXX]{{item.materialName}}
					</view>
					<view class="">
                      <uni-tag text="高" type="warning" size="small"></uni-tag>
                    <!--  <uni-tag text="低" type="error" size="small"></uni-tag> -->
					</view>
				</view>
				<view class="u-f mt-5">
					<view class="u-f1">
						编号:{{item.materialCode}}
					</view>
					<view class="u-f1">
						型号:{{item.materialSpec}}
					</view>
				</view>
				<view class="u-f mt-5">
					<view class="u-f1">
						库位号:{{item.locationCode}}
					</view>
					<view class="u-f1">
						容器号:{{item.containerCode}}
					</view>
				</view>
				<view class="u-f mt-5">
					<view class="u-f1">
						仓库:{{item.warehouseCode}}
					</view>
					<view class="u-f1 qty">
						库存:{{item.qty}}
					</view>
				</view>
			</view>
			<uni-load-more :iconSize="18" :status="loadStatus"></uni-load-more>
		</view>
		
		<uni-drawer mode="right" ref="showDrawer" :width="320">
			<view class="drawer-box" style="overflow: ;">
				<view class="drawer-title">
					筛选
					<view class="close" @tap="closeDrawer">
						<uni-icons type="closeempty" size="25" color="#fff"></uni-icons>
					</view>
				</view>
				<view class="container">
					<view class="container-content">
						<view class="container-item u-f u-f-aic">
							<view class="container-label u-f1">
								物料名称
							</view>
							<view class="container-input u-f2">
								<input class="f-z" type="text" v-model="queryParams.name" placeholder="请输入" />
							</view>
						</view>
						<view class="container-item u-f u-f-aic">
							<view class="container-label u-f1">
								物料规格
							</view>
							<view class="container-input u-f2">
								<input class="f-z" type="text" v-model="queryParams.spec" placeholder="请输入" />
							</view>
						</view>
						<view class="container-item u-f u-f-aic">
							<view class="container-label u-f1">
								物料类别
							</view>
							<view class="container-input u-f2">
								<picker @change="typePickerChange" :value="typeIndex" :range-key="'name'" :range="materialTypeArr">
									<view class="uni-input"><text class="placeholder-color" v-if="typeIndex == -1">请选择</text><text v-else>{{materialTypeArr[typeIndex].name}}</text></view>
								</picker>
							</view>
						</view>
						<view class="container-item u-f u-f-aic">
							<view class="container-label u-f1">
								开始日期
							</view>
							<view class="container-input u-f2">
								<picker mode="date" :value="queryParams.startTime" :start="startDate" :end="endDate" @change="startDateChange">
									<view class="uni-input"><text class="placeholder-color" v-if="!queryParams.startTime">请选择</text><text v-else>{{queryParams.startTime}}</text></view>
								</picker>
							</view>
						</view>
						<view class="container-item u-f u-f-aic">
							<view class="container-label u-f1">
								结束日期
							</view>
							<view class="container-input u-f2">
								<picker mode="date" :value="queryParams.endTime" :start="startDate" :end="endDate" @change="endDateChange">
									<view class="uni-input"><text class="placeholder-color" v-if="!queryParams.endTime">请选择</text><text v-else>{{queryParams.endTime}}</text></view>
								</picker>
							</view>
						</view>
					</view>
				</view>
				<view class="drawer-footer u-f u-f-jcsb">
					<view class="reset u-f1" @tap="handleReset">
						重置
					</view>
					<view class="confirm u-f1" @tap="handleSubmit">
						确定
					</view>
				</view>
			</view>
		</uni-drawer>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				// 查询参数
				queryParams: {
					// code: undefined,
					// name: undefined,
					// spec: undefined,
					// type: undefined,
					// startTime: undefined,
					// endTime: undefined,
					materialCode: undefined,
					pageNum: 1,
					pageSize: 10
				},
				loadStatus: "",
				total: null,
				inventoryList: [],
				materialTypeArr: [],
				typeIndex: -1,
				inputValue: '',
				title:''

			}
		},
		onNavigationBarButtonTap() {
			this.$refs.showDrawer.open()

		},
		computed: {
			startDate() {
				return this.getDate('start');
			},
			endDate() {
				return this.getDate('end');
			}
		},
		onLoad(option) {
			this.title = option.title;
			this.getInventory();
			this.$http.material.getMaterialType().then(res => {
				console.log(res);
				this.materialTypeArr = res.data.data
			});
		
		},
		onReady() {
			if(this.title == 'inventory') {
				uni.setNavigationBarTitle({
				    title: '总库存'
				});
			}else {
				uni.setNavigationBarTitle({
				    title: '库存预警'
				});
			}
		},
		onPullDownRefresh() {
			this.queryParams.code = this.inputValue;
			this.queryParams.pageNum = 1;
			this.getInventory()
		},
		onReachBottom() {
			if (this.queryParams.pageNum >= this.total / 10) {
				this.loadStatus = "noMore";
				return
			}
			this.loadStatus = "loading";
			this.queryParams.pageNum++;
			this.getInventory()
		},
		methods: {
			// 顶部搜索
			handleSearch(e) {
				this.queryParams.pageNum = 1;
				this.queryParams.materialCode = e.value;
				this.getInventory()
			},
			// 清除搜索
			handleClear() {
				this.queryParams.materialCode = undefined;
				this.getMaterial()
			},
			// 搜索输入事件
			searchInput(e) {
				this.inputValue = e.value
			},
			// 获取库存
			getInventory() {
				this.$http.inventory.inventoryDetailList(this.queryParams).then(res => {
					console.log(res);
					if (res.data.code == 200) {
						if (this.queryParams.pageNum > 1) {
							this.inventoryList = this.inventoryList.concat(res.data.rows);
						} else {
							this.inventoryList = res.data.rows
						}
						this.total = res.data.total;
						uni.stopPullDownRefresh();
					} else {
						uni.stopPullDownRefresh();
					}

				})
			},
			// 物料类型字典翻译
			materialTypeFormat(type) {
				return this.selectCommonLabel(this.materialTypeArr, type);
			},
			// 列表点击
			goDetail(id) {
				uni.navigateTo({
					url: 'detail?id=' + id
				});
			},

			// 开始日期选择器点击
			startDateChange: function(e) {
				this.queryParams.startTime = e.target.value
			},
			// 结束日期选择器点击
			endDateChange: function(e) {
				this.queryParams.endTime = e.target.value
			},
			// 选择日期格式化
			getDate(type) {
				const date = new Date();
				let year = date.getFullYear();
				let month = date.getMonth() + 1;
				let day = date.getDate();

				if (type === 'start') {
					year = year - 60;
				} else if (type === 'end') {
					year = year + 2;
				}
				month = month > 9 ? month : '0' + month;;
				day = day > 9 ? day : '0' + day;
				return `${year}-${month}-${day}`;
			},
			// 物料类别选择器点击
			typePickerChange: function(e) {
				this.typeIndex = e.target.value;
				this.queryParams.type = this.materialTypeArr[this.typeIndex].code
			},
			// X点击关闭抽屉
			closeDrawer() {
				this.$refs.showDrawer.close()
			},
			// 筛选重置按钮点击
			handleReset() {
				this.queryParams = {
					code: undefined,
					name: undefined,
					spec: undefined,
					type: undefined,
					startTime: undefined,
					endTime: undefined
				};
				this.typeIndex = -1;
			},
			// 筛选确定按钮点击
			handleSubmit() {
				this.$refs.showDrawer.close();
				this.queryParams.pageNum = 1;
				this.getInventory()
			}
		}

	}
</script>
<style lang='scss' scoped>
	.search {
		position: fixed;
		top: 88rpx;
		width: 100%;
		z-index: 1;

		&::after {
			content: "  ";
			position: absolute;
			left: 0;
			bottom: 0;
			width: 100%;
			height: 2rpx;
			background-color: $uni-border-color;
			transform: scaleY(.5);
		}
	}

	.inventory-list {
		margin-top: 125rpx;
		.item {
			padding: $uni-spacing-row-base;
			margin-top: $uni-spacing-col-base;
			background-color: $uni-bg-color;
		}
		.name {
			font-size: $uni-font-size-lg;
			font-weight: bold;
		}
		.qty {
			color: $uni-color-primary;
		}
	}
	
	

	.drawer-box {
		position: relative;
		height: 100%;

		.drawer-title {
			position: relative;
			height: 88rpx !important;
			line-height: 88rpx;
			text-align: center;
			font-size: $uni-font-size-lg;
			color: $uni-text-color-inverse;
			background-color: $uni-color-primary;

			.close {
				position: absolute;
				top: 0;
				right: $uni-spacing-row-lg;
			}
		}

		.container {
			position: relative;
			padding: 0 $uni-spacing-row-lg;

			.container-content {
				.container-item {
					height: 80rpx;
					border-bottom: 2rpx dashed $uni-border-color;

					.container-input {
						text-align: right;

						.uni-input-placeholder {
							font-size: $uni-font-size-base;
						}

						/deep/.uni-input-input {
							font-size: $uni-font-size-base;
						}

					}
				}
			}

		}

		.drawer-footer {
			position: absolute;
			width: 100%;
			height: 80rpx;
			line-height: 80rpx;
			bottom: 0;
			border-top: 2rpx solid $uni-border-color;

			.reset {
				text-align: center;
				color: $uni-color-primary;
				font-size: $uni-font-size-lg;
			}

			.confirm {
				text-align: center;
				color: $uni-text-color-inverse;
				background-color: $uni-color-primary;
				font-size: $uni-font-size-lg;
			}
		}
	}
</style>