payment.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  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: null,
  73. orderDetails: []
  74. }
  75. },
  76. onLoad(options) {
  77. if (options.orderId) {
  78. this.orderId = options.orderId;
  79. this.getOrderDetail();
  80. } else {
  81. uni.showToast({
  82. title: '订单参数错误',
  83. icon: 'none'
  84. });
  85. setTimeout(() => {
  86. uni.navigateBack();
  87. }, 1500);
  88. }
  89. },
  90. methods: {
  91. // 获取订单详情
  92. async getOrderDetail() {
  93. try {
  94. uni.showLoading({
  95. title: '加载中...'
  96. });
  97. const res = await getOrderPayDetail(this.orderId);
  98. if (res.code === 200 && res.data) {
  99. this.orderInfo = res.data.orderInfo;
  100. this.orderDetails = res.data.orderDetails;
  101. // 如果订单状态不是待付款,提示并返回
  102. if (this.orderInfo.status !== 1) {
  103. uni.showToast({
  104. title: '订单状态已改变',
  105. icon: 'none'
  106. });
  107. setTimeout(() => {
  108. uni.navigateBack();
  109. }, 1500);
  110. }
  111. } else {
  112. uni.showToast({
  113. title: res.msg || '获取订单信息失败',
  114. icon: 'none'
  115. });
  116. }
  117. } catch (e) {
  118. console.error('获取订单详情失败:', e);
  119. uni.showToast({
  120. title: '获取订单信息失败',
  121. icon: 'none'
  122. });
  123. } finally {
  124. uni.hideLoading();
  125. }
  126. },
  127. // 处理支付
  128. async handlePay() {
  129. if (!this.orderInfo) {
  130. return uni.showToast({
  131. title: '订单信息错误',
  132. icon: 'none'
  133. });
  134. }
  135. try {
  136. // 调用后端获取支付参数
  137. const payRes = await getWxPayParams(this.orderId);
  138. if (payRes.code !== 200 || !payRes.data) {
  139. throw new Error(payRes.msg || '获取支付参数失败');
  140. }
  141. // 调起微信支付
  142. uni.requestPayment({
  143. provider: 'wxpay',
  144. timeStamp: payRes.data.timestamp,
  145. nonceStr: payRes.data.noncestr,
  146. package: payRes.data.package,
  147. signType: payRes.data.signType,
  148. paySign: payRes.data.sign,
  149. success: (res) => {
  150. uni.showToast({
  151. title: '支付成功',
  152. icon: 'success'
  153. });
  154. // 支付成功后跳转到订单列表
  155. setTimeout(() => {
  156. uni.redirectTo({
  157. url: '/pages/order/list?status=2'
  158. });
  159. }, 1500);
  160. },
  161. fail: (err) => {
  162. console.error('支付失败:', err);
  163. uni.showToast({
  164. title: '支付失败',
  165. icon: 'none'
  166. });
  167. }
  168. });
  169. } catch (e) {
  170. console.error('支付异常:', e);
  171. uni.showToast({
  172. title: e.message || '支付失败',
  173. icon: 'none'
  174. });
  175. }
  176. }
  177. }
  178. }
  179. </script>
  180. <style lang="scss">
  181. .payment-container {
  182. min-height: 100vh;
  183. background-color: #f8f8f8;
  184. padding-bottom: 120rpx;
  185. }
  186. .address-section {
  187. background-color: #fff;
  188. padding: 30rpx;
  189. margin-bottom: 20rpx;
  190. .address-content {
  191. .contact-info {
  192. margin-bottom: 10rpx;
  193. .name {
  194. margin-right: 20rpx;
  195. font-weight: bold;
  196. }
  197. .phone {
  198. color: #666;
  199. }
  200. }
  201. .address-detail {
  202. color: #333;
  203. font-size: 28rpx;
  204. }
  205. }
  206. }
  207. .goods-section {
  208. background-color: #fff;
  209. padding: 30rpx;
  210. margin-bottom: 20rpx;
  211. .goods-title {
  212. font-size: 32rpx;
  213. font-weight: bold;
  214. margin-bottom: 20rpx;
  215. }
  216. .goods-item {
  217. display: flex;
  218. margin-bottom: 20rpx;
  219. .goods-img {
  220. width: 160rpx;
  221. height: 160rpx;
  222. margin-right: 20rpx;
  223. border-radius: 8rpx;
  224. }
  225. .goods-info {
  226. flex: 1;
  227. .goods-name {
  228. font-size: 28rpx;
  229. margin-bottom: 10rpx;
  230. }
  231. .goods-spec {
  232. font-size: 24rpx;
  233. color: #666;
  234. margin-bottom: 10rpx;
  235. }
  236. .price-num {
  237. display: flex;
  238. justify-content: space-between;
  239. .price {
  240. color: #ff4d4f;
  241. font-weight: bold;
  242. }
  243. .num {
  244. color: #666;
  245. }
  246. }
  247. }
  248. }
  249. }
  250. .pay-section {
  251. background-color: #fff;
  252. padding: 30rpx;
  253. margin-bottom: 20rpx;
  254. .pay-title {
  255. font-size: 32rpx;
  256. font-weight: bold;
  257. margin-bottom: 20rpx;
  258. }
  259. .method-item {
  260. display: flex;
  261. align-items: center;
  262. .pay-icon {
  263. width: 40rpx;
  264. height: 40rpx;
  265. margin-right: 20rpx;
  266. }
  267. }
  268. }
  269. .amount-section {
  270. background-color: #fff;
  271. padding: 30rpx;
  272. .amount-item {
  273. display: flex;
  274. justify-content: space-between;
  275. margin-bottom: 20rpx;
  276. font-size: 28rpx;
  277. &.total {
  278. margin-top: 20rpx;
  279. padding-top: 20rpx;
  280. border-top: 1px solid #eee;
  281. .total-price {
  282. color: #ff4d4f;
  283. font-weight: bold;
  284. font-size: 32rpx;
  285. }
  286. }
  287. }
  288. }
  289. .footer {
  290. position: fixed;
  291. bottom: 0;
  292. left: 0;
  293. right: 0;
  294. height: 100rpx;
  295. background-color: #fff;
  296. display: flex;
  297. align-items: center;
  298. padding: 0 30rpx;
  299. box-shadow: 0 -2rpx 10rpx rgba(0,0,0,0.05);
  300. .total-section {
  301. flex: 1;
  302. .total-price {
  303. color: #ff4d4f;
  304. font-weight: bold;
  305. font-size: 36rpx;
  306. }
  307. }
  308. .pay-btn {
  309. width: 240rpx;
  310. height: 80rpx;
  311. background-color: #ff4d4f;
  312. color: #fff;
  313. display: flex;
  314. align-items: center;
  315. justify-content: center;
  316. border-radius: 40rpx;
  317. font-size: 32rpx;
  318. }
  319. }
  320. </style>