<template>
	<view>
		<view class="cmain">
			<view class="form_group">
				<view class="lable re">海关申报单号</view>
				<input placeholder="请输入" v-model="item.declareOdd" />
			</view>
			<view class="form_group">
				<view class="lable re">商品名称</view>
				<input placeholder="请输入" v-model="item.goodsName" />
			</view>
			<view class="form_group">
				<view class="lable re">商品产地</view>
				<input placeholder="请输入" v-model="item.placeOrigin" />
			</view>
			<view class="form_group">
				<view class="lable re">商品类型</view>
				<picker :range="dict.goodsType" @change="picker($event, 'goodsType')">
					<input placeholder="请选择" v-model="item.goodsType" :disabled="true" />
					<view class="icon more">&#xe8f2;</view>
				</picker>
			</view>
			<view class="form_group">
				<view class="lable re">商品单位</view>
				<picker :range="dict.goodsUnits" @change="picker($event, 'goodsUnits')">
					<input placeholder="请选择" v-model="item.goodsUnits" :disabled="true" />
					<view class="icon more">&#xe8f2;</view>
				</picker>
			</view>
			<view class="form_group">
				<view class="lable re">商品价格</view>
				<input type="number" placeholder="请输入" v-model="item.price" />
				<view class="ops">元</view>
			</view>
			<view class="form_group">
				<view class="lable re">商品数量</view>
				<input type="number" placeholder="请输入" v-model="item.stock" />
				<view class="ops">{{ item.goodsUnits }}</view>
			</view>
			<view class="form_group">
				<view class="lable re">净重</view>
				<input placeholder="请输入" v-model="item.netWeight" />
				<view class="ops">吨</view>
			</view>
			<view class="form_group">
				<view class="lable re">毛重</view>
				<input placeholder="请输入" v-model="item.grossWeight" />
				<view class="ops">吨</view>
			</view>
			<view class="form_group">
				<view class="lable re">商品状态</view>
				<picker :range="dict.goodsStatus" @change="picker($event, 'goodsStatus')">
					<input placeholder="请选择" :value="item.goodsStatus == 1 ? '在售' : '下架'" :disabled="true" />
					<view class="icon more">&#xe8f2;</view>
				</picker>
			</view>
			<view class="form_group">
				<view class="lable re">商品描述</view>
				<textarea v-model="item.description" placeholder="请输入"></textarea>
			</view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			item: {},
			dict: {
				goodsType: ['水果', '药品', '茶叶'],
				goodsUnits: ['吨', '个', '柜'],
				goodsStatus: ['在售', '下架']
			}
		};
	},
	onLoad(e) {
		if (e.id) {
			this.http.request({
				url: '/level-one-server/app/TbGoodsTransit/getById?id=' + e.id,
				success: res => {
					this.item = res.data.data;
					uni.setNavigationBarTitle({ title: '编辑商品' });
				}
			});
		}
	},
	methods: {
		picker(e, tag) {
			this.item[tag] = this.dict[tag][e.detail.value];
			this.$forceUpdate();
		}
	},
	onNavigationBarButtonTap() {
		let rule = [
			{ name: 'goodsName', checkType: 'notnull', errorMsg: '请输入商品名称' },
			{ name: 'placeOrigin', checkType: 'notnull', errorMsg: '请输入商品产地' },
			{ name: 'goodsStatus', checkType: 'notnull', errorMsg: '请选择状态' }
		];
		if (!this.verify.check(this.item, rule)) {
			uni.showModal({ content: this.verify.error, showCancel: false });
			return false;
		}
		this.http.request({
			url: '/level-one-server/app/TbGoodsTransit/transactionGoods',
			method: 'POST',
			data: this.item,
			success: res => {
				uni.showToast({ title: '操作成功' });
				setTimeout(() => {
					uni.$emit('goodsHandle');
					uni.navigateBack();
				}, 1000);
			}
		});
	}
};
</script>

<style lang="scss"></style>
