1.页面

2.品类列表展示

  1. let listBody = this.state.list.map((category, index) => {
  2.             return (
  3.                 <tr key={index}>
  4.                     <td>{category.id}</td>
  5.                     <td>{category.name}</td>
  6.                     <td>
  7.                         <a className="opear"
  8.                             onClick={(e) => this.onUpdateName(category.id, category.name)}>修改名称</a>
  9.                         {
  10.                             category.parentId === 0
  11.                             ? <Link to={`/product-category/index/${category.id}`}>查看子品类</Link>
  12.                             : null
  13.                         }
  14.                     </td>
  15.                 </tr>
  16.             );
  17.         });
  18.         return (
  19.             <div id="page-wrapper">
  20.                 <PageTitle title="品类列表">
  21.                     <div className="page-header-right">
  22.                         <Link to="/product-category/add" className="btn btn-primary">
  23.                             <i className="fa fa-plus"></i>
  24.                             <span>添加品类</span>
  25.                         </Link>
  26.                     </div>
  27.                 </PageTitle>
  28.                 <div className="row">
  29.                     <div className="col-md-12">
  30.                         <p>父品类ID: {this.state.parentCategoryId}</p>
  31.                     </div>
  32.                 </div>
  33.                 <TableList tableHeads={['品类ID', '品类名称', '操作']}>
  34.                     {listBody}
  35.                 </TableList>
  36.             </div>
  37.         );
  38.     }

3.加载品类列表

  1. // 加载品类列表
  2.     loadCategoryList(){
  3.        _product.getCategoryList(this.state.parentCategoryId).then(res => {
  4.            this.setState({
  5.                list : res
  6.            });
  7.        }, errMsg => {
  8.            this.setState({
  9.                list : []
  10.            });
  11.            _mm.errorTips(errMsg);
  12.        });
  13.    }

4.修改品类名称

  1. // 更新品类的名字
  2.     onUpdateName(categoryId, categoryName){
  3.        let newName = window.prompt('请输入新的品类名称', categoryName);
  4.        if(newName){
  5.            _product.updateCategoryName({
  6.                categoryId: categoryId,
  7.                categoryName : newName
  8.            }).then(res => {
  9.                _mm.successTips(res);
  10.                this.loadCategoryList();
  11.            }, errMsg => {
  12.                _mm.errorTips(errMsg);
  13.            });
  14.        }
  15.    }

5.添加品类

  1. import React from 'react';
  2. import MUtil from 'util/mm.jsx'
  3. import Product from 'service/product-service.jsx'
  4.  
  5. import PageTitle from 'component/page-title/index.jsx';
  6.  
  7. const _mm = new MUtil();
  8. const _product = new Product();
  9.  
  10.  
  11. class CategoryAdd extends React.Component{
  12.     constructor(props){
  13.         super(props);
  14.         this.state = {
  15.             categoryList : [],
  16.             parentId : 0,
  17.             categoryName : ''
  18.         };
  19.     }
  20.     componentDidMount(){
  21.         this.loadCategoryList();
  22.     }
  23.     // 加载品类列表,显示父品类列表
  24.     loadCategoryList(){
  25.         _product.getCategoryList().then(res => {
  26.             this.setState({
  27.                 categoryList : res
  28.             });
  29.         }, errMsg => {
  30.             _mm.errorTips(errMsg);
  31.         });
  32.     }
  33.     // 表单的值发生变化
  34.     onValueChange(e){
  35.         let name = e.target.name,
  36.             value = e.target.value;
  37.         this.setState({
  38.             [name] : value
  39.         });
  40.     }
  41.     // 提交
  42.     onSubmit(e){
  43.         let categoryName = this.state.categoryName.trim();
  44.         // 品类名称不为空,提交数据
  45.         if(categoryName){
  46.             _product.saveCategory({
  47.                 parentId : this.state.parentId,
  48.                 categoryName : categoryName
  49.             }).then((res) => {
  50.                 _mm.successTips(res);
  51.                 this.props.history.push('/product-category/index');
  52.             }, (errMsg) => {
  53.                 _mm.errorTips(errMsg);
  54.             });
  55.         }
  56.         // 否则,提示错误
  57.         else{
  58.             _mm.errorTips('请输入品类名称');
  59.         }
  60.     }
  61.     render(){
  62.         return (
  63.             <div id="page-wrapper">
  64.                 <PageTitle title="品类列表"/>
  65.                 <div className="row">
  66.                     <div className="col-md-12">
  67.                         <div className="form-horizontal">
  68.                             <div className="form-group">
  69.                                 <label className="col-md-2 control-label">所属品类</label>
  70.                                 <div className="col-md-5">
  71.                                     <select name="parentId"
  72.                                         className="form-control"
  73.                                         onChange={(e) => this.onValueChange(e)}>
  74.                                         <option value="">根品类/</option>
  75.                                         {
  76.                                             this.state.categoryList.map((category, index) => {
  77.                                                 return <option value={category.id} key={index}>根品类/{category.name}</option>
  78.                                             })
  79.                                         }
  80.                                     </select>
  81.                                 </div>
  82.                             </div>
  83.                             <div className="form-group">
  84.                                 <label className="col-md-2 control-label">品类名称</label>
  85.                                 <div className="col-md-5">
  86.                                     <input type="text" className="form-control"
  87.                                         placeholder="请输入品类名称"
  88.                                         name="categoryName"
  89.                                         value={this.state.name}
  90.                                         onChange={(e) => this.onValueChange(e)}/>
  91.                                 </div>
  92.                             </div>
  93.                             <div className="form-group">
  94.                                 <div className="col-md-offset-2 col-md-10">
  95.                                     <button type="submit" className="btn btn-primary"
  96.                                         onClick={(e) => {this.onSubmit(e)}}>提交</button>
  97.                                 </div>
  98.                             </div>
  99.                         </div>
  100.                     </div>
  101.                 </div>
  102.             </div>
  103.         );
  104.     }
  105. }
  106.  
  107. export default CategoryAdd;

