index.jsx 6.5KB

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