Browse Source

静态页面

xcx 4 years ago
parent
commit
27367ac153
1 changed files with 99 additions and 13 deletions
  1. 99
    13
      src/pages/WuYe/BaoXiuFeiYong/index.jsx

+ 99
- 13
src/pages/WuYe/BaoXiuFeiYong/index.jsx View File

1
-import React, { useState } from 'react'
1
+import React, { useState, useEffect } from 'react'
2
 import Taro, { Current } from '@tarojs/taro'
2
 import Taro, { Current } from '@tarojs/taro'
3
 import SlidePopup from '@/components/SlidePopup/index'
3
 import SlidePopup from '@/components/SlidePopup/index'
4
 import UploadImg from '@/components/UploadImg/index'
4
 import UploadImg from '@/components/UploadImg/index'
5
 import Page from '@/layouts'
5
 import Page from '@/layouts'
6
+import request, { apis } from '@/utils/request'
7
+import { useModel } from '@/store'
8
+import toolclass from '@/utils/toolclass.js'
6
 import '@/assets/css/reset.less'
9
 import '@/assets/css/reset.less'
7
 import '@/assets/css/iconfont.less'
10
 import '@/assets/css/iconfont.less'
8
 import './index.less'
11
 import './index.less'
9
 
12
 
10
 export default function BaoXiuFeiYong () {
13
 export default function BaoXiuFeiYong () {
11
 
14
 
15
+  const { user } = useModel('user')
12
   const [ShowPopup, setShowPopup] = useState(false)
16
   const [ShowPopup, setShowPopup] = useState(false)
13
   const [PopupType, setPopupType] = useState(0)
17
   const [PopupType, setPopupType] = useState(0)
14
-  const CurrnetBaoXiuId = Current.router.params.id
18
+  const [CurrnetBaoXiuId] = useState(Current.router.params.id)
19
+  const [DetailInfo, setDetailInfo] = useState(null)
20
+  const [BillInfo, setBillInfo] = useState(null)
21
+
22
+  useEffect(() => {
23
+    Init()
24
+  }, [CurrnetBaoXiuId])
25
+
26
+  const Init = () => {
27
+    request({ ...apis.getGongDanDetail, args: { orgId: user.orgId }, params: { ticketId: CurrnetBaoXiuId } }).then((res) => { // 获取工单详情
28
+      setDetailInfo(res)
29
+      request({ ...apis.getBillInvoiced, args: { orgId: user.orgId, id: res.billInvoiceId } }).then((cRes) => { // 获取费用详情
30
+        setBillInfo(cRes)
31
+      })
32
+    })
33
+  }
15
 
34
 
16
   const SlidePopupClose = () => {
35
   const SlidePopupClose = () => {
17
     setShowPopup(false)
36
     setShowPopup(false)
18
   }
37
   }
19
 
38
 
39
+  const CancelOrder = (outTradeNo) => {
40
+    return new Promise((resolve, reject) => {
41
+      if (outTradeNo) {
42
+        request({ ...apis.wxCancelPay, args: { outTradeNo }, params: { type: 'bill' } })
43
+          .then(res => resolve(res))
44
+          .catch(err => reject(err))
45
+      } else {
46
+        resolve()
47
+      }
48
+    })
49
+  }
50
+
51
+  const WechatPay = (idArray) => {
52
+    return new Promise((resolve, reject) => {
53
+      // 准备下单
54
+      request({ ...apis.wxStartPay, data: { type: 'bill', idArray } }).then((res) => {
55
+        const outTradeNo = res.outTradeNo
56
+        // 下单
57
+        request({ ...apis.wxUnifiedOrder, args: { outTradeNo }, params: { type: 'bill' } }).then(() => {
58
+          Taro.requestPayment({
59
+            timeStamp: res.timeStamp,
60
+            nonceStr: res.nonceStr,
61
+            package: res.package,
62
+            paySign: res.sign,
63
+            signType: res.signType,
64
+            success: resp => {
65
+              resolve(resp)
66
+            },
67
+            fail: err => {
68
+              CancelOrder(outTradeNo)
69
+              reject(err)
70
+            }
71
+          })
72
+        }).catch(err => {
73
+          CancelOrder(outTradeNo)
74
+          reject(err)
75
+        })
76
+      }).catch(err => reject(err))
77
+    })
78
+  }
79
+
80
+  const ToPay = () => {
81
+    Taro.showModal({
82
+      title: '提示',
83
+      content: `确定缴费 ${BillInfo.payPrice} 元?`,
84
+      success: res => {
85
+        if (res.confirm) {
86
+          WechatPay([BillInfo.id - 0]).then(() => {
87
+            Taro.showToast({
88
+              title: '缴费成功',
89
+              icon: 'success'
90
+            })
91
+            setBillInfo({ ...BillInfo, billStatus: 1 })
92
+          }).catch(err => {
93
+            Taro.showToast({
94
+              title: (err.message || err.errMsg || err),
95
+              icon: 'none'
96
+            })
97
+          })
98
+        }
99
+      }
100
+    })
101
+  }
102
+
20
   return (
103
   return (
21
     <Page>
104
     <Page>
22
       <view className='BaoXiuFeiYong'>
105
       <view className='BaoXiuFeiYong'>
24
         {/* 费用信息 */}
107
         {/* 费用信息 */}
25
         <view className='Info'>
108
         <view className='Info'>
26
           <view>
109
           <view>
27
-            <text>1栋3单元2楼-3楼走廊声控灯出现故障</text>
110
+            <text>{DetailInfo === null ? '' : DetailInfo.ticketTitle}</text>
28
             <view className='flex-h'>
111
             <view className='flex-h'>
29
               <text className='flex-item'>报修类型</text>
112
               <text className='flex-item'>报修类型</text>
30
-              <text>公共区域问题</text>
113
+              <text>{DetailInfo === null ? '' : DetailInfo.repairName}问题</text>
31
             </view>
114
             </view>
32
             <view className='flex-h'>
115
             <view className='flex-h'>
33
               <text className='flex-item'>报修单号</text>
116
               <text className='flex-item'>报修单号</text>
34
-              <text>201810120020</text>
117
+              <text>{DetailInfo === null ? '' : DetailInfo.id}</text>
35
             </view>
118
             </view>
36
             <view className='flex-h'>
119
             <view className='flex-h'>
37
               <text className='flex-item'>报修时间</text>
120
               <text className='flex-item'>报修时间</text>
38
-              <text>2018-10-12 18:00</text>
121
+              <text>{DetailInfo === null ? '' : toolclass.FormatDate(DetailInfo.createDate)}</text>
39
             </view>
122
             </view>
40
             <view className='flex-h'>
123
             <view className='flex-h'>
41
               <text className='flex-item'>报修进度</text>
124
               <text className='flex-item'>报修进度</text>
42
-              <text>已修缮</text>
125
+              <text>{DetailInfo === null ? '' : DetailInfo.ticketRecordList[DetailInfo.ticketRecordList.length - 1].ticketStatusName}</text>
43
             </view>
126
             </view>
44
             <view className='flex-h'>
127
             <view className='flex-h'>
45
               <text className='flex-item'>处理人</text>
128
               <text className='flex-item'>处理人</text>
46
-              <text>郭培军</text>
129
+              <text>{DetailInfo === null ? '' : DetailInfo.ticketRecordList[DetailInfo.ticketRecordList.length - 1].createUser || '-'}</text>
47
             </view>
130
             </view>
48
             <view className='flex-h'>
131
             <view className='flex-h'>
49
               <text className='flex-item'>报修费用</text>
132
               <text className='flex-item'>报修费用</text>
50
-              <text className='Red'>¥150</text>
133
+              <text className='Red'>¥{BillInfo === null ? '' : BillInfo.payPrice}</text>
51
             </view>
134
             </view>
52
           </view>
135
           </view>
53
           <view className='InfoBottom'></view>
136
           <view className='InfoBottom'></view>
54
         </view>
137
         </view>
55
 
138
 
56
         <view className='BottomBtn'>
139
         <view className='BottomBtn'>
57
-          <text className='active' onClick={() => { setPopupType(1); setShowPopup(true) }}>我要缴费</text>
58
-          <text onClick={() => { setPopupType(2); setShowPopup(true) }}>线下缴费</text>
140
+          {
141
+            BillInfo !== null &&
142
+            <text className={BillInfo.billStatus - 0 === 0 ? 'active' : ''} onClick={() => { if (BillInfo.billStatus - 0 === 0) { setPopupType(1); setShowPopup(true) } }}>{BillInfo.billStatus - 0 === 0 ? '我要缴费' : '已缴费'}</text>
143
+          }
144
+          {/* <text onClick={() => { setPopupType(2); setShowPopup(true) }}>线下缴费</text> */}
59
         </view>
145
         </view>
60
 
146
 
61
         {/* 弹窗 */}
147
         {/* 弹窗 */}
65
           {
151
           {
66
             PopupType - 0 === 1 &&
152
             PopupType - 0 === 1 &&
67
             <view className='JiaoFeiPopup XianShang'>
153
             <view className='JiaoFeiPopup XianShang'>
68
-              <view className='Price'>立即支付<text>150</text>元</view>
154
+              <view className='Price'>立即支付<text>{BillInfo === null ? '' : BillInfo.payPrice}</text>元</view>
69
               <view className='flex-h'>
155
               <view className='flex-h'>
70
                 <text className='iconfont iconweixinzhifu'></text>
156
                 <text className='iconfont iconweixinzhifu'></text>
71
                 <text className='flex-item'>微信支付</text>
157
                 <text className='flex-item'>微信支付</text>
72
                 <text className='iconfont icongou'></text>
158
                 <text className='iconfont icongou'></text>
73
               </view>
159
               </view>
74
               <view className='Btn'>
160
               <view className='Btn'>
75
-                <text>去付款</text>
161
+                <text onClick={ToPay}>去付款</text>
76
               </view>
162
               </view>
77
             </view>
163
             </view>
78
           }
164
           }