gaoluyang
2026-05-18 da57fbd8e7fa021614fb32502fb1520ea4e34e1e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<template>
  <div>
    <el-dialog v-model="isShow"
               title="编辑库存"
               width="800"
               @close="closeModal">
      <el-form label-width="140px"
               :model="formState"
               label-position="top"
               ref="formRef">
        <el-form-item label="产品名称"
                      prop="productName">
          <el-input v-model="formState.productName" disabled />
        </el-form-item>
        <el-form-item label="规格"
                      prop="model">
          <el-input v-model="formState.model" disabled />
        </el-form-item>
        <el-form-item label="单位"
                      prop="unit">
          <el-input v-model="formState.unit" disabled />
        </el-form-item>
        <el-form-item label="批号"
                      prop="batchNo">
          <el-input v-model="formState.batchNo" disabled />
        </el-form-item>
        <el-form-item label="合格库存数量"
                      prop="qualifiedQuantity">
          <el-input-number v-model="formState.qualifiedQuantity"
                           :step="1"
                           :min="0"
                           style="width: 100%" />
        </el-form-item>
        <el-form-item label="不合格库存数量"
                      prop="unQualifiedQuantity">
          <el-input-number v-model="formState.unQualifiedQuantity"
                           :step="1"
                           :min="0"
                           style="width: 100%" />
        </el-form-item>
        <el-form-item label="库存预警数量"
                      prop="warnNum">
          <el-input-number v-model="formState.warnNum"
                           :step="1"
                           :min="0"
                           style="width: 100%" />
        </el-form-item>
        <el-form-item label="备注"
                      prop="remark">
          <el-input v-model="formState.remark"
                    type="textarea" />
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary"
                     @click="handleSubmit">确认</el-button>
          <el-button @click="closeModal">取消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>
 
<script setup>
  import { ref, computed, watch, getCurrentInstance } from "vue";
  import { ElMessage } from "element-plus";
  import { updateStockInventory } from "@/api/inventoryManagement/stockInventory.js";
 
  const { proxy } = getCurrentInstance();
 
  const props = defineProps({
    visible: {
      type: Boolean,
      default: false,
    },
    record: {
      type: Object,
      default: () => ({}),
    },
  });
 
  const emits = defineEmits(["update:visible", "completed"]);
 
  const isShow = computed({
    get: () => props.visible,
    set: (val) => emits("update:visible", val),
  });
 
  const formRef = ref();
 
  const formState = ref({
    id: undefined,
    productId: undefined,
    productModelId: undefined,
    productName: "",
    model: "",
    unit: "",
    batchNo: "",
    qualifiedQuantity: 0,
    unQualifiedQuantity: 0,
    warnNum: 0,
    remark: "",
  });
 
  // 监听弹窗显示,回填数据
  watch(
    () => props.visible,
    (val) => {
      if (val && props.record) {
        const row = props.record;
        console.log('编辑数据:', row);
        formState.value.id = row.id;
        formState.value.productId = row.productId;
        formState.value.productModelId = row.productModelId;
        formState.value.productName = row.productName || '';
        formState.value.model = row.model || '';
        formState.value.unit = row.unit || '';
        formState.value.batchNo = row.batchNo || '';
        formState.value.qualifiedQuantity = row.qualifiedQuantity || 0;
        formState.value.unQualifiedQuantity = row.unQualifiedQuantity || 0;
        formState.value.warnNum = row.warnNum || 0;
        formState.value.remark = row.remark || '';
      }
    },
    { immediate: true }
  );
 
  const closeModal = () => {
    isShow.value = false;
    resetForm();
  };
 
  const resetForm = () => {
    formState.value = {
      id: undefined,
      productId: undefined,
      productModelId: undefined,
      productName: "",
      model: "",
      unit: "",
      batchNo: "",
      qualifiedQuantity: 0,
      unQualifiedQuantity: 0,
      warnNum: 0,
      remark: "",
    };
  };
 
  const handleSubmit = () => {
    proxy.$refs["formRef"].validate((valid) => {
      if (valid) {
        const params = { ...formState.value };
        updateStockInventory(params)
          .then(() => {
            ElMessage.success("编辑成功");
            closeModal();
            emits("completed");
          })
          .catch(() => {
            ElMessage.error("编辑失败");
          });
      }
    });
  };
</script>
 
<style scoped lang="scss"></style>