licp
2024-12-27 6d0552908bc5c17ab9af74120819ec6d3e5df674
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
<template>
    <div>
        <TableCard :showTitle="false">
            <template slot="form">
                <div class="action-box">
                    <div></div>
                    <div class="flex">
                        <el-button :disabled="contentsId == 0" icon="el-icon-plus" type="primary" @click="showDialog()">
                            新建
                        </el-button>
                        <el-button icon="el-icon-upload2" @click="exportExcel">
                            导出Excel
                        </el-button>
                    </div>
                </div>
            </template>
            <template v-slot:table>
                <ZTTable
                    :column="columns"
                    :height="'70vh'"
                    :isSelection="true"
                    :table-data="tableData"
                    style="margin-top: 18px; padding: 0 15px;"
                >
                    <div slot="action" slot-scope="scope">
                        <el-button type="text" @click="showDialog(scope)">编辑</el-button>
                        <el-button type="text" @click="delRow(scope)">
                            <span style="color: #F56C6C">删除</span>
                        </el-button>
                    </div>
                </ZTTable>
                <div class="pagination">
                    <div></div>
                    <el-pagination
                        :page-size="pagination.pageSize"
                        :page-sizes="[10, 20, 30, 40]"
                        :total="pagination.total"
                        layout="total, sizes, prev, pager, next, jumper"
                        @current-change="handleCurrent"
                        @size-change="handleSize"
                    >
                    </el-pagination>
                </div>
            </template>
        </TableCard>
        <Edit ref="editRef" :contentsId="contentsId" @submit="getTableData" type="编辑" />
    </div>
</template>
 
<script>
import TableCard from '@/components/caorui/TableCard/index.vue';
import ZTTable from '@/components/caorui/ZTTable/index.vue';
import Edit from "../components/Edit.vue"
import { selectQualifiedSupplierManagementPage, delSupplierManagement, exportSupplierManagement } from "@/assets/api/api";
import axios from "axios";
 
export default {
    components: {
        TableCard, ZTTable, Edit
    },
    props: {
        contentsId: {
            type: Number,
            default: 0
        }
    },
    data() {
        return {
            columns: [
                {
                    label: "供应商编号",
                    prop: "supplierRef"
                },
                {
                    label: "供应商",
                    prop: "supplierName"
                },
                {
                    label: "供应物品(服务)名称",
                    prop: "supplierItemServiceName"
                },
                {
                    label: "地址",
                    prop: "adress"
                },
                {
                    label: "联系电话",
                    prop: "phone"
                },
                {
                    fixed: "right",
                    dataType: "slot",
                    slot: "action",
                    label: "操作"
                }
            ],
            tableData: [],
            pagination: {
                current: 1,
                pageSize: 20,
                total: 0
            },
        }
    },
    mounted() {
        this.getTableData()
    },
    watch: {
        contentsId(newVal) {
            if (newVal !== 0) {
                this.getTableData();
            }
        },
    },
    methods: {
        // 获取表格数据
        async getTableData() {
            const {code, data } = await axios({
                method: 'get',
                url: selectQualifiedSupplierManagementPage,
                params: {
                  ...this.pagination,
                  parentId: this.contentsId
                }
            })
            if(code == 200) {
                this.tableData = data.records;
            }
        },
        showDialog(scope) {
            this.$refs.editRef.openDialog(scope)
        },
        handleCurrent(val) {
            this.pagination.current = val;
            this.getTableData()
        },
        handleSize(size) {
            this.pagination.pageSize = size;
            this.getTableData()
        },
        // 删除数据
        delRow(scope) {
            this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then( async () => {
                const { code } = await axios({
                    method: 'post',
                    url: `${delSupplierManagement}/${scope.row.supplierManagementId}`,
                })
                if(code == 200) {
                    this.$message.success('删除成功')
                    this.getTableData()
                } else {
                    this.$message.error('删除失败')
                }
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消删除'
                });
            })
        },
        async exportExcel() {
            const res = await axios({
                method: "post",
                url: `${exportSupplierManagement}/${this.contentsId}`,
                responseType: "blob"
            })
            const blob = new Blob([res], {type: 'application/octet-stream'});
          //将Blob 对象转换成字符串
          let reader = new FileReader();
          reader.readAsText(blob, 'utf-8');
          reader.onload = () => {
            try {
              let result = JSON.parse(reader.result);
              if (result.message) {
                this.$message.error(result.message);
              } else {
                const url = URL.createObjectURL(blob);
                const link = document.createElement('a');
                link.href = url;
                link.download = '合格供应商.xlsx';
                link.click();
                this.$message.success('导出成功')
              }
            } catch (err) {
              console.log(err);
              const url = URL.createObjectURL(blob);
              const link = document.createElement('a');
              link.href = url;
              link.download = '合格供应商.xlsx';
              link.click();
              this.$message.success('导出成功')
            }
          }
        }
    }
}
</script>
 
<style scoped>
.flex {
    display: flex;
}
.action-box {
    width: 100%;
    padding-top: 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.pagination {
    padding-top: 15px;
    padding-right: 10px;
    display: flex;
    justify-content: space-between
}
</style>