admin
6 天以前 f6789ac9f44a6b1f9d95421329bb1f0a7cd52d6d
提交 | 用户 | 时间
f6789a 1 <template>
A 2   <div class="app-container">
3     <el-card class="box-card">
4         <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
5           <el-form-item label="物料编码" prop="materialCode">
6             <el-input
7               v-model="queryParams.materialCode"
8               placeholder="请输入物料编码"
9               clearable
10               @keyup.enter.native="handleQuery"
11             />
12           </el-form-item>
13           <el-form-item label="物料名称" prop="materialName">
14             <el-input
15               v-model="queryParams.materialName"
16               placeholder="请输入物料名称"
17               clearable
18               @keyup.enter.native="handleQuery"
19             />
20           </el-form-item>
21           <el-form-item style="float: right">
22             <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
23             <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
24           </el-form-item>
25         </el-form>
26     </el-card>
27
28     <el-card style="margin-top: 10px" class="box-card">
29         <el-row :gutter="10" class="mb8">
30           <el-col :span="1.5">
31             <el-button
32               type="primary"
33               plain
34               icon="el-icon-plus"
35               size="mini"
36               @click="handleAdd"
37               v-hasPermi="['sc:materialConf:add']"
38             >新增</el-button>
39           </el-col>
40           <el-col :span="1.5">
41             <el-button
42               type="success"
43               plain
44               icon="el-icon-edit"
45               size="mini"
46               :disabled="single"
47               @click="handleUpdate"
48               v-hasPermi="['sc:materialConf:edit']"
49             >修改</el-button>
50           </el-col>
51           <el-col :span="1.5">
52             <el-button
53               type="danger"
54               plain
55               icon="el-icon-delete"
56               size="mini"
57               :disabled="multiple"
58               @click="handleDelete"
59               v-hasPermi="['sc:materialConf:remove']"
60             >删除</el-button>
61           </el-col>
62           <el-col :span="1.5">
63             <el-button
64               type="warning"
65               plain
66               icon="el-icon-download"
67               size="mini"
68               @click="handleExport"
69               v-hasPermi="['sc:materialConf:export']"
70             >导出</el-button>
71           </el-col>
72           <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
73         </el-row>
74
75         <el-table border v-loading="loading" :data="materialConfList" @selection-change="handleSelectionChange">
76           <el-table-column type="selection" width="55" align="center" />
77           <el-table-column label="物料编码" align="center" prop="materialCode">
78           </el-table-column>
79           <el-table-column label="物料名称" align="center" prop="materialName">
80           </el-table-column>
81           <el-table-column label="模组类型" align="center" prop="modelCode">
82           </el-table-column>
83           <el-table-column label="状态" align="center" width="100">
84             <template slot-scope="scope">
85               <el-switch
86                 v-model="scope.row.status"
87                 active-value="0"
88                 inactive-value="1"
89                 @change="handleStatusChange(scope.row)"
90               ></el-switch>
91             </template>
92           </el-table-column>
93           <el-table-column label="备注" align="center" prop="remark">
94           </el-table-column>
95           <el-table-column label="创建用户" align="center" prop="createUser">
96           </el-table-column>
97           <el-table-column label="创建时间" align="center" prop="createTime">
98           </el-table-column>
99           <el-table-column label="更改用户" align="center" prop="updateUser">
100           </el-table-column>
101           <el-table-column label="更改时间" align="center" prop="updateTime">
102           </el-table-column>
103           <el-table-column width="200" label="操作" align="center" class-name="small-padding fixed-width">
104             <template slot-scope="scope">
105               <el-button
106                 size="mini"
107                 type="success"
108                 plain
109                 style="width: 72px"
110                 icon="el-icon-edit"
111                 @click="handleUpdate(scope.row)"
112                 v-hasPermi="['sc:materialConf:edit']"
113               >修改</el-button>
114               <el-button
115                 size="mini"
116                 type="danger"
117                 plain
118                 style="width: 72px"
119                 icon="el-icon-delete"
120                 @click="handleDelete(scope.row)"
121                 v-hasPermi="['sc:materialConf:remove']"
122               >删除</el-button>
123             </template>
124           </el-table-column>
125         </el-table>
126     </el-card>
127
128     <pagination
129       v-show="total>0"
130       :total="total"
131       :page.sync="queryParams.pageNum"
132       :limit.sync="queryParams.pageSize"
133       @pagination="getList"
134     />
135
136     <!-- 添加或修改工单物料配置对话框 -->
137     <el-dialog v-dialogpop-up :title="title" :visible.sync="open" width="500px" append-to-body>
138       <span slot="title">
139         <i class="el-icon-s-order"></i>
140         {{titleName}}
141       </span>
142       <el-form ref="form" :model="form" :rules="rules" label-width="80px">
143         <el-form-item label="物料编码" prop="materialCode">
144           <el-input v-model="form.materialCode" placeholder="请输入物料编码" />
145         </el-form-item>
146         <el-form-item label="物料名称" prop="materialName">
147           <el-input v-model="form.materialName" placeholder="请输入物料名称" />
148         </el-form-item>
149         <el-form-item label="模组类型" prop="modelCode">
150           <el-input v-model="form.modelCode" placeholder="请输入模组类型" />
151         </el-form-item>
152         <el-form-item label="备注" prop="remark">
153           <el-input v-model="form.remark" placeholder="请输入备注" />
154         </el-form-item>
155       </el-form>
156       <div slot="footer" class="dialog-footer">
157         <el-button type="primary" @click="submitForm">确 定</el-button>
158         <el-button @click="cancel">取 消</el-button>
159       </div>
160     </el-dialog>
161   </div>
162 </template>
163
164 <script>
165 import {
166   listMaterialConf,
167   getMaterialConf,
168   delMaterialConf,
169   addMaterialConf,
170   updateMaterialConf,
171   changeMaterialStatus
172 } from "@/api/main/sc/materialConf/materialConf";
173 import {changeRoleStatus} from "@/api/system/role";
174
175 export default {
176   name: "MaterialConf",
177   data() {
178     return {
179       // 遮罩层
180       loading: true,
181       titleName: "",
182       // 选中数组
183       ids: [],
184       // 非单个禁用
185       single: true,
186       // 非多个禁用
187       multiple: true,
188       // 显示搜索条件
189       showSearch: true,
190       // 总条数
191       total: 0,
192       // 工单物料配置表格数据
193       materialConfList: [],
194       // 弹出层标题
195       title: "",
196       // 是否显示弹出层
197       open: false,
198       // 查询参数
199       queryParams: {
200         pageNum: 1,
201         pageSize: 10,
202         materialCode: null,
203         materialName: null,
204       },
205       // 表单参数
206       form: {},
207       // 表单校验
208       rules: {
209         id: [
210           { required: true, message: "主键id不能为空", trigger: "blur" }
211         ],
212       }
213     };
214   },
215   created() {
216     this.getList();
217   },
218   methods: {
219     handleStatusChange(row) {
220       let text = row.status === "0" ? "启用" : "停用";
221       // 计算状态为1的物料数量
222       const activeMaterialCount = this.materialConfList.filter(material => material.status === "0").length;
223       // 如果要启用物料,检查状态为1的物料数量是否大于2
224       if (activeMaterialCount > 2) {
225         // 恢复状态
226         row.status = "1"; // 假设原始状态是1
227         this.$modal.msgWarning("已经有两个物料处于启用状态,不能启用更多物料。");
228         return;
229       }
230
231       this.$modal.confirm('确认要"' + text + '""' + row.materialCode + '"物料吗?').then(function() {
232         return changeMaterialStatus(row.id, row.status);
233       }).then(() => {
234         this.$modal.msgSuccess(text + "成功");
235       }).catch(function() {
236         row.status = row.status === "0" ? "1" : "0";
237       });
238     },
239     /** 查询工单物料配置列表 */
240     getList() {
241       this.loading = true;
242       listMaterialConf(this.queryParams).then(response => {
243         this.materialConfList = response.rows;
244         this.total = response.total;
245         this.loading = false;
246       });
247     },
248     // 取消按钮
249     cancel() {
250       this.open = false;
251       this.reset();
252     },
253     // 表单重置
254     reset() {
255       this.form = {
256         id: null,
257         materialCode: null,
258         materialName: null,
259         remark: null,
260         sparefield1: null,
261         sparefield2: null,
262         createUser: null,
263         createTime: null,
264         updateUser: null,
265         updateTime: null,
266         status: null,
267         modelCode: null
268
269       };
270       this.resetForm("form");
271     },
272     /** 搜索按钮操作 */
273     handleQuery() {
274       this.queryParams.pageNum = 1;
275       this.getList();
276     },
277     /** 重置按钮操作 */
278     resetQuery() {
279       this.resetForm("queryForm");
280       this.handleQuery();
281     },
282     // 多选框选中数据
283     handleSelectionChange(selection) {
284       this.ids = selection.map(item => item.id)
285       this.single = selection.length!==1
286       this.multiple = !selection.length
287     },
288     /** 新增按钮操作 */
289     handleAdd() {
290       this.reset();
291       this.open = true;
292       this.titleName = "添加工单物料配置";
293     },
294     /** 修改按钮操作 */
295     handleUpdate(row) {
296       this.reset();
297       const id = row.id || this.ids
298       getMaterialConf(id).then(response => {
299         this.form = response.data;
300         this.open = true;
301         this.titleName = "修改工单物料配置";
302       });
303     },
304     /** 提交按钮 */
305     submitForm() {
306       this.$refs["form"].validate(valid => {
307         if (valid) {
308           if (this.form.id != null) {
309             updateMaterialConf(this.form).then(response => {
310               this.$modal.msgSuccess("修改成功");
311               this.open = false;
312               this.getList();
313             });
314           } else {
315             addMaterialConf(this.form).then(response => {
316               this.$modal.msgSuccess("新增成功");
317               this.open = false;
318               this.getList();
319             });
320           }
321         }
322       });
323     },
324     /** 删除按钮操作 */
325     handleDelete(row) {
326       const ids = row.id || this.ids;
327       this.$modal.confirm('是否确认删除工单物料配置编号为"' + ids + '"的数据项?').then(function() {
328         return delMaterialConf(ids);
329       }).then(() => {
330         this.getList();
331         this.$modal.msgSuccess("删除成功");
332       }).catch(() => {});
333     },
334     /** 导出按钮操作 */
335     handleExport() {
336       this.download('sc/materialConf/export', {
337         ...this.queryParams
338       }, `materialConf_${new Date().getTime()}.xlsx`)
339     }
340   }
341 };
342 </script>