fast.vue 8.36 KB
<template>
	<view class="main">
		<view class="u-f u-f-aic common plr-10">
			<view class="u-f1 require">
				容器号
			</view>
			<view class="u-f3 inp">
				<input placeholder="请输入" v-model="receiptContainerCode" />
			</view>
		</view>
		<view class="select-material plr-10" @tap="selectMaterial">
			<view class="fl">
				物料
			</view>
			<view class="select fr u-f u-f-aic">
				<text class="set-color">点击选择物料</text>
				<uni-icons type="arrowright" size="18" color="gray"></uni-icons>
			</view>
		</view>
		<view class="select-content">
			<view class="select-list u-f u-f-jcsb u-f-aic plr-10" v-for="(item,index) in materialList" :key="index"
				@tap="showPop(item)">
				<view class="left-content">
					<view class="name">
						{{item.name}}
					</view>
					<view class="code">
						编号:{{item.code}}
					</view>
					<view class="total">
						数量:{{item.qty}}
					</view>
				</view>
				<view class="spec u-f u-f-aic">
					<text class="model">型号:{{item.spec}}123</text>
					<uni-icons type="arrowright" size="18" color="gray"></uni-icons>
				</view>
			</view>
		</view>
		<view class="footer">
			<view class="plr-10 u-f u-f-aic u-f-jcsb">
				<view>
					数量:<text class="total">{{selectTotal}}</text>
				</view>
				<view class="btn u-f u-f-aic" @tap="submit">
					<button hover-class="none" :loading="loading" type="primary" size="mini"
						:disabled="disabled">保存</button>
				</view>
			</view>
		</view>
		<uni-popup ref="popup" type="bottom">
			<view class="pop-box">
				<view class="pop-title u-f u-f-jcsb u-f-aic plr-10">
					<view>
						编辑明细
					</view>
					<view @tap="clearCart" class="u-f u-f-aic">
						<uni-icons type="close" size="17"></uni-icons>
						<text class="clear">关闭</text>
					</view>
				</view>
				<view class="pop-content" @touchmove.stop.prevent>
					<view class="pop-content-box u-f u-f-jcsb u-f-aic plr-10">
						<view>
							<view class="name">
								{{detailInfo.name}}
							</view>
							<view class="code">
								编号:{{detailInfo.code}}
							</view>
							<view class="model">
								型号:{{detailInfo.spec}}
							</view>
						</view>
						<view>
							<uni-number-box :min="1" :value="detailInfo.qty" @change="getQty"></uni-number-box>
						</view>
					</view>
				</view>
				<view class="pop-footer u-f u-f-aic">
					<button hover-class="none" type="default" plain class="delBtn" @tap="detailDel">删除</button>
					<button hover-class="none" type="primary" class="saveBtn" @tap="detailSave">保存</button>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				receiptContainerCode: '',
				materialList: [],
				selectTotal: 0,
				detailInfo: {},
				materialQty: null,
				timer: null,
				loading: false,
				disabled: false
			}
		},
		onLoad() {
			uni.$on('materialSelectData', (data) => {

				this.materialList = this.materialList.concat(data.data);
				this.materialList = this.unique(this.materialList);
				this.selectTotal = this.materialList.reduce((total, item) => total + item.qty, 0);
			});
		},
		onUnload() {
			uni.$off('materialSelectData');
			if (this.timer) {
				clearTimeout(this.timer);
				this.timer = null;
			}
		},
		methods: {
			selectMaterial() {
				uni.navigateTo({
					url: '../material/select'
				})
			},
			showPop(item) {

				this.detailInfo = item;
				this.$refs.popup.open();
			},
			clearCart() {
				this.$refs.popup.close();
			},
			getQty(value) {
				this.materialQty = value;
			},
			detailDel() {
				this.$refs.popup.close();
				this.materialList.forEach(item => {
					if (item.code == this.detailInfo.code) {
						this.materialList.splice(this.materialList.indexOf(item), 1)
					}
				});
				this.selectTotal = this.materialList.reduce((total, item) => total + item.qty, 0);
			},
			detailSave() {
				this.$refs.popup.close();
				this.materialList.forEach(item => {
					if (item.code == this.detailInfo.code) {
						item.qty = parseInt(this.materialQty)
					}
				});
				this.selectTotal = this.materialList.reduce((total, item) => total + item.qty, 0);
			},
			submit() {
				if (!this.receiptContainerCode.trim()) {
					uni.showModal({
						title: '提示',
						content: '请输入容器号!',
						showCancel: false
					});
					return;
				}
				if (this.materialList.length == 0) {
					uni.showModal({
						title: '提示',
						content: '请选择物料!',
						showCancel: false
					});
					return;
				}
				let params = this.materialList.map(item => ({
					receiptContainerCode: this.receiptContainerCode,
					receiptDetailId: item.id,
					companyCode: item.companyCode,
					materialCode: item.code,
					materialName: item.name,
					qty: item.qty
				}));
				this.loading = true;
				this.disabled = true;
				this.$api.receipt.quickReceipt(params).then(res => {
					if (res.data.code == 200) {
						this.$wx.showToast({
							title: '保存成功!'
						});

						this.timer = setTimeout(() => {
							uni.redirectTo({
								url: 'fast?empty'
							});
							this.loading = false;
							this.disabled = false;
						}, 400);

					} else {
						uni.showModal({
							title: '提示',
							content: res.data.msg
						});
						this.loading = false;
						this.disabled = false;
					}
				}).catch(err => {
					this.loading = false;
					this.disabled = false;
				})

			}
		}
	}
