<template>
	<view class="nvue-page-root">

		<view class="uni-common-mt" style="padding: 5px;">
			<view class="uni-form-item uni-column">
				<view class="uni-input-wrapper" style="margin: 5px auto;">
					<input id="s_name" class="uni-input" value="" placeholder="请填写货物名称" @input="tmp_name" />
					<input id="s_code" class="uni-input" value="" placeholder="请填写存货编码" @input="tmp_code" />
					<button class="mini-btn" type="primary" size="mini" style="width: 20%;"
						@click="Search()">搜索</button>
				</view>
				<view class="uni-input-wrapper table-title">
					<view class="tab-tr" style="width: 42%;">名称</view>
					<view class="tab-tr" style="width: 42%;">存货编码</view>
					<view class="tab-tr-end" style="width: 15%;">数量</view>
				</view>
				<!-- <view>
					<view class="" style="line-height: 35px;border: 1px solid #ccc;margin: auto;text-align: center;width: 49%;display: inline-block;">1</view>
					<view class="" style="line-height: 35px;border: 1px solid #ccc;margin: auto;text-align: center;width: 49%;display: inline-block;">2</view>
					<view class="" style="line-height: 35px;border: 1px solid #ccc;margin: auto;text-align: center;width: 49%;display: inline-block;">3</view>
					<view class="" style="line-height: 35px;border: 1px solid #ccc;margin: auto;text-align: center;width: 49%;display: inline-block;">4</view>
				</view> -->
				<view style="min-height:350px;overflow-y:auto;max-height:350px">
					<view class="uni-input-wrapper table-data" v-for="(item,index) in tableData" :key="index"
						@click="OutStock(item)">
						<view class="tab-tr"
							style="width: 42%;white-space: nowrap;overflow: hidden;text-overflow: ellipsis">
							{{item.name}}
						</view>
						<view class="tab-tr"
							style="width: 42%;white-space: nowrap;overflow: hidden;text-overflow: ellipsis">
							{{item.code}}
						</view>
						<view class="tab-tr-end" style="width: 15%;">{{item.num ||0}}</view>
					</view>
				</view>
			</view>
		</view>
		<view>
			<!-- 输入框示例 -->
			<uni-popup ref="inputDialog" type="dialog">
				<uni-popup-dialog ref="inputClose" mode="input" :title="product_name" value="" placeholder="请填写出库数量"
					@confirm="dialogInputConfirm"></uni-popup-dialog>
			</uni-popup>
		</view>
	</view>
</template>
<script>
	let _this = null;
	var reqRootUrl = plus.storage.getItem("reqRootUrl");

	export default {
		data() {
			return {
				url: '',
				product_name: "正常出库",
				tableData: [],
			}
		},
		methods: {
			onLoad() {
				this.platform = uni.getSystemInfoSync().platform
				// #ifdef APP-PLUS-NVUE
				this.isNvue = true
				// #endif
				_this = this;
				setTimeout(() => {
					this.getList();
				}, 350);
			},
			onShow() {
				setTimeout(() => {
					// this.getList();
				}, 350);
			},
			tmp_name: function(event) {
				var value = event.detail.value;
				uni.setStorageSync("tmp_name", value)
				// uni.setStorageSync(key, value)
				// uni.getStorageSync("batch")
				// uni.removeStorageSync(key)
			},
			tmp_code: function(event) {
				var value = event.detail.value;
				uni.setStorageSync("tmp_code", value)
			},
			Search() {
				var name = uni.getStorageSync("tmp_name");
				var code = uni.getStorageSync("tmp_code");
				uni.request({
					url: reqRootUrl + '/wms/api',
					method: 'POST',
					headers: {
						'Content-Type': 'application/json'
					},
					data: JSON.stringify({
						"method": "ProductGet",
						"param": {
							"name": name,
							"code": code,
						}
					}),
					success: (ret) => {
						let rows = ret.data.data;
						this.tableData = rows;
						//处理成功逻辑
					},
					fail: (err) => {
						// console.log('request fail', err);
					},
					complete: () => {
						// console.log('complete');
					}
				})


			},
			OutStock(item) {
				console.log("item", item["name"])
				item["num"] = 10
				this.product_name = item["name"] + ":" + item["num"]
				this.$refs.inputDialog.open()
			},
			dialogInputConfirm(val) {
				setTimeout(() => {
					uni.hideLoading()
					if (parseFloat(val) <= 0) {
						modal.toast({
							message: msg,
							duration: 6
						});
						return
					} else {
						uni.request({
							url: reqRootUrl + '/wms/api',
							method: 'POST',
							headers: {
								'Content-Type': 'application/json'
							},
							data: JSON.stringify({
								"method": "ProductGet",
								"param": {
									"disable": false,
								}
							}),
							success: (ret) => {
								_this.getList()
								//处理成功逻辑
							},
							fail: (err) => {
								// console.log('request fail', err);
							},
							complete: () => {
								// console.log('complete');
							}
						})
					}
					// 关闭窗口后，恢复默认内容
					this.$refs.inputDialog.close()
				}, 30)
			},

			getList() {
				// uni.setStorageSync(key, value)
				// uni.getStorageSync("batch")
				// uni.removeStorageSync(key)

				let batch = uni.getStorageSync("batch");
				batch = "202312101535"
				uni.request({
					url: reqRootUrl + '/wms/api',
					method: 'POST',
					headers: {
						'Content-Type': 'application/json'
					},
					data: JSON.stringify({
						"method": "ProductGet",
						"param": {
							"disable": false,
						}
					}),
					success: (ret) => {
						let rows = ret.data.data;
						this.tableData = rows;
						//处理成功逻辑
					},
					fail: (err) => {
						// console.log('request fail', err);
					},
					complete: () => {
						// console.log('complete');
					}
				})
			},
		},
	}
</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>