liyong
18 小时以前 fd2ebc8e2b8ae6d15b11a0201858878fc85fbf62
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
<template>
  <div>
    <el-dialog
        v-model="isShow"
        :title="operationType === 'frozen' ? '冻结库存' : '解冻库存'"
        width="800"
        @close="closeModal"
    >
      <el-form label-width="140px" :model="formState" ref="formRef">
        <el-form-item
            label="库存类型"
            prop="type"
            :rules="[
                {
                required: true,
                message: '请选择库存类型',
                trigger: 'change',
              }
            ]"
        >
          <el-select v-model="formState.type" placeholder="请选择库存类型" @change="handleChangeType">
            <el-option label="合格库存" value="qualified" :disabled="(operationType === 'frozen' && props.record.qualifiedUnLockedQuantity <= 0) || (operationType === 'thaw' && props.record.qualifiedLockedQuantity <= 0)" />
            <el-option label="不合格库存" value="unqualified" :disabled="(operationType === 'frozen' && props.record.unQualifiedUnLockedQuantity <= 0) || (operationType === 'thaw' && props.record.unQualifiedLockedQuantity <= 0)" />
          </el-select>
        </el-form-item>
 
        <el-form-item
            :label="operationType === 'frozen' ? '冻结数量:' : '解冻数量:'"
            prop="lockedQuantity"
        >
          <el-input-number v-model="formState.lockedQuantity" :step="1" :min="maxCount > 0 ? 1 : 0" precision="0" style="width: 100%" :max="maxCount" :disabled="maxCount < 1" />
        </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, getCurrentInstance, onMounted} from "vue";
import {frozenStockInventory, thawStockInventory} from "@/api/inventoryManagement/stockInventory.js";
import {frozenStockUninventory, thawStockUninventory} from "@/api/inventoryManagement/stockUninventory.js";
 
const props = defineProps({
  visible: {
    type: Boolean,
    required: true,
  },
 
  operationType: {
    type: String,
    required: true,
    default: 'frozen',
  },
 
  record: {
    type: Object,
    default: () => {},
  }
});
 
const emit = defineEmits(['update:visible', 'completed']);
 
// 响应式数据(替代选项式的 data)
const formState = ref({
  type: undefined,
  lockedQuantity: undefined,
});
 
const isShow = computed({
  get() {
    return props.visible;
  },
  set(val) {
    emit('update:visible', val);
  },
});
 
 
let { proxy } = getCurrentInstance()
 
const closeModal = () => {
  // 重置表单数据
  formState.value = {
    lockedQuantity: undefined,
    type: undefined,
  };
  isShow.value = false;
};
 
const maxCount = computed(() => {
  // 冻结库存最大数量为未解冻数量
  if (props.operationType === 'frozen') {
    // 冻结合格库存最大数量为未解冻合格数量
    if (formState.value.type === 'qualified') {
      return Math.max(0, props.record.qualifiedUnLockedQuantity || 0)
    }
    // 冻结不合格库存最大数量为未解冻不合格数量
    return Math.max(0, props.record.unQualifiedUnLockedQuantity || 0)
  }
  // 解冻库存最大数量为已冻结数量
  if (formState.value.type === 'qualified') {
    // 解冻合格库存最大数量为已冻结合格数量
    return Math.max(0, props.record.qualifiedLockedQuantity || 0)
  }
  // 解冻不合格库存最大数量为已冻结不合格数量
  return Math.max(0, props.record.unQualifiedLockedQuantity || 0)
})
 
const handleChangeType = (type) => {
  formState.value.lockedQuantity = maxCount.value;
}
 
const handleSubmit = () => {
  proxy.$refs["formRef"].validate(valid => {
    if (valid) {
      const data = Object.assign({}, formState.value);
      if (formState.value.type === 'qualified') {
        data.id = props.record.qualifiedId;
        // 冻结
        if (props.operationType === 'frozen') {
          frozenStockInventory(data).then(res => {
            if (res.code === 200) {
              // 关闭模态框
              isShow.value = false;
              // 告知父组件已完成
              emit('completed');
              proxy.$modal.msgSuccess("提交成功");
            } else {
              proxy.$modal.msgError(res.msg);
            }
          })
        } else {
          thawStockInventory(data).then(res => {
            if (res.code === 200) {
              // 关闭模态框
              isShow.value = false;
              // 告知父组件已完成
              emit('completed');
              proxy.$modal.msgSuccess("提交成功");
            } else {
              proxy.$modal.msgError(res.msg);
            }
          })
        }
      } else {
        data.id = props.record.unQualifiedId;
        if (props.operationType === 'frozen') {
          frozenStockUninventory(data).then(res => {
            if (res.code === 200) {
              // 关闭模态框
              isShow.value = false;
              // 告知父组件已完成
              emit('completed');
              proxy.$modal.msgSuccess("提交成功");
            } else {
              proxy.$modal.msgError(res.msg);
            }
          })
        } else {
          thawStockUninventory(data).then(res => {
            if (res.code === 200) {
              // 关闭模态框
              isShow.value = false;
              // 告知父组件已完成
              emit('completed');
              proxy.$modal.msgSuccess("提交成功");
            } else {
              proxy.$modal.msgError(res.msg);
            }
          })
        }
      }
    }
  })
};
 
onMounted(() => {
})
 
defineExpose({
  closeModal,
  handleSubmit,
  isShow,
});
</script>