Your Name 4 年之前
父節點
當前提交
44cefe59c7
共有 1 個檔案被更改,包括 36 行新增45 行删除
  1. 36
    45
      src/pages/share/index.jsx

+ 36
- 45
src/pages/share/index.jsx 查看文件

@@ -1,8 +1,8 @@
1 1
 import React, { useEffect, useMemo, useState } from 'react'
2
-// import { useEffect, useLayoutEffect, useReducer, useState, useContext, useRef, useCallback, useMemo } from '@tarojs/taro'
3 2
 import Taro, { useShareAppMessage, useRouter } from "@tarojs/taro";
4 3
 import { useSelector, } from 'react-redux'
5
-import { View, Input, Text, Image, Picker } from '@tarojs/components'
4
+import { View, Input, Text, Image, Picker, Button } from '@tarojs/components'
5
+import { AtModal, AtModalHeader, AtModalContent, AtModalAction } from "taro-ui"
6 6
 import Layout from '../../layout/index'
7 7
 import Tab from '../../compents/tab/index'
8 8
 import Container from '../../compents/container/index'
@@ -33,52 +33,46 @@ const index = (props) => {
33 33
     const [personNum, setPersonNum] = useState()
34 34
     const [startTime, setStartTime] = useState('')
35 35
     const [endTime, setEndTime] = useState('')
36
-    useEffect(() => {
37
-
38
-        // console.log(page, 'page')
39
-        setList([
40
-            {
41
-                name: 'zhou',
42
-                phone: '177'
43
-            },
44
-            {
45
-                name: 'zhou',
46
-                phone: '177'
47
-            },
48
-            {
49
-                name: 'zhou',
50
-                phone: '177'
51
-            }
52
-        ])
53
-    }, [])
54
-    useShareAppMessage(res => {
55
-        Taro.showLoading({
56
-            title: '分享中',
57
-          })
58
-        if (res.from === 'button') {
59
-            // 来自页面内转发按钮
60
-            console.log(res.target)
61
-        }
36
+    const [shareObj, setShareObj] = useState()
37
+    const [showShareModal, setShowShareModal] = useState(false)
38
+    
39
+    const onTimeChange = (e) => {
40
+        setStartTime(e.detail.value)
41
+    }
62 42
 
43
+    const handleShareReady = () => {
44
+        
63 45
         const data = {
64 46
             houseId,
65 47
             personNum,
66 48
             startDate: startTime,
67 49
             endDate: endTime
68 50
         }
51
+        
52
+        Taro.showLoading({
53
+            title: '正在生成分享内容,请稍后...'
54
+        })
55
+
69 56
         return request({ url: '/taHouseSetting', method: 'post', data }).then(res => {
70 57
             const { data } = res.data
71 58
             if (res.data.data) {
72 59
                 console.log(data.taHouseOrder.orderId)
73 60
                 const { orderId } = data.taHouseOrder
74 61
                 return request({ url: `/taHouse/${houseId}/share` }).then(res => {
75
-                    Taro.hideLoading()
76
-                    return {
62
+
63
+                    const share = {
77 64
                         title: '分享到微信',
65
+                        imageUrl: (res.data.data || {}).image,
78 66
                         path: `/pages/index/index?houseId=${houseId}&personNum=${personNum}&startTime=${startTime}&endTime=${endTime}&orderId=${orderId}`
79 67
                     }
68
+
69
+                    setShareObj(share)
70
+                    console.log('----before-->', JSON.stringify(share))
71
+                    Taro.hideLoading()
72
+                    setShowShareModal(true)
80 73
                 })
81 74
             } else {
75
+                Taro.hideLoading()
82 76
                 Taro.showModal({
83 77
                     title: '输入信息有误',
84 78
                     content: '请重新输入',
@@ -95,20 +89,12 @@ const index = (props) => {
95 89
 
96 90
         })
97 91
 
98
-
99
-
100
-    })
101
-
102
-    async function syncAddOrder() {
103
-
104
-
105
-    }
106
-
107
-    const onTimeChange = (e) => {
108
-        console.log(e, '111')
109
-        setStartTime(e.detail.value)
110 92
     }
111 93
 
94
+    useShareAppMessage(() => {  
95
+        console.log('----after-->', JSON.stringify(shareObj))      
96
+        return shareObj
97
+    })
112 98
 
113 99
     return <View className='share'>
114 100
         <Layout>
@@ -142,9 +128,14 @@ const index = (props) => {
142 128
                 </Container>
143 129
             </View>
144 130
         </Layout>
145
-        <Tab openType="share" className='addhousetab' color='#ffffff' pageState='3' onClick={(e) => console.log(33)} value={['分享到微信']} ></Tab>
146
-
147
-
131
+        <Tab className='addhousetab' color='#ffffff' pageState='3' onClick={handleShareReady} value={['分享到微信']} ></Tab>
132
+        <AtModal isOpened={showShareModal}>
133
+            <AtModalHeader>分享到微信</AtModalHeader>
134
+            <AtModalAction>
135
+                <Button onClick={() => setShowShareModal(false)}>取消</Button>
136
+                <Button open-type="share" onClick={() => setShowShareModal(false)}>确定</Button>
137
+            </AtModalAction>
138
+        </AtModal>
148 139
     </View>
149 140
 }
150 141