React后台管理系统-品类的增加、修改和查看的更多相关文章

  1. React后台管理系统-品类选择器二级联动组件

    1.页面大致是这个样子 2.页面结构 <div className="col-md-10">            <select name="&quo ...

  2. 《React后台管理系统实战 :四》产品分类管理页:添加产品分类、修改(更新)产品分类

    一.静态页面 目录结构 F:\Test\react-demo\admin-client\src\pages\admin\category add-cate-form.jsx index.jsx ind ...

  3. react后台管理系统路由方案及react-router原理解析

        最近做了一个后台管理系统主体框架是基于React进行开发的,因此系统的路由管理,选用了react-router(4.3.1)插件进行路由页面的管理配置. 实现原理剖析 1.hash的方式   ...

  4. 《React后台管理系统实战 :一》:目录结构、引入antd、引入路由、写login页面、使用antd的form登录组件、form前台验证、高阶函数/组件

    实战 上接,笔记:https://blog.csdn.net/u010132177/article/details/104150177 https://gitee.com/pasaulis/react ...

  5. 【共享单车】—— React后台管理系统开发手记:主页面架构设计

    前言:以下内容基于React全家桶+AntD实战课程的学习实践过程记录.最终成果github地址:https://github.com/66Web/react-antd-manager,欢迎star. ...

  6. 《React后台管理系统实战 :二》antd左导航:cmd批量创建子/目录、用antd进行页面布局、分离左导航为单独组件、子路由、动态写左导航、css样式相对陷阱

    一.admin页面布局及路由创建 0)cmd批量创建目录及子目录 //创建各个目录,及charts和子目录bar md home category product role user charts\b ...

  7. 【共享单车】—— React后台管理系统开发手记:UI菜单各个组件使用(Andt UI组件)

    前言:以下内容基于React全家桶+AntD实战课程的学习实践过程记录.最终成果github地址:https://github.com/66Web/react-antd-manager,欢迎star. ...

  8. 《React后台管理系统实战 零》:基础笔记

    day01 1. 项目开发准备 1). 描述项目 2). 技术选型 3). API接口/接口文档/测试接口 2. 启动项目开发 1). 使用react脚手架创建项目 2). 开发环境运行: npm s ...

  9. React后台管理系统-添加商品组件

    引入了CategorySelector 二级联动组件.FileUploader图片上传组件和RichEditor富文本编辑组件 import React from 'react'; import MU ...

随机推荐

  1. jndi理解

    java中很多这些接口规范,jndi就是其中一个,而下面那些包就是jndi接口的提供商程序实现包,他们都是遵循jndi规范的. 主要接口功能是:添加命名与对象的映射到jndi树中,客户能快速查找并使用 ...

  2. Ubuntu14.04-PXE搭建

    什么是PXE? PXE(Pre-boot Execution Environment,预启动执行环境)是由Intel公司开发的最新技术,工作于Client/Server的网络模式,支持工作站通过网络从 ...

  3. 深入理解java虚拟机阅读笔记(1)运行时数据区域

    java虚拟机所管理的内存区域主要分为方法区.堆:虚拟机栈.本地方法栈.程序计数器,如图: 1.程序计数器是当前线程所执行的字节码行号指示器,用以记录当前指令执行的位置.程序计数器是线程私有的,每个线 ...

  4. FastDFS 基础知识

    FastDFS是一个开源的轻量级分布式文件系统,它用纯C语言实现,支持Linux.FreeBSD.AIX等UNIX系统.它只能通过专有API对文件进行存取访问,不支持POSIX接口方式,不能mount ...

  5. Redis入门--(二)Redis的概述

    1.Redis的由来 创始人觉得Mysql不好用,就自己写了: 国内使用Redis的网站有新浪微博,知乎: 国外GitHub: VMWare也支持redis的开发 2.Redis的概述 官方提供的测试 ...

  6. jQuery的定时执行和延迟执行

    jQuery的定时执行和延迟执行 //延迟执行 setTimeout(function(){ console.log("实战授课,100%就业"); },600); //定时执行 ...

  7. jQueryMobile(二)

    三].按钮 <!-- 一个jQueryMobile页面 --> <div data-role='page'> <div data-role='header'>< ...

  8. 添加并发请求PDF到工作流附件

    本节实现将并发请求输出PDF文件添加到工作流附件 省去了工作流中其他部分,只对附件部分介绍 1.       建立一个类型为Document的Attribute

  9. 关于android项目的习惯

    编码使用UTF-8. 布局中多写style,常用字号颜色尺寸写进values对应文件 如中号 小号 大号 下部按钮颜色 上标题颜色 左边距,右边距,等. 任何文件类型通用名放在最前 如item_a;i ...

  10. MSSQL复制分发对异构数据库之间大容量数据分发造成异常

    由于历史遗留的问题,现有的架构中存在采用MSSQL的复制分发功能,从Oracle发布数据到MSSQL. 关于这项发布的实现原理,官方表述如下: Oracle 事务发布是通过使用 SQL Server ...