知与行后台管理端

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. import React, { useState, useEffect } from 'react';
  2. import { Form, Icon, Input, Button, DatePicker, Select, Card, Row, Col, Pagination, Alert, notification, Modal } from 'antd';
  3. import moment from 'moment';
  4. import request from '../../../utils/request';
  5. import apis from '../../../services/apis';
  6. import Styles from './style.less';
  7. import { router } from 'umi';
  8. import AuthButton from '@/components/AuthButton';
  9. import SelectCity from '../../../components/SelectButton/CitySelect'
  10. const { Option } = Select;
  11. // eslint-disable-next-line @typescript-eslint/no-unused-vars
  12. const { Meta } = Card;
  13. const tempDate = [{ code: 's101' }]
  14. function openNotificationWithIcon(type, message) {
  15. notification[type]({
  16. message,
  17. description:
  18. '',
  19. });
  20. }
  21. /**
  22. *卡片
  23. *
  24. * @returns
  25. */
  26. function CartBody(props) {
  27. const { data } = props
  28. function toEdi(record) {
  29. router.push({
  30. pathname: '/building/list/add',
  31. query: {
  32. id: record.buildingId,
  33. },
  34. })
  35. }
  36. /**
  37. *发布 取消 发布
  38. *
  39. * @param {*} record
  40. */
  41. function pulicAndUnPulic(record) {
  42. const modal = Modal.confirm();
  43. const buidingStatus = record.status === 1 ? 2 : 1
  44. const title = record.status === 1 ? '项目会在小程序端隐藏,后台可继续编辑重新发布?' : '确认发布此数据?'
  45. modal.update({
  46. content: title,
  47. okText: '确认',
  48. cancelText: '关闭',
  49. onOk: () => {
  50. request({ ...apis.building.updateStatus, data: { id: record.buildingId, status: buidingStatus } }).then(() => {
  51. openNotificationWithIcon('success', '操作成功')
  52. props.onSuccess()
  53. }).catch(err => {
  54. openNotificationWithIcon('error', err.message)
  55. })
  56. modal.destroy();
  57. },
  58. onCancel: () => {
  59. modal.destroy();
  60. },
  61. });
  62. }
  63. /**
  64. *删除楼盘
  65. *
  66. * @param {*} record
  67. */
  68. function deleteBuilding(record) {
  69. const modal = Modal.confirm();
  70. modal.update({
  71. content: '项目会被删除,小程序端和后台都无法再看到',
  72. okText: '确认',
  73. cancelText: '关闭',
  74. onOk: () => {
  75. request({ ...apis.building.deleteBuilding, urlData: { id: record.buildingId } }).then(() => {
  76. openNotificationWithIcon('success', '操作成功')
  77. props.onSuccess()
  78. }).catch(err => {
  79. // openNotificationWithIcon('error', err.message)
  80. })
  81. modal.destroy();
  82. },
  83. onCancel: () => {
  84. modal.destroy();
  85. },
  86. });
  87. }
  88. const { buildingImg } = data
  89. console.log("buildingImg: ", data.buildingImg, "data: ", data)
  90. return (
  91. <Card
  92. hoverable
  93. style={{ minWidth: '330px', borderRadius: '12px', margin: '10px', boxShadow: '0px 0px 16px 2px rgba(0,0,0,0.12)' }}
  94. cover={<img alt="example" src={((data.buildingImg && data.buildingImg[0]) || {}).url} style={{ borderRadius: '12px 12px 0 0', width: '100%', height: '14vw' }}></img>}
  95. bodyStyle={{ padding: '10px 20px' }}
  96. >
  97. <p className={Styles.cardText}>
  98. <span className={Styles.title}>楼盘编号</span>
  99. <span >:{data.code}</span>
  100. <AuthButton name="admin.building.update.put" noRight={null}>
  101. <span className={Styles.ediText} onClick={() => toEdi(data)}>
  102. 编辑
  103. <Icon type="form" style={{ color: '#C0C4CC', marginLeft: '10px' }} />
  104. </span>
  105. </AuthButton>
  106. </p>
  107. <p className={Styles.cardText}>
  108. <span className={Styles.title}>楼盘名称</span>
  109. <span >:{data.buildingName || data.name}</span>
  110. </p>
  111. <p className={Styles.cardItem}>
  112. <span className={Styles.title}>均价</span>
  113. <span >
  114. :约<span style={{ color: '#FF0707', fontSize: '20px' }}> {data.price || '待定'} </span>元/m²
  115. </span>
  116. </p>
  117. <p className={Styles.cardItem}>
  118. <span className={Styles.title}>项目地址</span>
  119. <span className={Styles.address}>:{data.address}</span>
  120. </p>
  121. <p className={Styles.cardItem}>
  122. <span className={Styles.title}>发布状态</span>
  123. <span >:{data.status === 1 ? '已发布' : '未发布'}</span>
  124. </p>
  125. <p className={Styles.cardItem}>
  126. <span className={Styles.title}>录入时间</span>
  127. <span >:{moment(data.createDate).format('YYYY-MM-DD HH:mm:ss')}</span>
  128. </p>
  129. <p style={{ margin: '15px 0', position: 'relative', fontSize: '0.106rem' }}>
  130. <AuthButton name="admin.building.update.status.put" noRight={null}>
  131. <span style={{ color: '#FF4A4A' }} onClick={() => pulicAndUnPulic(data)}>
  132. {/* 已发布的时候,需要显示取消发布的字样 */}
  133. {data.status === 1 ? '取消发布' : '发布'}
  134. <Icon type={data.status === 1 ? 'close-circle' : 'form'} style={{ color: '#C0C4CC', marginLeft: '8px' }} />
  135. </span>
  136. </AuthButton>
  137. <AuthButton name="admin.building.delete.id.delete" noRight={null}>
  138. <span style={{
  139. color: '#FF4A4A', position: 'absolute', right: '0',
  140. }} onClick={() => deleteBuilding(data)}>
  141. 删除
  142. <Icon type="rest" style={{ color: '#C0C4CC', marginLeft: '8px' }} />
  143. </span>
  144. </AuthButton>
  145. </p>
  146. </Card>
  147. )
  148. }
  149. /**
  150. *
  151. *
  152. * @param {*} props
  153. * @returns
  154. */
  155. function body(props) {
  156. const { getFieldDecorator } = props.form
  157. // eslint-disable-next-line react-hooks/rules-of-hooks
  158. const [dataSource, setDataSource] = useState({ records: [] })
  159. // eslint-disable-next-line react-hooks/rules-of-hooks
  160. useEffect(() => {
  161. getList({ pageNum: 1, pageSize: 9 })
  162. }, [])
  163. function getList(params) {
  164. // 网路请求
  165. request({ ...apis.building.getList, params: { ...params } }).then(res => {
  166. setDataSource(res)
  167. console.log("res:",res)
  168. }).catch(err => {
  169. // eslint-disable-next-line no-unused-expressions
  170. <Alert
  171. style={{
  172. marginBottom: 24,
  173. }}
  174. message={err}
  175. type="error"
  176. showIcon
  177. />
  178. })
  179. }
  180. // 提交事件
  181. function handleSubmit(e) {
  182. e.preventDefault();
  183. props.form.validateFields((err, values) => {
  184. if (!err) {
  185. // eslint-disable-next-line no-console
  186. console.log('提交数据: ', values)
  187. const { startDate } = values
  188. if (values.startDate !== undefined) {
  189. values.startDate = `${moment(startDate).format('YYYY-MM-DDT00:00:00.000')}Z`
  190. }
  191. getList({ pageNum: 1, pageSize: 9, ...values })
  192. }
  193. });
  194. }
  195. // Change 事件
  196. function handleSelectChange(e) {
  197. // eslint-disable-next-line no-console
  198. console.log(e)
  199. }
  200. // 分页
  201. function onChange(pageNumber) {
  202. // eslint-disable-next-line react-hooks/rules-of-hooks
  203. getList({ pageNum: pageNumber, pageSize: 9, ...props.form.getFieldsValue() })
  204. }
  205. function getDate(value, dateString) {
  206. // moment(value).format('YYYY-MM-DD HH:mm:ss')
  207. console.log(value, dateString)
  208. }
  209. function toAdd() {
  210. // 判断楼盘是否最可以添加
  211. request({ ...apis.building.verifyMax}).then(res => {
  212. router.push({ pathname: '/building/list/add' })
  213. }).catch(err => {
  214. // eslint-disable-next-line no-unused-expressions
  215. <Alert
  216. style={{
  217. marginBottom: 24,
  218. }}
  219. message={err}
  220. type="error"
  221. showIcon
  222. />
  223. return
  224. })
  225. }
  226. /**
  227. * 重置搜索
  228. */
  229. function handleReset() {
  230. props.form.resetFields();
  231. getList({ pageNum: 1, pageSize: 9 })
  232. }
  233. return (
  234. <>
  235. <Form layout="inline" onSubmit={e => handleSubmit(e, props)}>
  236. <Form.Item>
  237. {getFieldDecorator('code')(
  238. <Input
  239. prefix={<Icon type="text" style={{ color: 'rgba(0,0,0,.25)' }} />}
  240. placeholder="楼盘编号"
  241. />,
  242. )}
  243. </Form.Item>
  244. <Form.Item>
  245. {getFieldDecorator('name')(
  246. <Input
  247. prefix={<Icon type="text" style={{ color: 'rgba(0,0,0,.25)' }} />}
  248. placeholder="楼盘名称"
  249. />,
  250. )}
  251. </Form.Item>
  252. <Form.Item>
  253. {getFieldDecorator('startDate')(
  254. <DatePicker placeholder="开盘时间" format="YYYY-MM-DD" onChange={getDate} />,
  255. )}
  256. </Form.Item>
  257. <Form.Item>
  258. {getFieldDecorator('buildingStatus')(
  259. <Select style={{ width: '180px' }} placeholder="楼盘状态" onChange={handleSelectChange}>
  260. <Option value="1">发布</Option>
  261. <Option value="2">未发布</Option>
  262. </Select>,
  263. )}
  264. </Form.Item>
  265. <Form.Item>
  266. {getFieldDecorator('marketStatus')(
  267. <Select style={{ width: '180px' }} placeholder="销售状态" onChange={handleSelectChange}>
  268. <Option value="待定">待定</Option>
  269. <Option value="在售">在售</Option>
  270. <Option value="售完">售完</Option>
  271. </Select>,
  272. )}
  273. </Form.Item>
  274. <Form.Item>
  275. {getFieldDecorator('cityId')(
  276. <SelectCity />,
  277. )}
  278. </Form.Item>
  279. <Form.Item>
  280. {getFieldDecorator('isMain')(
  281. <Select style={{ width: '180px' }} placeholder="首页推荐" onChange={handleSelectChange}>
  282. <Option value="1">首页推荐</Option>
  283. <Option value="2">首页未推荐</Option>
  284. </Select>,
  285. )}
  286. </Form.Item>
  287. <Form.Item>
  288. <Button type="primary" htmlType="submit">
  289. 搜索
  290. </Button>
  291. <Button style={{ marginLeft: 8 }} onClick={handleReset}>
  292. 重置
  293. </Button>
  294. </Form.Item>
  295. </Form>
  296. <AuthButton name="admin.building.add.post" noRight={null}>
  297. <Button type="danger" className={Styles.addButton} onClick={() => toAdd()}>
  298. 新增楼盘
  299. </Button>
  300. </AuthButton>
  301. {/* 卡片内容,显示楼盘项目 */}
  302. <Row style={{ padding: ' 0 10px' }}>
  303. {
  304. dataSource.records.map((item, _) => (
  305. <Col span={8}>
  306. <CartBody data={item} key={item.buildingId} onSuccess={getList} />
  307. </Col>
  308. ))
  309. }
  310. </Row>
  311. {/* 分页 */}
  312. <div style={{ display: 'flex', justifyContent: 'flex-end', marginTop: '30px' }}>
  313. <Pagination showQuickJumper defaultCurrent={1} total={dataSource.total} onChange={onChange} pageSize={dataSource.size} />
  314. </div>
  315. </>
  316. );
  317. }
  318. const WrappedBody = Form.create({ name: 'body' })(body);
  319. export default WrappedBody