index.jsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. import React from "react";
  2. import styles from "./index.css";
  3. import { getData } from "../../api/index";
  4. import Box from "../../components/Box/index.jsx";
  5. import Title from "../../components/Title/index.jsx";
  6. import { LevelList2 } from "../../components/LeveList2/index.jsx";
  7. import EditTpl from "../../components/edit/index";
  8. import { LevelList1 } from '../../components/LevelList1/index.jsx';
  9. import { NumTostring } from '../../components/numTostring';
  10. var QRCode = require('qrcode.react');
  11. class Industry extends React.Component {
  12. state = {
  13. //商品列表 搜索 接口配置
  14. productListData: {
  15. data: {
  16. list: []
  17. }
  18. },
  19. //搜索框
  20. inputValue: "",
  21. //分类数据
  22. classificationListData: {
  23. data: {
  24. list: []
  25. }
  26. },
  27. ProductDetailsData: {
  28. data: {
  29. }
  30. },
  31. //产品轮播下标
  32. productSubscript: 0,
  33. activeItem:2
  34. }
  35. //搜索功能
  36. searTime = null;
  37. searchValue = e => {
  38. e.persist();
  39. const search = e.target.value || '';
  40. this.setState({
  41. inputValue: search
  42. });
  43. clearTimeout(this.searTime);
  44. this.searTime = setTimeout(() => {
  45. this.searchDealWith({
  46. search
  47. });
  48. }, 800);
  49. }
  50. //搜索函数
  51. searchDealWith(e = {},index) {
  52. const {
  53. match: {
  54. params = {}
  55. }
  56. } = this.props;
  57. //商品列表 搜索 接口配置 productListData
  58. getData({
  59. port: "productListData",
  60. ...params,
  61. params: {
  62. pageNum: 1,
  63. pageSize: 5000,
  64. ...e
  65. }
  66. }).then(res => {
  67. const { config, config: {
  68. data: {
  69. list = []
  70. }
  71. } } = res;
  72. this.setState({ productListData: config,activeItem:index || 0});
  73. this.getProductDetails(list[0] || {}, 0);
  74. list.length && this.startProductCarousel();
  75. });
  76. }
  77. //分类查询
  78. classification = e => {
  79. const {
  80. match: {
  81. params = {}
  82. }
  83. } = this.props;
  84. getData({
  85. port: "classificationListData",
  86. ...params
  87. }).then(res => {
  88. const { config, config: {
  89. data: {
  90. list = []
  91. }
  92. } } = res;
  93. this.setState({ classificationListData: config});
  94. this.searchDealWith({
  95. typeId: (list[this.state.activeItem] || {}).id || ''
  96. },this.state.activeItem);
  97. });
  98. }
  99. //获取详情
  100. getProductDetails = (e = {}, productSubscript) => {
  101. const {
  102. match: {
  103. params = {}
  104. }
  105. } = this.props;
  106. this.setState({ productSubscript });
  107. return getData({
  108. port: "ProductDetailsData",
  109. ...params,
  110. params: {
  111. ...e
  112. }
  113. }).then(res => {
  114. const { config } = res;
  115. const {data:{id = ''}} = config;
  116. config.data.qrcode = id?`http://wxh5.gzqlyx.com/#/pages/product/product?id=${id}`:'';
  117. this.setState({ ProductDetailsData: config, productSubscript });
  118. });
  119. }
  120. carouselTime = null;
  121. //start启动产品轮播
  122. startProductCarousel = e => {
  123. clearTimeout(this.carouselTime);
  124. const time = this.state.productListData.data.scrollTime - 0 || 0;
  125. time && (this.carouselTime = setTimeout(e => {
  126. const {
  127. data: {
  128. list = []
  129. }
  130. } = this.state.productListData;
  131. const index = this.state.productSubscript < list.length - 1 ? this.state.productSubscript + 1 : 0;
  132. this.getProductDetails(list[index], index).then(e => {
  133. this.startProductCarousel();
  134. });
  135. }, time));
  136. }
  137. componentDidMount() {
  138. this.classification();
  139. }
  140. componentWillUnmount() {
  141. //组件销毁
  142. clearTimeout(this.carouselTime);
  143. }
  144. //进入内页
  145. goLink = (e,i)=>{
  146. //处理path 替换 页面 与 pId
  147. let {match:{
  148. path,
  149. url
  150. }} = this.props;
  151. url = url.split("/");
  152. path = path.split("/").map((x,i)=>{
  153. const iu = url[i];
  154. if(i == 1){
  155. return "detail";
  156. }
  157. const k = x.indexOf(":"),
  158. j = x.indexOf("?");
  159. if (k != -1) {
  160. x = x.substring(k + 1, j);
  161. }
  162. if (x == 'pId') {
  163. return iu+"-"+e.id;
  164. }
  165. return iu;
  166. }).join("/");
  167. return path;
  168. }
  169. LevelList2Click(e){
  170. const {data:{minTitle = [],firmId}} = this.state.ProductDetailsData;
  171. if((minTitle[e] || {}).key === 'umsCompanyInfo'){
  172. this.props.history.push(this.goLink({id:firmId}));
  173. }
  174. }
  175. render() {
  176. const { productSubscript, classificationListData, productListData, inputValue, ProductDetailsData, ProductDetailsData: { data: DetailsData } ,activeItem=0} = this.state,
  177. p_list = (((productListData || {}).data || {}).list || []);
  178. const PovertyAlleviationArticle = {
  179. data: {
  180. list: (DetailsData.minTitle || []).map(x=>{
  181. return {
  182. title:x.name,
  183. name:DetailsData[x.key]
  184. }
  185. }),
  186. a:['brandName', 'spec', 'qualityGuaranteePeriod', 'placeOfProduction', 'umsCompanyInfo'].map((x, i) => {
  187. const name = DetailsData[x];
  188. if (name) {
  189. return {
  190. title: DetailsData[`minTitle${i + 1}`],
  191. name
  192. }
  193. }
  194. }).filter(x => {
  195. if (x) return x;
  196. })
  197. }
  198. };
  199. return (
  200. <div className={styles.Box}>
  201. <div className={styles.Left}>
  202. <Box no={true} style={{ height: "100%" }} className={styles.LeftBox}>
  203. <EditTpl
  204. style={{
  205. bottom: "auto"
  206. }}
  207. data={productListData}
  208. upData={productListData => this.setState({ productListData })}></EditTpl>
  209. <div className={styles.searchBox}>
  210. <i className={`iconfont icon-sousuo ${styles.iconSearch}`}></i>
  211. <input placeholder="输入名称" className={styles.searchText} onChange={e => this.searchValue(e)} />
  212. </div>
  213. {!inputValue ? <LevelList1 activeItem={activeItem} style={{ position: "relative", flex: "none" }} data={classificationListData} active={({ id },index) => this.searchDealWith({ typeId: id },index)} ></LevelList1> : ''}
  214. {p_list.length ? <ul className={styles.ulList}>
  215. {p_list.map((x, i) => {
  216. return (<li key={i} onClick={e => this.getProductDetails(x, i)}>
  217. <div className={`${styles.ulListItem} ${productSubscript == i ? styles.hover : ''}`}>
  218. <div className={styles.img} style={{ backgroundImage: `url(${x.pic}?imageMogr2/quality/60/thumbnail/100x100)` }}></div>
  219. <h3>{x.name}</h3>
  220. <div className={"level-line"}></div>
  221. <div className={styles.itemText}>
  222. {x.brandName ? <span>品牌:{x.brandName || ''}</span> : ''}
  223. {x.price ? <span key={x.spec}>规格:{x.spec || ''}</span> : ''}
  224. </div>
  225. {x.umsCompanyInfo ? <div className={styles.itemText}>
  226. <span key={x.qualityGuaranteePeriod}>{x.qualityGuaranteePeriod?`保质期:${x.qualityGuaranteePeriod}`:'参考包装'}</span>
  227. </div> : ''}
  228. </div>
  229. </li>)
  230. })}
  231. </ul> : <div className={styles.NoData}>没有数据</div>}
  232. </Box>
  233. </div>
  234. <Box className={styles.Right} no={true}>
  235. <EditTpl data={ProductDetailsData} upData={ProductDetailsData => this.setState({ ProductDetailsData })}></EditTpl>
  236. <div className={styles.RightBox}>
  237. <Box style={{ height: "58%", display: "flex" }}>
  238. <div className={styles.productImges} style={{ backgroundImage: `url(${DetailsData.pic})` }}></div>
  239. <div className={styles.productHref}>
  240. {DetailsData.qrcode && <QRCode value={DetailsData.qrcode} style={{width:"10vw",height:"10vw"}} ></QRCode>}
  241. <div className={styles.retailPrice}>{DetailsData.retailPriceTitle}</div>
  242. <div className={styles.NumTostring}><span style={{fontSize:"40px"}}>{DetailsData.priceIcon}{DetailsData.price || '暂无售价'}</span></div>
  243. <div className={styles.retailPrice}>{(DetailsData.buyUrls || []).length?DetailsData.PurchaseLinkTitle:''}</div>
  244. <div className={styles.BuyLink}>
  245. {(DetailsData.buyUrls || []).map((x, i) => {
  246. return (
  247. <a target={"_blank"} href={x.shopUrl} key={i}>
  248. <img src={x.shopImg} />
  249. </a>)
  250. })}
  251. </div>
  252. </div>
  253. </Box>
  254. <br />
  255. <Title>{DetailsData.name}</Title>
  256. <br />
  257. <LevelList2 active={(...e)=>this.LevelList2Click(...e)} data={PovertyAlleviationArticle}></LevelList2>
  258. <br />
  259. <Box no={true} style={{ flex: 1 }}>
  260. <Title>{DetailsData.IntroductionTitle}</Title>
  261. <div className={styles.IntroductionInfo} dangerouslySetInnerHTML={{__html:DetailsData.description}}></div>
  262. </Box>
  263. </div>
  264. </Box>
  265. </div>
  266. )
  267. }
  268. }
  269. export {
  270. Industry
  271. }
  272. export default Industry