</script>

<style lang="scss" scoped>
	.main {
		overflow-y: auto;
		padding-bottom: 100rpx;

		.common {
			height: 90rpx;
			font-size: $uni-font-size-lg;
			background-color: $uni-bg-color;
			border-bottom: 2rpx solid $uni-border-color;

			.inp {
				text-align: right;
			}

			.require {
				position: relative;

				&::after {
					position: absolute;
					content: '*';
					color: red;
					font-size: 50rpx;
					top: 0;
					left: -18rpx;
				}
			}
		}

		.select-material {
			height: 90rpx;
			line-height: 90rpx;
			margin-top: $uni-spacing-col-base;
			background-color: $uni-bg-color;
			font-size: 32rpx;
			border-bottom: 2rpx solid $uni-border-color;

			.select {
				.set-color {
					color: $uni-color-primary;
				}

				.uni-icons {
					width: 30rpx;
				}
			}
		}

		.select-content {
			.select-list {
				height: 170rpx;
				background-color: $uni-bg-color;
				border-bottom: 2rpx solid $uni-border-color;

				.left-content {
					.name {
						font-size: $uni-font-size-lg;
						font-weight: bold;
					}

					.code,
					.total {
						margin-top: $uni-spacing-col-sm;
					}

					.code {

						color: $uni-text-color-gray;
					}

					.total {

						color: $uni-color-primary;
					}
				}

				.spec {
					color: $uni-text-color-gray;

					// .uni-icons {
					//     margin-right: -5px;
					// }
					.model {
						margin-right: $uni-spacing-row-sm;
					}
				}
			}
		}

		.footer {
			position: fixed;
			width: 100%;
			bottom: 0;
			height: 100rpx;
			line-height: 100rpx;
			border-top: 2rpx solid $uni-border-color;
			background-color: $uni-bg-color;

			.total {
				color: $uni-color-primary;
			}

			.btn {
				uni-button {
					display: flex;
					justify-content: center;
					align-items: center;
					width: 220rpx;
					font-size: 32rpx;
					border-radius: $uni-border-radius-lg;

					&:after {
						border: none;
					}
				}
			}
		}

		.pop-box {
			position: relative;
			background-color: $uni-bg-color-grey;
			height: 800rpx;

			.pop-title {
				height: 80rpx;

				.clear {
					margin-left: 4rpx;
				}
			}

			.pop-content {
				.pop-content-box {
					height: 170rpx;
					background-color: $uni-bg-color;
					border-bottom: 2rpx solid $uni-border-color;


					.name {
						font-size: $uni-font-size-lg;
						font-weight: bold;
					}

					.code,
					.model {
						margin-top: $uni-spacing-col-sm;
					}

					/deep/ .uni-numbox {
						height: 60rpx;
						line-height: 60rpx;

						.uni-numbox__minus,
						.uni-numbox__value,
						.uni-numbox__plus {
							height: 60rpx;
							line-height: 60rpx;
						}
					}

				}
			}

			.pop-footer {
				position: absolute;
				width: 100%;
				bottom: 0;
				height: 130rpx;
				border-top: 2rpx solid $uni-border-color;
				border-bottom: 2rpx solid $uni-border-color;
				background-color: $uni-bg-color;

				.delBtn,
				.saveBtn {
					width: 340rpx;
					border-radius: 90rpx !important;
				}

				.delBtn {
					margin-left: $uni-spacing-row-base;
					border-color: $uni-border-color;
				}

				.saveBtn {
					margin-right: $uni-spacing-row-base;
				}
			}
		}
	}
</style>