吴健
2024-11-16 d1851ded02d6f253ed2ca1459c4e514102c975d5
提交 | 用户 | 时间
a6316e 1 <template>
A 2   <div class="app-container">
3     <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
4       <el-form-item label="车间编码" prop="workshopCode">
5         <el-input
6           v-model="queryParams.workshopCode"
7           placeholder="请输入车间编码"
8           clearable
9           @keyup.enter.native="handleQuery"
10         />
11       </el-form-item>
12       <el-form-item label="车间名称" prop="workshopName">
13         <el-input
14           v-model="queryParams.workshopName"
15           placeholder="请输入车间名称"
16           clearable
17           @keyup.enter.native="handleQuery"
18         />
19       </el-form-item>
20       <el-form-item>
21         <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
22         <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
23       </el-form-item>
24     </el-form>
25
26     <el-row :gutter="10" class="mb8">
27       <el-col :span="1.5">
28         <el-button
29           type="primary"
30           plain
31           icon="el-icon-plus"
32           size="mini"
33           @click="handleAdd"
34           v-hasPermi="['bs:workshop:add']"
35         >新增</el-button>
36       </el-col>
37       <el-col :span="1.5">
38         <el-button
39           type="success"
40           plain
41           icon="el-icon-edit"
42           size="mini"
43           :disabled="single"
44           @click="handleUpdate"
45           v-hasPermi="['bs:workshop:edit']"
46         >修改</el-button>
47       </el-col>
48       <el-col :span="1.5">
49         <el-button
50           type="danger"
51           plain
52           icon="el-icon-delete"
53           size="mini"
54           :disabled="multiple"
55           @click="handleDelete"
56           v-hasPermi="['bs:workshop:remove']"
57         >删除</el-button>
58       </el-col>
59       <el-col :span="1.5">
60         <el-button
61           type="warning"
62           plain
63           icon="el-icon-download"
64           size="mini"
65           @click="handleExport"
66           v-hasPermi="['bs:workshop:export']"
67         >导出</el-button>
68       </el-col>
69       <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
70     </el-row>
71
72     <el-table v-loading="loading" :data="workshopList" @selection-change="handleSelectionChange">
73       <el-table-column type="selection" width="55" align="center" />
74       <el-table-column label="id" align="center" prop="id" />
75       <el-table-column label="车间编码" align="center" prop="workshopCode" />
76       <el-table-column label="车间名称" align="center" prop="workshopName" />
77       <el-table-column label="备注" align="center" prop="remarks" />
78       <el-table-column label="创建人" align="center" prop="createBy" />
79 <!--      <el-table-column label="创建时间" align="center" prop="createTime" width="180">-->
80 <!--        <template slot-scope="scope">-->
81 <!--          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>-->
82 <!--        </template>-->
83 <!--      </el-table-column>-->
84       <el-table-column label="更新人" align="center" prop="updateBy" />
85 <!--      <el-table-column label="更新时间" align="center" prop="updateTime" width="180">-->
86 <!--        <template slot-scope="scope">-->
87 <!--          <span>{{ parseTime(scope.row.updateTime, '{y}-{m}-{d}') }}</span>-->
88 <!--        </template>-->
89 <!--      </el-table-column>-->
90       <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
91         <template slot-scope="scope">
92           <el-button
93             size="mini"
94             type="text"
95             icon="el-icon-edit"
96             @click="handleUpdate(scope.row)"
97             v-hasPermi="['bs:workshop:edit']"
98           >修改</el-button>
99           <el-button
100             size="mini"
101             type="text"
102             icon="el-icon-delete"
103             @click="handleDelete(scope.row)"
104             v-hasPermi="['bs:workshop:remove']"
105           >删除</el-button>
106         </template>
107       </el-table-column>
108     </el-table>
109
110     <pagination
111       v-show="total>0"
112       :total="total"
113       :page.sync="queryParams.pageNum"
114       :limit.sync="queryParams.pageSize"
115       @pagination="getList"
116     />
117
118     <!-- 添加或修改车间信息对话框 -->
119     <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
120       <el-form ref="form" :model="form" :rules="rules" label-width="80px">
121         <el-form-item label="车间编码" prop="workshopCode">
122           <el-input v-model="form.workshopCode" placeholder="请输入车间编码" />
123         </el-form-item>
124         <el-form-item label="车间名称" prop="workshopName">
125           <el-input v-model="form.workshopName" placeholder="请输入车间名称" />
126         </el-form-item>
127         <el-form-item label="备用字段1" prop="spareField1">
128           <el-input v-model="form.spareField1" placeholder="请输入备用字段1" />
129         </el-form-item>
130         <el-form-item label="备用字段2" prop="spareField2">
131           <el-input v-model="form.spareField2" placeholder="请输入备用字段2" />
132         </el-form-item>
133         <el-form-item label="备注" prop="remarks">
134           <el-input v-model="form.remarks" placeholder="请输入备注" />
135         </el-form-item>
136       </el-form>
137       <div slot="footer" class="dialog-footer">
138         <el-button type="primary" @click="submitForm">确 定</el-button>
139         <el-button @click="cancel">取 消</el-button>
140       </div>
141     </el-dialog>
142   </div>
143 </template>
144
145 <script>
146 import { listWorkshop, getWorkshop, delWorkshop, addWorkshop, updateWorkshop } from "@/api/main/bs/workshop";
147
148 export default {
149   name: "Workshop",
150   data() {
151     return {
152       // 遮罩层
153       loading: true,
154       // 选中数组
155       ids: [],
156       // 非单个禁用
157       single: true,
158       // 非多个禁用
159       multiple: true,
160       // 显示搜索条件
161       showSearch: true,
162       // 总条数
163       total: 0,
164       // 车间信息表格数据
165       workshopList: [],
166       // 弹出层标题
167       title: "",
168       // 是否显示弹出层
169       open: false,
170       // 查询参数
171       queryParams: {
172         pageNum: 1,
173         pageSize: 10,
174         workshopCode: null,
175         workshopName: null,
176       },
177       // 表单参数
178       form: {},
179       // 表单校验
180       rules: {
181       }
182     };
183   },
184   created() {
185     this.getList();
186   },
187   methods: {
188     /** 查询车间信息列表 */
189     getList() {
190       this.loading = true;
191       listWorkshop(this.queryParams).then(response => {
192         this.workshopList = response.rows;
193         this.total = response.total;
194         this.loading = false;
195       });
196     },
197     // 取消按钮
198     cancel() {
199       this.open = false;
200       this.reset();
201     },
202     // 表单重置
203     reset() {
204       this.form = {
205         id: null,
206         workshopCode: null,
207         workshopName: null,
208         spareField1: null,
209         spareField2: null,
210         remarks: null,
211         createBy: null,
212         createTime: null,
213         updateBy: null,
214         updateTime: null
215       };
216       this.resetForm("form");
217     },
218     /** 搜索按钮操作 */
219     handleQuery() {
220       this.queryParams.pageNum = 1;
221       this.getList();
222     },
223     /** 重置按钮操作 */
224     resetQuery() {
225       this.resetForm("queryForm");
226       this.handleQuery();
227     },
228     // 多选框选中数据
229     handleSelectionChange(selection) {
230       this.ids = selection.map(item => item.id)
231       this.single = selection.length!==1
232       this.multiple = !selection.length
233     },
234     /** 新增按钮操作 */
235     handleAdd() {
236       this.reset();
237       this.open = true;
238       this.title = "添加车间信息";
239     },
240     /** 修改按钮操作 */
241     handleUpdate(row) {
242       this.reset();
243       const id = row.id || this.ids
244       getWorkshop(id).then(response => {
245         this.form = response.data;
246         this.open = true;
247         this.title = "修改车间信息";
248       });
249     },
250     /** 提交按钮 */
251     submitForm() {
252       this.$refs["form"].validate(valid => {
253         if (valid) {
254           if (this.form.id != null) {
255             updateWorkshop(this.form).then(response => {
256               this.$modal.msgSuccess("修改成功");
257               this.open = false;
258               this.getList();
259             });
260           } else {
261             addWorkshop(this.form).then(response => {
262               this.$modal.msgSuccess("新增成功");
263               this.open = false;
264               this.getList();
265             });
266           }
267         }
268       });
269     },
270     /** 删除按钮操作 */
271     handleDelete(row) {
272       const ids = row.id || this.ids;
273       this.$modal.confirm('是否确认删除车间信息编号为"' + ids + '"的数据项?').then(function() {
274         return delWorkshop(ids);
275       }).then(() => {
276         this.getList();
277         this.$modal.msgSuccess("删除成功");
278       }).catch(() => {});
279     },
280     /** 导出按钮操作 */
281     handleExport() {
282       this.download('bs/workshop/export', {
283         ...this.queryParams
284       }, `workshop_${new Date().getTime()}.xlsx`)
285     }
286   }
287 };
288 </script>