<template>
	<view class="nvue-page-root">
		<view class="head">
			<view class="header-wrap">
				<view class="index-header">
					<uni-icons class="fanhui" custom-prefix="iconfont" type="icon-fanhui"
						@click="leftClick"></uni-icons>
					<view class="input-wrap">
						<text class="iconfont">货物</text>
					</view>
					<view class="map-wrap">
					</view>
				</view>
			</view>
			<view class="blank"></view>
		</view>
		<view class="uni-common-mt" style="padding: 5px;height: 400px">
			<view class="uni-form-item uni-column">
				<view class="uni-input-wrapper" style="margin: 5px auto;">
					<text class="uni-form-item__title" style="width: 20%;text-align: right;">货物码: </text>
					<input class="uni-input" :value="code" @input="tmp_code" style="width: 80%;" />

				</view>

				<view class="uni-input-wrapper" style="margin: 5px auto;">
					<text class="uni-form-item__title" style="width: 20%;text-align: right;">名称: </text>
					<input class="uni-input" :value="name" @input="tmp_name" style="width: 80%;" />
				</view>
				<view class="uni-input-wrapper">
					<text class="uni-form-item__title" style="width: 20%;text-align: right;">类别: </text>
					<select-lay :zindex="1211" :value="category_sn" name="category_sn" placeholder="请选择项目"
						:options="catList" @selectitem="selectitem" style="width: 80%;">
					</select-lay>
				</view>
			</view>
		</view>
		<view class="uni-input-wrapper button-sp-area">
			<button type="primary" plain="true" @click="groupDisk()" class="sm">新建</button>
		</view>
	</view>
</template>

<script>
	let _this = null;
	var reqRootUrl = plus.storage.getItem("reqRootUrl");
	const modal = uni.requireNativePlugin('modal');
	export default {
		data() {
			return {
				catList: [],
				code: uni.getStorageSync("product_code"),
				name: "",
				category_sn: "",
			}
		},
		methods: {
			leftClick: function() {
				setTimeout(() => {
					uni.navigateBack();
					// uni.redirectTo({
					// 	url: '/pages/sample/main',
					// })
				}, 30);
				// this.$emit('change', this.value)
			},
			onLoad() {
				this.platform = uni.getSystemInfoSync().platform
				// #ifdef APP-PLUS-NVUE
				this.isNvue = true
				// #endif
				_this = this;
				setTimeout(() => {
					this.CateGet();
				}, 350);

			},
			CateGet() {
				uni.request({
					url: reqRootUrl + '/wms/api',
					method: 'POST',
					headers: {
						'Content-Type': 'application/json'
					},
					data: JSON.stringify({
						"method": "CateGet",
						"param": {
							"disable": false,
						}
					}),
					success: (ret) => {
						if (ret.data.ret === "ok") {
							let rows = ret.data.data;
							for (var i = 0; i < rows.length; i++) {
								this.catList.push({
									label: rows[i].name,
									value: rows[i].sn
								})
							}
						}
					},
					fail: (err) => {
						// console.log('request fail', err);
					},
					complete: () => {
						// console.log('complete');
					}
				})
			},
			tmp_code: function(event) {
				this.code = event.detail.value;
			},
			tmp_name: function(event) {
				this.name = event.detail.value;
			},
			selectitem(index, item) {
				if (index >= 0) {
					this.category_sn = item.value;
				} else {
					this.category_sn = ""
				}
			},
			groupDisk: function() {
				let code = this.code;
				let name = this.name;
				let category_sn = this.category_sn;
				if (code === "") {
					code = uni.getStorageSync("product_code");
				}
				if (name === "") {
					modal.toast({
						message: '名称不能为空',
						duration: 6
					});
					return
				}
				if (category_sn === "") {
					modal.toast({
						message: '类别不能为空',
						duration: 6
					});
					return
				}
				uni.showModal({
					title: "提示",
					content: "确定新建?",
					success: function(res) {
						if (res.confirm) {
							uni.request({
								url: reqRootUrl + '/wms/api',
								method: 'POST',
								headers: {
									'Content-Type': 'application/json'
								},
								data: JSON.stringify({
									"method": "ProductAdd",
									"param": {
										"code": code,
										"name": name,
										"category_sn": category_sn,
									}
								}),
								success: (ret) => {
									if (ret.data.ret === "ok") {
										let batch = uni.getStorageSync("batch");
										uni.request({
											url: reqRootUrl + '/wms/api',
											method: 'POST',
											headers: {
												'Content-Type': 'application/json'
											},
											data: JSON.stringify({
												"method": "GroupDiskAdd",
												"param": {
													"code": code,
													"batch": batch
												}
											}),
											success: (ret) => {
												if (ret.data.ret === "ok") {
													setTimeout(() => {
														uni.navigateBack();
														// uni.redirectTo({
														// 	url: '/pages/sample/group',
														// })
													}, 30);
												}
											},
											fail: (err) => {
												// console.log('request fail', err);
											},
											complete: () => {
												// console.log('complete');
											}
										})

									} else {
										console.log('request fail', ret.data.msg);
									}
								},
								fail: (err) => {
									// console.log('request fail', err);
								},
								complete: () => {
									// console.log('complete');
								}
							})
						} else {

						}
					}
				})
			},
		}
	}
</script>
<style scoped>
	.nvue-page-root {
		background-color: #F8F8F8;
		padding-bottom: 0px;
	}

	.uni-form-item__title {
		margin: 5px auto;
	}

	.uni-input-wrapper {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: row;
		flex-wrap: nowrap;
		background-color: #FFFFFF;
	}

	.uni-input {
		height: 28px;
		line-height: 28px;
		font-size: 15px;
		padding: 1px;
		flex: 1;
		border-radius: 5px;
		border: 1px solid #cfdadd;
		background-color: #FFFFFF;
	}

	.mini-btn {
		height: 30px;
		padding-left: 1px;
		padding-right: 1px;
	}

	.uni-eye-active {
		color: #007AFF;
	}

	.table-title {
		background-color: aliceblue;
		font-weight: 700;
		margin-top: 10px;
		height: 40px;
	}

	.table-data {
		background-color: aliceblue;
		font-weight: 700;
		margin-top: 1px;
		height: 40px;
	}

	.tab-tr {
		width: 25%;
		line-height: 25px;
		border-right: 1px solid #ccc;
		margin: auto;
		text-align: center;
	}

	.tab-tr-end {
		width: 25%;
		line-height: 25px;
		border-right: 0px solid #ccc;
		margin: auto;
		text-align: center;
	}
</style>
<style lang="scss">
	.content {
		width: 300px;
		padding: 20px 0;
		margin: 0 auto;

		.item {
			margin-bottom: 10px;
		}

		.btn {
			margin-top: 20px;
		}
	}
</style>

<style lang="scss">
	$color-base: #0039a6;
	$words-color-base: #333333;
	$words-color-light: #999999;

	.header-wrap {
		width: 100%;
		position: fixed;
		top: 0;
		z-index: 999;

		.index-header {
			height: 88upx;
			line-height: 88upx;
			padding: 0 30upx;
			padding-top: 40upx;
			background-color: $color-base;
			font-Size: 28upx;
			color: #fff;
			display: flex;
			align-items: center;
			justify-content: space-between;

			.fanhui {
				color: #fff !important;
				font-size: 28px;
				padding-top: 5px;
				font-weight: 700;
			}

			.lanya {
				color: #fff !important;
				font-size: 28px;
				padding-top: 5px;
			}

			.map-wrap {
				padding-top: 5px;
			}
		}
	}

	.blank {
		height: 126upx;
	}
</style>