Browse Source

fix: MoneyInput金额格式化问题

lanjianrong 4 năm trước cách đây
mục cha
commit
c3b6e6a701

+ 2 - 1
src/components/MoneyInput/index.tsx

@@ -12,7 +12,8 @@ interface MoneyInputProps {
   // setValue: (val: string | null) => void
 }
 const MoneyInput: React.FC<MoneyInputProps> = (props) => {
-  const { minPrice, maxPrice, value, onChange, digitLimit = 2 } = props
+  const { minPrice, maxPrice, onChange, digitLimit = 2 } = props
+  const value = props.value ? props.value.toString() : ''
 
   // const reg = new RegExp("^(\d*)\.?(\d{0," + digitLimit + "})")
   const [ inputVal, setInputVal ] = useState('')

+ 2 - 1
src/pages/Contract/Content/Income/components/Modal/index.tsx

@@ -99,7 +99,7 @@ const ContractModal: React.FC<iModalCommonProps> = ({ modalObj: { type, visible,
         form.setFieldsValue({ treeId: row.contractId === contractTreeBaseId ? row.id : row.parentId })
       }
       if (type === 'update') {
-        const { content = '', name = '', price = '', partyA = '', partyB = '', partyASigner = '', partyBSigner = '', signerTime = '', remarks = '' } = contractStore.contract
+        const { content = '', name = '', price = 0, partyA = '', partyB = '', partyASigner = '', partyBSigner = '', signerTime = '', remarks = '' } = contractStore.contract
         form.setFieldsValue({ content, name, price, partyA, partyB, partyASigner, partyBSigner, signerTime: signerTime ? dayjs(signerTime) : '', remarks })
       } else if (type === 'add') {
         commonStore.returnWayOptions && commonStore.queryWayOptions()
@@ -156,6 +156,7 @@ const ContractModal: React.FC<iModalCommonProps> = ({ modalObj: { type, visible,
                   form.resetFields()
                   if (type === 'update') {
                     values.signerTime = dayjsFormat(values.signerTime, 'YYYY-MM-DD HH:mm:ss')
+                    values.price = parseFloat(values.price)
                   }
                   if (type === 'del') {
                     delete values.warningText

+ 3 - 3
src/pages/Contract/Content/Income/components/Tabs/Receivable/index.tsx

@@ -124,13 +124,13 @@ const Receivable: React.FC<ReceivableProps> = ({ updateTreeAndContract, type })
   }
   const save = async (key: React.Key) => {
     try {
-      const row = (await form.validateFields()) as iReceivableState
+      const row = await form.validateFields()
 
       const newData = [ ...data ]
       const index = newData.findIndex(item => key === item.id)
       if (index > -1) {
         const item = newData[index]
-        const payload = { ...row, time: dayjsFormat(row.time, 'YYYY-MM-DD'), createTime: dayjsFormat(row.createTime, 'YYYY-MM-DD'), id: item.id, bidsectionId: item.bidsectionId, contractsId: item.contractsId }
+        const payload = { ...row, time: dayjsFormat(row.time, 'YYYY-MM-DD'), createTime: dayjsFormat(row.createTime, 'YYYY-MM-DD'), id: item.id, bidsectionId: item.bidsectionId, contractsId: item.contractsId, price: parseFloat(row.price) }
         const { code = -1 } = await apiUpdateReturn(type, payload)
         if (code === consts.RET_CODE.SUCCESS) {
           newData.splice(index, 1, {
@@ -171,7 +171,7 @@ const Receivable: React.FC<ReceivableProps> = ({ updateTreeAndContract, type })
       editable: true,
       width: '12%',
       // eslint-disable-next-line react/display-name
-      render: (text: string) => <span className="pi-text-right pi-width-100P">{formatMoney(new BigNumber(text).toString())}</span>
+      render: (text: string) => <span className="pi-text-right pi-width-100P">{formatMoney(text)}</span>
     },
     {
       title: type === ContractType.INCOME ? '回款方式' : '支付方式',

+ 1 - 1
src/store/mobx/contract/index.ts

@@ -15,7 +15,7 @@ const initData = {
   partyASigner: '',
   partyB: '',
   partyBSigner: '',
-  price: '0.00',
+  price: 0,
   projectId: '',
   remarks: '',
   returned: '0.00',

+ 2 - 3
src/types/contract.d.ts

@@ -82,8 +82,7 @@ export interface iContractState {
   partyASigner: string
   partyB: string
   partyBSigner: string
-  price: string
-  paid: string
+  price: number
   projectId: string
   remarks: string
   returned: string
@@ -103,7 +102,7 @@ export interface iReceivableState {
   fileCounts: number
   id: string
   page: number
-  price: string
+  price: number
   projectId: string
   remarks: string
   time: string