马宇豪
2024-01-26 c694cffc8541d921e5256d33e14e3237454de950
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
<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="examJoinRate">
              <el-input v-model.trim="form.examJoinRate" placeholder="考试参与率" type="number" clearable>
                <template #append>%</template>
              </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="examPassRate">
              <el-input v-model.trim="form.examPassRate" placeholder="考试合格率" type="number" clearable>
                <template #append>%</template>
              </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="missExam">
              <el-input v-model.trim="form.missExam" placeholder="缺考总数" type="number" 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="repairNum">
              <el-input v-model.trim="form.repairNum" placeholder="待补课总数" type="number" 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="studyAverage">
              <el-input v-model.trim="form.studyAverage" placeholder="人均学时" type="number" 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="studyQualifyRate">
              <el-input v-model.trim="form.studyQualifyRate" placeholder="学时达标率" type="number" clearable>
                <template #append>%</template>
              </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="trainPerson">
              <el-input v-model.trim.number="form.trainPerson" placeholder="培训人数" type="number" 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="trainJoinRate">
              <el-input v-model.trim="form.trainJoinRate" placeholder="培训参与率" type="number" clearable>
                <template #append>%</template>
              </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 {educateTrainApi} from "/@/api/dataUpload/educateTrain";
 
// 定义接口来定义对象的类型
interface DataState {
  title: string
  isShowDialog: boolean
  form: {
    examJoinRate: string
    examPassRate: string
    missExam: string
    rankWeek: string
    repairNum: string
    studyAverage: string
    studyQualifyRate: string
    trainPerson: null | number
    trainJoinRate: string
  }
  rules:{}
}
 
export default defineComponent({
  name: 'reportDialog',
  setup(props, context) {
    const formRef = ref()
    const state = reactive<DataState>({
      title: '',
      isShowDialog: false,
      form: {
        examJoinRate: '',
        examPassRate: '',
        missExam: '',
        rankWeek: '',
        repairNum: '',
        studyAverage: '',
        studyQualifyRate: '',
        trainPerson: null,
        trainJoinRate: ''
      },
      rules:{
        examJoinRate: [{ required: true, message: '请填写考试参与率', trigger: 'blur' }],
        examPassRate: [{ required: true, message: '请填写考试合格率', trigger: 'blur' }],
        missExam: [{ required: true, message: '请填写缺考总数', trigger: 'blur' }],
        repairNum: [{ required: true, message: '请填写待补课总数', trigger: 'blur' }],
        studyAverage: [{ required: true, message: '请填写人均学时', trigger: 'blur' }],
        studyQualifyRate: [{ required: true, message: '请填写学时达标率', trigger: 'blur' }],
        trainPerson: [{ required: true, message: '请填写培训人数', trigger: 'blur' }],
        trainJoinRate: [{ required: true, message: '请填写培训参与率', trigger: 'blur' }]
      }
    })
 
    // 页面加载时
    onMounted(() => {
 
    })
    // 打开弹窗
    const open = (type: string, data: object) => {
      state.isShowDialog = true;
      if (type === 'add') {
        state.title = '新增上报';
        state.form = {
          examJoinRate: '',
          examPassRate: '',
          missExam: '',
          rankWeek: getWeekNumber(),
          repairNum: '',
          studyAverage: '',
          studyQualifyRate: '',
          trainPerson: null,
          trainJoinRate: ''
        };
      }
    };
 
    // 新增修改
    const onSubmit = async () => {
      formRef.value.validate(async (valid:Boolean) => {
        if(valid){
          const res = await educateTrainApi().addTrain([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:'请完善基本信息'
          })
        }
      })
    }
 
    function getWeekNumber() {
      // 获取当前日期
      const today = new Date();
 
      // 获取当前年的第一天
      const firstDayOfYear = new Date(today.getFullYear(), 0, 1);
 
      // 计算当前日期与第一天之间的时间差(毫秒)
      const timeDiff = today - firstDayOfYear;
 
      // 计算经过的天数,并将其转换为周数
      const weekNumber = Math.ceil((timeDiff / (24 * 60 * 60 * 1000) + 1) / 7);
 
      return weekNumber.toString()
    }
 
    return {
      formRef,
      open,
      onSubmit,
      ...toRefs(state)
    };
  }
});
</script>