mayf
2024-09-09 c5ed2b03fb6f53a6144cf4d3a18bf31a9075d67a
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
<template>
  <el-bus-crud ref="crud" v-bind="tableConfig" />
</template>
 
<script>
import { getSortConfig } from '@/utils/form-item-config'
export default {
  data() {
    return {
      tableConfig: {
        url: 'flower/api/flower/category/tree',
        hasPagination: false,
        saveQuery: false,
        isTree: true,
        hasView: false,
        canNewChild: (row) => !row.parentId,
        dialogAttrs: {
          width: '70%',
        },
        beforeOpen(row, isNew) {
          if (isNew && row.name) {
            row.parentName = row.name
          }
          if (!isNew && !row.parentId && row.parentName) {
            row.parentName = ''
          }
        },
        extraParentKeys: ['parentName', 'levelLimit'],
        tableAttrs: {
          rowKey: 'id',
        },
        columns: [
          { label: '分类名称', prop: 'name' },
          {
            label: '分类图片',
            formatter: (row) => (
              <el-bus-image
                style="width:50px;height:50px"
                lazy={true}
                src={row.imageUrl}
              />
            ),
          },
          { label: '排序', prop: 'sortBy' },
          {
            label: '是否显示',
            formatter: (row) => (
              <el-switch
                value={row.shown}
                onChange={this.onShownChange.bind(this, row)}
              ></el-switch>
            ),
          },
        ],
        searchForm: [
          {
            type: 'row',
            items: [{ label: '分类名称', id: 'name', type: 'input' }],
          },
        ],
        form: [
          {
            label: '上级分类:',
            id: 'parentName',
            type: 'input',
            readonly: true,
            hidden: (row) => !row.parentName,
          },
          {
            label: '分类名称:',
            id: 'name',
            type: 'input',
            rules: {
              required: true,
              message: '请输入分类名称',
              trigger: 'blur',
            },
          },
          {
            label: '分类图片:',
            id: 'imageUrl',
            type: 'bus-upload',
            el: {
              listType: 'picture-card',
              limit: 1,
              limitSize: 2,
              tipText: '建议上传164*164的图片,大小不超过2M',
              valueType: 'string',
            },
            rules: { required: true, message: '请上传分类图片' },
          },
          {
            label: '等级:',
            id: 'levelLimit',
            type: 'bus-select-dict',
            el: {
              code: 'FLOWER_LEVEL',
              multiple: true,
              style: 'width:100%',
            },
            rules: { required: true, message: '请选择等级' },
            inputFormat: (row) => {
              if ('levelLimit' in row) {
                return row.levelLimit ? row.levelLimit.split(',') : []
              }
            },
            outputFormat: (val) => {
              return Array.isArray(val) ? val.join(',') : null
            },
            hidden: (row) => row.parentName,
          },
          {
            label: '分类颜色:',
            id: 'color',
            type: 'input',
            hidden: (row) => !row.parentName,
          },
          {
            label: '规格:',
            id: 'unit',
            type: 'input',
            hidden: (row) => !row.parentName,
          },
          {
            type: 'row',
            items: [
              {
                label: 'A级重量:',
                id: 'weightA',
                type: 'input-number',
                el: {
                  min: 0,
                  precision: 1,
                  controls: false,
                },
                unit: 'kg',
                hidden: (row) =>
                  !row.parentName ||
                  !row.levelLimit ||
                  !row.levelLimit.includes('A'),
                rules: {
                  required: true,
                  message: '请输入A级重量',
                  trigger: 'blur',
                },
              },
              {
                label: 'B级重量:',
                id: 'weightB',
                type: 'input-number',
                el: {
                  min: 0,
                  precision: 1,
                  controls: false,
                },
                unit: 'kg',
                hidden: (row) =>
                  !row.parentName ||
                  !row.levelLimit ||
                  !row.levelLimit.includes('B'),
                rules: {
                  required: true,
                  message: '请输入B级重量',
                  trigger: 'blur',
                },
              },
              {
                label: 'C级重量:',
                id: 'weightC',
                type: 'input-number',
                el: {
                  min: 0,
                  precision: 1,
                  controls: false,
                },
                unit: 'kg',
                hidden: (row) =>
                  !row.parentName ||
                  !row.levelLimit ||
                  !row.levelLimit.includes('C'),
                rules: {
                  required: true,
                  message: '请输入C级重量',
                  trigger: 'blur',
                },
              },
              {
                label: 'D级重量:',
                id: 'weightD',
                type: 'input-number',
                el: {
                  min: 0,
                  precision: 1,
                  controls: false,
                },
                unit: 'kg',
                hidden: (row) =>
                  !row.parentName ||
                  !row.levelLimit ||
                  !row.levelLimit.includes('D'),
                rules: {
                  required: true,
                  message: '请输入D级重量',
                  trigger: 'blur',
                },
              },
              {
                label: 'E级重量:',
                id: 'weightE',
                type: 'input-number',
                el: {
                  min: 0,
                  precision: 1,
                  controls: false,
                },
                unit: 'kg',
                hidden: (row) =>
                  !row.parentName ||
                  !row.levelLimit ||
                  !row.levelLimit.includes('E'),
                rules: {
                  required: true,
                  message: '请输入E级重量',
                  trigger: 'blur',
                },
              },
              {
                label: 'O级重量:',
                id: 'weightO',
                type: 'input-number',
                el: {
                  min: 0,
                  precision: 1,
                  controls: false,
                },
                unit: 'kg',
                hidden: (row) =>
                  !row.parentName ||
                  !row.levelLimit ||
                  !row.levelLimit.includes('O'),
                rules: {
                  required: true,
                  message: '请输入O级重量',
                  trigger: 'blur',
                },
              },
            ],
          },
          {
            ...getSortConfig(),
          },
        ],
      },
    }
  },
  head() {
    return {
      title: '分类管理',
    }
  },
  methods: {
    onShownChange(row, e) {
      const url = e
        ? 'flower/api/flower/category/tree/shown'
        : 'flower/api/flower/category/tree/hidden'
      const text = e ? '显示' : '隐藏'
      this.$elBusUtil
        .confirm(`确定要${text}这个分类吗?`)
        .then(async () => {
          const { code } = await this.$elBusHttp.request(url, {
            params: {
              id: row.id,
            },
          })
          if (code === 0) {
            this.$message.success(`${text}成功`)
            this.$refs.crud.getList()
          }
        })
        .catch(() => {})
    },
  },
}
</script>
 
<style lang="scss" scoped>
.category-list {
}
</style>