index.jsx 8.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. import BlackSpot from "@/assets/icons/GuideCheck/BlackSpot.png";
  2. import Taro from "@tarojs/taro";
  3. import { Button, Textarea, View } from "@tarojs/components";
  4. import formatPrice from "@/utils/formatPrice";
  5. import formatTime from "@/utils/formatTime";
  6. import { useState, useEffect } from "react";
  7. import withLayout from "@/layouts";
  8. import { getOrderSub, refund } from "@/services/payOrder";
  9. import food from "@/assets/icons/ProCard/food.png";
  10. import ProCard_hot from "@/assets/icons/ProCard/ProCard_hot.png";
  11. import CustomNav from "@/components/CustomNav";
  12. import "./style.less";
  13. const options = [
  14. {
  15. title: "计划有变,没时间消费",
  16. key: 1,
  17. },
  18. {
  19. title: "误认为是外卖",
  20. key: 2,
  21. },
  22. {
  23. title: "没看清楚使用规则,要用时才发现限制很多",
  24. key: 3,
  25. },
  26. {
  27. title: "预约不上",
  28. key: 4,
  29. },
  30. {
  31. title: "店里更优惠",
  32. key: 5,
  33. },
  34. {
  35. title: "网友/朋友评价不好",
  36. key: 6,
  37. },
  38. ];
  39. export default withLayout((props) => {
  40. const { router, person } = props;
  41. const { id } = props.router.params;
  42. // 说明
  43. const [explain, setExplain] = useState();
  44. const [list, setList] = useState([]);
  45. // 总价 totalPrice
  46. const [totalPrice, setTotalPrice] = useState({});
  47. const [checkeds, setCheckeds] = useState([1]);
  48. const getData = (orderId) => {
  49. Taro.showLoading();
  50. getOrderSub({
  51. pageNum: 1,
  52. pageSize: 50,
  53. orderId: orderId,
  54. }).then((res) => {
  55. setList(res.records);
  56. Taro.hideLoading();
  57. });
  58. };
  59. useEffect(() => {
  60. getData(id);
  61. }, []);
  62. const viewOK = (e) => {
  63. if (checkeds.indexOf(e.key) > -1) {
  64. setCheckeds(checkeds.filter((x) => x != e.key));
  65. } else {
  66. let arr = checkeds;
  67. arr.push(e.key);
  68. setCheckeds([...arr]);
  69. }
  70. };
  71. const onRefund = () => {
  72. Taro.showLoading({
  73. title: '退款中',
  74. })
  75. refund(id, {
  76. refundDecription: checkeds?.map(x => options.filter(y => y.key == x)[0]?.title).join(';'),
  77. refundReason: explain,
  78. }).then((res) => {
  79. Taro.hideLoading();
  80. Taro.navigateTo({ url: '/pages/MineUserAll/AllOrder/index?tabJump=0' })
  81. Taro.showToast({
  82. title: "退款成功",
  83. icon: "none",
  84. duration: 3000,
  85. });
  86. });
  87. };
  88. useEffect(() => {
  89. let total = {
  90. cashback: 0, //已获返现
  91. charges: 0, //实付金额
  92. refundPrice: 0, //退款金额
  93. };
  94. list.map((x) => {
  95. total.cashback += x.cashback;
  96. total.charges += x.charges;
  97. total.refundPrice += x.charges - x.cashback;
  98. });
  99. setTotalPrice(total);
  100. }, [list]);
  101. return (
  102. <view>
  103. <view className='index-navbar'>
  104. <CustomNav title='售后退款' />
  105. </view>
  106. <scroll-view scroll-y style='height: calc(100vh - 65px);' >
  107. <View className='index-container box-content'>
  108. <view className='Refund-Content-box'>
  109. <view className='title-image'>
  110. <image
  111. mode='scaleToFill'
  112. className='title-image-cup'
  113. src={BlackSpot}
  114. />
  115. <text className='title-title-boss'>商品信息</text>
  116. </view>
  117. </view>
  118. {/* 商品信息结束 */}
  119. <view>
  120. {(list || []).map((item) => {
  121. return (
  122. <view class='wrapper' key={item.orderId}>
  123. <view class='left-complete-one'>
  124. <image className='left-image-1' src={ProCard_hot}></image>
  125. <view className='left-viewText'>
  126. 返现¥{formatPrice(item.cashback)}
  127. </view>
  128. <view className='title-image'>
  129. <image
  130. className='image-1'
  131. mode='scaleToFill'
  132. src={item.poster}
  133. ></image>
  134. <image className='image-2' src={food}></image>
  135. </view>
  136. <view className='title-content'>
  137. <view className='Pro-title'>
  138. <View className='cpn-card-text'>
  139. <View style={{ flex: '1' }}>{(item.packageDescription).toString().length > 25 ? (item.packageDescription).substring(0, 25) + '...' : (item.packageDescription)}</View>
  140. <text className='title-money-2'>
  141. 数量:{item.amount}张
  142. </text>
  143. </View>
  144. </view>
  145. <text className='title-money'>
  146. ¥{formatPrice(item.unitPrice)}元
  147. <text className='title-money-2'>
  148. 门市价{formatPrice(item.standardPrice)}元
  149. </text>
  150. </text>
  151. <view className='title-time'>
  152. 有效期:{formatTime(item?.startTime, "yyyy/MM/dd")}-
  153. {formatTime(item.endTime, "yyyy/MM/dd")}
  154. </view>
  155. </view>
  156. </view>
  157. <view class='right-complete-two'>
  158. </view>
  159. </view>
  160. );
  161. })}
  162. </view>
  163. {/* 卡片结束 */}
  164. <view className='Refund-Content-box'>
  165. <view className='title-image'>
  166. <image
  167. mode='scaleToFill'
  168. className='title-image-cup'
  169. src={BlackSpot}
  170. />
  171. <text className='title-title-boss'>退款原因</text>
  172. </view>
  173. {/* 退款结束 */}
  174. </view>
  175. <view className='Refund-content'>
  176. {options.map((x) => {
  177. return (
  178. <text
  179. className={`Refund-star-view1 ${checkeds.indexOf(x.key) > -1
  180. ? "bg2"
  181. : `Refund-star-view2`
  182. }`}
  183. key={x.key}
  184. onClick={() => viewOK(x)}
  185. >
  186. {x.title}
  187. </text>
  188. );
  189. })}
  190. </view>
  191. <view className='Refund-Content-box'>
  192. <view className='title-image'>
  193. <image
  194. mode='scaleToFill'
  195. className='title-image-cup'
  196. src={BlackSpot}
  197. />
  198. <text className='title-title-boss'>退款说明</text>
  199. </view>
  200. </view>
  201. <view class='section'>
  202. <Textarea
  203. placeholder='请补充退款说明(选填)!'
  204. onInput={(e) => setExplain(e.detail.value)}
  205. confirm-type='done'
  206. />
  207. </view>
  208. <view className='money-title'>
  209. 实付金额:{" "}
  210. <text className='money-name'>{formatPrice(totalPrice.charges)}元</text>
  211. </view>
  212. <view className='money-title'>
  213. 已获返现:{" "}
  214. <text className='money-name'>{formatPrice(totalPrice.cashback)}元</text>
  215. </view>
  216. <view className='money-title'>
  217. 退款金额:{" "}
  218. <text className='money-name'>{formatPrice(totalPrice.refundPrice)}元</text>
  219. </view>
  220. <view className='ul-li-text'>
  221. <view className='ul-li-view'></view>
  222. <text className='ul-li-textname'>退款金额不可修改</text>
  223. </view>
  224. <view className='ul-li-text'>
  225. <view className='ul-li-view'></view>
  226. <text className='ul-li-textname'>
  227. 下单获得返现金额,会在退款时被扣除;
  228. </text>
  229. </view>
  230. <view className='ul-li-text'>
  231. <view className='ul-li-view'></view>
  232. <text className='ul-li-textname'>退款将在七个工作日内原路退还。</text>
  233. </view>
  234. <view className='button-info'>
  235. <Button className='button-box' onClick={() => onRefund()}>
  236. 提交申请
  237. </Button>
  238. </view>
  239. </View>
  240. </scroll-view>
  241. </view >
  242. );
  243. });