1. 程式人生 > >React後端管理系統-商品詳情detail組件

React後端管理系統-商品詳情detail組件

clas get xtend tde url -c let new save

哇哇哇哇哇哇哇哇水水水水水水水水水水水嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻

哇哇哇哇哇哇哇哇水水水水水水水水水水水嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻

哇哇哇哇哇哇哇哇水水水水水水水水水水水嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻

哇哇哇哇哇哇哇哇水水水水水水水水水水水嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻

  1. import React from ‘react‘;
  2. import MUtil from ‘util/mm.jsx‘
  3. import Product from ‘service/product-service.jsx‘
  4. import PageTitle from ‘component/page-title/index.jsx‘;
  5. import CategorySelector from ‘./category-selector.jsx‘;
  6. import ‘./save.scss‘;
  7. const _mm = new MUtil();
  8. const _product = new Product();
  9. class ProductDetail extends React.Component{
  10. constructor(props){
  11. super(props);
  12. this.state = {
  13. id : this.props.match.params.pid,
  14. name : ‘‘,
  15. subtitle : ‘‘,
  16. categoryId : 0,
  17. parentCategoryId : 0,
  18. subImages : [],
  19. price : ‘‘,
  20. stock : ‘‘,
  21. detail : ‘‘,
  22. status : 1 //商品狀態1為在售
  23. }
  24. }
  25. componentDidMount(){
  26. this.loadProduct();
  27. }
  28. // 加載商品詳情
  29. loadProduct(){
  30. // 有id的時候,表示是編輯功能,需要表單回填
  31. if(this.state.id){
  32. _product.getProduct(this.state.id).then((res) => {
  33. let images = res.subImages.split(‘,‘);
  34. res.subImages = images.map((imgUri) => {
  35. return {
  36. uri: imgUri,
  37. url: res.imageHost + imgUri
  38. }
  39. });
  40. this.setState(res);
  41. }, (errMsg) => {
  42. _mm.errorTips(errMsg);
  43. });
  44. }
  45. }
  46. render(){
  47. return (
  48. <div id="page-wrapper">
  49. <PageTitle title="添加商品" />
  50. <div className="form-horizontal">
  51. <div className="form-group">
  52. <label className="col-md-2 control-label">商品名稱</label>
  53. <div className="col-md-5">
  54. <p className="form-control-static">{this.state.name}</p>
  55. </div>
  56. </div>
  57. <div className="form-group">
  58. <label className="col-md-2 control-label">商品描述</label>
  59. <div className="col-md-5">
  60. <p className="form-control-static">{this.state.subtitle}</p>
  61. </div>
  62. </div>
  63. <div className="form-group">
  64. <label className="col-md-2 control-label">所屬分類</label>
  65. <CategorySelector
  66. readOnly
  67. categoryId={this.state.categoryId}
  68. parentCategoryId={this.state.parentCategoryId}/>
  69. </div>
  70. <div className="form-group">
  71. <label className="col-md-2 control-label">商品價格</label>
  72. <div className="col-md-3">
  73. <div className="input-group">
  74. <input type="number" className="form-control"
  75. value={this.state.price} readOnly/>
  76. <span className="input-group-addon">元</span>
  77. </div>
  78. </div>
  79. </div>
  80. <div className="form-group">
  81. <label className="col-md-2 control-label">商品庫存</label>
  82. <div className="col-md-3">
  83. <div className="input-group">
  84. <input type="number" className="form-control"
  85. value={this.state.stock} readOnly/>
  86. <span className="input-group-addon">件</span>
  87. </div>
  88. </div>
  89. </div>
  90. <div className="form-group">
  91. <label className="col-md-2 control-label">商品圖片</label>
  92. <div className="col-md-10">
  93. {
  94. this.state.subImages.length ? this.state.subImages.map(
  95. (image, index) => (
  96. <div className="img-con" key={index}>
  97. <img className="img" src={image.url} />
  98. </div>)
  99. ) : (<div>暫無圖片</div>)
  100. }
  101. </div>
  102. </div>
  103. <div className="form-group">
  104. <label className="col-md-2 control-label">商品詳情</label>
  105. <div className="col-md-10" dangerouslySetInnerHTML={{__html: this.state.detail}}></div>
  106. </div>
  107. </div>
  108. </div>
  109. )
  110. }
  111. }
  112. export default ProductDetail;

React後端管理系統-商品詳情detail組件