CaseShow.jsx 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. import React, {Component} from 'react';
  2. import {Layout, Card, Button, Avatar, Spin, Icon, Row, Col, notification,Tag } from 'antd';
  3. import lo from '../../../images/lo.png'
  4. import './index.css'
  5. import {graphqlUrl} from "../../../config";
  6. import {SHOW_ALL_CASE, SHOW_CASE} from "../../../gql";
  7. import {FormattedMessage} from 'react-intl';
  8. import {request} from 'graphql-request'
  9. import UserCustom from "./UserCustom";
  10. import {Query} from "react-apollo";
  11. import gql from "graphql-tag";
  12. import {getCookie} from "../../../cookie";
  13. const {Content} = Layout;
  14. const {Meta} = Card;
  15. class CaseShow extends Component {
  16. constructor(props) {
  17. super(props);
  18. this.state = {
  19. examplesIoobot: [],
  20. examplesOthers: [],
  21. showCustom: false,
  22. chosenSchemaID: ''
  23. }
  24. }
  25. componentWillMount() {
  26. this._isMounted = true;
  27. // 查询是否登录
  28. let userID = getCookie('user_id');
  29. if (userID !== undefined && userID !== '') {
  30. this.setState({
  31. userID
  32. });
  33. }
  34. request(graphqlUrl, SHOW_ALL_CASE, {}).then(data => {
  35. let cases = data.case_by_props;
  36. // console.log(cases);
  37. let examplesIoobot = cases.filter(case1 => case1.user_id.id === 'ioobot');
  38. let IooList = this.examplesFilter(examplesIoobot);
  39. let examplesOthers = cases.filter(case2 => case2.user_id.id !== 'ioobot');
  40. let UserList = this.examplesFilter(examplesOthers);
  41. if (this._isMounted) {
  42. this.setState({
  43. examplesIoobot:IooList,
  44. examplesOthers:UserList
  45. })
  46. }
  47. }
  48. )
  49. }
  50. examplesFilter(example) {
  51. // console.log('examples',example);
  52. let hash = {},i = 0,list = [];
  53. example.forEach(function(item) {
  54. let {title} = item;
  55. hash[title] ? list[hash[title] - 1].content.push(item) : hash[title] = ++i && list.push({
  56. title,
  57. content: [item],
  58. });
  59. });
  60. // console.log('list',list);
  61. return list;
  62. }
  63. componentWillUnmount() {
  64. this._isMounted = false;
  65. }
  66. schemaIDChangeBucket = (schemaID) => {
  67. if (this.props.location && this.props.location.state) {
  68. switch (schemaID) {
  69. case 'order_schemaID':
  70. return 'appointment';
  71. case 'ecommerce_schemaID':
  72. return 'e-commerce';
  73. case 'bills_schemaID':
  74. return 'bills';
  75. default:
  76. break;
  77. }
  78. }
  79. };
  80. backToMe = () => {
  81. this.setState({
  82. showCustom: false
  83. })
  84. };
  85. showCustom = (item) => {
  86. this.setState({
  87. showCustom: true,
  88. chosenSchemaID: item
  89. })
  90. };
  91. render() {
  92. let {userID, showCustom, chosenSchemaID} = this.state;
  93. return (
  94. <div id="example-show">
  95. <Layout style={{padding: '24px 48px', minHeight: '300px'}}>
  96. {
  97. !showCustom ?
  98. <div>
  99. <div className={'card card-head'}>
  100. <Card.Grid className={'card-head-item orange-change'} >
  101. <p>我们永久无年费 &nbsp;&nbsp;&nbsp;&nbsp; 告别高成本</p>
  102. <p>省钱、更省心</p>
  103. </Card.Grid>
  104. <Card.Grid className={'card-head-item pink-change'} >
  105. <p>数据完全私有 &nbsp;&nbsp;&nbsp;&nbsp; 安全更可靠</p>
  106. <p>数据分析图表为您提供更细致的服务</p>
  107. </Card.Grid>
  108. <Card.Grid className={'card-head-item blue-change'} >
  109. <p>模板不满意 &nbsp;&nbsp;&nbsp;&nbsp; 快来定制化吧!</p>
  110. <p>上手有困难,联系我们即可</p>
  111. <Button
  112. onClick={() => {
  113. this.props.history.push({
  114. pathname: `/common/communication`
  115. })}}>立即定制</Button>
  116. </Card.Grid>
  117. </div>
  118. <div className={'schema-name'}>
  119. <FormattedMessage id='ioobot case'/>
  120. </div>
  121. <div>
  122. {
  123. this.state.examplesIoobot.length === 0 ?
  124. <Spin/>
  125. :
  126. this.state.examplesIoobot.map((item, index) => {
  127. let exampleList = item.content;
  128. let gzh = exampleList.filter(case1 => case1.description === '微信公众号');
  129. let xcx = exampleList.filter(case1 => case1.description === '微信小程序');
  130. let value = exampleList[0];
  131. return(
  132. <Row key={index} className='card card-case' type="flex" justify="space-around" align="middle">
  133. <Col span={6} style={{padding:'20px'}}>
  134. <div className="wrap">
  135. <div className="case-name">{value.title}</div>
  136. <div className="wrapper">
  137. <div >
  138. <div >
  139. <div >模板简介:</div>
  140. <div >{value.detailDescription ? value.detailDescription : '暂无简介' }</div>
  141. </div>
  142. <br/>
  143. <div >
  144. {value.detailAttention ?
  145. <div>适用行业: &nbsp;&nbsp;
  146. <Tag color="blue">{value.detailAttention}</Tag>
  147. </div>
  148. :
  149. ''
  150. }
  151. </div>
  152. <br/>
  153. <div className="left-end">
  154. <div>
  155. <Icon type="mail"/>&nbsp;&nbsp;
  156. {
  157. value.user_id.email ? value.user_id.email : '该作者未留下联系方式'
  158. }
  159. </div>
  160. <div>
  161. <Icon type="github"/>&nbsp;&nbsp;
  162. {
  163. value.codeAddress ?
  164. <a href={value.codeAddress}>查看源码 可自行修改使用</a>
  165. :
  166. '该作者未留下代码仓库地址'
  167. }
  168. </div>
  169. </div>
  170. </div>
  171. </div>
  172. </div>
  173. </Col>
  174. <Col span={9} style={{padding:'20px'}}>
  175. {gzh.length ?
  176. <CaseShowDetail caseContent={gzh} showCustom={this.showCustom}/>
  177. :
  178. <div>敬请期待</div>
  179. }
  180. </Col>
  181. <Col span={9} style={{padding:'20px'}}>
  182. {xcx.length ?
  183. <CaseShowDetail caseContent={xcx} showCustom={this.showCustom}/>
  184. :
  185. <div>敬请期待</div>
  186. }
  187. </Col>
  188. </Row>
  189. )
  190. })
  191. }
  192. </div>
  193. </div>
  194. :
  195. <UserCustom
  196. userID={userID}
  197. bucketName={this.schemaIDChangeBucket(chosenSchemaID)}
  198. history={this.props.history}
  199. backToMe={this.backToMe}
  200. />
  201. }
  202. </Layout>
  203. </div>
  204. )
  205. }
  206. }
  207. export default CaseShow;
  208. class CaseShowDetail extends Component {
  209. constructor(props) {
  210. super(props);
  211. this.state = {
  212. }
  213. }
  214. render() {
  215. let caseDetail = this.props.caseContent[0];
  216. // console.log('caseDetail',caseDetail);
  217. return(
  218. <div key={caseDetail.id}>
  219. <Query query={gql(SHOW_CASE)} variables={{id: caseDetail.id}}>
  220. {
  221. ({loading, error, data}) => {
  222. if (loading) {
  223. return <Spin/>
  224. }
  225. if (error) {
  226. return 'error!';
  227. }
  228. let thisCase = data.case_by_id;
  229. return (
  230. <div>
  231. <div className={'case-show-head'}>{caseDetail.description}</div>
  232. <div className={'wrapper'}>
  233. <div >
  234. <img
  235. key={thisCase.detailImages[0]}
  236. src={thisCase.detailImages[0]}
  237. alt=""
  238. height="500"
  239. />
  240. </div>
  241. <div className={'right'}>
  242. <div className="cl-center" >
  243. <div className='cover-div'>
  244. <img
  245. className='cover-img'
  246. src={caseDetail.img}
  247. alt={caseDetail.title + '' + caseDetail.description}/>
  248. </div>
  249. </div>
  250. <div className="cl-center">
  251. 微信扫一扫立即体验
  252. </div>
  253. <div className="cl-center">
  254. <Button type="primary"
  255. style={{borderRadius:30}}
  256. onClick={() => {
  257. this.props.showCustom(caseDetail.schema_id.id);
  258. }}><FormattedMessage id='Publish immediately'/></Button>
  259. </div>
  260. </div>
  261. </div>
  262. </div>
  263. )
  264. }
  265. }
  266. </Query>
  267. </div>
  268. )
  269. }
  270. }