|
|
@@ -1,12 +1,13 @@
|
|
|
import consts from '@/basic/consts'
|
|
|
import { apiUpdateContract } from '@/services/contact'
|
|
|
-import { Input, Form, Row, Col } from 'antd'
|
|
|
+import { Input, Row, Col } from 'antd'
|
|
|
import React, { useState, useEffect, useRef } from 'react'
|
|
|
import './index.less'
|
|
|
|
|
|
-const EditableFormItem = ({ label, dataIndex, record }) => {
|
|
|
+const EditableFormItem = ({ label, dataIndex, record, dataId, width = '100%' }) => {
|
|
|
const [editing, setEditing] = useState(false)
|
|
|
const inputRef = useRef(null)
|
|
|
+ const [val, setVal] = useState(record)
|
|
|
useEffect(() => {
|
|
|
if (editing) {
|
|
|
inputRef.current.focus()
|
|
|
@@ -18,33 +19,34 @@ const EditableFormItem = ({ label, dataIndex, record }) => {
|
|
|
}
|
|
|
|
|
|
const handleConfirm = async value => {
|
|
|
- const { code = -1 } = await apiUpdateContract({ [dataIndex]: value })
|
|
|
+ const { code = -1 } = await apiUpdateContract({ [dataIndex]: value, id: dataId })
|
|
|
if (code === consts.RET_CODE.SUCCESS) {
|
|
|
toggleEdit()
|
|
|
}
|
|
|
}
|
|
|
const save = async e => {
|
|
|
const { value = '' } = e.currentTarget
|
|
|
- try {
|
|
|
- toggleEdit()
|
|
|
- await handleConfirm(value)
|
|
|
- } catch (errInfo) {
|
|
|
- console.log('Save failed:', errInfo)
|
|
|
+ toggleEdit()
|
|
|
+ if (value === val) {
|
|
|
+ return
|
|
|
}
|
|
|
+ setVal(value)
|
|
|
+ await handleConfirm(value)
|
|
|
}
|
|
|
|
|
|
const cell = editing ? (
|
|
|
// <Form.Item name={dataIndex} noStyle initialValue={record}>
|
|
|
// <Input ref={inputRef} onPressEnter={save} onBlur={save} />
|
|
|
// </Form.Item>
|
|
|
- <Input ref={inputRef} onPressEnter={save} onBlur={save} />
|
|
|
+ <Input ref={inputRef} onPressEnter={save} onBlur={save} value={val} />
|
|
|
) : (
|
|
|
<div className="editable-cell-value-wrap" onClick={toggleEdit}>
|
|
|
{record}
|
|
|
</div>
|
|
|
)
|
|
|
+
|
|
|
return (
|
|
|
- <Row>
|
|
|
+ <Row style={{ width }}>
|
|
|
<Col span={2} className="zh-text-right zh-mg-bottom-8">
|
|
|
<span className="zh-lh-32 zh-mg-right-10">{label}:</span>
|
|
|
</Col>
|