<template>
	<view>
		<uni-forms ref="form" :modelValue="formData" :rules="rules">
			<uni-forms-item label="发货点位：" :labelWidth='90' name="srcLocationCode">
				<uni-easyinput suffixIcon="scan" @iconClick="scanSrcLocationUuid" v-model="formData.srcLocationCode" />
			</uni-forms-item>
			<uni-forms-item label="目的点位：" :labelWidth='90' name="destLocationCode">
				<uni-easyinput v-model="formData.destLocationCode" />
			</uni-forms-item>
		</uni-forms>
		<u-button type="primary" @click="handleCall">呼叫</u-button>
	</view>
</template>

<script>
import { addDeliveryTask, getLastPalletRecyclingDest } from "@/api/les/lesPalletReturn.js";
import LesDeliveryTaskType from "@/utils/enums/LesDeliveryTaskType";

export default {
	data() {
		return {
			formData: {
				srcLocationCode: null,
				destLocationCode: null,
				taskType: LesDeliveryTaskType.PALLET_RECYCLING
			},
			/** 校验规则 */
			rules: {
				srcLocationCode: {
					rules: [{
						required: true,
						errorMessage: '请选择发货点位',
					}, ]
				},
				destLocationCode: {
					rules: [{
						required: true,
						errorMessage: '请选择目的货位',
					}, ]
				},
			},
		}
	},
	created() {
		getLastPalletRecyclingDest().then(res => {
			if (res.code == 200) {
				this.$set(this.formData, "destLocationCode", res.data);
			}
		})
	},
	methods: {
		scanSrcLocationUuid() {
			const _this = this;
			uni.scanCode({
				scanType: ['qrCode', 'barCode'],
				success: function(res) {
					_this.formData.destLocationCode = res.result;
				}
			});
		},
		handleCall() {
			const _this = this;
			this.$refs.form.validate().then(res => {
				if (_this.formData.srcLocationCode && _this.formData.destLocationCode) {
					_this.$modal.loading('提交中')
					addDeliveryTask(_this.formData).then(res => {
						_this.$modal.closeLoading();
						_this.$modal.msgSuccess("提交成功！");
						setTimeout(() => {
							this.$tab.switchTab("/pages/work/index");
						}, 500);
					})
				} else {
					_this.$modal.msg("请将信息补充完整")
				}
			})
		},
	}
}
</script>

<style scoped>
::v-deep .uni-easyinput__content-input {
	height: 80rpx;
	line-height: 60rpx;
	display: flex;
	align-items: center;
}

.u-button {
	height: 10% !important;
	position: absolute;
	bottom: 0;
}
</style>