|
@@ -0,0 +1,313 @@
|
|
|
+<template>
|
|
|
+ <div class="categoryBrand">
|
|
|
+ <div class="top">
|
|
|
+ <el-form label-width="auto">
|
|
|
+ <el-row>
|
|
|
+ <el-col :span="12">
|
|
|
+ <el-form-item label="品牌">
|
|
|
+ <el-select
|
|
|
+ style="width:90%"
|
|
|
+ v-model="searchObj.brandId"
|
|
|
+ placeholder="请选择品牌"
|
|
|
+ >
|
|
|
+ <el-option
|
|
|
+ v-for="(item, index) in list"
|
|
|
+ :key="index"
|
|
|
+ :label="item.name"
|
|
|
+ :value="item.id"
|
|
|
+ />
|
|
|
+ </el-select>
|
|
|
+ </el-form-item>
|
|
|
+ </el-col>
|
|
|
+ <el-col :span="12">
|
|
|
+ <el-form-item label="分类">
|
|
|
+ <el-cascader
|
|
|
+ v-model="categoryList"
|
|
|
+ style="width:90%"
|
|
|
+ :props="conProps"
|
|
|
+ />
|
|
|
+ </el-form-item>
|
|
|
+ </el-col>
|
|
|
+ </el-row>
|
|
|
+ <el-row>
|
|
|
+ <el-button size="small" type="primary" @click="handleSearch">
|
|
|
+ 搜索
|
|
|
+ </el-button>
|
|
|
+ <el-button size="small" @click="handleReset">重置</el-button>
|
|
|
+ </el-row>
|
|
|
+ </el-form>
|
|
|
+ </div>
|
|
|
+ <div class="mid">
|
|
|
+ <el-button size="small" type="success" @click="handleAdd">添加</el-button>
|
|
|
+ </div>
|
|
|
+ <div class="bottom">
|
|
|
+ <el-table :data="tableData" style="width: 100%">
|
|
|
+ <el-table-column label="分类" prop="categoryName" />
|
|
|
+ <el-table-column label="品牌" prop="brandName" />
|
|
|
+ <el-table-column label="品牌图标" prop="logo">
|
|
|
+ <template #default="scope">
|
|
|
+ <img :src="scope.row.logo" width="50" />
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column label="创建时间" prop="createTime" />
|
|
|
+ <el-table-column align="right">
|
|
|
+ <template #default="scope">
|
|
|
+ <el-button
|
|
|
+ type="primary"
|
|
|
+ size="small"
|
|
|
+ @click="handleEdit(scope.row)"
|
|
|
+ >
|
|
|
+ 修改
|
|
|
+ </el-button>
|
|
|
+ <el-button
|
|
|
+ size="small"
|
|
|
+ type="danger"
|
|
|
+ @click="handleDelete(scope.row)"
|
|
|
+ >
|
|
|
+ 删除
|
|
|
+ </el-button>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ </el-table>
|
|
|
+ <el-pagination
|
|
|
+ :current-page="pageMain.page"
|
|
|
+ :page-size="pageMain.limit"
|
|
|
+ :page-sizes="[2, 10, 20, 30, 40]"
|
|
|
+ layout="sizes, prev, pager, next"
|
|
|
+ :total="total"
|
|
|
+ @size-change="handleSizeChange"
|
|
|
+ @current-change="handleCurrentChange"
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ <!-- 弹框 -->
|
|
|
+ <el-dialog v-model="dialogFormVisible" :title="title" class="addDialog">
|
|
|
+ <el-form v-model="form1">
|
|
|
+ <el-form-item label="品牌">
|
|
|
+ <el-select
|
|
|
+ class="text"
|
|
|
+ v-model="form1.brandId"
|
|
|
+ placeholder="请选择品牌"
|
|
|
+ >
|
|
|
+ <el-option
|
|
|
+ v-for="(item, index) in list"
|
|
|
+ :key="index"
|
|
|
+ :label="item.name"
|
|
|
+ :value="item.id"
|
|
|
+ />
|
|
|
+ </el-select>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="分类">
|
|
|
+ <el-cascader
|
|
|
+ v-model="categoryForm"
|
|
|
+ style="width:90%"
|
|
|
+ :props="conProps1"
|
|
|
+ />
|
|
|
+ </el-form-item>
|
|
|
+ </el-form>
|
|
|
+ <template #footer>
|
|
|
+ <div class="dialog-footer">
|
|
|
+ <el-button @click="dialogFormVisible = false">取消</el-button>
|
|
|
+ <el-button type="primary" @click="submitForm">
|
|
|
+ 提交
|
|
|
+ </el-button>
|
|
|
+ </div>
|
|
|
+ </template>
|
|
|
+ </el-dialog>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+<script setup name="categoryBrand">
|
|
|
+import { pageData, addSave, delSave, updateSave } from '@/api/categoryBrand.js'
|
|
|
+import { GetUserInfo } from '@/api/category.js'
|
|
|
+import { FindAllBrand } from '@/api/brand.js'
|
|
|
+import { ElMessage, ElMessageBox } from 'element-plus'
|
|
|
+import { ref, onMounted } from 'vue'
|
|
|
+
|
|
|
+const dialogFormVisible = ref(false)
|
|
|
+const form1 = ref({
|
|
|
+ id: '',
|
|
|
+ brandId: '',
|
|
|
+ categoryId: '',
|
|
|
+})
|
|
|
+let title = ref('')
|
|
|
+let list = ref([])
|
|
|
+let total = ref(0)
|
|
|
+let searchObj = ref({
|
|
|
+ brandId: '',
|
|
|
+ categoryId: '',
|
|
|
+})
|
|
|
+let categoryList = ref([])
|
|
|
+let categoryForm = ref([])
|
|
|
+let paramsPage = {
|
|
|
+ page: 1,
|
|
|
+ limit: 2,
|
|
|
+}
|
|
|
+let tableData = ref([])
|
|
|
+let pageMain = ref(paramsPage)
|
|
|
+onMounted(() => {
|
|
|
+ init()
|
|
|
+ getList()
|
|
|
+})
|
|
|
+// 品牌
|
|
|
+const init = async () => {
|
|
|
+ let { data } = await FindAllBrand()
|
|
|
+ list.value = data
|
|
|
+}
|
|
|
+// 分类
|
|
|
+const props = {
|
|
|
+ lazy: true,
|
|
|
+ value: 'id',
|
|
|
+ label: 'name',
|
|
|
+ leaf: 'leaf',
|
|
|
+ async lazyLoad(node, resolve) {
|
|
|
+ if (typeof node.value == 'undefined') {
|
|
|
+ node.value = 0
|
|
|
+ }
|
|
|
+ let { data } = await GetUserInfo(node.value)
|
|
|
+ data.forEach(ele => {
|
|
|
+ ele.leaf = !ele.hasChildren
|
|
|
+ })
|
|
|
+ resolve(data)
|
|
|
+ },
|
|
|
+}
|
|
|
+// 弹框中的分类
|
|
|
+const props1 = {
|
|
|
+ lazy: true,
|
|
|
+ value: 'id',
|
|
|
+ label: 'name',
|
|
|
+ leaf: 'leaf',
|
|
|
+ async lazyLoad(node, resolve) {
|
|
|
+ if (typeof node.value == 'undefined') {
|
|
|
+ node.value = 0
|
|
|
+ }
|
|
|
+ let { data } = await GetUserInfo(node.value)
|
|
|
+ data.forEach(ele => {
|
|
|
+ ele.leaf = !ele.hasChildren
|
|
|
+ })
|
|
|
+ resolve(data)
|
|
|
+ },
|
|
|
+}
|
|
|
+let conProps = ref(props)
|
|
|
+let conProps1 = ref(props1)
|
|
|
+
|
|
|
+// 搜索
|
|
|
+const handleSearch = () => {
|
|
|
+ if (categoryList.value.length === 3) {
|
|
|
+ searchObj.value.categoryId = categoryList.value[2]
|
|
|
+ }
|
|
|
+ getList()
|
|
|
+}
|
|
|
+// 表格
|
|
|
+const getList = async () => {
|
|
|
+ let { data } = await pageData(
|
|
|
+ pageMain.value.page,
|
|
|
+ pageMain.value.limit,
|
|
|
+ searchObj.value
|
|
|
+ )
|
|
|
+ tableData.value = data.list
|
|
|
+ total.value = data.total
|
|
|
+}
|
|
|
+// 切换条数
|
|
|
+const handleSizeChange = size => {
|
|
|
+ pageMain.value.limit = size
|
|
|
+ getList()
|
|
|
+}
|
|
|
+// 切换页数
|
|
|
+const handleCurrentChange = page => {
|
|
|
+ pageMain.value.page = page
|
|
|
+ getList()
|
|
|
+}
|
|
|
+// 重置
|
|
|
+const handleReset = () => {
|
|
|
+ searchObj.value = {
|
|
|
+ brandId: '',
|
|
|
+ categoryId: '',
|
|
|
+ }
|
|
|
+ getList()
|
|
|
+}
|
|
|
+// 添加
|
|
|
+const handleAdd = () => {
|
|
|
+ form1.value = {}
|
|
|
+ categoryForm.value = []
|
|
|
+ dialogFormVisible.value = true
|
|
|
+ title.value = '添加'
|
|
|
+}
|
|
|
+// 提交保存按钮
|
|
|
+const submitForm = () => {
|
|
|
+ if (categoryForm.value.length === 3) {
|
|
|
+ form1.value.categoryId = categoryForm.value[2]
|
|
|
+ }
|
|
|
+ if (form1.value.id) {
|
|
|
+ updateSave(form1.value).then(res => {
|
|
|
+ if (res.code == 200) {
|
|
|
+ ElMessage({
|
|
|
+ message: res.message,
|
|
|
+ type: 'success',
|
|
|
+ })
|
|
|
+ dialogFormVisible.value = false
|
|
|
+ getList()
|
|
|
+ }
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ addSave(form1.value).then(res => {
|
|
|
+ if (res.code == 200) {
|
|
|
+ ElMessage({
|
|
|
+ message: res.message,
|
|
|
+ type: 'success',
|
|
|
+ })
|
|
|
+ dialogFormVisible.value = false
|
|
|
+ getList()
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+}
|
|
|
+// 修改
|
|
|
+const handleEdit = row => {
|
|
|
+ dialogFormVisible.value = true
|
|
|
+ title.value = '修改'
|
|
|
+ form1.value.brandId = row.brandId
|
|
|
+ form1.value.id = row.id
|
|
|
+ form1.value.categoryId = row.categoryId
|
|
|
+}
|
|
|
+// 删除
|
|
|
+const handleDelete = row => {
|
|
|
+ ElMessageBox.confirm('确认删除该数据?', '提示', {
|
|
|
+ confirmButtonText: '确定',
|
|
|
+ cancelButtonText: '取消',
|
|
|
+ type: 'warning',
|
|
|
+ })
|
|
|
+ .then(() => {
|
|
|
+ delSave(row.id).then(res => {
|
|
|
+ if (res.code == 200) {
|
|
|
+ ElMessage({
|
|
|
+ message: res.message,
|
|
|
+ type: 'success',
|
|
|
+ })
|
|
|
+ getList()
|
|
|
+ }
|
|
|
+ })
|
|
|
+ })
|
|
|
+ .catch(() => {})
|
|
|
+}
|
|
|
+</script>
|
|
|
+<style scoped lang="scss">
|
|
|
+.categoryBrand {
|
|
|
+ padding: 10px;
|
|
|
+ .top {
|
|
|
+ width: 100%;
|
|
|
+ background: #fff;
|
|
|
+ padding: 10px;
|
|
|
+ }
|
|
|
+ .mid {
|
|
|
+ width: 100%;
|
|
|
+ background: #fff;
|
|
|
+ padding: 10px;
|
|
|
+ margin-top: 10px;
|
|
|
+ }
|
|
|
+ .addDialog {
|
|
|
+ width: 500px;
|
|
|
+ .text {
|
|
|
+ width: 80%;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+</style>
|