feat(pages): 添加新页面组件
- 创建了 add.config.ts 配置文件 - 实现了 add.tsx 页面组件 - 添加了 index.config.ts 配置文件 - 创建了 index.tsx 页面组件
This commit is contained in:
4
src/credit/creditMpCustomer/add.config.ts
Normal file
4
src/credit/creditMpCustomer/add.config.ts
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
export default definePageConfig({
|
||||||
|
navigationBarTitleText: '新增小程序端客户',
|
||||||
|
navigationBarTextStyle: 'black'
|
||||||
|
})
|
||||||
98
src/credit/creditMpCustomer/add.tsx
Normal file
98
src/credit/creditMpCustomer/add.tsx
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
import {useEffect, useState, useRef} from "react";
|
||||||
|
import {useRouter} from '@tarojs/taro'
|
||||||
|
import {Button, Loading, CellGroup, Input, TextArea, Form} from '@nutui/nutui-react-taro'
|
||||||
|
import Taro from '@tarojs/taro'
|
||||||
|
import {View} from '@tarojs/components'
|
||||||
|
import {CreditMpCustomer} from "@/api/credit/creditMpCustomer/model";
|
||||||
|
import {getCreditMpCustomer, listCreditMpCustomer, updateCreditMpCustomer, addCreditMpCustomer} from "@/api/credit/creditMpCustomer";
|
||||||
|
|
||||||
|
const AddCreditMpCustomer = () => {
|
||||||
|
const {params} = useRouter();
|
||||||
|
const [loading, setLoading] = useState<boolean>(true)
|
||||||
|
const [FormData, setFormData] = useState<CreditMpCustomer>({})
|
||||||
|
const formRef = useRef<any>(null)
|
||||||
|
|
||||||
|
const reload = async () => {
|
||||||
|
if (params.id) {
|
||||||
|
const data = await getCreditMpCustomer(Number(params.id))
|
||||||
|
setFormData(data)
|
||||||
|
} else {
|
||||||
|
setFormData({})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 提交表单
|
||||||
|
const submitSucceed = async (values: any) => {
|
||||||
|
try {
|
||||||
|
if (params.id) {
|
||||||
|
// 编辑模式
|
||||||
|
await updateCreditMpCustomer({
|
||||||
|
...values,
|
||||||
|
id: Number(params.id)
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
// 新增模式
|
||||||
|
await addCreditMpCustomer(values)
|
||||||
|
}
|
||||||
|
|
||||||
|
Taro.showToast({
|
||||||
|
title: `操作成功`,
|
||||||
|
icon: 'success'
|
||||||
|
})
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
return Taro.navigateBack()
|
||||||
|
}, 1000)
|
||||||
|
} catch (error) {
|
||||||
|
Taro.showToast({
|
||||||
|
title: `操作失败`,
|
||||||
|
icon: 'error'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const submitFailed = (error: any) => {
|
||||||
|
console.log(error, 'err...')
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
reload().then(() => {
|
||||||
|
setLoading(false)
|
||||||
|
})
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
if (loading) {
|
||||||
|
return <Loading className={'px-2'}>加载中</Loading>
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Form
|
||||||
|
ref={formRef}
|
||||||
|
divider
|
||||||
|
initialValues={FormData}
|
||||||
|
labelPosition="left"
|
||||||
|
onFinish={(values) => submitSucceed(values)}
|
||||||
|
onFinishFailed={(errors) => submitFailed(errors)}
|
||||||
|
footer={
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
justifyContent: 'center',
|
||||||
|
width: '100%'
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
nativeType="submit"
|
||||||
|
type="success"
|
||||||
|
size="large"
|
||||||
|
className={'w-full'}
|
||||||
|
block
|
||||||
|
>
|
||||||
|
{params.id ? '更新' : '保存'}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<CellGroup style={{padding: '4px 0'}}>
|
||||||
|
<Form.Item name="toUser" label="拖欠方" initialValue={FormData.toUser} required>
|
||||||
4
src/credit/creditMpCustomer/index.config.ts
Normal file
4
src/credit/creditMpCustomer/index.config.ts
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
export default definePageConfig({
|
||||||
|
navigationBarTitleText: '小程序端客户管理',
|
||||||
|
navigationBarTextStyle: 'black'
|
||||||
|
})
|
||||||
64
src/credit/creditMpCustomer/index.tsx
Normal file
64
src/credit/creditMpCustomer/index.tsx
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
import {useState} from "react";
|
||||||
|
import Taro, {useDidShow} from '@tarojs/taro'
|
||||||
|
import {Button, Cell, CellGroup, Space, Empty, ConfigProvider, Divider} from '@nutui/nutui-react-taro'
|
||||||
|
import {Dongdong, ArrowRight, CheckNormal, Checked} from '@nutui/icons-react-taro'
|
||||||
|
import {View} from '@tarojs/components'
|
||||||
|
import {CreditMpCustomer} from "@/api/credit/creditMpCustomer/model";
|
||||||
|
import {listCreditMpCustomer, removeCreditMpCustomer, updateCreditMpCustomer} from "@/api/credit/creditMpCustomer";
|
||||||
|
|
||||||
|
const CreditMpCustomerList = () => {
|
||||||
|
const [list, setList] = useState<CreditMpCustomer[]>([])
|
||||||
|
|
||||||
|
const reload = () => {
|
||||||
|
listCreditMpCustomer({
|
||||||
|
// 添加查询条件
|
||||||
|
})
|
||||||
|
.then(data => {
|
||||||
|
setList(data || [])
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
Taro.showToast({
|
||||||
|
title: '获取数据失败',
|
||||||
|
icon: 'error'
|
||||||
|
});
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const onDel = async (id?: number) => {
|
||||||
|
await removeCreditMpCustomer(id)
|
||||||
|
Taro.showToast({
|
||||||
|
title: '删除成功',
|
||||||
|
icon: 'success'
|
||||||
|
});
|
||||||
|
reload();
|
||||||
|
}
|
||||||
|
|
||||||
|
useDidShow(() => {
|
||||||
|
reload()
|
||||||
|
});
|
||||||
|
|
||||||
|
if (list.length == 0) {
|
||||||
|
return (
|
||||||
|
<ConfigProvider>
|
||||||
|
<div className={'h-full flex flex-col justify-center items-center'} style={{
|
||||||
|
height: 'calc(100vh - 300px)',
|
||||||
|
}}>
|
||||||
|
<Empty
|
||||||
|
style={{
|
||||||
|
backgroundColor: 'transparent'
|
||||||
|
}}
|
||||||
|
description="暂无数据"
|
||||||
|
/>
|
||||||
|
<Space>
|
||||||
|
<Button onClick={() => Taro.navigateTo({url: '/credit/creditMpCustomer/add'})}>新增小程序端客户</Button>
|
||||||
|
</Space>
|
||||||
|
</div>
|
||||||
|
</ConfigProvider>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{list.map((item, _) => (
|
||||||
|
<Cell.Group key={item.
|
||||||
Reference in New Issue
Block a user