|
|
@@ -3,9 +3,21 @@ import { editFormApi } from '@/services/common'
|
|
|
import { Input, Row, Col, Select } from 'antd'
|
|
|
import React, { useState, useEffect, useRef } from 'react'
|
|
|
import LazyCascader from '../LazyCascader'
|
|
|
+import { connect } from 'dva'
|
|
|
import './index.less'
|
|
|
|
|
|
-const EditableFormItem = ({ label, dataIndex, record, dataId, span, editCellType, requestUrl }) => {
|
|
|
+const EditableFormItem = ({
|
|
|
+ label,
|
|
|
+ dataSource,
|
|
|
+ dataIndex,
|
|
|
+ span,
|
|
|
+ editCellType,
|
|
|
+ requestUrl,
|
|
|
+ dispatch
|
|
|
+}) => {
|
|
|
+ const record = dataSource[dataIndex]
|
|
|
+ const dataId = dataSource.id
|
|
|
+
|
|
|
const [editing, setEditing] = useState(false)
|
|
|
const iRef = useRef(null)
|
|
|
const [val, setVal] = useState('')
|
|
|
@@ -15,9 +27,16 @@ const EditableFormItem = ({ label, dataIndex, record, dataId, span, editCellType
|
|
|
}, [])
|
|
|
useEffect(() => {
|
|
|
// 处于编辑状态自动聚焦
|
|
|
- if (editing) {
|
|
|
+ if (editing && editCellType !== 'cascader') {
|
|
|
iRef.current.focus()
|
|
|
}
|
|
|
+ // 对级联数据初始化, key一定要是district!!
|
|
|
+ if (editCellType === 'cascader' && record) {
|
|
|
+ dispatch({
|
|
|
+ type: 'district/fetchWithValues',
|
|
|
+ payload: record
|
|
|
+ })
|
|
|
+ }
|
|
|
// 当val为空时,需要设置默认值
|
|
|
if (!val) {
|
|
|
setVal(record)
|
|
|
@@ -75,14 +94,18 @@ const EditableFormItem = ({ label, dataIndex, record, dataId, span, editCellType
|
|
|
case 'cascader':
|
|
|
cell = (
|
|
|
<LazyCascader
|
|
|
+ // ref={iRef}
|
|
|
defaultValue={val}
|
|
|
- onChange={value => save({ currentTarget: { value } })}></LazyCascader>
|
|
|
+ className="zh-width-100P"
|
|
|
+ onChange={value => save({ currentTarget: { value } })}
|
|
|
+ />
|
|
|
)
|
|
|
break
|
|
|
case 'select':
|
|
|
cell = (
|
|
|
<Select
|
|
|
defaultValue={val}
|
|
|
+ ref={iRef}
|
|
|
// onBlur={save}
|
|
|
onChange={value => save({ currentTarget: { value } })}
|
|
|
className="zh-width-100P">
|
|
|
@@ -103,9 +126,13 @@ const EditableFormItem = ({ label, dataIndex, record, dataId, span, editCellType
|
|
|
break
|
|
|
}
|
|
|
} else {
|
|
|
+ let content = val
|
|
|
+ if (editCellType === 'cascader') {
|
|
|
+ content = dataSource.local
|
|
|
+ }
|
|
|
cell = (
|
|
|
<div className="editable-cell-value-wrap" onClick={toggleEdit}>
|
|
|
- {val}
|
|
|
+ {content}
|
|
|
</div>
|
|
|
)
|
|
|
}
|
|
|
@@ -122,4 +149,4 @@ const EditableFormItem = ({ label, dataIndex, record, dataId, span, editCellType
|
|
|
)
|
|
|
}
|
|
|
|
|
|
-export default EditableFormItem
|
|
|
+export default connect()(EditableFormItem)
|