xcx 4 år sedan
förälder
incheckning
27367ac153
1 ändrade filer med 99 tillägg och 13 borttagningar
  1. 99
    13
      src/pages/WuYe/BaoXiuFeiYong/index.jsx

+ 99
- 13
src/pages/WuYe/BaoXiuFeiYong/index.jsx Visa fil

@@ -1,22 +1,105 @@
1
-import React, { useState } from 'react'
1
+import React, { useState, useEffect } from 'react'
2 2
 import Taro, { Current } from '@tarojs/taro'
3 3
 import SlidePopup from '@/components/SlidePopup/index'
4 4
 import UploadImg from '@/components/UploadImg/index'
5 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 9
 import '@/assets/css/reset.less'
7 10
 import '@/assets/css/iconfont.less'
8 11
 import './index.less'
9 12
 
10 13
 export default function BaoXiuFeiYong () {
11 14
 
15
+  const { user } = useModel('user')
12 16
   const [ShowPopup, setShowPopup] = useState(false)
13 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 35
   const SlidePopupClose = () => {
17 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 103
   return (
21 104
     <Page>
22 105
       <view className='BaoXiuFeiYong'>
@@ -24,38 +107,41 @@ export default function BaoXiuFeiYong () {
24 107
         {/* 费用信息 */}
25 108
         <view className='Info'>
26 109
           <view>
27
-            <text>1栋3单元2楼-3楼走廊声控灯出现故障</text>
110
+            <text>{DetailInfo === null ? '' : DetailInfo.ticketTitle}</text>
28 111
             <view className='flex-h'>
29 112
               <text className='flex-item'>报修类型</text>
30
-              <text>公共区域问题</text>
113
+              <text>{DetailInfo === null ? '' : DetailInfo.repairName}问题</text>
31 114
             </view>
32 115
             <view className='flex-h'>
33 116
               <text className='flex-item'>报修单号</text>
34
-              <text>201810120020</text>
117
+              <text>{DetailInfo === null ? '' : DetailInfo.id}</text>
35 118
             </view>
36 119
             <view className='flex-h'>
37 120
               <text className='flex-item'>报修时间</text>
38
-              <text>2018-10-12 18:00</text>
121
+              <text>{DetailInfo === null ? '' : toolclass.FormatDate(DetailInfo.createDate)}</text>
39 122
             </view>
40 123
             <view className='flex-h'>
41 124
               <text className='flex-item'>报修进度</text>
42
-              <text>已修缮</text>
125
+              <text>{DetailInfo === null ? '' : DetailInfo.ticketRecordList[DetailInfo.ticketRecordList.length - 1].ticketStatusName}</text>
43 126
             </view>
44 127
             <view className='flex-h'>
45 128
               <text className='flex-item'>处理人</text>
46
-              <text>郭培军</text>
129
+              <text>{DetailInfo === null ? '' : DetailInfo.ticketRecordList[DetailInfo.ticketRecordList.length - 1].createUser || '-'}</text>
47 130
             </view>
48 131
             <view className='flex-h'>
49 132
               <text className='flex-item'>报修费用</text>
50
-              <text className='Red'>¥150</text>
133
+              <text className='Red'>¥{BillInfo === null ? '' : BillInfo.payPrice}</text>
51 134
             </view>
52 135
           </view>
53 136
           <view className='InfoBottom'></view>
54 137
         </view>
55 138
 
56 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 145
         </view>
60 146
 
61 147
         {/* 弹窗 */}
@@ -65,14 +151,14 @@ export default function BaoXiuFeiYong () {
65 151
           {
66 152
             PopupType - 0 === 1 &&
67 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 155
               <view className='flex-h'>
70 156
                 <text className='iconfont iconweixinzhifu'></text>
71 157
                 <text className='flex-item'>微信支付</text>
72 158
                 <text className='iconfont icongou'></text>
73 159
               </view>
74 160
               <view className='Btn'>
75
-                <text>去付款</text>
161
+                <text onClick={ToPay}>去付款</text>
76 162
               </view>
77 163
             </view>
78 164
           }