Newer
Older
adminAccountabilityFront / src / views / system / expire / edit.vue
liyaguang on 11 Sep 2023 2 KB first
<script lang="ts" setup name="EditExpire">
import type { Ref } from 'vue'
import { nextTick, reactive } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import type { FormInstance, FormRules } from 'element-plus'
import { getList, updateRemind } from '@/api/system/expire'
// ----------------------- 以下是字段定义 emits props ---------------------
const emits = defineEmits(['closeRefresh'])

const dialogVisible = ref(false)
const data = ref({
  createDeptId: 0,
  createDeptName: '',
  createTime: '',
  createUserId: '',
  createUserName: '',
  id: '',
  remindName: '',
  remindTime: 0,
  updateTime: '',
})
// ---------------表单提交--------------------------------
// 表单对象
const dataFormRef = ref<FormInstance>()

// 表单提交
function submitForm() {
  if (dataFormRef) {
    dataFormRef.value?.validate((valid: boolean) => {
      if (valid) {
        updateRemind(data.value).then((res) => {
          ElMessage.success('修改成功')
          dialogVisible.value = false
          emits('closeRefresh')
        })
      }
    })
  }
}

// ----------初始化、关闭对话框相关-----------------
function initDialog(row: any) {
  dialogVisible.value = true
  data.value = row
}

// 关闭并刷新
function closeRefresh() {
  dialogVisible.value = false
  emits('closeRefresh')
}
// 关闭弹窗
function dialogClose() {
  dialogVisible.value = false
}
// ----------------------- 以下是暴露的方法内容 ----------------------------
defineExpose({ initDialog })
</script>

<template>
  <el-dialog
    v-model="dialogVisible"
    title="到期提醒-编辑"
    width="30%"
    :before-close="dialogClose"
    append-to-body
    :open-delay="0"
    :close-on-click-modal="false"
  >
    <el-form
      ref="dataFormRef" :model="data" label-position="left" label-width="80px" class="form-container"
      size="default" @submit.prevent
    >
      <el-row :gutter="24">
        <el-col :span="24" class="grid-cell">
          <el-form-item label="提醒名称" prop="tips" class="required">
            <el-input v-model="data.remindName" type="text" disabled />
          </el-form-item>
        </el-col>
        <el-col :span="24" class="grid-cell">
          <el-form-item label="提醒时间" prop="tips" class="required">
            <el-input-number v-model="data.remindTime" controls-position="right" placeholder="到期前xx天" />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <template #footer>
      <div class="dialog-footer">
        <el-button type="primary" @click="submitForm">
          保存
        </el-button>
        <el-button @click="dialogClose">
          取消
        </el-button>
      </div>
    </template>
  </el-dialog>
</template>

<style lang="scss" scoped>
.form-container {
  width: 100%;

  .full-width-input {
    width: 100%;
  }

  .dict-detail {
    padding: 10px;

    .title {
      font-size: 16px;
      font-weight: bold;
      margin-bottom: 15px;
    }
  }
}
</style>