WYB
2021-03-22 91b8cdad021ab052e4991f3d41834a6f0ddc36b8
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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
<template>
  <section>
    <!--工具条-->
    <toolbar :buttonList="buttonList" @callFunction="callFunction"></toolbar>
 
    <!--列表-->
    <el-table
      :data="WMProductClass"
      highlight-current-row
      v-loading="listLoading"
      @selection-change="selsChange"
      @current-change="selectCurrentRow"
      @select="selsChangeOne"
      row-key="Id"
      lazy
      :load="load"
      :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
      style="width: 100%"
      ref="multipleTable"
    >
      <el-table-column type="selection" width="50"></el-table-column>
      <el-table-column type="index" width="200"></el-table-column>
      <el-table-column label="分类名称">
        <template slot-scope="scope">{{ scope.row.ClassName }}</template>
      </el-table-column>
      <el-table-column label="分类编号">
        <template slot-scope="scope">{{ scope.row.ClassCode }}</template>
      </el-table-column>
      <el-table-column prop="Sort" label="排序" width="400"></el-table-column>
      <el-table-column
        prop="LevelId"
        label="分类级别(数字代表相应的级别)"
        width="400"
      ></el-table-column>
      <!-- <el-table-column label="操作">
        <template scope="scope">
          <el-button size="small" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
          <el-button type="danger" size="small" @click="handleDel(scope.$index, scope.row)">删除</el-button>
        </template>
      </el-table-column> -->
    </el-table>
 
    <!--工具条-->
    <el-col :span="24" class="toolbar">
      <el-pagination
        layout="prev, pager, next"
        @current-change="handleCurrentChange"
        :page-size="20"
        :total="total"
        style="float: right"
      ></el-pagination>
    </el-col>
 
    <!--编辑界面-->
    <el-dialog
      title="编辑"
      :visible.sync="editFormVisible"
      v-model="editFormVisible"
      :close-on-click-modal="false"
    >
      <el-form
        :model="editForm"
        label-width="80px"
        :rules="editFormRules"
        ref="editForm"
      >
        <el-form-item prop="ParentIdArr" label="父级分类" width sortable>
          <el-cascader
            placeholder="请选择分类,支持搜索功能"
            style="width: 400px"
            v-model="editForm.ParentIdArr"
            :options="options"
            filterable
            change-on-select
          ></el-cascader>
        </el-form-item>
        <el-form-item label="分类名称" prop="ClassName">
          <el-input
            v-model="editForm.ClassName"
            placeholder="请输入分类名称"
          ></el-input>
        </el-form-item>
        <el-form-item label="排序" prop="Sort">
          <el-input
            type="number"
            v-model="editForm.Sort"
            placeholder="请输入排序"
          ></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click.native="editFormVisible = false">取消</el-button>
        <el-button
          type="primary"
          @click.native="editSubmit"
          :loading="editLoading"
          >提交</el-button
        >
      </div>
    </el-dialog>
 
    <!--新增界面-->
    <el-dialog
      title="新增"
      :visible.sync="addFormVisible"
      v-model="addFormVisible"
      :close-on-click-modal="false"
    >
      <el-form
        :model="addForm"
        label-width="80px"
        :rules="addFormRules"
        ref="addForm"
      >
        <el-form-item prop="ParentIdArr" label="父级分类" width sortable>
          <el-cascader
            placeholder="请选择分类,支持搜索功能"
            style="width: 400px"
            v-model="addForm.ParentIdArr"
            :options="options"
            filterable
            change-on-select
          ></el-cascader>
        </el-form-item>
        <el-form-item label="分类名称" prop="ClassName">
          <el-input
            v-model="addForm.ClassName"
            placeholder="请输入分类名称"
          ></el-input>
        </el-form-item>
        <el-form-item label="排序" prop="Sort">
          <el-input v-model="addForm.Sort" placeholder="请输入排序"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click.native="addFormVisible = false">取消</el-button>
        <el-button
          type="primary"
          @click.native="addSubmit"
          :loading="addLoading"
          >提交</el-button
        >
      </div>
    </el-dialog>
 
    <!--导入界面-->
    <!-- <el-dialog
      title="导入"
      :visible.sync="importFormVisible"
      v-model="importFormVisible"
      :close-on-click-modal="false"
    >
      <el-upload
        class="upload-demo"
        ref="upload"
        action="/api/WMProductClass/ImportProductClass"
        :on-preview="handlePreview"
        :on-remove="handleRemove"
        :on-change="handleChange"
        :file-list="fileList"
        :auto-upload="false"
      >
        <el-button slot="trigger" size="small" type="primary">选取商品分类表格</el-button>
        <el-button
          style="margin-left: 10px;"
          size="small"
          type="success"
          @click="submitUpload"
        >批量导入表格</el-button>
      </el-upload>
    </el-dialog> -->
 
    <el-dialog
      title="导入"
      :visible.sync="importFormVisible"
      v-model="importFormVisible"
      :close-on-click-modal="false"
    >
      <form id="upFileBox" style="display: inline-block">
        <input
          class="upload-demo"
          id="inputId"
          type="file"
          ref="files"
          style="width: 268px"
        />
      </form>
 
      <el-button
        class="el-icon-upload"
        type="primary"
        @click="submitForm($event)"
        v-loading.fullscreen.lock="uploading"
        element-loading-text="拼命导入中....."
        element-loading-spinner="el-icon-loading"
        element-loading-background="rgba(0, 0, 0, 0.8)"
        >导入表格</el-button
      >
    </el-dialog>
  </section>
