Просмотр исходного кода

外来人员签出时间组件

lidie 1 год назад
Родитель
Сommit
aa8c2229ff
1 измененных файлов с 157 добавлено и 0 удалено
  1. 157 0
      src/views/platform/registrationOutsiders/checkOut.vue

+ 157 - 0
src/views/platform/registrationOutsiders/checkOut.vue

@@ -0,0 +1,157 @@
+<template>
+    <el-dialog
+        :title="title"
+        :visible.sync="dialogVisible"
+        :close-on-click-modal="false"
+        :close-on-press-escape="false"
+        append-to-body
+        class="dialog1 test-dialog"
+        @close="closeDialog"
+    >
+        <el-form ref="ruleForm" :model="formList" label-width="80px">
+            <el-form-item
+                label="签出时间"
+                prop="dataTime"
+                :rules="[
+                    { required: true, message: '签出时间不能为空!'},
+                    { validator: validateDataTime, trigger: 'change' }
+                ]"
+            >
+                <el-date-picker
+                    v-model="formList.dataTime"
+                    type="datetime"
+                    placeholder="选择签出时间"
+                    value-format="yyyy-MM-dd HH:mm"
+                    style="width: 100%;"
+                />
+            </el-form-item>
+        </el-form>
+        <div slot="footer" class="dialog-footer">
+            <ibps-toolbar
+                :actions="toolbars"
+                @action-event="handleActionEvent"
+            />
+        </div>
+    </el-dialog>
+</template>
+
+<script>
+export default {
+    props: {
+        visible: {
+            type: Boolean,
+            default: false
+        },
+        dataList: {
+            type: Object,
+            default: () => ({})
+        }
+    },
+    data () {
+        return {
+            title: '签出',
+            dialogVisible: this.visible,
+            formList: {
+                dataTime: new Date()
+            },
+            toolbars: [
+                { key: 'confirm' },
+                { key: 'cancel' }
+            ]
+        }
+    },
+    watch: {
+        visible (val) {
+            this.dialogVisible = val
+        }
+    },
+    methods: {
+        validateDataTime (rule, value, callback) {
+            if (value === '') {
+                callback(new Error('签出时间不能为空!'))
+            } else {
+                const joinTime = new Date(this.dataList.jin_ru_shi_jian_.replace(' ', 'T'))
+                const selectedTime = new Date(value.replace(' ', 'T'))
+                const currentTime = new Date()
+
+                // 检查日期是否有效
+                if (isNaN(joinTime.getTime()) || isNaN(selectedTime.getTime())) {
+                    callback(new Error('进入或签出时间有误!'))
+                    return
+                }
+
+                // 签出时间 > 进入时间
+                if (joinTime >= selectedTime) {
+                    callback(new Error('签出时间不能早于进入时间!'))
+                    return
+                }
+
+                // 签出时间 < 当前时间
+                if (selectedTime >= currentTime) {
+                    callback(new Error('签出时间不能晚于当前时间!'))
+                    return
+                }
+
+                callback()
+            }
+        },
+        submitForm (formName) {
+            this.$refs[formName].validate((valid) => {
+                if (valid) {
+                    const params = { li_kai_shi_jian_: this.formList.dataTime }
+                    const updateParamsRecord = {
+                        tableName: 't_wlrydjb', // 数据库名
+                        updList: [{
+                            where: {
+                                id_: this.dataList.id_ // 修改数据的id
+                            },
+                            param: params // 要修改的数据
+                        }]
+                    }
+
+                    console.log('updateParamsRecord', updateParamsRecord)
+                    this.$common.request('update', updateParamsRecord).then(res => {
+                        this.$message.success('签出成功!')
+                        this.closeDialog()
+                    }).catch(() => {
+                        this.$message.error('签出失败!')
+                        this.closeDialog()
+                    })
+                } else {
+                    console.log('校验失败')
+                    return false
+                }
+            })
+        },
+        closeDialog () {
+            this.$emit('close', false)
+        },
+        handleActionEvent ({ key }) {
+            switch (key) {
+                case 'confirm':
+                    this.submitForm('ruleForm')
+                    break
+                case 'cancel':
+                    this.closeDialog()
+                    break
+                default:
+                    break
+            }
+        }
+    }
+}
+</script>
+
+<style lang="scss">
+.dialog1 {
+    .el-form {
+        margin: 30px 0;
+    }
+    .el-dialog__footer {
+        text-align: center !important;
+    }
+    .el-form-item__error {
+        top: 120%  !important;
+    }
+}
+</style>