董国庆
2025-03-25 74ef5f08c232e5d0c71ff0deb7ff5e086c748788
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
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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
<template>
  <div class="app-container">
    <!-- 搜索区域 -->
    <div class="search-area">
      <el-form :inline="true" :model="queryParams" class="search-form">
        <el-form-item label="镇街">
          <el-select v-model="queryParams.street" placeholder="请选择" clearable size="small">
            <el-option v-for="item in streetOptions" :key="item.dictCode" :label="item.dictLabel" :value="item.dictLabel"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="资料名称">
          <el-input v-model="queryParams.name" placeholder="请输入" clearable size="small" />
        </el-form-item>
        <el-form-item>
          <el-button type="default" @click="resetQuery">重置</el-button>
          <el-button type="primary" @click="handleQuery">查询</el-button>
        </el-form-item>
      </el-form>
    </div>
 
    <!-- 操作按钮区域 -->
    <div class="action-buttons">
      <el-button v-hasPermi="['storing-data:add']" type="primary" @click="handleAdd">新增资料</el-button>
    </div>
 
    <!-- 表格区域 -->
    <el-table v-loading="loading" :data="tableData" border style="width: 100%">
      <el-table-column prop="street" label="镇/街道" min-width="120" align="center" />
      <el-table-column prop="name" label="资料名称" min-width="100" align="center">
        
      </el-table-column>
      <el-table-column prop="totalApplicants" label="附件内容" min-width="100" align="center" >
        <template slot-scope="scope">
          <el-button type="text" @click="handleDownload(scope.row)">{{ scope.row.attachName }}</el-button>
        </template>
      </el-table-column>
      <el-table-column prop="updateTime" label="更新时间" min-width="150" align="center" />
 
      <el-table-column label="操作" width="180" align="center" fixed="right">
        <template slot-scope="scope">
          <template>
            <el-button v-hasPermi="['storing-data:detail']" size="mini" type="text" @click="handleView(scope.row, 'detail')">详情</el-button>
            <el-button v-hasPermi="['storing-data:edit']" size="mini" type="text" @click="handleView(scope.row, 'edit')">编辑</el-button>
            <el-button v-hasPermi="['storing-data:delete']" size="mini" type="text" @click="handleDelete(scope.row)">删除</el-button>
          </template>
        </template>
      </el-table-column>
    </el-table>
 
    <!-- 分页区域 -->
    <div class="pagination-container">
      <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange"
        :current-page="queryParams.pageNum" :page-sizes="[10, 20, 30, 40]" :page-size="queryParams.pageSize"
        layout="total, sizes, prev, pager, next, jumper" :total="total">
      </el-pagination>
    </div>
 
 
    <!-- 上传组件 -->
    <upload-dialog ref="uploadDialog" :visible.sync="uploadDialogVisible" :type="uploadType" :streetOptions="streetOptions"
      @success="handleUploadSuccess" />
  </div>
</template>
 
<script>
import Pagination from "@/components/Pagination";
import UploadDialog from "./components/UploadDialog";
import { list, add, del, update } from "@/api/storing-data";
import { getDictData } from '@/api/placement'
 
export default {
  name: "StoringData",
  components: {
    Pagination,
    UploadDialog,
  },
  data() {
    return {
      // 遮罩层
      loading: false,
      // 总条数
      total: 4,
      // 状态数据字典
      statusOptions: [
        { value: "待审核", label: "待审核" },
        { value: "已通过", label: "已通过" },
        { value: "已驳回", label: "已驳回" },
      ],
      // 审核相关
      approvalType: "audit", // 'audit' 或 'detail'
      currentRow: {},
      // 上传相关
      uploadDialogVisible: false,
      uploadType: "add", // 'add' 或 'batch'
      // 表格数据
      tableData: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        street: undefined,
        name: undefined
      },
      streetOptions: []
    };
  },
  created() {
    this.getList();
    // 镇(街道)
    getDictData('street').then(response => {
      this.streetOptions = response.data
    })
  },
  methods: {
    /** 查询列表 */
    getList() {
      list(this.queryParams).then(res => {
        this.tableData = res.data.records;
        this.total = res.data.total;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        projectName: undefined,
        town: undefined,
        owner: undefined,
        idCard: undefined,
        status: undefined,
      };
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.uploadType = "add";
      this.uploadDialogVisible = true;
    },
    /** 导入模板下载操作 */
    handleImport() {
      // 实现下载逻辑
    },
    handleSizeChange(size) {
      this.queryParams.pageSize = size;
      this.getList();
    },
    handleCurrentChange(page) {
      this.queryParams.pageNum = page;
      this.getList();
    },
    /** 批量导入按钮操作 */
    handleBatchImport() {
      this.uploadType = "batch";
      this.uploadDialogVisible = true;
    },
    /** 统一的查看/详情按钮操作 */
    handleView(row, type) {
      this.$refs.uploadDialog.form = JSON.parse(JSON.stringify(row));
      this.$refs.uploadDialog.fileList = [{name: row.attachName, url: row.attachUrl}];
      this.uploadType = type;
      this.uploadDialogVisible = true;
    },
    /** 审核提交处理 */
    handleApprovalSubmit(data) {
      // 处理审核提交
      const { result, comment } = data;
      this.$message({
        type: "success",
        message: result === "pass" ? "审核通过成功!" : "审核驳回成功!",
      });
      // 刷新列表
      this.getList();
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      this.$confirm("是否确认删除该资料?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          del({id: row.id}).then(res => {
            this.$message({
              type: "success",
              message: "删除成功!",
            });
            this.getList();
          })
          .catch(() => { });
      })
      .catch(() => { });
    },
    /** 上传成功回调 */
    handleUploadSuccess() {
      this.uploadDialogVisible = false;
      this.getList();
      this.$message({
        type: "success",
        message: this.uploadType === "add" ? "新增成功!" : "批量导入成功!",
      });
    },
    // 处理文件下载
    handleDownload(row) {
      if (!row.attachUrl) {
        this.$message.error('文件不存在');
        return;
      }
      
      // 显示加载提示
      this.loading = true;
      
      // 使用fetch获取文件内容
      fetch(row.attachUrl)
      .then(response => response.blob())
      .then(blob => {
        // 创建blob URL
        const url = window.URL.createObjectURL(blob);
        // 创建临时a标签
        const link = document.createElement('a');
        link.href = url;
        link.download = row.attachName || '下载文件';
        document.body.appendChild(link);
        link.click();
        // 清理
        document.body.removeChild(link);
        window.URL.revokeObjectURL(url);
      })
      .catch(error => {
        console.error('下载失败:', error);
        this.$message.error('文件下载失败');
      })
      .finally(() => {
        this.loading = false;
      });
    },
  },
};
</script>
 
<style lang="scss" scoped>
.app-container {
  padding: 20px;
  background-color: #fff;
 
  .search-area {
    background-color: #fff;
    padding: 15px 0;
    margin-bottom: 20px;
    border-radius: 4px;
 
    .search-form {
      display: flex;
      align-items: center;
 
      .el-form-item {
        margin-bottom: 0;
        margin-right: 20px;
      }
    }
  }
 
  .action-buttons {
    margin-bottom: 20px;
 
    .el-button {
      margin-right: 10px;
    }
  }
 
  .el-table {
    margin-bottom: 20px;
 
    .el-button--text {
      padding: 0 8px;
 
      &:not(:last-child) {
        border-right: 1px solid #dcdfe6;
      }
    }
  }
 
  .pagination-container {
    text-align: center;
    margin-top: 20px;
  }
 
  .el-tag {
    border-radius: 2px;
  }
}
</style>