<script setup lang="ts">

import StackerLocationStatusFormatter from "@/plugin/formatter/StackerLocationStatusFormatter.ts";
import MessageUtils from "@/utils/MessageUtils.ts";
import StackerLocationApi from "@/api/stackerLocation.ts";
import {AppServeResponseCodeEnum} from "@/constant/enums/AppServeResponseCodeEnum.ts";
import type {AppServeResponse} from "@/interface/api/AppServeResponse.ts";

const modelValue = defineModel('modelValue', {required: true, default: false});
const emit = defineEmits(['reLoadingTableData']);
const props = defineProps(['formData']);
const close = () => {modelValue.value = false;};
const stackerLocationStatusFormatter = new StackerLocationStatusFormatter();

// 保存修改
const save = () => {
  MessageUtils.confirmMessageBox('确定保存上述数据？','二次确认').then(() => {
    const loadingInstance = MessageUtils.loading();
    StackerLocationApi.updateStackerLocation(props.formData).then((res) => {
      const responseString = JSON.stringify(res.data);
      const response = JSON.parse(responseString) as AppServeResponse;
      if (response && response.code == AppServeResponseCodeEnum.SUCCESS) {
        MessageUtils.successMessage('保存成功');
        emit('reLoadingTableData');
        close();
        return;
      }
      MessageUtils.warningMessageBox(response.msg, '警告');
    }).catch(() => {}).finally(() => {
      loadingInstance.close();
    });
  }).catch(() => {});
};

</script>

<template>
  <el-dialog :model-value="modelValue" title="查看/编辑货位信息" @close="close" :close-on-click-modal="false">
    <el-scrollbar style="height:50vh">
      <el-row>
        <el-col :span="20">
          <el-form label-position="right" :model="formData" label-width="120px" require-asterisk-position="right" style="width: 100%; margin-right: 10px">
            <el-form-item label="货位编号：" required>
              <el-input v-model="formData.locationId" disabled></el-input>
            </el-form-item>
            <el-form-item label="货位状态：" required>
              <el-select v-model="formData.locationStatus" placeholder="请选择货位类型">
                <el-option v-for="item in stackerLocationStatusFormatter.stackerLocationStatusTagStyle" :key="item.value" :label="item.label" :value="item.value"/>
              </el-select>
            </el-form-item>
            <el-form-item label="业务货位：" required>
              <el-input v-model="formData.businessLocation" placeholder="请输入业务货位"></el-input>
            </el-form-item>
            <el-form-item label="货位类型：" required>
              <el-select v-model="formData.locationType" placeholder="请选择货位类型">
                <el-option label="普通" :value="0"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="巷道号：" required>
              <el-input-number v-model="formData.laneId" :min="1" :max="999"></el-input-number>
            </el-form-item>
            <el-form-item label="设备号：" required>
              <el-input-number v-model="formData.machineId" :min="1" :max="999"></el-input-number>
            </el-form-item>
            <el-form-item label="排号：" required>
              <el-input-number v-model="formData.lRow" :min="1" :max="999"></el-input-number>
            </el-form-item>
            <el-form-item label="列号：" required>
              <el-input-number v-model="formData.lLine" :min="1" :max="999"></el-input-number>
            </el-form-item>
            <el-form-item label="层号：" required>
              <el-input-number v-model="formData.lLayer" :min="1" :max="999"></el-input-number>
            </el-form-item>
            <el-form-item label="深度：" required>
              <el-input-number v-model="formData.lDepth" :min="1" :max="999"></el-input-number>
            </el-form-item>
            <el-form-item label="货位标签：">
              <el-input v-model="formData.locationTag"></el-input>
            </el-form-item>
            <el-form-item label="载具号：">
              <el-input v-model="formData.vehicleNo"></el-input>
            </el-form-item>
            <el-form-item label="创建时间：">
              <el-text type="primary">{{formData.createTime}}</el-text>
            </el-form-item>
            <el-form-item label="上次更新时间：">
              <el-text type="primary">{{formData.updateTime}}</el-text>
            </el-form-item>
            <el-form-item label="备注：">
              <el-input v-model="formData.remark"></el-input>
            </el-form-item>
          </el-form>
        </el-col>
      </el-row>
    </el-scrollbar>
    <template #footer>
      <el-button-group>
        <el-button type="primary" @click="save">保存/修改</el-button>
        <el-button type="danger" @click="close">关闭窗口</el-button>
      </el-button-group>
    </template>
  </el-dialog>
</template>

<style scoped>

</style>