detail.vue 6.75 KB
<template>
	<view>
		<view class="content">
			<view class="top">
				<view class="common u-f u-f-jcsb plr-10">
					<view>
						物料名称
					</view>
					<view>
						{{detailInfo.name}}
					</view>
				</view>
				<view class="common u-f u-f-jcsb plr-10">
					<view>
						物料编码
					</view>
					<view>
						{{detailInfo.code}}
					</view>
				</view>
				<view class="common u-f u-f-jcsb plr-10">
					<view>
						物料分类
					</view>
					<view>
						{{materialTypeFormat(detailInfo.type)}}
					</view>
				</view>
				<view class="common u-f u-f-jcsb plr-10">
					<view>
						规格型号
					</view>
					<view>
						{{detailInfo.spec}}
					</view>
				</view>
				<view class="common u-f u-f-jcsb plr-10">
					<view>
						单位
					</view>
					<view>
						{{detailInfo.unit}}
					</view>
				</view>
				<view class="common u-f u-f-jcsb plr-10">
					<view>
						货主
					</view>
					<view>
						{{companyCodeFormat(detailInfo.companyCode)}}
					</view>
				</view>
			</view>
			
			<view class="bottom">
				<view class="common u-f u-f-jcsb plr-10">
					<view>
						自动生成序列号
					</view>
					<view>
						{{isAutoFormat(detailInfo.autoGenSerialNum)}}
					</view>
				</view>
				<view class="common u-f u-f-jcsb plr-10">
					<view>
						保质期
					</view>
					<view>
						{{detailInfo.daysToExpire}}天
					</view>
				</view>
				<view class="common u-f u-f-jcsb plr-10">
					<view>
						状态
					</view>
					<view>
						{{enableFormat(detailInfo.enable)}}
					</view>
				</view>
				<view class="common u-f u-f-jcsb plr-10">
					<view>
						是否允许混放
					</view>
					<view>
						{{isMixFormat(detailInfo.isMix)}}
					</view>
				</view>
				<view class="common u-f u-f-jcsb plr-10">
					<view>
						收货预警天数
					</view>
					<view>
						{{detailInfo.minShelfLifeDays}}天
					</view>
				</view>
				<view class="common u-f u-f-jcsb plr-10">
					<view>
						记录序列号
					</view>
					<view>
						{{detailInfo.trackSerialNum}}
					</view>
				</view>
				<view class="common u-f u-f-jcsb plr-10">
					<view>
						数据版本
					</view>
					<view>
						{{detailInfo.version}}
					</view>
				</view>
				<view class="common u-f u-f-jcsb plr-10">
					<view>
						仓库
					</view>
					<view>
						{{warehouseCodeFormat(detailInfo.warehouseCode)}}
					</view>
				</view>
			</view>
			
		</view>
		<view class="footer u-f u-f-aic">
			<button type="default" size="mini" plain class="delBtn" @tap="delMaterial(detailInfo.id,index)">
				<uni-icons type="trash" size="14"></uni-icons>删除
			</button>
			<button type="default" size="mini" plain class="saveBtn" @tap="goEdit(detailInfo.id,index)">
				<uni-icons type="compose" size="14"></uni-icons>修改
			</button>
		</view>
	</view>

</template>

<script>
	export default {
		data() {
			return {
				detailInfo: {},
				companyArr: [],
				warehouseArr: [],
				enableArr: [],
				materialTypeArr: [],
				mixArr: [],
				serialNumArr: [],
				timer: null,
				index: null
			}
		},
		onBackPress(e){
					this.$prePage(2).handleEdit(this.index,this.detailInfo);	
		},
		onLoad(option) {
			this.index = option.index;
			this.getMaterial(option.id);
			this.$http.dict.getCompaniesByToken().then(res => {
				console.log(res);
				this.companyArr = res.data
			});
			this.getDicts("autoGenSerialNum").then(res => {
				this.serialNumArr = res.data.data;
			});
			this.getDicts("enable").then(res => {
				console.log(res)
				this.enableArr = res.data.data;
			});
			this.$http.material.getMaterialType().then(res => {
				console.log(res);
				this.materialTypeArr = res.data.data
			});
			try {
			    const value = uni.getStorageSync('historyUser').username;
			    if (value) {
			       this.$http.dict.getWarehouseByUserCode(value).then(res => {
			       	this.warehouseArr = res.data.data
			       });
			    }
			} catch (e) {
			    // error
			}
			
			this.getDicts("isMix").then(res => {
				console.log(res)
				this.mixArr = res.data.data;
			});
			uni.$on('editUpdateMaterial',() => {
				this.getMaterial(option.id)
			})
		},

		onUnload() {
			if(this.timer) {
				clearTimeout(this.timer);  
				this.timer = null;  
			}  
		},
		methods: {
			// 获取物料详情
			getMaterial(id) {
				this.$http.material.getCurrMaterial(id).then(res => {
					if (res.data.code == 200) {
						this.detailInfo = res.data.data;
					}
				});
			},
			// 货主字典翻译
			companyCodeFormat(companyCode) {
				return this.selectCommonLabel(this.companyArr, companyCode);
			},
			// 仓库字典翻译
			warehouseCodeFormat(warehouseCode) {
				return this.selectCommonLabel(this.warehouseArr, warehouseCode);
			},
			// 自动生成序列号字典翻译
			isAutoFormat(autoGenSerialNum) {
				return this.selectDictLabel(this.serialNumArr, autoGenSerialNum);
			},
			// 是否有效字典翻译
			enableFormat(enable) {
				return this.selectDictLabel(this.enableArr, enable);
			},
			// 物料类型字典翻译
			materialTypeFormat(type) {
				return this.selectCommonLabel(this.materialTypeArr, type);
			},
			// 是否允许混放字典翻译
			isMixFormat(isMix) {
				return this.selectDictLabel(this.mixArr, isMix);
			},
			// 删除按钮操作
			delMaterial(id,index) {
				console.log(id)
				uni.showModal({
					title: '提示',
					content: '确定要删除该物料吗?',
					success: (res) => {
						 if (res.confirm) {
							 this.$http.material.delMaterial(id).then(res => {
								if(res.data.code == 200){
									this.$prePage(2).handleDel(index);
									this.$msg('删除成功!');
									this.timer = setTimeout(() => {
										uni.navigateBack()
									}, 400)
								} else {
									uni.showModal({
									    title: '提示',
									    content: res.data.msg
									});
								}
							 })
					      } else if (res.cancel) {
							  console.log('用户点击取消');
						  }
					}
				});
				
			},
			// 点击修改按钮
			goEdit(id) {
				uni.navigateTo({
					url: 'add-edit?page=detail&type=edit&id='+id
				})
			}
			
		}

	}
</script>

<style lang="scss" scoped>
		.content {
			overflow-y: auto;
			padding-bottom: 100rpx;
			
			.top,.bottom {
				background-color: $uni-bg-color;
				.common {
					height: 90rpx;
					line-height: 90rpx;
					font-size: $uni-font-size-lg;
					border-bottom: 2rpx solid $uni-border-color;
				}
				
			}
			.bottom {
				margin: $uni-spacing-col-base 0;
			}
		
		}
		
		.footer {
			position: fixed;
			width: 100%;
			bottom: 0;
			height: 100rpx;
			border-top: 2rpx solid $uni-border-color;
			border-bottom: 2rpx solid $uni-border-color;
			background-color: $uni-bg-color;
		
			.delBtn,
			.saveBtn {
				width: 320rpx;
				border-radius: 90rpx !important;
				margin-left: $uni-spacing-row-base;
				border-color: $uni-border-color;
			}
		
		}
	
	
</style>