首页 > 其他分享 >react.js+easyui 做一个简单的商品表

react.js+easyui 做一个简单的商品表

时间:2022-10-18 01:22:40浏览次数:50  
标签:easyui value js react state listtime row setState

效果图:

 

 

    import React from 'react'; import { Form, FormField, Layout,DataList,LayoutPanel,Panel, Label, CheckBox, TextBox,Tabs,TabPanel, DateBox, NumberBox, RadioButton, ComboBox, LinkButton } from 'rc-easyui'; import '../css/style.css'; import * as demo from 'rc-easyui/dist/locale/easyui-lang-zh_CN.js'; import { reqdoSQL } from '../../api/functions.js'; import 'rc-easyui/dist/themes/gray/radiobutton.css'; import 'rc-easyui/dist/themes/gray/checkbox.css'; export default class Page401 extends React.Component {   constructor(props) {     super(props);     this.state = {      product:{},      data:[],      topic:["饮料","零食","速食产品","母婴用品","鞋包饰品","厨房日用品"],      topicchecked:[],      onlist:["上市","未上市"],      onlists:"",      datetime:new Date(),      listtime:[]
    }   }   getImage(row) {     return "/myServer/mybase/products/"+row.productid+".jpg";   }
  async componentDidMount() {     let p={};     p.selectsql='select productid,productname,unitprice from products';     let rs= await reqdoSQL(p);     this.setState({data:rs.rows});       }
  renderItem({ row }) {     return (       <div key={row.productid}>         <img src={this.getImage(row)} style={{width:"100px",height:"100px"}} />         <div>           <p>{row.productid} - {row.productname}</p>             <p>¥ {row.unitprice}</p>         </div>       </div>     )   }
  handleChange(name, value) {  //同一个函数,用name来区分       let product = Object.assign({}, this.state.product);     product[name] = value;     this.setState({product: product,open:false });     console.log(name,value);   }
handleSelectionChange(row){     this.setState({product:row})     console.log(111111,row);
  }
  handleChangelist(value, checked) {     if (checked) {       this.setState({ onlists: value },() => {         setTimeout(()=>{           if(this.state.onlists=="上市"){             var listtime=[];             listtime.push(<div style={{ margin: '10px'}}>           <Label htmlFor="onlisttime" align="left">上市时间:</Label>           <DateBox inputId="onlisttime" id="onlisttime" value={this.state.datetime} onChange={(value) => this.datetimeChange(value)} format="yyyy-MM-dd"           style={{width:"300px",fontFamily:"楷体",height:"30px"}}></DateBox>           </div>);             this.setState({listtime:listtime})                 }else{                   this.setState({listtime:[]});           }         },100);           });       } }

  datetimeChange(value){     this.setState({datetime: value});   }   render() {
    return (       <div>         <Layout style={{width:"100%",height:"100%",position:"absolute"}}>
          <LayoutPanel region="west" style={{width:200}}>             <div>             <DataList           style={{ width: "100%", height: "100%" ,textAlign:"center"}}           renderItem={this.renderItem.bind(this)}           data={this.state.data}           selectionMode="single"           onSelectionChange={this.handleSelectionChange.bind(this)}           />                   </div>           </LayoutPanel>
          <LayoutPanel region="center" >                           <Panel title="商品信息" collapsible >           <div style={{position:'relative', height:120}} >           <Label htmlFor="productid" className="labelStyle" style={{position:'absolute', top:'20px', left:'16px'}}>商品编号:</Label>           <TextBox inputId="productid" id="productid" value={this.state.product.productid}           onChange={(value) => this.handleChange("pid", value)}           style={{position:'absolute', top:'20px', left:'85px', width:'200px'}}></TextBox>
          <Label htmlFor="productname" className="labelStyle" style={{position:'absolute', top:70, left:'16px'}}>商品名称:</Label>           <TextBox inputId="productname" id="productname" value={this.state.product.productname} onChange={(value) => this.handleChange("productname", value)}           style={{position:'absolute', top:'70px', left:'85px', width:200}}></TextBox>                    </div>         </Panel>         <div>         <Tabs tabPosition='top'  >                 <TabPanel ref={ref => this.myTab1 = ref} key="myTab1" title="客户列表">         <div style={{margin:"10px"}}>             <Label htmlFor="customerid" align="left">客户编码:</Label>             <TextBox inputId="customerid" iconCls="icon-man" style={{ width: '30%' }}></TextBox>         </div>                   <div style={{margin:"10px"}}>             <Label htmlFor="companyname" align="left">公司名称:</Label>             <TextBox inputId="companyname" iconCls="icon-man" style={{ width: '30%' }}></TextBox>         </div>         <div style={{margin:"10px"}}>         <Label htmlFor="companyname" align="left">售货类型:</Label>         {           this.state.topic.map(topic => {             return (               <div key={topic} style={{display:"inline-block"}}>                 <CheckBox inputId={topic} multiple value={topic} values={this.state.topicchecked} onChange={this.handleChange.bind(this)}></CheckBox>                 <Label htmlFor={topic} style={{margin:'0px 0px 0px 5px'}}>{topic}</Label>               </div>             )           })                   }         </div>         <div style={{margin:"10px"}}>         <Label htmlFor="onlist" align="left">公司类型:</Label>         {   this.state.onlist.map(onlist => {     return (       <div key={onlist} style={{display:"inline-block"}}>         <RadioButton           inputId={onlist}           value={onlist}           groupValue={this.state.onlists}           onChange={(checked) => this.handleChangelist(onlist, checked)}         />         <Label htmlFor={onlist} style={{ margin: '0 5px' }}>{onlist}</Label>       </div>     )   }) } </div>
{this.state.listtime}

        <div style={{ margin: '10px' }}>             <Label htmlFor="note" align="left">公司简历:</Label>             <TextBox inputId="note" multiline value={this.state.description} style={{ width: '70%', height: 100 }}></TextBox>         </div>         </TabPanel>         </Tabs>       </div>         </LayoutPanel>         </Layout>       </div>     );   } }         做了个选中才出现的信息框,开始做有异步,点击“上市”不出现“上市时间”,点击“未上市”才出现,后来还是用setTimeout()做的,如果有更好的方法可以指点指点的。    handleChangelist(value, checked) {     if (checked) {       this.setState({ onlists: value },() => {         setTimeout(()=>{           if(this.state.onlists=="上市"){             var listtime=[];             listtime.push(<div style={{ margin: '10px'}}>           <Label htmlFor="onlisttime" align="left">上市时间:</Label>           <DateBox inputId="onlisttime" id="onlisttime" value={this.state.datetime} onChange={(value) => this.datetimeChange(value)} format="yyyy-MM-dd"           style={{width:"300px",fontFamily:"楷体",height:"30px"}}></DateBox>           </div>);             this.setState({listtime:listtime})                 }else{                   this.setState({listtime:[]});           }         },100);           });       }

 

}

 

 

 

   

标签:easyui,value,js,react,state,listtime,row,setState
From: https://www.cnblogs.com/mdddd-yep/p/16801252.html

相关文章

  • 用js调试css 画出所有的css布局
    打开浏览器调试模式,在Console模式下复制下面代码执行[].forEach.call($$("*"),function(a){a.style.outline="1pxsolid#"+(~~(Math.random()*(1<<24))).toString(16)})......
  • 笔记:node.js的http模块
    教程来自b站黑马程序员https://www.bilibili.com/video/BV1a34y167AZ/?spm_id_from=333.1007.top_right_bar_window_custom_collection.content.click      ......
  • 原生js中offsetTop, offsetLeft与offsetParent的详细讲解
    简单说下:offsetTopoffsetTop:为只读属性。返回的是一个数字。它返回当前元素相对于其offsetParent元素的顶部内边距的距离。它等价于offsetTop==>元素到offsetPare......
  • 基于JSP的抑郁症科普交流网站-计算机毕业设计源码+LW文档
    摘 要本抑郁症科普交流网站设计目标是实现抑郁症科普的信息化管理,提高管理效率,使得抑郁症科普工作规范化、科学化、高效化。本文研究的抑郁症科普交流网站基于SSM架构,采......
  • JS实现控制台简易进度条
    JS实现控制台输出简易的进度条代码效果如下运行环境:vscode+node.js控制台输出进度条的原理暂停效果实现//在js里面可以定义一个延时函数//延时函数,ms为需要......
  • Js-Ajax
    jQueryAjax1ajax$.ajax({type:'POST',//请求方式GET/POSTurl:"/api/jsonws/cch-portlet.scorestatisticshelper/list-exam-score",//url地址......
  • 通过Js来设置页面样式
    介绍我们可以在编辑HTML源码的时候将CSS样式写死到.css文件或者HTML元素的style属性中,但又时候可能会需要动态地来修改某个元素的样式。我这里介绍两种方式:修改HTML元素的s......
  • 移动端适配+flexible.js+rem适配
    !function(a,b){functionc(){varb=f.getBoundingClientRect().width;b/i>540&&(b=540*i);varc=b/10;f.style.fontSize=c+"px",k.rem=a.rem=c}vard,e=a.document,f=e.d......
  • 原生js document.getElementById("XXX").disabled="false";无效
    想要设置表单元素不能访问时,使用document.getElementById("XXX").disabled="true";但是想要取消disabled的时候,发现document.getElementById("XXX").disabled="false";无......
  • Spring boot JSP
        路径            静态资源图片读取     ......