马宇豪
2024-04-02 d91fd1557ebed3e9bcb8c051c71b9d41c0e36eef
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
<template>
  <div class="system-add-user-container">
    <el-dialog :title="title" v-model="isShowDialog" width="50%">
      <el-form :model="form" size="default" ref="formRef" :rules="rules" label-width="120px">
        <el-row :gutter="35">
          <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
            <el-form-item label="证书名称" prop="name">
              <el-input v-model.trim="form.name" placeholder="证书名称" clearable></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
            <el-form-item label="分类名称" prop="cateName">
              <el-input v-model.trim="form.cateName" placeholder="分类名称" clearable></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
            <el-form-item label="发证机构" prop="orgName">
              <el-input v-model.trim="form.orgName" placeholder="发证机构" clearable></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
            <el-form-item label="发证日期">
              <el-date-picker v-model="form.pusTime" value-format="YYYY-MM-DD HH:mm:ss" type="datetime" placeholder="选择发证日期" style="width: 100%" />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
            <el-form-item label="有效期至">
              <el-date-picker v-model="form.effectiveTime" value-format="YYYY-MM-DD HH:mm:ss" type="datetime" placeholder="选择有效期至" style="width: 100%" />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
            <el-form-item label="到期提醒时间">
              <el-date-picker v-model="form.dueTime" value-format="YYYY-MM-DD HH:mm:ss" type="datetime" placeholder="选择到期提醒时间" style="width: 100%" />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
            <el-form-item label="提醒人" prop="notifyUser">
              <el-input v-model.trim="form.notifyUser" placeholder="提醒人" clearable></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <template #footer>
        <span class="dialog-footer">
            <el-button @click="isShowDialog = !isShowDialog" size="default">取 消</el-button>
            <el-button type="primary" v-throttle @click="onSubmit" size="default">确 定</el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>
 
<script lang="ts">
import { reactive, toRefs, onMounted, defineComponent, ref } from 'vue';
import { ElMessageBox, ElMessage } from 'element-plus';
import axios from "axios";
import {workApplyApi} from "/@/api/specialWorkSystem/workApply";
import {judgeReportApi} from "/@/api/dataUpload/saftyBaseInfo/judgeReport";
 
// 定义接口来定义对象的类型
interface DataState {
  title: string
  isShowDialog: boolean
  form: {
    uuid: string
    name: string
    cateName: string
    orgName: string
    pusTime: string
    effectiveTime: string
    dueTime: string
    notifyUser: string
  }
  rules:{}
}
 
export default defineComponent({
  name: 'reportDialog',
  setup(props, context) {
    const formRef = ref()
    const state = reactive<DataState>({
      title: '',
      isShowDialog: false,
      form: {
        uuid:'',
        name: '',
        cateName: '',
        orgName: '',
        pusTime: '',
        effectiveTime: '',
        dueTime: '',
        notifyUser: ''
      },
      rules:{
        name: [{ required: true, message: '请填写证书名称', trigger: 'blur' }],
        cateName: [{ required: true, message: '请填写分类名称', trigger: 'blur' }],
        orgName: [{ required: true, message: '请填写发证机构', trigger: 'blur' }],
        notifyUser: [{ required: true, message: '请填写提醒人', trigger: 'blur' }]
      }
    })
 
    // 页面加载时
    onMounted(() => {
 
    })
    // 打开弹窗
    const open = (type: string, data: object) => {
      state.isShowDialog = true;
      if (type === 'add') {
        state.title = '新增上报';
        state.form = {
          uuid:'',
          name: '',
          cateName: '',
          orgName: '',
          pusTime: '',
          effectiveTime: '',
          dueTime: '',
          notifyUser: ''
        }
      }else{
        state.title = '重新上报'
        Object.keys(state.form).forEach(key => {
          if (Object.prototype.hasOwnProperty.call(data,key)) {
            state.form[key] = JSON.parse(JSON.stringify(data))[key];
          }
        })
        // state.form = {
        //   uuid: data.uuid,
        //   name: '',
        //   cateName: '',
        //   orgName: '',
        //   pusTime: '',
        //   effectiveTime: '',
        //   dueTime: '',
        //   notifyUser: ''
        // }
      }
    };
 
    // 新增修改
    const onSubmit = async () => {
      formRef.value.validate(async (valid:Boolean) => {
        if(valid){
          const res = await judgeReportApi().addCard([state.form])
          if(res.data.code == 200){
            ElMessage({
              type:'success',
              message:'数据上报成功'
            })
            state.isShowDialog = false
          }else{
            ElMessage({
              type:'warning',
              message:res.data.msg
            })
          }
          context.emit('refresh')
        }else{
          ElMessage({
            type:'warning',
            message:'请完善基本信息'
          })
        }
      })
    }
 
 
    return {
      formRef,
      open,
      onSubmit,
      ...toRefs(state)
    };
  }
});
</script>