aaa
doum
2026-06-08 3ac279c9df7181c9f21d35a689a321b990b87b22
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
<template>
  <GlobalWindow
    :title="title"
    :visible.sync="visible"
    :confirm-working="isWorking"
    @confirm="confirm"
  >
    <el-form :model="form" ref="form" :rules="rules" label-width="100px">
      <el-form-item label="子类别名称" prop="name">
        <el-input v-model="form.name" maxlength="30" placeholder="请输入子类别名称" v-trim/>
      </el-form-item>
      <el-form-item label="排序码" prop="sortnum">
        <el-input v-model="form.sortnum" type="number" placeholder="升序排列" v-trim/>
      </el-form-item>
      <el-form-item label="图标">
        <el-upload
          :action="action"
          :file-list="form.fileList"
          :data="{ folder: 'category_img' }"
          list-type="picture-card"
          :limit="1"
          :on-success="fileSuccess"
          :on-remove="handleRemove">
          <i class="el-icon-plus"></i>
        </el-upload>
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-switch v-model="form.status" :active-value="0" :inactive-value="1" />
      </el-form-item>
    </el-form>
  </GlobalWindow>
</template>
 
<script>
import GlobalWindow from '@/components/common/GlobalWindow'
import { createSub, updateSub } from '@/api/business/category'
 
export default {
  name: 'OperaSubCategoryWindow',
  components: { GlobalWindow },
  data () {
    return {
      title: '',
      visible: false,
      isWorking: false,
      action: process.env.VUE_APP_API_PREFIX + '/public/upload',
      form: {
        id: null,
        parentId: null,
        name: '',
        sortnum: 1,
        imgurl: '',
        status: 0,
        fileList: []
      },
      rules: {
        name: [{ required: true, message: '不能为空', trigger: 'blur' }]
      }
    }
  },
  methods: {
    open (title, parentRow, editRow) {
      this.title = title
      this.visible = true
      if (editRow) {
        const previewUrl = editRow.imgurl && editRow.prefixUrl
          ? editRow.prefixUrl + editRow.imgurl
          : (editRow.imgurl && editRow.imgurl.indexOf('http') === 0 ? editRow.imgurl : '')
        this.form = {
          id: editRow.id,
          parentId: editRow.parentId,
          name: editRow.name,
          sortnum: editRow.sortnum || 1,
          imgurl: editRow.imgurl || '',
          status: editRow.status != null ? editRow.status : 0,
          fileList: previewUrl ? [{ url: previewUrl, name: editRow.imgurl }] : []
        }
      } else {
        this.form = {
          id: null,
          parentId: parentRow.id,
          name: '',
          sortnum: 1,
          imgurl: '',
          status: 0,
          fileList: []
        }
      }
    },
    fileSuccess (response) {
      if (response && response.data) {
        this.form.imgurl = response.data.imgaddr
        this.form.fileList = [{ url: response.data.url, name: response.data.imgname || response.data.imgaddr }]
      }
    },
    handleRemove () {
      this.form.imgurl = ''
      this.form.fileList = []
    },
    confirm () {
      this.$refs.form.validate(valid => {
        if (!valid) return
        this.isWorking = true
        const api = this.form.id ? updateSub : createSub
        api(this.form).then(() => {
          this.$message.success('操作成功')
          this.visible = false
          this.$emit('success')
        }).finally(() => {
          this.isWorking = false
        })
      })
    }
  }
}
</script>