order.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  1. <template>
  2. <view class="page-container bg-f5f7fa" v-if="list">
  3. <!-- 金额卡片 -->
  4. <view class="amount-card bg-theme br-16 mx-32 mt-32 p-36 shadow-md">
  5. <view class="flex-column items-center">
  6. <view class="fs-26 color-fff mb-12">实付金额</view>
  7. <view class="flex-align-center">
  8. <text class="fs-44 color-fff mr-10">¥</text>
  9. <text class="fs-64 fw-600 color-fff lh-64">{{ price }}</text>
  10. </view>
  11. <view class="fs-22 color-fff opacity-80 mt-12" v-if="orderDetail">
  12. {{ orderDetail.chargeStatus === 2 ? '充电中' : '已完成' }}
  13. </view>
  14. </view>
  15. </view>
  16. <!-- 订单信息卡片 -->
  17. <view class="info-card bg-fff br-20 mx-32 mt-28 p-36 shadow-sm">
  18. <!-- 充电站点 -->
  19. <view class="info-item flex-align-center pb-32 border-b border-eee">
  20. <view class="info-icon flex-center w-56 h-56 bg-theme-light br-10 mr-20">
  21. <uni-icons type="location" size="26" color="#2d9e95"></uni-icons>
  22. </view>
  23. <view class="flex-grow">
  24. <view class="fs-24 color-999 mb-8">充电站点</view>
  25. <view class="fs-28 fw-500 color-333">{{ list[0]?.value }}</view>
  26. </view>
  27. </view>
  28. <!-- 充电详情 -->
  29. <view class="charge-detail mt-32">
  30. <view class="fs-28 fw-500 color-333 mb-24">充电详情</view>
  31. <view class="detail-grid">
  32. <!-- 累计充电量 -->
  33. <view class="detail-item flex-column items-center p-24 bg-f5f7fa br-12">
  34. <view class="fs-24 color-999 mb-8">累计充电量</view>
  35. <view class="fs-32 fw-600 color-333">{{ list[1]?.value }}</view>
  36. </view>
  37. <!-- 充电用时 -->
  38. <view class="detail-item flex-column items-center p-24 bg-f5f7fa br-12 ml-16">
  39. <view class="fs-24 color-999 mb-8">充电用时</view>
  40. <view class="fs-32 fw-600 color-333">{{ list[list.length - 2]?.value }}</view>
  41. </view>
  42. </view>
  43. </view>
  44. <!-- 订单信息列表 -->
  45. <view class="info-list mt-36">
  46. <block v-for="(item, index) in list" :key="index">
  47. <view
  48. class="info-row flex-align-center justify-between py-20"
  49. v-if="index > 1 && index < list.length - 2"
  50. >
  51. <view class="fs-26 color-666">
  52. {{ item.label }}
  53. </view>
  54. <view
  55. class="fs-26"
  56. :class="{ 'color-theme': item.color === '#F43636', 'color-333': !item.color }"
  57. :style="{ color: item.color ? 'var(--color-primary)' : '' }"
  58. >
  59. {{ item.value }}
  60. <uni-icons
  61. v-if="item.copy"
  62. type="copy"
  63. size="24"
  64. color="#999"
  65. class="ml-12"
  66. @click="copyText(item.value)"
  67. ></uni-icons>
  68. </view>
  69. </view>
  70. </block>
  71. </view>
  72. <!-- 优惠信息 -->
  73. <view class="discount-info mt-32 pt-32 border-t border-eee">
  74. <view
  75. class="flex-align-center justify-between cursor-pointer"
  76. @click="handleClickDesc"
  77. v-if="orderDetail && orderDetail.discountAmount > 0"
  78. >
  79. <view class="fs-26 color-666">优惠信息</view>
  80. <view class="flex-align-center">
  81. <view class="fs-26 color-theme mr-12">查看详情</view>
  82. <uni-icons type="right" size="24" color="#999"></uni-icons>
  83. </view>
  84. </view>
  85. </view>
  86. </view>
  87. <!-- 优惠券详情组件 -->
  88. <order-coupon-detail ref="order_coupon_detail_ref"></order-coupon-detail>
  89. </view>
  90. <!-- 加载状态 -->
  91. <view class="loading-state flex-center" v-else>
  92. <uni-icons type="spinner" size="40" color="#2d9e95" class="loading-icon"></uni-icons>
  93. <view class="fs-28 color-999 ml-16">加载中...</view>
  94. </view>
  95. </template>
  96. <script setup lang="ts">
  97. import { fetchOrder} from "../../api/user";
  98. import { onLoad } from "@dcloudio/uni-app";
  99. import { ref } from "vue";
  100. import OrderCouponDetail from "@/components/order-coupon-detail/order-coupon-detail.vue";
  101. import { to } from "@/utils/navigate";
  102. import { formatDuration, parseDate } from "@/utils/date";
  103. import { formatMoney, fenToYuan } from "@/utils/money";
  104. const list = ref<any[]>();
  105. const price = ref();
  106. const orderDetail = ref();
  107. const order_coupon_detail_ref = ref();
  108. const handleClickDesc = () => {
  109. let {startChargeSeq,discountType} = orderDetail.value;
  110. order_coupon_detail_ref.value?.open(startChargeSeq,discountType);
  111. }
  112. // 复制文本
  113. const copyText = (text: string) => {
  114. uni.setClipboardData({
  115. data: text,
  116. success() {
  117. uni.showToast({
  118. title: "复制成功",
  119. icon: "success",
  120. duration: 1500
  121. });
  122. }
  123. });
  124. };
  125. onLoad((options: any) => {
  126. fetchOrder(options.id)
  127. .then((res) => {
  128. orderDetail.value = res;
  129. const discountAmount = fenToYuan(res.discountAmount);
  130. const discountAmountText = res.rightsDesc;
  131. const startChargeSeq = res.startChargeSeq;
  132. const start = parseDate(res.startTime);
  133. const end = res.endTime ? parseDate(res.endTime) : new Date();
  134. const time = formatDuration(start, end, 1);
  135. const _list = [
  136. {
  137. label: "充电站点",
  138. value: `${res.stationName}`,
  139. },
  140. {
  141. label: "累计充电量",
  142. value: `${res.totalPower}度`,
  143. },
  144. {
  145. label: "电费",
  146. value: `${formatMoney(res.elecMoney)}元`,
  147. },
  148. {
  149. label: "服务费",
  150. value: `${formatMoney(res.serviceMoney)}元`,
  151. },
  152. {
  153. label: "订单金额",
  154. value: `${formatMoney(res.totalMoney)}元`,
  155. },
  156. {
  157. label: "开始时间",
  158. value: res.startTime,
  159. color: "",
  160. },
  161. {
  162. label: "结束时间",
  163. value: res.chargeStatus === 2 ? "充电中" : res.endTime,
  164. },
  165. {
  166. label: "充电用时",
  167. value: time,
  168. }, {
  169. label: "订单号",
  170. value: startChargeSeq,
  171. copy:true
  172. },
  173. ];
  174. if (Number(discountAmount) > 0) {
  175. _list.splice(2, 0, {
  176. label: "优惠金额",
  177. value: `${
  178. Number(discountAmount) <= 0 ? "" : "-"
  179. }${discountAmount}元${discountAmountText}`,
  180. color: "#F43636",
  181. discount:true
  182. });
  183. }
  184. list.value = _list;
  185. price.value = fenToYuan(res.payAmount);
  186. })
  187. .catch(() => {
  188. uni.showModal({
  189. content: "出现错误,请退出重进",
  190. success() {
  191. uni.navigateBack();
  192. },
  193. });
  194. });
  195. });
  196. </script>
  197. <style lang="scss">
  198. .page-container {
  199. min-height: 100vh;
  200. padding-bottom: 40rpx;
  201. }
  202. /* 金额卡片 */
  203. .amount-card {
  204. background: var(--color-primary);
  205. box-shadow: 0 8rpx 24rpx rgba(45, 158, 149, 0.25);
  206. }
  207. /* 信息卡片 */
  208. .info-card {
  209. box-shadow: 0 2rpx 8rpx rgba(28, 43, 41, 0.04);
  210. }
  211. /* 充电详情网格 */
  212. .detail-grid {
  213. display: grid;
  214. grid-template-columns: 1fr 1fr;
  215. gap: 16rpx;
  216. }
  217. /* 操作按钮 */
  218. .btn-theme {
  219. background: var(--color-primary);
  220. transition: background-color 0.15s cubic-bezier(0.22, 1, 0.36, 1);
  221. box-shadow: 0 4rpx 12rpx rgba(45, 158, 149, 0.25);
  222. }
  223. .btn-theme.button-press {
  224. background: var(--color-primary-deep);
  225. }
  226. /* 加载状态 */
  227. .loading-state {
  228. min-height: 60vh;
  229. }
  230. .loading-icon {
  231. animation: spin 1s linear infinite;
  232. }
  233. @keyframes spin {
  234. from {
  235. transform: rotate(0deg);
  236. }
  237. to {
  238. transform: rotate(360deg);
  239. }
  240. }
  241. /* 工具类 */
  242. .bg-f5f7fa {
  243. background-color: var(--bg-page);
  244. }
  245. .bg-fff {
  246. background-color: #ffffff;
  247. }
  248. .bg-primary {
  249. background-color: var(--color-primary);
  250. }
  251. .bg-primary-light {
  252. background-color: var(--color-primary-tint);
  253. }
  254. .bg-success {
  255. background-color: var(--color-success);
  256. }
  257. .bg-success-light {
  258. background-color: rgba(52, 164, 108, 0.1);
  259. }
  260. .bg-theme {
  261. background-color: var(--color-primary);
  262. }
  263. .bg-theme-light {
  264. background-color: rgba(45, 158, 149, 0.1);
  265. }
  266. .br-12 {
  267. border-radius: 12rpx;
  268. }
  269. .br-16 {
  270. border-radius: 16rpx;
  271. }
  272. .br-20 {
  273. border-radius: 20rpx;
  274. }
  275. .mx-32 {
  276. margin-left: 32rpx;
  277. margin-right: 32rpx;
  278. }
  279. .mt-28 {
  280. margin-top: 28rpx;
  281. }
  282. .mt-32 {
  283. margin-top: 32rpx;
  284. }
  285. .mb-16 {
  286. margin-bottom: 16rpx;
  287. }
  288. .mb-24 {
  289. margin-bottom: 24rpx;
  290. }
  291. .mb-40 {
  292. margin-bottom: 40rpx;
  293. }
  294. .ml-12 {
  295. margin-left: 12rpx;
  296. }
  297. .ml-16 {
  298. margin-left: 16rpx;
  299. }
  300. .ml-24 {
  301. margin-left: 24rpx;
  302. }
  303. .mt-8 {
  304. margin-top: 8rpx;
  305. }
  306. .mt-16 {
  307. margin-top: 16rpx;
  308. }
  309. .p-24 {
  310. padding: 24rpx;
  311. }
  312. .p-36 {
  313. padding: 36rpx;
  314. }
  315. .p-40 {
  316. padding: 40rpx;
  317. }
  318. .pb-32 {
  319. padding-bottom: 32rpx;
  320. }
  321. .pt-32 {
  322. padding-top: 32rpx;
  323. }
  324. .py-20 {
  325. padding-top: 20rpx;
  326. padding-bottom: 20rpx;
  327. }
  328. .w-60 {
  329. width: 60rpx;
  330. }
  331. .h-60 {
  332. height: 60rpx;
  333. }
  334. .h-92 {
  335. height: 92rpx;
  336. }
  337. .flex-center {
  338. display: flex;
  339. align-items: center;
  340. justify-content: center;
  341. }
  342. .flex-align-center {
  343. display: flex;
  344. align-items: center;
  345. }
  346. .flex-column {
  347. display: flex;
  348. flex-direction: column;
  349. }
  350. .flex-grow {
  351. flex-grow: 1;
  352. }
  353. .justify-between {
  354. justify-content: space-between;
  355. }
  356. .items-center {
  357. align-items: center;
  358. }
  359. .border-b {
  360. border-bottom: 1rpx solid var(--divider);
  361. }
  362. .border-t {
  363. border-top: 1rpx solid var(--divider);
  364. }
  365. .border-eee {
  366. border-color: #eeeeee;
  367. }
  368. .shadow-sm {
  369. box-shadow: 0 2rpx 8rpx rgba(28, 43, 41, 0.04);
  370. }
  371. .shadow-md {
  372. box-shadow: 0 4rpx 16rpx rgba(28, 43, 41, 0.06);
  373. }
  374. .color-333 {
  375. color: #333333;
  376. }
  377. .color-666 {
  378. color: #666666;
  379. }
  380. .color-999 {
  381. color: #999999;
  382. }
  383. .color-fff {
  384. color: #ffffff;
  385. }
  386. .color-primary {
  387. color: var(--color-primary);
  388. }
  389. .color-success {
  390. color: var(--color-success);
  391. }
  392. .color-theme {
  393. color: var(--color-primary);
  394. }
  395. .fs-24 {
  396. font-size: 24rpx;
  397. }
  398. .fs-26 {
  399. font-size: 26rpx;
  400. }
  401. .fs-28 {
  402. font-size: 28rpx;
  403. }
  404. .fs-32 {
  405. font-size: 32rpx;
  406. }
  407. .fs-48 {
  408. font-size: 48rpx;
  409. }
  410. .fs-72 {
  411. font-size: 72rpx;
  412. }
  413. .lh-72 {
  414. line-height: 72rpx;
  415. }
  416. .fw-500 {
  417. font-weight: 500;
  418. }
  419. .fw-600 {
  420. font-weight: 600;
  421. }
  422. .opacity-80 {
  423. opacity: 0.8;
  424. }
  425. .cursor-pointer {
  426. cursor: pointer;
  427. }
  428. .w-full {
  429. width: 100%;
  430. }
  431. </style>