Quellcode durchsuchen

Merge branch 'master' of http://git.ycjcjy.com/zhiyuxing/estateagents-admin-manager

魏熙美 vor 5 Jahren
Ursprung
Commit
eb16c7e931
2 geänderte Dateien mit 174 neuen und 137 gelöschten Zeilen
  1. 101
    88
      src/pages/news/type/NewsType.jsx
  2. 73
    49
      src/pages/news/type/editNews.jsx

+ 101
- 88
src/pages/news/type/NewsType.jsx Datei anzeigen

@@ -1,115 +1,128 @@
1
-import React from 'react';
1
+import React, { useState, useEffect } from 'react';
2 2
 import { Form, Input, Button, Icon, Select, message, Table, Divider, Tag, Pagination, Modal,Breadcrumb } from 'antd';
3 3
 import { FormattedMessage } from 'umi-plugin-react/locale';
4
-import styles from './style.less';
4
+import styles from '../../style/GoodsList.less';
5 5
 import router from 'umi/router';
6
+import BuildSelect from '../../../components/SelectButton/BuildSelect'
7
+
8
+import request from '../../../utils/request'
6 9
 
7 10
 const { Option } = Select;
8
-// 提交事件
9
-function handleSubmit(e, props) {
10
-  e.preventDefault();
11
-  props.form.validateFields((err, values) => {
12
-    if (!err) {
13
-      console.log('提交数据: ', values)
14
-    }
15
-  });
16
-}
17
-// Change 事件
18
-function handleSelectChange(props) {
19
-  console.log(props)
20
-}
21 11
 
22
-// 分页
23
-function onChange(pageNumber) {
24
-  console.log('Page: ', pageNumber);
25
-}
26 12
 
