Blame view

antis-ncc-admin/src/views/attendance/BatchDeleteDialog.vue 6 KB
5b6e99a5   李宇   ```
1
  <template>
e5f8ae55   “wangming”   ```
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
    <el-dialog title="批量删除考勤数据" :visible.sync="visible" width="480px" custom-class="batch-delete-attendance-dialog"
      :close-on-click-modal="false" @close="close">
      <div class="batch-delete-body">
        <div class="batch-delete-intro">
          <i class="el-icon-warning-outline intro-icon" />
          <div class="intro-text">
            <p class="intro-title">按月份清空考勤汇总</p>
            <p class="intro-desc">将删除所选月份下全部汇总记录(含 Excel 导入与打卡同步),删除后无法恢复。</p>
          </div>
        </div>
  
        <el-form :model="form" label-width="88px" label-position="right" :rules="rules" ref="form"
          class="batch-delete-form" @submit.native.prevent>
          <el-form-item label="删除月份" prop="statMonth">
            <el-date-picker v-model="form.statMonth" type="month" value-format="yyyy-MM" format="yyyy年MM月"
              placeholder="请选择要删除的月份" style="width: 100%" :picker-options="pickerOptions" clearable
              @change="onMonthChange" />
5b6e99a5   李宇   ```
19
20
          </el-form-item>
        </el-form>
e5f8ae55   “wangming”   ```
21
22
23
24
25
26
27
28
29
30
31
32
  
        <div v-if="selectedLabel" class="batch-delete-target">
          <div class="target-label">即将删除范围</div>
          <div class="target-value">
            <i class="el-icon-date" />
            <span>{{ selectedLabel }}</span>
          </div>
          <div class="target-hint">该月所有员工的考勤汇总数据将被永久删除</div>
        </div>
  
        <el-alert class="batch-delete-alert" title="操作不可撤销" type="warning" description="建议在删除前先导出模板备份,或确认该月数据已不再需要。"
          show-icon :closable="false" />
5b6e99a5   李宇   ```
33
      </div>
e5f8ae55   “wangming”   ```
34
  
5b6e99a5   李宇   ```
35
36
      <div slot="footer" class="dialog-footer">
        <el-button @click="close">取消</el-button>
e5f8ae55   “wangming”   ```
37
38
        <el-button type="danger" icon="el-icon-delete" :disabled="!form.statMonth" :loading="deleting"
          @click="confirmDelete">
5b6e99a5   李宇   ```
39
40
41
42
43
44
45
46
47
48
49
50
          确定删除
        </el-button>
      </div>
    </el-dialog>
  </template>
  
  <script>
  import request from '@/utils/request'
  
  export default {
    name: 'BatchDeleteDialog',
    data() {
e5f8ae55   “wangming”   ```
51
52
53
      const now = new Date()
      const minYear = now.getFullYear() - 5
      const maxYear = now.getFullYear() + 1
5b6e99a5   李宇   ```
54
55
56
57
      return {
        visible: false,
        deleting: false,
        form: {
e5f8ae55   “wangming”   ```
58
          statMonth: null,
