Your Name
2023-01-06 e3d63f84a43db07fa5992de2937ee23fc67bad38
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
<template>
    <div class="system-add-menu-container">
        <el-dialog :title="goodsDetailAddState.title" :close-on-click-modal="false" v-model="goodsDetailAddState.goodsDetailAddVisible" width="30%">
            <el-form
                :model="goodsDetailAddState.goodsDetailForm"
                :rules="goodsDetailAddState.goodsDetailRules"
                ref="goodsDetailFormRef"
                size="default"
                v-loading="goodsDetailAddState.loading"
                element-loading-text="Loading..."
                label-width="120px">
                <el-row>
                    <el-col :span="24" class="mb20">
                        <el-form-item label="选择物资" prop="smId">
                            <el-row :gutter="6">
<!--                                <el-col :span="8">-->
<!--                                    <el-select-->
<!--                                        filterable-->
<!--                                        placeholder="请选择部门"-->
<!--                                        clearable-->
<!--                                        @change="changeDepartment"-->
<!--                                        v-model="goodsDetailAddState.depId">-->
<!--                                        <el-option-->
<!--                                            v-for="item in goodsDetailAddState.departmentList"-->
<!--                                            :key="item.depId"-->
<!--                                            :value="item.depId"-->
<!--                                            :label="item.depName"-->
<!--                                        ></el-option>-->
<!--                                    </el-select>-->
<!--                                </el-col>-->
                                <el-col :span="12">
                                    <el-select v-model="goodsDetailAddState.classifyId" placeholder="选择分类" @change="changeClassify" filterable clearable>
                                        <el-option
                                            v-for="item in goodsDetailAddState.classifyList"
                                            :key="item.materialClassifyId"
                                            :value="item.materialClassifyId"
                                            :label="item.materialClassifyName"
                                        ></el-option>
                                    </el-select>
                                </el-col>
                                <el-col :span="12">
                                    <el-select v-model="goodsDetailAddState.goodsDetailForm.smId" placeholder="选择物资" filterable clearable>
                                        <el-option
                                            v-for="item in goodsDetailAddState.goodsList"
                                            :key="item.smId"
                                            :value="item.smId"
                                            :label="item.materialName"
                                        ></el-option>
                                    </el-select>
                                </el-col>
                            </el-row>
                        </el-form-item>
                    </el-col>
                    <el-col :span="24" class="mb20">
                        <el-row :gutter="6">
                            <el-col :span="12">
                                <el-form-item label="RFID起:" prop="startRfid">
                                    <el-input v-model="goodsDetailAddState.RFID" placeholder="选填">
                                    </el-input>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-input v-model="goodsDetailAddState.startRfid" @blur="checkLength('start')" @input="onVerifiyNumberInteger($event, 'start')" placeholder="选填">
                                </el-input>
                            </el-col>
                        </el-row>
                    </el-col>
                    <el-col :span="24" class="mb20">
                        <el-row :gutter="6">
                            <el-col :span="12">
                                <el-form-item label="RFID止:" prop="endRfid">
                                    <el-input v-model="goodsDetailAddState.RFID" placeholder="选填">
                                    </el-input>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-input @blur="checkLength('end')" @input="onVerifiyNumberInteger($event, 'end')" v-model="goodsDetailAddState.endRfid" placeholder="选填">
                                </el-input>
                            </el-col>
                        </el-row>
                    </el-col>
                    <el-col :span="24" class="mb20">
                        <el-form-item label="入库数量:" prop="wareHousingCount">
                            <el-input @input="onVerifiyNumberInteger($event, 'wareHousingCount')"  v-model="goodsDetailAddState.goodsDetailForm.wareHousingCount" placeholder="入库总数">
                            </el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="24" class="mb20">
                        <el-form-item label="有效期类型:" prop="validType">
                            <el-radio-group v-model="goodsDetailAddState.goodsDetailForm.validType">
                                <el-radio :label="0">长期</el-radio>
                                <el-radio :label="1">非长期</el-radio>
                            </el-radio-group>
                        </el-form-item>
                    </el-col>
                    <el-col :span="24" class="mb20" v-if="goodsDetailAddState.goodsDetailForm.validType === 1">
                        <el-form-item label="有效期至:" prop="validTime">
                            <el-date-picker
                                v-model="goodsDetailAddState.goodsDetailForm.validTime"
                                type="datetime"
                                format="YYYY-MM-DD HH:mm:ss"
                                value-format="YYYY-MM-DD HH:mm:ss"
                                placeholder="选择日期时间"
                                style="width: 100%" />
                        </el-form-item>
                    </el-col>
 
                </el-row>
            </el-form>
            <template #footer>
                <span class="dialog-footer">
                    <el-button @click="goodsDetailAddState.goodsDetailAddVisible = !goodsDetailAddState.goodsDetailAddVisible" size="default">取 消</el-button>
                    <el-button type="primary" @click="submitGoodsDetail" v-throttle size="default">确 定</el-button>
                </span>
            </template>
        </el-dialog>
    </div>
</template>
 
<script lang="ts" setup>
import {reactive, ref, watch} from 'vue'
import {
    BaseMaterialListType,
    ClassificationListType,
    DepartmentType,
    GoodsDetailDataType,
    GoodsDetailAddType
} from "/@/views/facilityManagement/goodsDetailManage/index";
import {isValidKey} from "/@/views/facilityManagement/safetyGoodsAndEquipment/index";
import {ElMessage} from "element-plus/es";
import {goodsDetailApi} from "/@/api/facilityManagement/goodsDetailManage";
import {verifiyNumberInteger, verifyString} from "/@/utils/toolsValidate";
import {useUserInfo} from "/@/stores/userInfo";
 
