index.jsx 6.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. import { View, Text } from "@tarojs/components"
  2. import { useEffect, useState, useMemo } from "react"
  3. import Taro, { useDidShow } from "@tarojs/taro"
  4. import CustomNav from '@/components/CustomNav'
  5. import ButtontWX from '@/components/ButtontWX'
  6. import formatTimes from "@/utils/codeSegment"
  7. import withLayout from '@/layouts'
  8. import formatPrice from "@/utils/formatPrice"
  9. import AssessModel from "@/components/AssessModel"
  10. import useProcessStatus, { getProcessSignBy } from "@/utils/hooks/useProcessStatus"
  11. import { orderPrepay, orderDelete, orderInfo, orderRefund } from "@/services/order"
  12. // import BottomMoadl from '@/components/BottomMoadl/index'
  13. import './style.less'
  14. export default withLayout((props) => {
  15. // const { stateType } = props
  16. const $instance = Taro.getCurrentInstance()
  17. const { orderId } = $instance.router.params
  18. const [orderInfos, setOrderInfos] = useState()
  19. const [isAssessVisible, setIsAssessVisible] = useState(false)
  20. const { processStatus } = useProcessStatus(orderInfos)
  21. //底部弹窗
  22. // const [showFrame, setShowFrame] = useState(false)
  23. // const setRecommend = () => {
  24. // setShowFrame(!showFrame)
  25. // }
  26. const cancelPay = () => {
  27. Taro.showModal({
  28. title: '提示',
  29. content: '您确定要取消此订单吗?',
  30. success: function (res) {
  31. if (res.confirm) {
  32. orderDelete(orderId).then((e) => {
  33. console.log('订单取消/删除', e);
  34. Taro.showToast({
  35. title: '订单取消成功',
  36. icon: 'success',
  37. duration: 2000
  38. }).then(() => {
  39. setTimeout(() => {
  40. Taro.navigateBack({
  41. delta: 1
  42. })
  43. }, 1000)
  44. })
  45. })
  46. } else if (res.cancel) {
  47. console.log('用户点击取消')
  48. }
  49. }
  50. })
  51. }
  52. useEffect(() => {
  53. if (orderId) {
  54. orderInfo(orderId).then((res) => {
  55. setOrderInfos(res)
  56. })
  57. } else {
  58. Taro.showToast({
  59. title: '暂无订单详情',
  60. icon: 'error',
  61. duration: 2000
  62. }).then(() => {
  63. setTimeout(() => {
  64. Taro.navigateBack({
  65. delta: 1
  66. })
  67. }, 1000)
  68. })
  69. }
  70. }, [orderId])
  71. const requestPayment = (params) => {
  72. Taro.hideLoading()
  73. console.log("🚀 ~ file: index.jsx ~ line 92 ~ requestPayment ~ params", params)
  74. Taro.requestPayment({
  75. ...params,
  76. package: params.packageValue,
  77. success: () => {
  78. Taro.showToast({
  79. title: "支付成功",
  80. icon: "success",
  81. duration: 1000,
  82. }).then(() => {
  83. setTimeout(() => {
  84. Taro.reLaunch({
  85. url: `/pages/index/index?tab=2`
  86. })
  87. }, 400)
  88. })
  89. },
  90. fail: (e) => {
  91. Taro.showToast({
  92. title: "支付失败",
  93. icon: "none",
  94. duration: 2000,
  95. });
  96. Taro.reLaunch({
  97. // url: `/pages/MineUserAll/AllOrder/index?tabJump=1`
  98. })
  99. },
  100. })
  101. }
  102. const pay = () => {
  103. orderPrepay(orderId, {
  104. payType: 'wx',
  105. }).then((e) => {
  106. console.log('订单返回', e);
  107. Taro.showLoading({
  108. title: '支付中',
  109. })
  110. requestPayment(e)
  111. })
  112. //支付逻辑
  113. }
  114. //退单
  115. const orderRefunds = () => {
  116. Taro.showLoading({
  117. title: '退单申请中',
  118. })
  119. orderRefund(orderId).then(() => {
  120. Taro.showLoading()
  121. Taro.showToast({
  122. title: "退单成功",
  123. icon: "none",
  124. duration: 2000,
  125. }).then(() => {
  126. setTimeout(() => {
  127. Taro.navigateBack({
  128. delta: 1
  129. })
  130. }, 400)
  131. })
  132. }).catch(() => {
  133. Taro.showLoading()
  134. Taro.showToast({
  135. title: "请重试",
  136. icon: "error",
  137. duration: 2000,
  138. });
  139. })
  140. }
  141. const startModle = () => {
  142. setIsAssessVisible(true)
  143. }
  144. const onClose = () => {
  145. setIsAssessVisible(false)
  146. Taro.navigateBack({
  147. delta: 1
  148. })
  149. }
  150. const { processLabel, stateStyle, action : Actions } = useMemo(() => {
  151. const { label, color } = getProcessSignBy(processStatus)
  152. let action = <></>;
  153. switch (processStatus) {
  154. case 1:
  155. case 2:
  156. action = <ButtontWX butText='取消' styleType onClick={cancelPay} butWidth={150} butHeight={39} butFontSize={16} butBorderRadius={49} />;
  157. break;
  158. case 4:
  159. action = <ButtontWX butText='支付' onClick={pay} butWidth={150} butHeight={39} butFontSize={16} butBorderRadius={49} />;
  160. break;
  161. case 5:
  162. action = <ButtontWX butText='评价' onClick={startModle} butWidth={323} butHeight={49} butFontSize={16} butBorderRadius={49} />;
  163. break;
  164. case 3:
  165. case 6:
  166. default:
  167. break;
  168. }
  169. return {
  170. processLabel: label,
  171. stateStyle: color,
  172. action
  173. }
  174. }, [processStatus])
  175. return (
  176. <View className='page-index'>
  177. <View className='index-navbar'>
  178. <CustomNav title='订单详情' />
  179. </View>
  180. <AssessModel orderId={orderId} showCutover={isAssessVisible} maskClosable={isAssessVisible} onClose={onClose} onFinish={onClose} />
  181. {/* <BottomMoadl frameTitle='支付方式' flag={showFrame} onRecommend={setRecommend} /> */}
  182. <View className='orders-listBox-RihtboxBoxOrderViewText'>
  183. <View className='View-LiftTextTop'>订单编号:<Text>{orderInfos?.orderNo}</Text></View>
  184. <View>农机名称:<Text>{orderInfos?.machineryName}</Text></View>
  185. <View>作业面积:<Text>{orderInfos?.amount}</Text></View>
  186. <View>需求时间:<Text>{formatTimes(orderInfos?.appointmentDate, 'yyyy-MM-dd')}</Text></View>
  187. <View>下单时间:<Text>{formatTimes(orderInfos?.createDate, 'yyyy-MM-dd')}</Text></View>
  188. <View>订单状态:<Text style={{ color: `${stateStyle}` }} >{processLabel}</Text></View>
  189. <View className='View-LiftTextBotton'>
  190. <View className='feiyongStyle'>费用:<Text className='feiyongStyle-charges' >{formatPrice(orderInfos?.charges)}</Text></View>
  191. <View className='feiyongStyle'>状态:<Text style={{ color: `${stateStyle}` }} className='feiyongStyle-stateStyle' >{orderInfos?.payStatus === 1 ? '已付款' : '待付款'}</Text></View>
  192. </View>
  193. </View>
  194. <View className='BottomtBut' >
  195. {Actions}
  196. </View>
  197. </View>
  198. )
  199. })