5b6e99a5   李宇   ```
59
60
61
62
          year: null,
          month: null
        },
        rules: {
e5f8ae55   “wangming”   ```
63
64
          statMonth: [
            { required: true, message: '请选择删除月份', trigger: 'change' }
5b6e99a5   李宇   ```
65
66
          ]
        },
e5f8ae55   “wangming”   ```
67
68
69
70
71
72
73
74
75
76
77
78
        pickerOptions: {
          disabledDate(date) {
            const y = date.getFullYear()
            return y < minYear || y > maxYear
          }
        }
      }
    },
    computed: {
      selectedLabel() {
        if (!this.form.year || !this.form.month) return ''
        return `${this.form.year}年${this.form.month}月`
5b6e99a5   李宇   ```
79
80
81
      }
    },
    methods: {
e5f8ae55   “wangming”   ```
82
      init(defaultMonth) {
5b6e99a5   李宇   ```
83
        this.visible = true
e5f8ae55   “wangming”   ```
84
        this.resetForm(defaultMonth)
5b6e99a5   李宇   ```
85
      },
e5f8ae55   “wangming”   ```
86
      resetForm(defaultMonth) {
5b6e99a5   李宇   ```
87
        this.deleting = false
e5f8ae55   “wangming”   ```
88
89
        this.form.statMonth = defaultMonth || null
        this.syncYearMonthFromStatMonth()
5b6e99a5   李宇   ```
90
91
92
93
94
95
        this.$nextTick(() => {
          if (this.$refs.form) {
            this.$refs.form.clearValidate()
          }
        })
      },
e5f8ae55   “wangming”   ```
96
97
98
99
100
101
102
103
104
105
106
107
108
109
      onMonthChange(val) {
        this.form.statMonth = val || null
        this.syncYearMonthFromStatMonth()
      },
      syncYearMonthFromStatMonth() {
        if (!this.form.statMonth) {
          this.form.year = null
          this.form.month = null
          return
        }
        const parts = this.form.statMonth.split('-')
        this.form.year = parseInt(parts[0], 10)
        this.form.month = parseInt(parts[1], 10)
      },
5b6e99a5   李宇   ```
110
111
      confirmDelete() {
        this.$refs.form.validate((valid) => {
e5f8ae55   “wangming”   ```
112
113
114
115
116
117
118
119
120
121
122
123
          if (!valid) return
          this.$confirm(
            `确定删除 ${this.selectedLabel} 的全部考勤汇总数据吗?此操作不可恢复!`,
            '确认删除',
            {
              confirmButtonText: '确定删除',
              cancelButtonText: '取消',
              type: 'warning'
            }
          ).then(() => {
            this.performDelete()
          }).catch(() => { })
5b6e99a5   李宇   ```
124
125
126
127
        })
      },
      performDelete() {
        this.deleting = true
5b6e99a5   李宇   ```
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
        request({
          url: `/api/Extend/lqattendancesummary/DeleteByMonth/${this.form.year}/${this.form.month}`,
          method: 'DELETE'
        }).then(res => {
          this.deleting = false
          if (res.code === 200) {
            this.$message.success(res.msg || '删除成功')
            this.close()
            this.$emit('refresh', true)
          } else {
            this.$message.error(res.msg || '删除失败')
          }
        }).catch(err => {
          this.deleting = false
          this.$message.error('删除失败,请重试')
          console.error('删除失败:', err)
        })
      },
      close() {
        this.visible = false
        this.resetForm()
      }
    }
  }
  </script>
  
e5f8ae55   “wangming”   ```
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
  <style lang="scss" scoped>
  .batch-delete-body {
    padding: 4px 0 0;
  }
  
  .batch-delete-intro {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 14px 16px;
    margin-bottom: 20px;
    background: #fdf6ec;
    border: 1px solid #faecd8;
    border-radius: 8px;
  
    .intro-icon {
      flex-shrink: 0;
      font-size: 22px;
      color: #e6a23c;
      margin-top: 2px;
    }
  
    .intro-title {
      margin: 0 0 6px;
      font-size: 14px;
      font-weight: 600;
      color: #303133;
      line-height: 1.4;
    }
  
    .intro-desc {
      margin: 0;
      font-size: 13px;
      color: #606266;
      line-height: 1.5;
    }
  }
  
  .batch-delete-form {
    margin-bottom: 16px;
  }
  
  .batch-delete-target {
    padding: 14px 16px;
    margin-bottom: 16px;
    background: #f5f7fa;
    border-radius: 8px;
    border: 1px solid #ebeef5;
  
    .target-label {
      font-size: 12px;
      color: #909399;
      margin-bottom: 8px;
    }
  
    .target-value {
      display: flex;
      align-items: center;
      gap: 8px;
      font-size: 18px;
      font-weight: 600;
      color: #f56c6c;
      line-height: 1.4;
  
      i {
        font-size: 18px;
      }
    }
  
    .target-hint {
      margin-top: 8px;
      font-size: 12px;
      color: #909399;
      line-height: 1.4;
    }
  }
  
  .batch-delete-alert {
    border-radius: 8px;
  }
  
5b6e99a5   李宇   ```
235
236
237
238
  .dialog-footer {
    text-align: right;
  }
  </style>