Browse Source

feat: 报事报修暂存

touchitvoid 2 years ago
parent
commit
0912984b59

+ 1 - 1
src/router/config.tsx

@@ -85,7 +85,7 @@ const UserRoles = lazy(() => import('../views/User/roles'))
 const UserList = lazy(() => import('../views/User/account'))
 
 
-// 报报修相关
+// 报报修相关
 const FixType = lazy(() => import('../views/Fix/type'))
 const FixOnlineForm = lazy(() => import('../views/Fix/online-form'))
 // const FixReturnVisit = lazy(() => import('../views/Fix/return-visit'))

+ 7 - 7
src/services/api.ts

@@ -32,6 +32,7 @@ export const PostLogin = params => request({
   method: 'post',
   data: params
 })
+
 // 省市区列表
 export const GetProvinceCityArea = params => request({
   url: '/area/province_city_area',
@@ -65,13 +66,6 @@ export const RoleApi: any = params => request({
   params: params.mt === 'delete' ? params : {}
 })
 
-// 获取小区列表
-export const GetGardenList: any = params => ListDataTransform(request({
-  url: '/garden',
-  method: 'get',
-  params
-}))
-
 // 街道列表
 export const GetStreetList: any = params => ListDataTransform(request({
   url: '/area/street_committee',
@@ -98,5 +92,11 @@ export const CreateCompany: any = data => request({
   data
 })
 
+// 获取小区列表
+export const GetGardenList: any = params => request({
+  url: '/garden/list',
+  method: 'get',
+  params
+})
 
 

+ 25 - 0
src/services/fix.ts

@@ -0,0 +1,25 @@
+import request from './request'
+
+export const FixApi = params => {
+  const config = {
+    url: '/repair/order',
+    method: params.method || 'get'
+  }
+  config[!['get', 'delete'].includes(config.method) ? 'data' : 'params'] = params
+  return request(config)
+}
+
+// 获取报事报修详情 /api/v1/repair/order/info
+export const GetFixOrderInfo = () => request({
+  url: '/repair/order/info',
+  method: 'get'
+})
+
+export const FixClassApi = params => {
+  const config = {
+    url: '/repair/class',
+    method: params.method || 'get'
+  }
+  config[!['get', 'delete'].includes(config.method) ? 'data' : 'params'] = params
+  return request(config)
+}

+ 13 - 0
src/views/Fix/hooks.ts

@@ -0,0 +1,13 @@
+import { useState } from "react"
+import { FixClassApi } from '../../services/fix'
+
+export const useFixClass = () => {
+  const [state, setState] = useState([])
+  const request = (params = { page: 1, pageSize: 9999 }) => {
+    FixClassApi(params)
+      .then(({ data }) => {
+        setState(data?.map(({ name, id }) => ({ value: id, label: name })))
+      })
+  }
+  return [state, request] as const
+}

+ 0 - 11
src/views/Fix/index.tsx

@@ -1,11 +0,0 @@
-import React from 'react'
-
-const CustomerService: React.FC = () => {
-  return (
-    <div>
-      Im客服
-    </div>
-  )
-}
-
-export default CustomerService

+ 47 - 34
src/views/Fix/online-form.tsx

@@ -1,11 +1,13 @@
 import React from 'react'
 import type { ActionType } from '@ant-design/pro-table'
 import ProTable from '@ant-design/pro-table'
-import {Button, Modal, Form, Radio, Input, message, Select, DatePicker, Upload} from 'antd'
+import { Button, Modal, Form, Input, message, Select, DatePicker, Upload } from 'antd'
 import { withRouter } from 'react-router-dom'
-import { User } from '../../services/user'
+import { FixApi } from '../../services/fix'
 import './index.scss'
-import {PlusOutlined} from "@ant-design/icons";
+import { PlusOutlined } from "@ant-design/icons"
+import { useFixClass } from "./hooks"
+import { useBuildingHouse } from "../building/hooks"
 
 const FixOnlineForm: React.FC = (props: any) => {
   const columns: any = [
@@ -16,43 +18,50 @@ const FixOnlineForm: React.FC = (props: any) => {
     },
     {
       title: '分类名称',
-      dataIndex: 'user_name',
+      dataIndex: 'class_name',
       search: true,
     },
     {
       title: '联系地址',
-      dataIndex: 'user_name',
+      dataIndex: 'house_name',
       search: false,
     },
     {
       title: '报修人',
-      dataIndex: 'user_name',
+      dataIndex: 'apply_people',
       search: true,
     },
     {
       title: '联系电话',
-      dataIndex: 'user_name',
+      dataIndex: 'apply_people_phone',
       search: true,
     },
     {
       title: '预约时间',
-      dataIndex: 'user_name',
+      dataIndex: 'appointment',
       search: false,
+      valueType: 'dateTime',
     },
     {
       title: '报修内容',
-      dataIndex: 'user_name',
+      dataIndex: 'apply_content',
       search: false,
     },
     {
       title: '报修时间',
-      dataIndex: 'user_name',
+      dataIndex: 'created_at',
       search: false,
+      valueType: 'dateTime',
     },
     {
       title: '状态',
-      dataIndex: 'phone',
+      dataIndex: 'status',
       search: true,
+      valueEnum: {
+        1: { text: '未派单' },
+        2: { text: '已派单' },
+        3: { text: '已完结' },
+      }
     },
     {
       title: '操作',
@@ -91,7 +100,7 @@ const FixOnlineForm: React.FC = (props: any) => {
               title: '删除记录',
               content: '你确定删除这条记录吗?',
               onOk: async () => {
-                await User({ method: 'delete', id: row.id })
+                await FixApi({ method: 'delete', id: row.id })
                 message.success('操作成功!')
                 actionRef.current.reload()
               }
@@ -103,6 +112,13 @@ const FixOnlineForm: React.FC = (props: any) => {
   ]
 
   const [pic, setPic]: any = React.useState([])
+  const [fixClass, setFixClass] = useFixClass()
+  const [buildHouse, setBuildHouse]: any = useBuildingHouse()
+
+  React.useEffect(() => {
+    setFixClass()
+    setBuildHouse()
+  }, [])
 
   const uploadButton = (
     <div>
@@ -122,16 +138,18 @@ const FixOnlineForm: React.FC = (props: any) => {
 
   const onSubmit = () => {
     form.validateFields().then(async values => {
-      await User({
-        method: 'post',
+      await FixApi({
+        method: state.editId ? 'put' : 'post',
         ...values,
-        group_id: 11,
-        department_id: 0
+        apply_pic: pic.map(({ response }) => response.data),
+        appointment: values.appointment.valueOf(),
+        id: state.editId,
+        // garden_id: 3,
       })
       message.success('操作成功!')
       form.resetFields()
       actionRef.current?.reloadAndRest()
-      setState(prevState => ({ ...prevState, visible: false }))
+      setState(prevState => ({ ...prevState, visible: false, editId: null }))
     })
   }
 
@@ -141,7 +159,7 @@ const FixOnlineForm: React.FC = (props: any) => {
         headerTitle="报事报修/在线报修"
         actionRef={actionRef}
         rowKey="key"
-        request={User}
+        request={FixApi}
         toolBarRender={() => [
           <Button
             type="primary"
@@ -186,36 +204,31 @@ const FixOnlineForm: React.FC = (props: any) => {
           wrapperCol={{ span: 15 }}
           form={form}
         >
-          <Form.Item label='报修分类' name="group_id" rules={[{ required: true }]}>
-            <Select placeholder='请选择' options={[]} />
+          <Form.Item label='报修分类' name="class_id" rules={[{ required: true }]}>
+            <Select placeholder='请选择' options={fixClass} />
           </Form.Item>
-          <Form.Item label='报修人' name="user_name" rules={[{ required: true }]}>
+          <Form.Item label='报修人' name="apply_people" rules={[{ required: true }]}>
             <Input placeholder="请输入" />
           </Form.Item>
-          <Form.Item label='联系方式' name="user_name" rules={[{ required: true }]}>
+          <Form.Item label='联系方式' name="apply_people_phone" rules={[{ required: true }]}>
             <Input placeholder="请输入" />
           </Form.Item>
-          <Form.Item label='预约时间' rules={[{ required: true }]}>
-            <DatePicker placeholder="选择时间" format="YYYY-MM-DD" />
+          <Form.Item label='预约时间' name="appointment" rules={[{ required: true }]}>
+            <DatePicker showTime placeholder="选择时间" format="YYYY-MM-DD" />
           </Form.Item>
-          <Form.Item label='报修内容' name="user_name" rules={[{ required: true }]}>
+          <Form.Item label='报修内容' name="apply_content" rules={[{ required: true }]}>
             <Input.TextArea placeholder="多行输入" rows={4} />
           </Form.Item>
-          <Form.Item label='报修图片' name="user_name" rules={[{ required: true }]}>
+          <Form.Item label='报修图片' name="apply_pic" rules={[{ required: true }]}>
             <Upload
               action="http://localhost:3000/api/v1/upload"
               listType="picture-card"
               fileList={pic}
               onChange={(({ fileList }) => setPic(fileList))}
-            >
-              { uploadButton }
-            </Upload>
+            >{ uploadButton }</Upload>
           </Form.Item>
-          <Form.Item label='分类状态' name="user_name" rules={[{ required: true }]}>
-            <Radio.Group>
-              <Radio value={true}>开启</Radio>
-              <Radio value={false}>关闭</Radio>
-            </Radio.Group>
+          <Form.Item label='联系地址' name="house_id" rules={[{ required: true }]}>
+            <Select placeholder='请选择' options={buildHouse} />
           </Form.Item>
         </Form>
       </Modal>

+ 5 - 0
src/views/Fix/order-detail.tsx

@@ -1,6 +1,7 @@
 import React from 'react'
 import { Button, Card, Divider, Form, Table, Col, Row, Image } from "antd"
 import { useHistory } from "react-router"
+import { GetFixOrderInfo } from "../../services/fix"
 
 const columns = [
   {
@@ -39,6 +40,10 @@ const OrderDetail: React.FC = () => {
 
   const history = useHistory()
 
+  React.useEffect(() => {
+    GetFixOrderInfo()
+  })
+
   return (
     <React.Fragment>
       <div className="flex justify-between items-center pb-3" style={{ fontSize: '18px' }}>

+ 15 - 12
src/views/Fix/type.tsx

@@ -3,7 +3,7 @@ import type { ActionType } from '@ant-design/pro-table'
 import ProTable from '@ant-design/pro-table'
 import { Button, Modal, Form, Radio, Input, message } from 'antd'
 import { withRouter } from 'react-router-dom'
-import { User } from '../../services/user'
+import { FixClassApi } from '../../services/fix'
 import './index.scss'
 
 const FixTypes: React.FC = (props: any) => {
@@ -15,13 +15,17 @@ const FixTypes: React.FC = (props: any) => {
     },
     {
       title: '分类名称',
-      dataIndex: 'user_name',
+      dataIndex: 'name',
       search: true,
     },
     {
       title: '状态',
-      dataIndex: 'phone',
+      dataIndex: 'enable',
       search: false,
+      valueEnum: {
+        true: { text: '开启', status: 'Success' },
+        false: { text: '关闭', status: 'Error' },
+      }
     },
     {
       title: '操作',
@@ -45,7 +49,7 @@ const FixTypes: React.FC = (props: any) => {
               title: '删除记录',
               content: '你确定删除这条记录吗?',
               onOk: async () => {
-                await User({ method: 'delete', id: row.id })
+                await FixClassApi({ method: 'delete', id: row.id })
                 message.success('操作成功!')
                 actionRef.current.reload()
               }
@@ -64,16 +68,15 @@ const FixTypes: React.FC = (props: any) => {
   const [form] = Form.useForm()
   const onSubmit = () => {
     form.validateFields().then(async values => {
-      await User({
-        method: 'post',
+      await FixClassApi({
+        method: state.editId ? 'put' : 'post',
         ...values,
-        group_id: 11,
-        department_id: 0
+        id: state.editId
       })
       message.success('操作成功!')
       form.resetFields()
       actionRef.current?.reloadAndRest()
-      setState(prevState => ({ ...prevState, visible: false }))
+      setState(prevState => ({ ...prevState, visible: false, editId: null }))
     })
   }
 
@@ -84,7 +87,7 @@ const FixTypes: React.FC = (props: any) => {
         actionRef={actionRef}
         rowKey="key"
         search={false}
-        request={User}
+        request={FixClassApi}
         toolBarRender={() => [
           <Button
             type="primary"
@@ -107,10 +110,10 @@ const FixTypes: React.FC = (props: any) => {
           wrapperCol={{ span: 15 }}
           form={form}
         >
-          <Form.Item label='分类名称' name="user_name" rules={[{ required: true }]}>
+          <Form.Item label='分类名称' name="name" rules={[{ required: true }]}>
             <Input placeholder="请输入" />
           </Form.Item>
-          <Form.Item label='分类状态' name="user_name" rules={[{ required: true }]}>
+          <Form.Item label='分类状态' name="enable" rules={[{ required: true }]}>
             <Radio.Group>
               <Radio value={true}>开启</Radio>
               <Radio value={false}>关闭</Radio>