index.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. <template>
  2. <view class="payment-container">
  3. <!-- 收货地址 -->
  4. <view class="address-section">
  5. <view class="address-content" v-if="orderInfo">
  6. <view class="contact-info">
  7. <text class="name">{{orderInfo.name}}</text>
  8. <text class="phone">{{orderInfo.mobile}}</text>
  9. </view>
  10. <view class="address-detail">
  11. {{orderInfo.province}}{{orderInfo.city}}{{orderInfo.area}}{{orderInfo.address}}
  12. </view>
  13. </view>
  14. </view>
  15. <!-- 商品信息 -->
  16. <view class="goods-section">
  17. <view class="goods-title">商品信息</view>
  18. <view class="goods-item" v-for="(item, index) in orderDetails" :key="index">
  19. <image :src="item.productImage" mode="aspectFill" class="goods-img"></image>
  20. <view class="goods-info">
  21. <view class="goods-name">{{item.productName}}</view>
  22. <view class="goods-spec">{{item.skuName}}</view>
  23. <view class="price-num">
  24. <text class="price">¥{{item.unitPrice}}</text>
  25. <text class="num">x{{item.quantity}}</text>
  26. </view>
  27. </view>
  28. </view>
  29. </view>
  30. <!-- 支付方式 -->
  31. <view class="pay-section">
  32. <view class="pay-title">支付方式</view>
  33. <view class="pay-method">
  34. <view class="method-item">
  35. <image src="/static/images/wxpay.png" mode="aspectFit" class="pay-icon"></image>
  36. <text>微信支付</text>
  37. </view>
  38. </view>
  39. </view>
  40. <!-- 订单金额信息 -->
  41. <view class="amount-section">
  42. <view class="amount-item">
  43. <text>商品总价</text>
  44. <text>¥{{orderInfo.paymentPrice}}</text>
  45. </view>
  46. <view class="amount-item total">
  47. <text>实付金额</text>
  48. <text class="total-price">¥{{orderInfo.paymentPrice}}</text>
  49. </view>
  50. </view>
  51. <!-- 底部支付按钮 -->
  52. <view class="footer">
  53. <view class="total-section">
  54. <text>实付金额:</text>
  55. <text class="total-price">¥{{orderInfo.paymentPrice}}</text>
  56. </view>
  57. <view class="pay-btn" @click="handlePay">
  58. 立即支付
  59. </view>
  60. </view>
  61. </view>
  62. </template>
  63. <script>
  64. import {
  65. getOrderPayDetail,
  66. getWxPayParams
  67. } from '@/config/api.js';
  68. export default {
  69. data() {
  70. return {
  71. orderId: '',
  72. orderInfo: {},
  73. orderDetails: []
  74. }
  75. },
  76. onLoad(options) {
  77. if (options.orderId) {
  78. console.log(this.orderId, "ORDER")
  79. this.orderId = options.orderId;
  80. this.getOrderDetail();
  81. } else {
  82. uni.showToast({
  83. title: '订单参数错误',
  84. icon: 'none'
  85. });
  86. setTimeout(() => {
  87. uni.navigateBack();
  88. }, 1500);
  89. }
  90. },
  91. methods: {
  92. // 获取订单详情
  93. async getOrderDetail() {
  94. try {
  95. uni.showLoading({
  96. title: '加载中...'
  97. });
  98. const res = await getOrderPayDetail(this.orderId);
  99. if (res.code === 200 && res.data) {
  100. this.orderInfo = res.data.orderInfo.order;
  101. this.orderDetails = res.data.orderDetails;
  102. // 如果订单状态不是待付款,提示并返回
  103. if (this.orderInfo.status !== 1) {
  104. uni.showToast({
  105. title: '订单状态已改变',
  106. icon: 'none'
  107. });
  108. setTimeout(() => {
  109. uni.navigateBack();
  110. }, 1500);
  111. }
  112. } else {
  113. uni.showToast({
  114. title: res.msg || '获取订单信息失败',
  115. icon: 'none'
  116. });
  117. }
  118. } catch (e) {
  119. console.error('获取订单详情失败:', e);
  120. uni.showToast({
  121. title: '获取订单信息失败',
  122. icon: 'none'
  123. });
  124. } finally {
  125. uni.hideLoading();
  126. }
  127. },
  128. // 处理支付
  129. async handlePay() {
  130. if (!this.orderInfo) {
  131. return uni.showToast({
  132. title: '订单信息错误',
  133. icon: 'none'
  134. });
  135. }
  136. try {
  137. // 调用后端获取支付参数
  138. const payRes = await getWxPayParams(this.orderId);
  139. if (payRes.code !== 200 || !payRes.data) {
  140. throw new Error(payRes.msg || '获取支付参数失败');
  141. }
  142. // 调起微信支付
  143. uni.requestPayment({
  144. provider: 'wxpay',
  145. timeStamp: payRes.data.timestamp,
  146. nonceStr: payRes.data.noncestr,
  147. package: payRes.data.package,
  148. signType: payRes.data.signType,
  149. paySign: payRes.data.sign,
  150. success: (res) => {
  151. uni.showToast({
  152. title: '支付成功',
  153. icon: 'success'
  154. });
  155. // 支付成功后跳转到订单列表
  156. setTimeout(() => {
  157. uni.redirectTo({
  158. url: '/packageOrder/pages/list/index?status=2'
  159. });
  160. }, 1500);
  161. },
  162. fail: (err) => {
  163. console.error('支付失败:', err);
  164. uni.showToast({
  165. title: '支付失败',
  166. icon: 'none'
  167. });
  168. setTimeout(() => {
  169. uni.redirectTo({
  170. url: '/packageOrder/pages/list/index?status=1'
  171. });
  172. }, 1000);
  173. }
  174. });
  175. } catch (e) {
  176. console.error('支付异常:', e);
  177. uni.showToast({
  178. title: e.message || '支付失败',
  179. icon: 'none'
  180. });
  181. }
  182. }
  183. }
  184. }
  185. </script>
  186. <style lang="scss">
  187. .payment-container {
  188. min-height: 100vh;
  189. background-color: #f8f8f8;
  190. padding-bottom: 120rpx;
  191. }
  192. .address-section {
  193. background-color: #fff;
  194. padding: 30rpx;
  195. margin-bottom: 20rpx;
  196. .address-content {
  197. .contact-info {
  198. margin-bottom: 10rpx;
  199. .name {
  200. font-size: 32rpx;
  201. font-weight: bold;
  202. margin-right: 20rpx;
  203. }
  204. .phone {
  205. font-size: 28rpx;
  206. color: #666;
  207. }
  208. }
  209. .address-detail {
  210. font-size: 28rpx;
  211. color: #333;
  212. line-height: 1.4;
  213. }
  214. }
  215. }
  216. .goods-section {
  217. background-color: #fff;
  218. margin-bottom: 20rpx;
  219. .goods-title {
  220. font-size: 32rpx;
  221. font-weight: bold;
  222. padding: 30rpx;
  223. border-bottom: 1rpx solid #f5f5f5;
  224. }
  225. .goods-item {
  226. display: flex;
  227. padding: 30rpx;
  228. border-bottom: 1rpx solid #f5f5f5;
  229. .goods-img {
  230. width: 160rpx;
  231. height: 160rpx;
  232. border-radius: 8rpx;
  233. margin-right: 20rpx;
  234. }
  235. .goods-info {
  236. flex: 1;
  237. .goods-name {
  238. font-size: 28rpx;
  239. color: #333;
  240. margin-bottom: 10rpx;
  241. }
  242. .goods-spec {
  243. font-size: 24rpx;
  244. color: #999;
  245. margin-bottom: 20rpx;
  246. }
  247. .price-num {
  248. display: flex;
  249. justify-content: space-between;
  250. align-items: center;
  251. .price {
  252. font-size: 32rpx;
  253. color: #ff4b4b;
  254. font-weight: bold;
  255. }
  256. .num {
  257. font-size: 28rpx;
  258. color: #999;
  259. }
  260. }
  261. }
  262. }
  263. }
  264. .pay-section {
  265. background-color: #fff;
  266. margin-bottom: 20rpx;
  267. .pay-title {
  268. font-size: 32rpx;
  269. font-weight: bold;
  270. padding: 30rpx;
  271. border-bottom: 1rpx solid #f5f5f5;
  272. }
  273. .pay-method {
  274. padding: 30rpx;
  275. .method-item {
  276. display: flex;
  277. align-items: center;
  278. .pay-icon {
  279. width: 48rpx;
  280. height: 48rpx;
  281. margin-right: 20rpx;
  282. }
  283. text {
  284. font-size: 28rpx;
  285. color: #333;
  286. }
  287. }
  288. }
  289. }
  290. .amount-section {
  291. background-color: #fff;
  292. padding: 30rpx;
  293. .amount-item {
  294. display: flex;
  295. justify-content: space-between;
  296. margin-bottom: 20rpx;
  297. text {
  298. font-size: 28rpx;
  299. color: #666;
  300. }
  301. &.total {
  302. margin-top: 30rpx;
  303. border-top: 1rpx solid #f5f5f5;
  304. padding-top: 30rpx;
  305. text {
  306. font-size: 32rpx;
  307. color: #333;
  308. font-weight: bold;
  309. &.total-price {
  310. color: #ff4b4b;
  311. }
  312. }
  313. }
  314. }
  315. }
  316. .footer {
  317. position: fixed;
  318. left: 0;
  319. right: 0;
  320. bottom: 0;
  321. height: 100rpx;
  322. background-color: #fff;
  323. display: flex;
  324. align-items: center;
  325. padding: 0rpx 30rpx;
  326. box-shadow: 0 -2rpx 10rpx rgba(0, 0, 0, 0.05);
  327. .total-section {
  328. flex: 1;
  329. text {
  330. font-size: 28rpx;
  331. color: #333;
  332. &.total-price {
  333. font-size: 36rpx;
  334. color: #ff4b4b;
  335. font-weight: bold;
  336. }
  337. }
  338. }
  339. .pay-btn {
  340. width: 240rpx;
  341. height: 80rpx;
  342. background-color: #F95B5B;
  343. color: #fff;
  344. font-size: 32rpx;
  345. font-weight: bold;
  346. border-radius: 40rpx;
  347. display: flex;
  348. align-items: center;
  349. justify-content: center;
  350. }
  351. }
  352. </style>