张延森 hace 2 años
padre
commit
883bb9f7a8

+ 1
- 0
src/components/Wangedit/Wangedit/WangEditor.jsx Ver fichero

@@ -19,6 +19,7 @@ export default (props) => {
19 19
       }
20 20
     },
21 21
     height: props.height || 300,
22
+    menus: props.menus
22 23
   })
23 24
 
24 25
   useEffect(() => {

+ 14
- 1
src/components/Wangedit/Wangedit/initEditor.js Ver fichero

@@ -1,6 +1,16 @@
1 1
 import E from 'wangeditor';
2 2
 import { fetch, apis } from '@/utils/request';
3 3
 
4
+function assign(targ = {}, src = {}) {
5
+  return Object.keys(src).reduce((acc, key) => {
6
+    const val = src[key]
7
+    if (val === undefined || val === null) return acc;
8
+
9
+    acc[key] = val;
10
+    return acc;
11
+  }, targ);
12
+}
13
+
4 14
 export default (elm, config) => {
5 15
   const editor = new E(elm);
6 16
 
@@ -41,6 +51,8 @@ export default (elm, config) => {
41 51
     'italic', // 斜体
42 52
     'underline', // 下划线
43 53
     // 'strikeThrough', // 删除线
54
+    'indent', // 缩进
55
+    'lineHeight', // 行高
44 56
     // 'foreColor', // 文字颜色
45 57
     'backColor', // 背景颜色
46 58
     'list', // 列表
@@ -68,7 +80,8 @@ export default (elm, config) => {
68 80
     }, ctt);
69 81
   };
70 82
 
71
-  Object.assign(editor.config, config || {})
83
+  // Object.assign(editor.config, config || {})
84
+  assign(editor.config, config)
72 85
 
73 86
   editor.create();
74 87
   // editor.$textElem.attr('contenteditable', props.contenteditable !== false);

+ 3
- 2
src/pages/building/Edit/Basic/index.jsx Ver fichero

@@ -26,7 +26,7 @@ const fullWidth= { width: '100%' }
26 26
 const Item = Form.Item
27 27
 
28 28
 const BuildingBasic = React.forwardRef((props, ref) => {
29
-  const { form, history, setMarketingCode,institutionIdChange, user ,isPublish,setIsPublish} = props;
29
+  const { form, history, setMarketingCode,institutionIdChange, user , isPublish, setIsPublish, onBuilding } = props;
30 30
   const { getFieldDecorator, getFieldValue, setFieldsValue } = form;
31 31
   const { query } = history.location;
32 32
   const { id } = query;
@@ -58,7 +58,7 @@ const BuildingBasic = React.forwardRef((props, ref) => {
58 58
     setMarketingCode(res.marketingCode)
59 59
     setCityId(res.cityId)
60 60
     institutionIdChange(res.institutionId)
61
-  
61
+    onBuilding(res)
62 62
 
63 63
     setIsPublish(res.status=== 1)
64 64
   })
@@ -131,6 +131,7 @@ const BuildingBasic = React.forwardRef((props, ref) => {
131 131
         updateFormLoading(true)
132 132
         saveData({
133 133
           ...values,
134
+          isBorker: undefined,  // 这个字段在全民经纪人页面更新
134 135
           pois,
135 136
           arrounds,
136 137
         }).then((res) => {

+ 126
- 0
src/pages/building/Edit/Borker/index.jsx Ver fichero

@@ -0,0 +1,126 @@
1
+
2
+import React, { useEffect, useRef, useState } from 'react'
3
+import { Button, Spin, Radio, Form, Input, Row, Col, notification } from 'antd'
4
+import { fetch, apis } from '@/utils/request';
5
+import Wangedit from '@/components/Wangedit/Wangedit';
6
+import { formItemLayout } from '../utils'
7
+
8
+const FormItem = Form.Item
9
+const updateBorker = fetch(apis.borker.updateBuildingBorker)
10
+const getAgreementList = fetch(apis.borker.getBkAgreementList)
11
+const saveAgreement = fetch(apis.borker.saveBkAgreement)
12
+const updateAgreement = fetch(apis.borker.updateBkAgreement)
13
+
14
+const editorMenus = [
15
+  'head', // 标题
16
+  'bold', // 粗体
17
+  'italic', // 斜体
18
+  'underline', // 下划线
19
+  'strikeThrough', // 删除线
20
+  'indent', // 缩进
21
+  'lineHeight', // 行高
22
+  'foreColor', // 文字颜色
23
+  'list', // 列表
24
+  'justify', // 对齐方式
25
+  'quote', // 引用
26
+  'undo', // 撤销
27
+];
28
+
29
+const Borker = React.forwardRef((props, ref) => {
30
+  const { form, buildingInfo = {} } = props
31
+  const buildingId = buildingInfo.buildingId
32
+
33
+  const [loading, setLoading] = useState(false)
34
+  const [isBorker, setIsBorker] = useState('false')
35
+  const [bkAgreement, setBkAgreement] = useState()
36
+
37
+  const canEdit = isBorker === 'true'
38
+
39
+  const handleBorkerChange = (e) => {
40
+    const { value } = e.target
41
+    setLoading(true)
42
+    updateBorker({ urlData: { id: buildingId }, params: { on: value } }).then(() => {
43
+      setLoading(false)
44
+      setIsBorker(value)
45
+    }).catch(() => {
46
+      setLoading(false)
47
+    })
48
+  }
49
+
50
+  const handelSubmit = () => {
51
+    form.validateFieldsAndScroll((err, values) => {
52
+      if (err) return;
53
+
54
+      const data = {
55
+        ...values || {},
56
+        buildingId,
57
+        buildingName: buildingInfo.name,
58
+        cityId: buildingInfo.cityId,
59
+      }
60
+
61
+      setLoading(true)
62
+      const p = data.ruleId ? updateAgreement({ urlData: { id: data.ruleId }, data }) : saveAgreement({ data })
63
+      p.then(res => {
64
+        setLoading(false)
65
+        // setBkAgreement(res)
66
+        form.setFieldsValue(res || {});
67
+        notification.success({ message: "操作成功" })
68
+      }).catch((err) => {
69
+        setLoading(false)
70
+      })
71
+    })
72
+  }
73
+
74
+  useEffect(() => {
75
+    if (buildingId) {
76
+      setLoading(true)
77
+      getAgreementList({ params: { buildingId } }).then(res => {
78
+        setLoading(false)
79
+        const { records = [] } = res
80
+        // setBkAgreement(records[0])
81
+        form.setFieldsValue(records[0] || {});
82
+      }).catch(() => {
83
+        setLoading(false)
84
+      })
85
+    }
86
+  }, [buildingId])
87
+
88
+  return (
89
+    <Spin spinning={loading}>
90
+      <div style={{ padding: '1.2em', paddingTop: 0 }}>
91
+        <Row type="flex" align="middle">
92
+          <Col span={2}>
93
+            <div style={{ textAlign: 'right', marginRight: '1em' }}>全民经纪人</div>
94
+          </Col>
95
+          <Col span={12}>
96
+            <Radio.Group value={isBorker} onChange={handleBorkerChange} buttonStyle="solid">
97
+              <Radio.Button value="true">开启</Radio.Button>
98
+              <Radio.Button value="false">关闭</Radio.Button>
99
+            </Radio.Group>
100
+          </Col>
101
+        </Row>
102
+      </div>
103
+      <div style={{ maxWidth: canEdit ? '100%' : '0', maxHeight: canEdit ? '100%' : '0',  overflow: 'hidden' }}>
104
+        <Form {...formItemLayout} onSubmit={handelSubmit} >
105
+          <FormItem label="有效期">
106
+            {form.getFieldDecorator('expirationDays', {
107
+              rules: [{ required: true, message: '请填写有效期' }],
108
+            })(<Input suffix="天" />)}          
109
+          </FormItem>
110
+          <FormItem label="佣金规则">
111
+            {form.getFieldDecorator('content', {
112
+              rules: [{ required: true, message: '请填写佣金规则' }],
113
+            })(<Wangedit menus={editorMenus} />)}          
114
+          </FormItem>
115
+          <FormItem colon={false} label=" ">
116
+            <Button type="primary" loading={loading} onClick={handelSubmit}>
117
+              提交
118
+            </Button>
119
+          </FormItem>
120
+        </Form>
121
+      </div>
122
+    </Spin>
123
+  )
124
+})
125
+
126
+export default Form.create()(Borker)

+ 15
- 1
src/pages/building/Edit/index.jsx Ver fichero

@@ -5,6 +5,7 @@ import Share from '@/components/Share'
5 5
 import Basic from './Basic'
6 6
 import Apartment from './Apartment'
7 7
 import AlbumList from './AlbumList'
8
+import Borker from './Borker'
8 9
 import Panorama from './Panorama'
9 10
 import Channel from './Channel'
10 11
 import News from './News'
@@ -18,6 +19,7 @@ export default (props) => {
18 19
   const { history } = props
19 20
   const { query } = history.location
20 21
   const { id } = query
22
+  const [buildingInfo, setBuildingInfo] = useState()
21 23
   const [institutionId, setInstitutionId] = useState()
22 24
   const [marketingCode, setMarketingCode] = useState('')
23 25
   const [isPublish, setIsPublish] = useState(false)
@@ -28,7 +30,14 @@ export default (props) => {
28 30
       <Tabs defaultActiveKey="1">
29 31
         <TabPane tab="基础信息" key="1">
30 32
           <div className={styles['tab-wrapper']} style={{ maxWidth: 1000 }}>
31
-            <Basic {...props} setMarketingCode={(e) => setMarketingCode(e)} institutionIdChange={(e) => setInstitutionId(e)} isPublish={isPublish} setIsPublish={(e) => setIsPublish(e)} />
33
+            <Basic
34
+              {...props}
35
+              setMarketingCode={(e) => setMarketingCode(e)}
36
+              institutionIdChange={(e) => setInstitutionId(e)}
37
+              isPublish={isPublish}
38
+              setIsPublish={(e) => setIsPublish(e)}
39
+              onBuilding={setBuildingInfo}
40
+            />
32 41
           </div>
33 42
         </TabPane>
34 43
         <TabPane tab="户型设置" key="2">
@@ -66,6 +75,11 @@ export default (props) => {
66 75
             <OnSiteService {...props} marketingCode={marketingCode} isPublish={isPublish} />
67 76
           </div>
68 77
         </TabPane>
78
+        <TabPane tab="全民经纪人" key="11">
79
+          <div className={styles['tab-wrapper']} style={{ maxWidth: '1200px' }}>
80
+            <Borker buildingInfo={buildingInfo} />
81
+          </div>
82
+        </TabPane>
69 83
         <TabPane tab="海报图片" key="5">
70 84
           <Poster target={target} rights="building.poster.save" {...props} submitBtn={!isPublish} />
71 85
         </TabPane>

+ 24
- 0
src/services/apis.js Ver fichero

@@ -2400,4 +2400,28 @@ export default {
2400 2400
     },
2401 2401
 
2402 2402
   },
2403
+
2404
+  // 全民经纪人
2405
+  borker: {
2406
+    // 开启功能
2407
+    updateBuildingBorker: {
2408
+      method: 'PUT',
2409
+      url: `${prefix}/building/:id/borker`,
2410
+    },
2411
+    // 获取规则
2412
+    getBkAgreementList: {
2413
+      method: 'GET',
2414
+      url: `${prefix}/bkAgreement`,
2415
+    },
2416
+    // 新增规则
2417
+    saveBkAgreement: {
2418
+      method: 'POST',
2419
+      url: `${prefix}/bkAgreement`,
2420
+    },
2421
+    // 更新规则
2422
+    updateBkAgreement: {
2423
+      method: 'PUT',
2424
+      url: `${prefix}/bkAgreement/:id`,
2425
+    },
2426
+  }
2403 2427
 };