27
-// 跳转到编辑资讯
28
-function toEditNews() {
29
-  router.push({
30
-    pathname: '/news/type/editNews',
31
-    query: {
32
-      a: 'b',
33
-    },
34
-  });
35
-}
13
+function header(props) {
14
+  // 获取初始化数据
15
+  const [ data, setData ] = useState({})
36 16
 
37
-/**
38
- *
39
- *
40
- * @param {*} props
41
- * @returns
42
- */
17
+  useEffect(() => {
18
+    getList({ pageNum: 1, pageSize: 10 });
19
+  },[])
43 20
 
44
-const dataSource = [
45
-  {
46
-    key: '1',
47
-    img: 'http://img0.imgtn.bdimg.com/it/u=4246326797,2657995307&fm=26&gp=0.jpg',
48
-    name: '华为P30 Pro',
49
-  },
50
-  {
51
-    key: '2',
52
-    img: '',
53
-    name: '大米',
54
-  },
55
-];
21
+  // 查询列表
22
+  const getList = (params) => {
23
+    request({
24
+        url: '/api/admin/taNewsType',
25
+        method: 'GET',
26
+        params: { ...params },
27
+    }).then((data) => {
28
+        console.log(data)
29
+        setData(data)
30
+    })
31
+  }
32
+  
33
+  // 提交事件
34
+  const handleSubmit = (e, props) => {
35
+    e.preventDefault();
36
+    props.form.validateFields((err, values) => {
37
+      if (!err) {
38
+        getList({ pageNum: 1, pageSize: 10, ...values })
39
+      }
40
+    });
41
+  }
56 42
 
57
-const columns = [
58
-  {
59
-    title: '类型图片',
60
-    dataIndex: 'img',
61
-    key: 'img',
62
-    align: 'left',
63
-    render: (text, record) => <img src={record.img} className={styles.touxiang} />,
64
-  },
65
-  {
66
-    title: '名称',
67
-    dataIndex: 'name',
68
-    key: 'name',
69
-    align: 'center',
43
+  const changePageNum = (pageNumber) => {
44
+    getList({ pageNum: pageNumber, pageSize: 10 })
45
+  }
46
+
47
+
48
+  // 跳转到编辑咨询
49
+  const toEditNews = (id) => () => {
50
+    router.push({
51
+      pathname: '/news/type/editNews',
52
+      query: {
53
+        id
54
+      },
55
+    });
56
+  }
57
+
58
+  
59
+  const changeNewsStatus = (row) => () => {
60
+    Modal.confirm({
61
+      title: '确认删除该商品?',
62
+      okText: '确认',
63
+      cancelText: '取消',
64
+      onOk() {
65
+        request({
66
+          url: '/api/admin/taNewsType',
67
+          method: 'PUT',
68
+          data: { ...row },
69
+        }).then((data) => {
70
+          message.info('操作成功!')
71
+          getList({ pageNum: 1, pageSize: 10 });
72
+        })
73
+      }
74
+    });
75
+  }
76
+  /**
77
+   *
78
+   *
79
+   * @param {*} props
80
+   * @returns
81
+   */
82
+  const columns = [
83
+    {
84
+      title: '类型图',
85
+      dataIndex: 'newsTypeImg',
86
+      key: 'newsTypeImg',
87
+      align: 'center',
88
+      render: (text, record) => <img src={record.newsTypeImg} className={styles.touxiang} />,
89
+    },
90
+    {
91
+      title: '名称',
92
+      dataIndex: 'newsTypeName',
93
+      key: 'newsTypeName',
94
+      align: 'center',
70 95
 
71
-  },
72
-  {
73
-    title: '操作',
74
-    dataIndex: 'handle',
75
-    key: 'handle',
76
-    align: 'center',
77
-    render: () => <>
78
-    <span style={{ color: '#1990FF', marginRight: '20px' }} onClick={confirm}>删除<Icon type="shopping-cart" className={styles.shoppingCart} /></span>
79
-    <span style={{ color: '#FF925C' }} onClick={toEditNews}>编辑<Icon type="form" className={styles.edit} /></span></>,
80
-  },
81
-];
82
-function confirm() {
83
-  Modal.confirm({
84
-    title: '确认删除该类型?',
85
-    okText: '确认',
86
-    cancelText: '取消',
87
-    onOk() {
88
-      console.log('OK');
89 96
     },
90
-    onCancel() {
91
-      console.log('Cancel');
97
+    {
98
+      title: '操作',
99
+      dataIndex: 'handle',
100
+      key: 'handle',
101
+      align: 'center',
102
+      render: (x, row) => <><span style={{ color: '#EF273A', marginRight: '20px' }} onClick={changeNewsStatus(row)}>{row.status == 1 ? '下架' : '上架'}<Icon type="shopping-cart" className={styles.shoppingCart} />
103
+                            </span><span style={{ color: '#FF925C' }} onClick={toEditNews(row.newsTypeId)}>编辑<Icon type="form" className={styles.edit} /></span></>,
92 104
     },
93
-  });
105
+  ];
94 106
 
95
-}
96
-function header(props) {
97 107
   const { getFieldDecorator } = props.form
98 108
   return (
99 109
 
100 110
     <>
101 111
       <Form layout="inline" onSubmit={e => handleSubmit(e, props)}>
102 112
         <Form.Item>
103
-          {getFieldDecorator('goodState')(
104
-            <Select style={{ width: '180px' }} placeholder="请选择" onChange={handleSelectChange}>
105
-              <Option value="1">上架</Option>
106
-              <Option value="0">下架</Option>
113
+          {getFieldDecorator('status')(
114
+            <Select style={{ width: '180px' }} placeholder="请选择">
115
+              <Option value="1">上架</Option>
116
+              <Option value="0">下架</Option>
107 117
             </Select>,
108 118
           )}
109 119
         </Form.Item>
110 120
       </Form>
111
-      <Button type="primary" className={styles.addBtn} onClick={toEditNews}>新增</Button>
112
-      <Table dataSource={dataSource} columns={columns} />
121
+      <Button type="primary" className={styles.addBtn} onClick={toEditNews()}>新增</Button>
122
+      <Table dataSource={data.records} columns={columns} pagination={false} />
123
+      <div style={{ display: 'flex', justifyContent: 'flex-end', marginTop: '30px' }}>
124
+        <Pagination showQuickJumper defaultCurrent={1} total={data.total} onChange={changePageNum} />
125
+      </div>
113 126
     </>
114 127
   )
115 128
 }

+ 73
- 49
src/pages/news/type/editNews.jsx Datei anzeigen

@@ -2,6 +2,8 @@ import React, { useState, useEffect } from 'react';
2 2
 import { Input, Menu, Dropdown, Button, Icon, message, Table, Divider, Tag, Select, Form, Alert } from 'antd';
3 3
 import { FormattedMessage } from 'umi-plugin-react/locale';
4 4
 import channels from '../../channel/channelList.less';
5
+import BuildSelect from '../../../components/SelectButton/BuildSelect'
6
+import XForm, { FieldTypes } from '../../../components/XForm';
5 7
 import router from 'umi/router';
6 8
 import request from '../../../utils/request'
7 9
 
@@ -9,65 +11,87 @@ const { TextArea } = Input;
9 11
 const { Option } = Select;
10 12
 
11 13
 const header = props => {
14
+  const newsId = props.location.query.id
15
+  console.log("newsId" + newsId);
16
+  const [ newsData, setNewsData ] = useState({})
17
+  if(newsId){
18
+    useEffect(() => {
19
+      getNewsData(newsId);
20
+    },[])
12 21
 
13
-  const [data, setData] = useState({ channelNmae: [], result: [] })
14
-
15
-  function goBack(){
16
-    router.push({
17
-      pathname: '/news/type/NewsType',
18
-    });
19
-  }
20
-
21
-  function addChannel(params) {
22
+  // 查询列表
23
+  const getNewsData = (newsId) => {
22 24
     request({
23
-      url: '/api/admin/channel',
24
-      method: 'POST',
25
-      data: { ...params },
26
-      // eslint-disable-next-line no-shadow
27
-    }).then(data => {
28
-      console.log(data)
29
-      setData(data)
30
-      // eslint-disable-next-line no-unused-expressions
31
-      router.go(-1)
25
+        url: '/api/admin/taNewsType/' + newsId,
26
+        method: 'GET',
27
+    }).then((data) => {
28
+        console.log(data)
29
+        setNewsData(data)
32 30
     })
33 31
   }
32
+  }
34 33
 
35
-  function handleSubmit(e) {
36
-    e.preventDefault();
37
-    props.form.validateFields((err, values) => {
38
-      if (!err) {
39
-        console.log('Received values of form: ', values);
40
-        // eslint-disable-next-line max-len
41
-        addChannel({ channelName: values.channelName, channelContact: values.channelContact, contactTel: values.contactTel })
34
+  const fields = [
35
+    {
36
+      label: '所属项目',
37
+      name: 'buildingId',
38
+      render: <BuildSelect />,
39
+      value: newsData.buildingId,
40
+      rules: [
41
+        {required: true, message: '请选择所属项目'},
42
+      ]
43
+    },
44
+    {
45
+      label: '类型图',
46
+      name: 'newsTypeImg',
47
+      type: FieldTypes.ImageUploader,
48
+      value: newsData.newsTypeImg,
49
+    },
50
+    {
51
+      label: '名称',
52
+      name: 'newsTypeName',
53
+      type: FieldTypes.Text,
54
+      value: newsData.newsTypeName,
55
+      rules: [
56
+        {required: true, message: '请输入咨询名称'},
57
+      ]
58
+    },
59
+  ]
60
+
61
+   
62
+  const handleSubmit = (values) => {
63
+    if(newsId){
64
+      values.newsTypeId = newsId
65
+      request({
66
+        url: '/api/admin/taNewsType/' + newsId,
67
+        method: 'PUT',
68
+        data: values,
69
+      }).then((data) => {
70
+        cancelPage()
71
+      }).catch((err) => {
72
+        message.info(err.msg || err.message)
73
+      })
74
+      }else{
75
+      request({
76
+        url: '/api/admin/taNewsType',
77
+        method: 'POST',
78
+        data: values,
79
+      }).then((data) => {
80
+        cancelPage()
81
+      }).catch((err) => {
82
+        message.info(err.msg || err.message)
83
+      })
42 84
       }
43
-    });
44 85
   }
45 86
 
46
-  const { getFieldDecorator } = props.form;
87
+  const cancelPage = () => {
88
+    router.push({
89
+      pathname: '/news/type/NewsType',
90
+    });
91
+  }
47 92
 
48 93
   return (
49
-    <>
50
-      <Form labelCol={{ span: 7 }} wrapperCol={{ span: 12 }} onSubmit={handleSubmit}>
51
-      <Form.Item label="类型图片">
52
-          {getFieldDecorator('newsName', {
53
-            rules: [{ message: '' }],
54
-          })(<Input className={channels.inpuit} />)}
55
-        </Form.Item>
56
-        <Form.Item label="名称">
57
-          {getFieldDecorator('newsName', {
58
-            rules: [{ message: '请输入资讯名称' }],
59
-          })(<Input className={channels.inpuit} />)}
60
-        </Form.Item>
61
-        <Form.Item wrapperCol={{ span: 15, offset: 7 }}>
62
-          <Button type="primary" htmlType="submit">
63
-            保存
64
-          </Button>
65
-          <Button className={channels.formButton} onClick={goBack} type="primary" htmlType="submit">
66
-            取消
67
-          </Button>
68
-        </Form.Item>
69
-      </Form>
70
-    </>
94
+    <XForm onSubmit={handleSubmit} onCancel={cancelPage} fields={fields}></XForm>
71 95
   )
72 96
 }
73 97