<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>
|