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