</template>
 
<script>
import util from "../../../../util/date";
import {
  getWMProductClassListPage,
  getWMProductClassTreeTable,
  // removeWMProductClass,
  editWMProductClass,
  addWMProductClass,
  getWMProductClassTree,
  ExportWMProductClass,
  uploadProductClass,
} from "../../../api/api";
import { getButtonList } from "../../../promissionRouter";
import Toolbar from "../../../components/Toolbar";
 
export default {
  components: { Toolbar },
  data() {
    return {
      buttonList: [],
      currentRow: null,
      options: [],
      filters: {
        ClassName: "",
      },
      WMProductClass: [],
      total: 0,
      page: 1,
      listLoading: false,
      sels: [], //列表选中列
      //编辑
      editFormVisible: false, //编辑界面是否显示
      editLoading: false,
      //验证是否必填
      editFormRules: {
        ParentIdArr: [
          { required: true, message: "请选择分类下拉", trigger: "blur" },
        ],
        ClassName: [
          { required: true, message: "请输入分类名称", trigger: "blur" },
        ],
      },
      //编辑界面数据
      editForm: {},
      //新增
      addDialogFormVisible: false,
      addFormVisible: false, //新增界面是否显示
      addLoading: false,
      //验证是否必填
      addFormRules: {
        ParentIdArr: [
          { required: true, message: "请选择分类下拉", trigger: "blur" },
        ],
        ClassName: [
          { required: true, message: "请输入分类名称", trigger: "blur" },
        ],
      },
      //新增界面数据
      addForm: {},
      //导入
      importFormVisible: false, //导入界面是否显示
      uploading: false, //导入加载显示
      fileList: [],
    };
  },
  methods: {
    //选中行时勾选框
    selsChangeOne(selection, row) {
      this.currentRow = row;
      this.$refs.multipleTable.toggleRowSelection(row); //选中当前选择
      this.selectCurrentRow(row);
    },
    selectCurrentRow(val) {
      this.currentRow = val;
      this.$refs.multipleTable.toggleRowSelection(val); //选中当前选择
    },
    callFunction(item) {
      this.filters = {
        ClassName: item.search,
      };
      this[item.Func].apply(this, item);
    },
    handleCurrentChange(val) {
      this.page = val;
      this.getWMProductClass();
    },
    load(tree, treeNode, resolve) {
      let para = {
        page: this.page,
        parent: tree.Id,
        key: this.filters.ClassName,
      };
      getWMProductClassTreeTable(para).then((res) => {
        resolve(res.data.response);
      });
    },
    //获取用户列表
    getWMProductClass() {
      let para = {
        page: this.page,
        key: this.filters.ClassName,
      };
      this.listLoading = true;
 
      getWMProductClassTreeTable(para).then((res) => {
        this.WMProductClass = res.data.response;
        this.listLoading = false;
      });
    },
    //删除
    // handleDel: function (index, row) {
    //   if (!row) {
    //     row = this.currentRow;
    //   }
    //   if (!row) {
    //     this.$message({
    //       message: "请选择要删除的一行数据!",
    //       type: "error",
    //     });
 
    //     return;
    //   }
    //   this.$confirm("确认删除该记录吗?", "提示", {
    //     type: "warning",
    //   })
    //     .then(() => {
    //       this.listLoading = true;
    //       //NProgress.start();
    //       let para = { id: row.Id };
    //       removeWMProductClass(para).then((res) => {
    //         if (util.isEmt.format(res)) {
    //           this.listLoading = false;
    //           return;
    //         }
    //         this.listLoading = false;
    //         //NProgress.done();
    //         if (res.data.success) {
    //           this.$message({
    //             message: "删除成功",
    //             type: "success",
    //           });
    //           this.getWMProductClass();
    //         } else {
    //           this.$message({
    //             message: res.data.msg,
    //             type: "error",
    //           });
    //         }
    //       });
    //     })
    //     .catch(() => {});
    // },
    //显示编辑界面
    handleEdit: function (index, row) {
      if (!row) {
        row = this.currentRow;
      }
      if (!row) {
        this.$message({
          message: "请选择要编辑的一行数据!",
          type: "error",
        });
 
        return;
      }
 
      this.editFormVisible = true;
      this.options = [];
      // this.editForm = {};
 
      let para = { parentId: row.Id };
      getWMProductClassTree(para).then((res) => {
        this.editForm = Object.assign({}, row);
        this.options.push(res.data.response);
      });
    },
    //显示新增界面
    handleAdd() {
      this.options = [];
      this.addFormVisible = true;
      this.addForm = {
        ClassName: "",
        Sort: 0,
        ParentIdArr: [],
      };
 
      let para = { parentId: 0 };
      getWMProductClassTree(para).then((res) => {
        this.options.push(res.data.response);
      });
    },
    //编辑
    editSubmit: function () {
      this.$refs.editForm.validate((valid) => {
        if (valid) {
          this.$confirm("确认提交吗?", "提示", {}).then(() => {
            this.editLoading = true;
            //NProgress.start();
            let para = Object.assign({}, this.editForm);
            para.ParentId = para.ParentIdArr.pop();
 
            if (para.Id == para.ParentId) {
              this.$message({
                message: "警告,父节点不能是自己!",
                type: "error",
              });
 
              this.editLoading = false;
              return;
            }
 
            editWMProductClass(para).then((res) => {
              if (util.isEmt.format(res)) {
                this.editLoading = false;
                return;
              }
              this.editLoading = false;
              if (res.data.success) {
                this.editLoading = false;
                //NProgress.done();
                this.$message({
                  message: res.data.msg,
                  type: "success",
                });
                this.$refs["editForm"].resetFields();
                this.editFormVisible = false;
                this.getWMProductClass();
              } else {
                this.$message({
                  message: res.data.msg,
                  type: "error",
                });
              }
            });
          });
        }
      });
    },
    //新增
    addSubmit: function () {
      this.$refs.addForm.validate((valid) => {
        if (valid) {
          this.$confirm("确认提交吗?", "提示", {}).then(() => {
            this.addLoading = true;
            //NProgress.start();
            let para = Object.assign({}, this.addForm);
            para.ParentId = para.ParentIdArr.pop();
 
            addWMProductClass(para).then((res) => {
              if (util.isEmt.format(res)) {
                this.addLoading = false;
                return;
              }
              this.addLoading = false;
              if (res.data.success) {
                this.addLoading = false;
                //NProgress.done();
                this.$message({
                  message: res.data.msg,
                  type: "success",
                });
                this.$refs["addForm"].resetFields();
                this.addFormVisible = false;
                this.getWMProductClass();
              } else {
                this.$message({
                  message: res.data.msg,
                  type: "error",
                });
              }
            });
          });
        }
      });
    },
    selsChange: function (sels) {
      this.sels = sels;
    },
    //导出
    handleExport() {
      ExportWMProductClass()
        .then((res) => {
          const blob = new Blob([res.data], {
            type: "application/x-xls",
          });
          const url = window.URL.createObjectURL(blob);
          const aLink = document.createElement("a");
          aLink.style.display = "none";
          aLink.href = url;
          aLink.setAttribute(
            "download",
            "商品分类" + new Date().getTime() + ".xlsx"
          );
          document.body.appendChild(aLink);
          aLink.click();
          document.body.removeChild(aLink); // 下载完成移除元素
          window.URL.revokeObjectURL(url); // 释放掉blob对象
        })
        .catch((err) => {
          console.log(err);
        });
    },
    //显示导入界面
    // handleImport() {
    //   this.importFormVisible = true;
    // },
    //导入表格
    //     submitUpload() {
    //          if (this.fileList.length == 0) {
    //         this.$message({
    //           message: "请先选取要上传的商品分类表格!",
    //           type: "error",
    //         });
    //         return;
    //       }
    //       this.$refs.upload.submit();
    //     },
    //     //移除表格
    //     handleRemove(file, fileList) {
    //       console.log(file, fileList);
    //     },
    //     //预览表格
    //     handlePreview(file) {
    //       console.log(file);
    //     },
    //     handleChange(file, fileList) {
    //       this.fileList = fileList;
    //     },
    //显示导入界面
    handleImport() {
      //上传成功清除文件
      document.getElementById("upFileBox") &&
        document.getElementById("upFileBox").reset();
      this.importFormVisible = true;
    },
    submitForm() {
      let fileVal = this.$refs.files.value;
      if (fileVal == "" || fileVal == null || !fileVal) {
        this.$message.error("请选择您要上传的文件");
        return false;
      }
      this.uploading = true;
      let file = this.$refs.files.files[0];
      let dataFile = new FormData();
      dataFile.append("file_upload", file);
      uploadProductClass(dataFile)
        .then((res) => {
          this.uploading = false;
          const data = res.data;
          if (data.success) {
            fileVal = ""; // 清空表单
            this.$message.success("上传成功");
            this.importFormVisible = false;
            this.uploading = false;
 
            return false;
          } else {
            this.$message.error(data.msg);
            this.importFormVisible = false;
            this.uploading = false;
            return false;
          }
        })
        .catch((err) => {
          this.$message.error("服务异常,请重试");
          this.importFormVisible = false;
          this.uploading = false;
          return false;
        });
    },
  },
  mounted() {
    this.getWMProductClass();
 
    let routers = window.localStorage.router
      ? JSON.parse(window.localStorage.router)
      : [];
    this.buttonList = getButtonList(this.$route.path, routers);
  },
};
</script>
 
<style scoped>
</style>