1002884655 4 gadus atpakaļ
vecāks
revīzija
22ddcdf4c5

+ 26
- 6
src/pages/WuYe/TianJiaBaoXiu/index.jsx Parādīt failu

@@ -11,7 +11,8 @@ export default function WuYeTianJiaBaoXiu () {
11 11
   const [Title, setTitle] = useState('')
12 12
   const [Desc, setDesc] = useState('')
13 13
   const [DataLock, setDataLock] = useState(false)
14
-  const CurrnetBaoXiuType = Current.router.params.type
14
+  const [CurrnetBaoXiuType] = useState(Current.router.params.type)
15
+  const [PhotoUrl, setPhotoUrl] = useState(null)
15 16
 
16 17
   const TitleChange = (e) => {
17 18
     setTitle(e.detail.value)
@@ -42,7 +43,8 @@ export default function WuYeTianJiaBaoXiu () {
42 43
         ticketTitle: Title,
43 44
         ticketContent: Desc,
44 45
         type: 2,
45
-        repairType: CurrnetBaoXiuType - 0
46
+        repairType: [CurrnetBaoXiuType] - 0,
47
+        imageUrl: PhotoUrl
46 48
       }
47 49
     }).then((res) => {
48 50
       Taro.showToast({ title: '报修提交成功', icon: 'none' })
@@ -60,11 +62,25 @@ export default function WuYeTianJiaBaoXiu () {
60 62
       sizeType: ['compressed'],
61 63
       sourceType: ['album', 'camera'],
62 64
       success: (res) => {
63
-        console.log(res)
65
+        const tempFilePaths = res.tempFilePaths
66
+        Taro.uploadFile({
67
+          url: apis.uploadImage.url,
68
+          filePath: tempFilePaths[0],
69
+          name: 'file',
70
+          formData: { user: 'upload' },
71
+          header: { 'x-action': 'miniapp', 'authorization': `Bearer ${Taro.getStorageSync('token')}` },
72
+          success: (res) => {
73
+            setPhotoUrl(JSON.parse(res.data).data)
74
+          }
75
+        })
64 76
       }
65 77
     })
66 78
   }
67 79
 
