魏熙美 5 лет назад
Родитель
Сommit
8fef442754

+ 1
- 1
config/config.js Просмотреть файл

@@ -479,7 +479,7 @@ export default {
479 479
 
480 480
   proxy: {
481 481
     '/api/': {
482
-      target: 'http://192.168.0.11:8080/',
482
+      target: 'http://localhost:8080/',
483 483
       changeOrigin: true,
484 484
       // pathRewrite: { '^/server': '' },
485 485
     },

+ 1
- 0
src/pages/building/list/add/components/base.jsx Просмотреть файл

@@ -79,6 +79,7 @@ function AddBuilding(props) {
79 79
     const api = data.buildingId === undefined ? apis.building.addBuilding : apis.building.updateBuilding
80 80
     request({ ...api, data: { ...data } }).then(() => {
81 81
       openNotificationWithIcon('success', '操作成功')
82
+      router.go(-1)
82 83
     }).catch(err => {
83 84
       openNotificationWithIcon('error', err.message)
84 85
     })

+ 18
- 35
src/pages/building/list/add/components/buildingProjectType.jsx Просмотреть файл

@@ -119,10 +119,7 @@ class ProjectTypeBody extends React.Component {
119 119
   }
120 120
 
121 121
   onSuccess = (values, item) => {
122
-    console.log('values: ', values)
123
-    console.log('data: ', this.state.data, 'item: ', item)
124 122
     const newData = this.getNewProjectType(values)
125
-    console.log('newData: ', newData)
126 123
     this.setState({ data: newData })
127 124
     if (typeof this.props.onChange === 'function') {
128 125
       this.props.onChange(newData)
@@ -130,14 +127,13 @@ class ProjectTypeBody extends React.Component {
130 127
   }
131 128
 
132 129
   onCheckboxChange = checkedValues => {
130
+      // console.log('checkedValues: ', checkedValues)
133 131
       const checked = (`${checkedValues}` || '').split(',')
134 132
       const { projectType } = this.state
135 133
       const buildingType = projectType.filter(item => checked.includes(`${item.buildingTypeId}`))
136 134
 
137
-      // 这里会把值替换掉
138
-
139 135
       const tempDate = buildingType.map(item => ({ buildingTypeId: item.buildingTypeId, buildingTypeName: item.buildingTypeName, price: '', decoration: '', rightsYear: '', status: '1' }))
140
-      const updateProjectDate = this.updateProjectType(checkedValues)
136
+      const updateProjectDate = this.updateProjectType(tempDate)
141 137
       console.log('updateProjectDate: ', updateProjectDate)
142 138
       this.setState({ data: updateProjectDate })
143 139
   }
@@ -145,7 +141,6 @@ class ProjectTypeBody extends React.Component {
145 141
   onClose = e => {
146 142
     const { data } = this.state
147 143
     const buildingType = data.filter(item => e.buildingTypeId !== item.buildingTypeId)
148
-    console.log('buildingType: ', buildingType)
149 144
     this.setState({ data: buildingType })
150 145
     this.setState({ defaultCheckboxValue: buildingType.map(item => item.buildingTypeId) })
151 146
   }
@@ -153,7 +148,6 @@ class ProjectTypeBody extends React.Component {
153 148
   getNewProjectType = values => {
154 149
     const data = []
155 150
     this.state.data.map(item => {
156
-      console.log('item: ', item)
157 151
       if (item.buildingTypeId === values.buildingTypeId) {
158 152
         data.push(values)
159 153
       } else {
@@ -165,18 +159,22 @@ class ProjectTypeBody extends React.Component {
165 159
   }
166 160
 
167 161
   updateProjectType = values => {
168
-    const data = []
169
-    this.state.data.map(item => {
170
-      values.map(va => {
171
-        if (item.buildingTypeId === va.buildingTypeId) {
172
-          data.push(va)
173
-        } else {
174
-          data.push(item)
175
-        }
176
-      })
177
-    })
162
+    // 获取所有复选框选中的id
163
+    const valueIdArray = values.map(item => item.buildingTypeId)
164
+    // console.log('valueIdArray: ', valueIdArray)
178 165
 
179
-    return data
166
+    // 获取 data 中已经赋值的数据  交集
167
+    const valueData = this.state.data.filter(item => valueIdArray.includes(item.buildingTypeId))
168
+    // console.log('valueData: ', valueData)
169
+
170
+    // 获取 非 data中数据(也就是没有赋值),交集
171
+    const trueValueArr = valueData.map(item => item.buildingTypeId)
172
+    const trueValueData = values.filter(item => !trueValueArr.includes(item.buildingTypeId))
173
+
174
+    // console.log('trueValueData: ', trueValueData)
175
+
176
+    // 把两个 数组的值,合并返回
177
+    return valueData.concat(trueValueData)
180 178
   }
181 179
 
182 180
   getList = params => {
@@ -196,11 +194,7 @@ class ProjectTypeBody extends React.Component {
196 194
       tempData = value
197 195
       tempCheckboxValue = tempData.map(item => item.buildingTypeId)
198 196
       this.setState({ defaultCheckboxValue: tempCheckboxValue })
199
-      this.setState({ data: tempData }, () => {
200
-        console.log("state: ", this.state.data)
201
-      })
202
-
203
-      console.log("tempData: ", tempData, "tempCheckboxValue: ", tempCheckboxValue, "value: ", value)
197
+      this.setState({ data: tempData })
204 198
     }
205 199
   }
206 200
 
@@ -229,17 +223,6 @@ class ProjectTypeBody extends React.Component {
229 223
   }
230 224
 
231 225
   render () {
232
-
233
-    // let tempData = []
234
-    // let tempCheckboxValue = []
235
-    // const { value } = this.props
236
-    // if (value !== undefined && value !== null) {
237
-    //   tempData = value
238
-    // } else {
239
-    //   tempData = this.state.data
240
-    // }
241
-
242
-    // tempCheckboxValue = tempData.map(item => item.buildingTypeId)
243 226
     return (
244 227
       <>
245 228
         <Button type="primary" icon="plus" size="large" onClick={() => this.showMadel()} />