优化分类

This commit is contained in:
gyq
2024-03-08 15:04:38 +08:00
parent bf60ee88e2
commit 273e20cccc
3 changed files with 15 additions and 22 deletions

View File

@@ -120,13 +120,13 @@ export function tbShopCategoryGet(params) {
} }
/** /**
* 新增分类/新增子分类 * 新增、编辑分类/新增、编辑子分类
* @returns * @returns
*/ */
export function tbShopCategoryPost(data) { export function tbShopCategoryPost(data, method = 'post') {
return request({ return request({
url: `/api/tbShopCategory`, url: `/api/tbShopCategory`,
method: 'post', method: method,
data data
}) })
} }

View File

@@ -115,7 +115,7 @@ export default {
const res = await tbShopCategoryGet({ const res = await tbShopCategoryGet({
page: this.tableData.page, page: this.tableData.page,
size: this.tableData.size, size: this.tableData.size,
sort: 'id', sort: 'id,desc',
shopId: localStorage.getItem('shopId') shopId: localStorage.getItem('shopId')
}) })
this.tableData.loading = false this.tableData.loading = false

View File

@@ -49,11 +49,11 @@ export default {
pid: '', pid: '',
isShow: 1, isShow: 1,
name: '', name: '',
shopId: localStorage.getItem('shopId'), sort: '',
sort: 0,
style: '#000000', style: '#000000',
pic: '' pic: ''
}, },
resetForm: '',
rules: { rules: {
name: [ name: [
{ {
@@ -65,18 +65,22 @@ export default {
} }
} }
}, },
mounted() {
this.resetForm = { ...this.form }
},
methods: { methods: {
onSubmitHandle() { onSubmitHandle() {
console.log(this.form) console.log(this.form)
this.$refs.form.validate(async valid => { this.$refs.form.validate(async valid => {
if (valid) { if (valid) {
try { try {
let res = await tbShopCategoryPost(this.form) this.form.shopId = localStorage.getItem('shopId')
let res = await tbShopCategoryPost(this.form, this.form.id ? 'put' : 'post')
this.$emit('success', res) this.$emit('success', res)
this.close() this.close()
this.$notify({ this.$notify({
title: '成功', title: '成功',
message: `${this.form.pid ? '编辑' : '添加'}成功`, message: `${this.form.id ? '编辑' : '添加'}成功`,
type: 'success' type: 'success'
}); });
} catch (error) { } catch (error) {
@@ -88,16 +92,11 @@ export default {
show(obj) { show(obj) {
// console.log(obj) // console.log(obj)
this.dialogVisible = true this.dialogVisible = true
if (obj && obj.pid) { if (obj.pid) {
this.form.pid = obj.pid this.form.pid = obj.pid
} }
if (obj && obj.id) { if (obj && obj.id) {
this.form.id = obj.id this.form = obj
this.form.isShow = obj.isShow
this.form.name = obj.name
this.form.sort = obj.sort
this.form.style = obj.style
this.form.pic = obj.pic
if (obj.pic) { if (obj.pic) {
setTimeout(() => { setTimeout(() => {
this.$refs.uploadImg.fileList = [ this.$refs.uploadImg.fileList = [
@@ -113,13 +112,7 @@ export default {
this.dialogVisible = false this.dialogVisible = false
}, },
reset() { reset() {
this.form.pid = '' this.form = { ...this.resetForm }
this.form.isShow = 1
this.form.name = ''
this.form.sort = 0
this.form.style = '#000000'
this.form.pic = ''
this.$refs.uploadImg.clearFiles() this.$refs.uploadImg.clearFiles()
} }
} }