80
+  const DeleteItem = () => {
81
+    setPhotoUrl(null)
82
+  }
83
+
68 84
   return (
69 85
     <view className='WuYeTianJiaBaoXiu'>
70 86
       <view className='Form'>
@@ -78,9 +94,13 @@ export default function WuYeTianJiaBaoXiu () {
78 94
             <text>添加图片</text>
79 95
           </view>
80 96
         </view>
81
-        <view className='PhotoItem'>
82
-          <text className='iconfont iconshanchu'></text>
83
-        </view>
97
+        {
98
+          PhotoUrl !== null &&
99
+          <view className='PhotoItem'>
100
+            <text className='iconfont iconshanchu' onClick={DeleteItem}></text>
101
+            <image mode='aspectFit' src={PhotoUrl}></image>
102
+          </view>
103
+        }
84 104
       </view>
85 105
       <view className='Btn'>
86 106
         <text onClick={Send}>确认发送</text>

+ 1
- 1
src/pages/WuYe/TianJiaBaoXiu/index.less Parādīt failu

@@ -83,7 +83,7 @@
83 83
           z-index: 1;
84 84
         }
85 85
 
86
-        >text {
86
+        >text.iconfont {
87 87
           display: inline-block;
88 88
           position: absolute;
89 89
           z-index: 2;

+ 37
- 5
src/pages/WuYe/XiuGaiBaoXiu/index.jsx Parādīt failu

@@ -13,6 +13,7 @@ export default function WuYeXiuGaiBaoXiu () {
13 13
   const [DataLock, setDataLock] = useState(false)
14 14
   const [DetailInfo, setDetailInfo] = useState(null)
15 15
   const [CurrnetId] = useState(Current.router.params.id)
16
+  const [PhotoUrl, setPhotoUrl] = useState(null)
16 17
 
17 18
   useEffect(() => {
18 19
     Init()
@@ -21,6 +22,7 @@ export default function WuYeXiuGaiBaoXiu () {
21 22
   const Init = () => {
22 23
     request({ ...apis.getGongDanDetail, args: { orgId: user.orgId }, params: { ticketId: CurrnetId } }).then((res) => {
23 24
       setDetailInfo(res)
25
+      setPhotoUrl(res.tdImagesList !== null && res.tdImagesList.length > 0 ? res.tdImagesList[0] : null)
24 26
     })
25 27
   }
26 28
 
@@ -53,7 +55,8 @@ export default function WuYeXiuGaiBaoXiu () {
53 55
       data: {
54 56
         ticketTitle: DetailInfo.ticketTitle,
55 57
         ticketContent: DetailInfo.ticketContent,
56
-        type: 2
58
+        type: 2,
59
+        imageUrl: PhotoUrl
57 60
       }
58 61
     }).then((res) => {
59 62
       Taro.showToast({ title: '报修修改成功', icon: 'none' })
@@ -65,6 +68,31 @@ export default function WuYeXiuGaiBaoXiu () {
65 68
     })
66 69
   }
67 70
 
71
+  const AddImg = () => { // 添加图片
72
+    Taro.chooseImage({
73
+      count: 1,
74
+      sizeType: ['compressed'],
75
+      sourceType: ['album', 'camera'],
76
+      success: (res) => {
77
+        const tempFilePaths = res.tempFilePaths
78
+        Taro.uploadFile({
79
+          url: apis.uploadImage.url,
80
+          filePath: tempFilePaths[0],
81
+          name: 'file',
82
+          formData: { user: 'upload' },
83
+          header: { 'x-action': 'miniapp', 'authorization': `Bearer ${Taro.getStorageSync('token')}` },
84
+          success: (res) => {
85
+            setPhotoUrl(JSON.parse(res.data).data)
86
+          }
87
+        })
88
+      }
89
+    })
90
+  }
91
+
92
+  const DeleteItem = () => {
93
+    setPhotoUrl(null)
94
+  }
95
+
68 96
   return (
69 97
     <view className='WuYeXiuGaiBaoXiu'>
70 98
       <view className='Form'>
@@ -72,15 +100,19 @@ export default function WuYeXiuGaiBaoXiu () {
72 100
         <Textarea placeholder='描述问题详情,以便我们更好的相处' onInput={DescChange} value={DetailInfo === null ? null : DetailInfo.ticketContent}></Textarea>
73 101
       </view>
74 102
       <view className='Photo'>
75
-        <view className='Add'>
103
+        <view className='Add' onClick={AddImg}>
76 104
           <view className='centerLabel'>
77 105
             <text className='iconfont iconxiangji'></text>
78 106
             <text>添加图片</text>
79 107
           </view>
80 108
         </view>
81
-        <view className='PhotoItem'>
82
-          <text className='iconfont iconshanchu'></text>
83
-        </view>
109
+        {
110
+          PhotoUrl !== null &&
111
+          <view className='PhotoItem'>
112
+            <text className='iconfont iconshanchu' onClick={DeleteItem}></text>
113
+            <image mode='aspectFit' src={PhotoUrl}></image>
114
+          </view>
115
+        }
84 116
       </view>
85 117
       <view className='Btn'>
86 118
         <text onClick={Send}>确认修改</text>

+ 4
- 0
src/utils/api.js Parādīt failu

@@ -1,6 +1,10 @@
1 1
 const prefix = `${HOST}/api/wx`
2 2
 
3 3
 const $api = {
4
+  uploadImage: { // 上传图片
5
+    method: 'post',
6
+    url: `${prefix}/image`
7
+  },
4 8
   getMessageList: { // 获取小区通知
5 9
     method: 'get',
6 10
     url: `${prefix}/message/:orgId/news`