Commit 8d08d5939fd18fcab76ab2c49934a87581ccd12d
1 parent
cc6c3d27
品牌 crud
Showing
1 changed file
with
50 additions
and
13 deletions
yudao-ui-admin/src/views/mall/product/brand/index.vue
| ... | ... | @@ -3,9 +3,6 @@ |
| 3 | 3 | |
| 4 | 4 | <!-- 搜索工作栏 --> |
| 5 | 5 | <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px"> |
| 6 | - <el-form-item label="分类编号" prop="categoryId"> | |
| 7 | - <el-input v-model="queryParams.categoryId" placeholder="请输入分类编号" clearable @keyup.enter.native="handleQuery"/> | |
| 8 | - </el-form-item> | |
| 9 | 6 | <el-form-item label="品牌名称" prop="name"> |
| 10 | 7 | <el-input v-model="queryParams.name" placeholder="请输入品牌名称" clearable @keyup.enter.native="handleQuery"/> |
| 11 | 8 | </el-form-item> |
| ... | ... | @@ -43,10 +40,13 @@ |
| 43 | 40 | |
| 44 | 41 | <!-- 列表 --> |
| 45 | 42 | <el-table v-loading="loading" :data="list"> |
| 46 | - <el-table-column label="品牌编号" align="center" prop="id"/> | |
| 47 | - <el-table-column label="分类编号" align="center" prop="categoryId"/> | |
| 43 | + <el-table-column label="商品分类" align="center" prop="categoryId"/> | |
| 48 | 44 | <el-table-column label="品牌名称" align="center" prop="name"/> |
| 49 | - <el-table-column label="品牌图片" align="center" prop="bannerUrl"/> | |
| 45 | + <el-table-column label="品牌图片" align="center" prop="bannerUrl"> | |
| 46 | + <template slot-scope="scope"> | |
| 47 | + <img v-if="scope.row.bannerUrl" :src="scope.row.bannerUrl" alt="分类图片" class="img-height"/> | |
| 48 | + </template> | |
| 49 | + </el-table-column> | |
| 50 | 50 | <el-table-column label="品牌排序" align="center" prop="sort"/> |
| 51 | 51 | <el-table-column label="品牌描述" align="center" prop="description"/> |
| 52 | 52 | <el-table-column label="状态" align="center" prop="status"> |
| ... | ... | @@ -77,8 +77,9 @@ |
| 77 | 77 | <!-- 对话框(添加 / 修改) --> |
| 78 | 78 | <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body> |
| 79 | 79 | <el-form ref="form" :model="form" :rules="rules" label-width="80px"> |
| 80 | - <el-form-item label="分类编号" prop="categoryId"> | |
| 81 | - <el-input v-model="form.categoryId" placeholder="请输入分类编号"/> | |
| 80 | + <el-form-item label="商品分类" prop="categoryId"> | |
| 81 | + <Treeselect v-model="form.categoryId" :options="categoryOptions" :normalizer="normalizer" :show-count="true" | |
| 82 | + placeholder="请选择商品分类"/> | |
| 82 | 83 | </el-form-item> |
| 83 | 84 | <el-form-item label="品牌名称" prop="name"> |
| 84 | 85 | <el-input v-model="form.name" placeholder="请输入品牌名称"/> |
| ... | ... | @@ -93,10 +94,11 @@ |
| 93 | 94 | <el-input v-model="form.description" type="textarea" placeholder="请输入内容"/> |
| 94 | 95 | </el-form-item> |
| 95 | 96 | <el-form-item label="状态" prop="status"> |
| 96 | - <el-select v-model="form.status" placeholder="请选择状态"> | |
| 97 | - <el-option v-for="dict in this.getDictDatas(DICT_TYPE.COMMON_STATUS)" | |
| 98 | - :key="dict.value" :label="dict.label" :value="parseInt(dict.value)"/> | |
| 99 | - </el-select> | |
| 97 | + <el-radio-group v-model="form.status"> | |
| 98 | + <el-radio v-for="dict in this.getDictDatas(DICT_TYPE.COMMON_STATUS)" | |
| 99 | + :key="dict.value" :label="parseInt(dict.value)">{{ dict.label }} | |
| 100 | + </el-radio> | |
| 101 | + </el-radio-group> | |
| 100 | 102 | </el-form-item> |
| 101 | 103 | </el-form> |
| 102 | 104 | <div slot="footer" class="dialog-footer"> |
| ... | ... | @@ -116,12 +118,15 @@ import { |
| 116 | 118 | getBrandPage, |
| 117 | 119 | updateBrand |
| 118 | 120 | } from "@/api/mall/product/brand"; |
| 121 | +import {listCategory} from "@/api/mall/product/category"; | |
| 119 | 122 | import ImageUpload from '@/components/ImageUpload'; |
| 123 | +import Treeselect from "@riophae/vue-treeselect"; | |
| 124 | +import "@riophae/vue-treeselect/dist/vue-treeselect.css"; | |
| 120 | 125 | |
| 121 | 126 | export default { |
| 122 | 127 | name: "Brand", |
| 123 | 128 | components: { |
| 124 | - ImageUpload, | |
| 129 | + ImageUpload, Treeselect, | |
| 125 | 130 | }, |
| 126 | 131 | data() { |
| 127 | 132 | return { |
| ... | ... | @@ -148,6 +153,8 @@ export default { |
| 148 | 153 | name: null, |
| 149 | 154 | status: null, |
| 150 | 155 | }, |
| 156 | + // 商品分类树选项 | |
| 157 | + categoryOptions: [], | |
| 151 | 158 | // 表单参数 |
| 152 | 159 | form: {}, |
| 153 | 160 | // 表单校验 |
| ... | ... | @@ -160,6 +167,7 @@ export default { |
| 160 | 167 | }; |
| 161 | 168 | }, |
| 162 | 169 | created() { |
| 170 | + this.getTreeselect(); | |
| 163 | 171 | this.getList(); |
| 164 | 172 | }, |
| 165 | 173 | methods: { |
| ... | ... | @@ -176,6 +184,26 @@ export default { |
| 176 | 184 | this.loading = false; |
| 177 | 185 | }); |
| 178 | 186 | }, |
| 187 | + /** 转换菜单数据结构 */ | |
| 188 | + normalizer(node) { | |
| 189 | + if (node.children && !node.children.length) { | |
| 190 | + delete node.children; | |
| 191 | + } | |
| 192 | + return { | |
| 193 | + id: node.id, | |
| 194 | + label: node.name, | |
| 195 | + children: node.children | |
| 196 | + }; | |
| 197 | + }, | |
| 198 | + /** 查询分类下拉树结构 */ | |
| 199 | + getTreeselect() { | |
| 200 | + listCategory().then(response => { | |
| 201 | + this.categoryOptions = []; | |
| 202 | + const menu = {id: 0, name: '商品分类', children: []}; | |
| 203 | + menu.children = this.handleTree(response.data, "id", "pid"); | |
| 204 | + this.categoryOptions.push(menu); | |
| 205 | + }); | |
| 206 | + }, | |
| 179 | 207 | /** 取消按钮 */ |
| 180 | 208 | cancel() { |
| 181 | 209 | this.open = false; |
| ... | ... | @@ -208,12 +236,14 @@ export default { |
| 208 | 236 | /** 新增按钮操作 */ |
| 209 | 237 | handleAdd() { |
| 210 | 238 | this.reset(); |
| 239 | + this.getTreeselect(); | |
| 211 | 240 | this.open = true; |
| 212 | 241 | this.title = "添加品牌"; |
| 213 | 242 | }, |
| 214 | 243 | /** 修改按钮操作 */ |
| 215 | 244 | handleUpdate(row) { |
| 216 | 245 | this.reset(); |
| 246 | + this.getTreeselect(); | |
| 217 | 247 | const id = row.id; |
| 218 | 248 | getBrand(id).then(response => { |
| 219 | 249 | this.form = response.data; |
| ... | ... | @@ -275,3 +305,10 @@ export default { |
| 275 | 305 | } |
| 276 | 306 | }; |
| 277 | 307 | </script> |
| 308 | + | |
| 309 | +<style scoped lang="scss"> | |
| 310 | +// | |
| 311 | +.img-height { | |
| 312 | + height: 150px; | |
| 313 | +} | |
| 314 | +</style> | ... | ... |