<template>
	<view>
		<uni-collapse>
			<uni-forms ref="form" :modelValue="formData" :rules="rules">
				<uni-forms-item label="件号" :labelWidth='90' name="pieceNo">
					<uni-easyinput v-model="formData.pieceNo" suffixIcon="scan" @confirm="scanBarCode"
						@iconClick="scanBar" type="text" />
				</uni-forms-item>
				<u-button type="primary" @click="submit">查询</u-button>

				<uni-collapse-item title="查询结果:" :open="true">
					<view>
						<uni-row>
							<uni-col :span="24">
								<uni-forms-item label="客户名称:" :labelWidth='90' name="customerName">
									<view style="margin-top: 9px;"><text class="text">{{formData.customerName}}</text>
									</view>
								</uni-forms-item>
							</uni-col>
							<uni-col :span="24">
								<uni-forms-item label="允许经销地区:" :labelWidth='90' name="allowDealPlace">
									<view style="margin-top: 9px;"><text class="text">{{formData.allowDealPlace}}</text>
									</view>

								</uni-forms-item>
							</uni-col>
							<!-- <uni-col :span="24">
									<uni-forms-item label="件号:" :labelWidth='90' name="pieceNo">
										<view style="margin-top: 9px;"><text class="text">{{formData.pieceNo}}</text></view>
										</uni-forms-item>
								</uni-col> -->
							<uni-col :span="24">
								<uni-forms-item label="物料编码:" :labelWidth='90' name="materialCode">
									<view style="margin-top: 9px;"><text class="text">{{formData.materialCode}}</text>
									</view>

								</uni-forms-item>
							</uni-col>
							<uni-col :span="24">
								<uni-forms-item label="物料名称:" :labelWidth='90' name="materialName">
									<view style="margin-top: 9px;"><text class="text">{{formData.materialName}}</text>
									</view>

								</uni-forms-item>
							</uni-col>
							<uni-col :span="24">
								<uni-forms-item label="物料批号:" :labelWidth='90' name="batchNo">
									<view style="margin-top: 9px;"><text class="text">{{formData.batchNo}}</text></view>

								</uni-forms-item>
							</uni-col>
							<uni-col :span="24">
								<uni-forms-item label="箱号:" :labelWidth='90' name="lotNo">
									<view style="margin-top: 9px;"><text class="text">{{formData.lotNo}}</text></view>

								</uni-forms-item>
							</uni-col>
						</uni-row>
					</view>
				</uni-collapse-item>
			</uni-forms>

		</uni-collapse>
	</view>
</template>

<script>
	import {
		listCustomer,
		handleQuery
	} from "@/api/srm/antiCrossCargo.js";
	export default {
		mounted() {},
		data() {
			return {
				formData: {
					pieceNo: null,
				},
				rules: {
					pieceNo: {
						rules: [{
							required: true,
							errorMessage: '请输入件号!'
						}]
					}
				},

			}
		},
		methods: {
			scanBarCode(code) {
				this.formData.pieceNo = code;
			},
			//客户编码
			scanBar() {
				const _this = this;
				uni.scanCode({
					scanType: ['barCode', 'qrCode'],
					success: function(res) {
						_this.formData.pieceNo = res.result;
						_this.scanBarCode(_this.formData.pieceNo);
					}
				});
			},
			submit() {
				const _this = this;
				if (_this.formData.pieceNo && _this.formData.pieceNo != "") {
					let data = _this.formData.pieceNo;
					_this.$modal.loading('提交中')
					handleQuery(data).then(async res => {
						_this.$modal.closeLoading();
						if (res.data == null) {
							_this.$modal.msg("该件号未销售登记，请确认！");
						} else {
							_this.formData = res.data;
						}

					});
				} else {
					this.$modal.msg("请输入件号!");
				}
			}
		}
	}
</script>

<style>
	.text {
		text-align: center;
	}
</style>