const goodsDetailFormRef = ref()
const userInfo = useUserInfo()
 
const goodsDetailAddState = reactive<GoodsDetailAddType>({
    title: '新增入库',
    RFID: 'RFIDXXX',
    startRfid: '',
    endRfid: '',
    depId: null,
    loading: false,
    classifyId: null,
    goodsDetailAddVisible: false,
    goodsDetailForm: {
        id: null,
        smId: null,
        validType: null,
        validTime: null,
        startRfid:  null,
        endRfid:  null ,
        wareHousingCount:  null,
    },
    goodsDetailRules: {
        smId: [{ required: true, message: '请选择物资名称', trigger: 'change' }],
        validType: [{ required: true, message: '请选择时间类型', trigger: 'change' }],
        validTime: [{ required: true, message: '请选择有效时间', trigger: 'change' }],
        wareHousingCount: [{ required: true, message: '请填写入库数量', trigger: 'blur' }],
    },
    departmentList: [],
    classifyList: [],
    goodsList: [],
})
 
watch(() => [goodsDetailAddState.startRfid,goodsDetailAddState.endRfid],(newVal, oldVal) => {
    if(goodsDetailAddState.startRfid.length === 8 && goodsDetailAddState.endRfid.length === 8){
        goodsDetailAddState.goodsDetailForm.wareHousingCount = Number(goodsDetailAddState.endRfid) - Number(goodsDetailAddState.startRfid) + 1
    }
},{immediate :false});
 
const openGoodsDetailAddDialog = async (title: string, value: GoodsDetailDataType, departmentList: DepartmentType []) => {
    goodsDetailAddState.goodsDetailAddVisible = true;
    goodsDetailAddState.departmentList = departmentList;
    setTimeout(() => {
        goodsDetailFormRef.value.clearValidate();
    });
    goodsDetailAddState.startRfid = '';
    goodsDetailAddState.endRfid = '';
    goodsDetailAddState.goodsDetailForm = {
        id: null,
        smId: null,
        validType: null,
        validTime: null,
        startRfid:  null,
        endRfid:  null ,
        wareHousingCount:  null,
    };
    goodsDetailAddState.classifyList = goodsDetailAddState.departmentList.find(item => item.depId === userInfo.userInfos.depId)?.classificationList as Array<ClassificationListType>
}
 
// const changeDepartment = (value: number | null) => {
//     goodsDetailAddState.classifyId = null
//     goodsDetailAddState.goodsDetailForm.smId = null
//     goodsDetailAddState.classifyList = goodsDetailAddState.departmentList.find(item => item.depId === value)?.classificationList as Array<ClassificationListType>
// }
 
const changeClassify = (value: number | null) => {
    goodsDetailAddState.goodsDetailForm.smId = null
    goodsDetailAddState.goodsList = JSON.parse(JSON.stringify(
        (goodsDetailAddState.classifyList.find(item => item.materialClassifyId === value) ?? {baseMaterialList:[]})?.baseMaterialList as Array<BaseMaterialListType>
    ))
}
 
const submitGoodsDetail = () => {
    goodsDetailFormRef.value.validate(async (valid: boolean) => {
        if(valid){
            goodsDetailAddState.goodsDetailForm.startRfid = `RFID${goodsDetailAddState.startRfid}`
            goodsDetailAddState.goodsDetailForm.endRfid = `RFID${goodsDetailAddState.endRfid}`
            goodsDetailAddState.loading = true
            let res = await goodsDetailApi().addGoodsDetail(goodsDetailAddState.goodsDetailForm)
            if(res.data.code === '200'){
                goodsDetailAddState.goodsDetailAddVisible = false
                emit('refreshData')
                ElMessage({
                    type: 'success',
                    message: '物资新增成功',
                    duration: 2000
                });
            }else{
                ElMessage({
                    type:'warning',
                    message:res.data.msg
                })
            }
            goodsDetailAddState.loading = false
        }else{
            ElMessage({
                type: 'warning',
                message: '请完善基本信息'
            })
        }
    })
}
 
const checkLength = (value: string) => {
    if(value === 'start' && goodsDetailAddState.startRfid.length !== 8){
        ElMessage({
            type:'warning',
            message: 'RFID起不符合规范,请重新填入'
        })
        goodsDetailAddState.startRfid = ''
        goodsDetailAddState.goodsDetailForm.wareHousingCount = null
    }else if(value === 'end' && goodsDetailAddState.endRfid.length !== 8){
        ElMessage({
            type:'warning',
            message: 'RFID止不符合规范,请重新填入'
        })
        goodsDetailAddState.endRfid = ''
        goodsDetailAddState.goodsDetailForm.wareHousingCount = null
    }else{
        return
    }
}
 
const onVerifiyNumberInteger = (val: number, title: string) => {
    if(title === 'wareHousingCount'){
        goodsDetailAddState.goodsDetailForm.wareHousingCount = Number(verifiyNumberInteger(val.toString())) === 0 ? null : Number(verifiyNumberInteger(val.toString()));
    }else if(title === 'start'){
        goodsDetailAddState.startRfid = verifyString(val.toString());
    }else{
        goodsDetailAddState.endRfid = verifyString(val.toString());
    }
 
};
 
const emit = defineEmits(['refreshData',])
 
defineExpose({
    openGoodsDetailAddDialog
})
 
</script>
 
<style scoped>
 
</style>