<template>
	<view class="cmain">
		<view class="form_group">
			<view class="lable re">监管商品类型</view>
			<input type="text" placeholder="请输入" v-model="item.id" />
		</view>
		<view class="form_group">
			<view class="lable re">商品名称</view>
			<input type="text" placeholder="请输入" v-model="item.goodsName" />
		</view>
		<view class="form_group">
			<view class="lable re">商品产地</view>
			<input type="text" placeholder="请输入" v-model="item.placeOrigin" />
		</view>
		<view class="form_group">
			<view class="lable re">商品类型</view>
			<picker @change="pickerChangeGoodsTypes" :value="index1" :range="goodsTypes" range-key="label">
				<view >{{goodsTypes[index1].label}}</view>
			</picker>
			<!-- <input type="text" placeholder="请输入" v-model="item.goodsType" /> -->
			<!-- <u-input type="select" v-model="item.goodsType" border="false" placeholder="请选择商品类型" @click="show = true"/>
			<u-action-sheet :list="goodsTypes" v-model="show" @click="actionSheetCallback"/> -->
		</view>
		<view class="form_group">
			<view class="lable re">商品单位</view>
			<input type="text" placeholder="请输入" v-model="item.goodsUnits" />
		</view>
		<view class="form_group">
			<view class="lable re">商品价格</view><!-- (0=下架,1=在售) -->
			<input type="text" placeholder="请输入" v-model="item.price" />
		</view>
		<view class="form_group">
			<view class="lable re">商品数量</view>
			<input type="text" placeholder="请输入" v-model="item.stock" />
		</view>
		<view class="form_group">
			<view class="lable re">净重</view>
			<input type="text" placeholder="请输入" v-model="item.netWeight" />
		</view>
		<view class="form_group">
			<view class="lable re">毛重</view>
			<input type="text" placeholder="请输入" v-model="item.grossWeight" />
		</view>
		<view class="form_group">
			<view class="lable re">商品状态</view>
			<picker @change="pickerChangeGoodsStatus" :value="index2" :range="goodsStatus" range-key="label">
				<view >{{goodsStatus[index2].label}}</view>
			</picker>
			<!-- <input type="text" placeholder="请输入" v-model="item.goodsStatus" /> -->
		</view>
		<view class="form_group">
			<view class="lable re">商品描述</view>
			<input type="text" placeholder="请输入" v-model="item.description" />
		</view>
		<view class="form_group">
			<view class="lable re">商品图片</view>
			<card v-model="item.goodsImg" pic="../../static/images/yyzz.png"></card>
		</view>
		<button class="btn" @click="save()">新增商品提交</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id: 0,
				item: {goodsType:''},
				index1: 0,
				index2: 1,
				goodsTypes: [
					{label:'请选择',value:0},
					{label:'水果',value:1},
					{label:'药品',value:2},
					{label:'茶叶',value:3},
				],
				goodsStatus: [
					{label:'下架',value:0},
					{label:'在售',value:1}
				],
				show: false,
			}
		},
		methods: {
			pickerChangeGoodsTypes: function(e) { //商品类型选择器
				this.index1 = e.detail.value;
			},
			pickerChangeGoodsStatus: function(e) { //商品状态选择器
				this.index2 = e.detail.value;
			},
			// 点击actionSheet回调
			actionSheetCallback(index) {
				console.log('index',index)
				this.item.goodsType = this.goodsTypes[index].label;
			},
			save() {
				/* let rule = [
					{ name: 'typeCode', checkType: 'notnull', errorMsg: '请输入编码' },
					{ name: 'typeName', checkType: 'notnull', errorMsg: '请输入名称' },
					{ name: 'status', 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('ctype');
							uni.navigateBack();
						}, 1000);
					}
				});
			}

		}
	}
</script>

<style lang="scss">
.btn {
	margin-top: 25px;
}
</style>
