200 lines
5.3 KiB
Vue
Raw Normal View History

2022-08-02 10:16:07 +08:00
<template>
<div>
<el-card>
<el-button type="primary"
@click="handAdd">新增</el-button>
<el-table ref="multipleTable"
:data="tableData"
tooltip-effect="dark"
style="width: 100%"
@selection-change="handleSelectionChange">
<el-table-column type="selection"
width="55">
</el-table-column>
<el-table-column prop="name"
label="商品种类">
</el-table-column>
<el-table-column prop=""
label="操作">
<template slot-scope="scope">
<el-button type="primary"
@click="handEdit(scope.row.id,scope.row)">编辑</el-button>
<el-button type="danger"
@click="handdel(scope.row.id)">删除</el-button>
</template>
</el-table-column>
</el-table>
</el-card>
<el-pagination @size-change="handleSizeChange"
@current-change="handleCurrentChange"
:current-page="page"
:page-sizes="[10, 20, 30, 40]"
:page-size="per_page"
:total="total"
layout="total, sizes, prev, pager, next, jumper">
</el-pagination>
<!-- 新增种类对话框 -->
<el-dialog title="新增种类"
:visible.sync="dialogFormVisible">
<el-form :model="form">
<el-form-item label="商品种类"
:label-width="formLabelWidth">
<el-input v-model="form.kindName"
autocomplete="off"></el-input>
</el-form-item>
</el-form>
<div slot="footer"
class="dialog-footer">
<el-button @click="dialogFormVisible = false"> </el-button>
<el-button type="primary"
@click="addSubmit"> </el-button>
</div>
</el-dialog>
<!-- 编辑 -->
<el-dialog title="编辑"
:visible.sync="dialogFormVisible1">
<el-form :model="form1">
<el-form-item label="编辑种类"
:label-width="formLabelWidth1">
<el-input v-model="form1.kindName1"
autocomplete="off"></el-input>
</el-form-item>
</el-form>
<div slot="footer"
class="dialog-footer">
<el-button @click="dialogFormVisible1 = false"> </el-button>
<el-button type="primary"
@click="EditSubmit"> </el-button>
</div>
</el-dialog>
</div>
</template>
<script>
import {
Brand_goods_types,
DelBrand_goods_types,
AddBrandgoods_types,
editBrand_types,
} from '../../api/rankingData'
export default {
data() {
return {
id: '', //每一项的id
page: 1,
per_page: 15,
tableData: [],
multipleSelection: [],
currentPage4: 4,
dialogFormVisible: false,
dialogFormVisible1: false,
form: {
kindName: '', //种类名
},
form1: {
kindName1: '', //种类名
},
formLabelWidth: '120px',
formLabelWidth1: '120px',
newKind: [],
}
},
created() {
this.getGoods_types()
},
methods: {
// 复选框按钮
handleSelectionChange(val) {
console.log(val)
this.multipleSelection = val
},
// 分页
handleSizeChange(val) {
console.log(`每页 ${val}`)
},
handleCurrentChange(val) {
console.log(`当前页: ${val}`)
},
// 新增
handAdd() {
this.form.kindName = ''
this.dialogFormVisible = true
},
// 确认新增
addSubmit() {
var string
string = this.form.kindName.replace(/\s/g, ',').split(',')
console.log(string, 'lkkkk')
AddBrandgoods_types({
names: string,
}).then((res) => {
this.$message({
type: 'success',
message: '添加成功',
})
this.getGoods_types()
})
this.dialogFormVisible = false
},
// 编辑
handEdit(id, item) {
this.id = id
console.log('item', item)
this.form1.kindName1 = item.name
this.dialogFormVisible1 = true
},
// 编辑确定按钮
EditSubmit() {
editBrand_types(this.id, {
name: this.form1.kindName1,
}).then((res) => {
this.$message({
type: 'success',
message: '编辑成功',
})
this.getGoods_types()
})
this.dialogFormVisible1 = false
},
// 删除
handdel(id) {
this.$confirm('确定删除此条商品种类吗?', '确认删除', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
})
.then(() => {
DelBrand_goods_types(id).then((res) => {
this.getGoods_types()
})
this.$message({
type: 'success',
message: '删除成功!',
})
})
.catch(() => {
this.$message({
type: 'info',
message: '已取消删除',
})
})
},
// 获取列表
getGoods_types() {
Brand_goods_types({
page: this.page,
per_page: this.per_page,
}).then((res) => {
console.log('res=>>>>>>>>', res)
this.tableData = res.data.data
this.total = res.data.data.length
})
},
},
}
</script>
<style>
</style>