paymentOrder.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537
  1. <template>
  2. <view class="content">
  3. <view class="inner">
  4. <!-- 时间、价格 -->
  5. <view class="time-price">
  6. <text class="time">待支付</text>
  7. <view class="price-box">
  8. <text class="unit">¥</text>
  9. <text class="num">{{order ? (Number(order.payMoney) || 0).toFixed(2) : "0.00"}}</text>
  10. </view>
  11. </view>
  12. <!-- 支付方式 -->
  13. <view class="pay-type">
  14. <view class="title">支付方式</view>
  15. <radio-group @change="handlePayTypeChange">
  16. <view class="item">
  17. <view class="left">
  18. <image src="/static/images/wecha_pay.png" mode=""></image>
  19. <text class="text">微信支付</text>
  20. </view>
  21. <label>
  22. <radio :value="1" :checked="payType === 1" />
  23. </label>
  24. </view>
  25. <!-- #ifdef APP-PLUS||H5 -->
  26. <view class="item">
  27. <view class="left">
  28. <image src="/static/images/zfb.png" mode=""></image>
  29. <text class="text">支付宝</text>
  30. </view>
  31. <label>
  32. <radio :value="2" :checked="payType === 2" />
  33. </label>
  34. </view>
  35. <!-- #endif -->
  36. </radio-group>
  37. </view>
  38. <!-- 订单详情查看 -->
  39. <view class="order-info">
  40. <view class="title">订单信息</view>
  41. <view class="item">
  42. <text class="label">订单编号</text>
  43. <view class="sn-box">
  44. <view>
  45. <view class="text">{{order.orderCode}}</view>
  46. </view>
  47. </view>
  48. </view>
  49. <view class="item">
  50. <text class="label">下单时间</text>
  51. <text class="text">{{ formattedDate}} </text>
  52. </view>
  53. <view class="item">
  54. <text class="label">订单金额</text>
  55. <text class="text"
  56. v-if="order!=null">{{order ? (Number(order.totalPrice) || 0).toFixed(2) : "0.00"}}</text>
  57. </view>
  58. <view class="item">
  59. <text class="label">优惠券</text>
  60. <text class="text">-¥{{order ? (Number(order.discountMoney) || 0).toFixed(2) : "0.00"}} </text>
  61. </view>
  62. </view>
  63. </view>
  64. <view class="btn-box">
  65. <view class="btn" @click="payOrder()">去支付</view>
  66. </view>
  67. </view>
  68. </template>
  69. <script>
  70. import dayjs from 'dayjs';
  71. import {
  72. weChatPayment
  73. } from '@/api/pay_new'
  74. import {
  75. zfbPayment,
  76. // weChatPayment
  77. } from '@/api/pay'
  78. export default {
  79. data() {
  80. return {
  81. payPrice: null,
  82. newOrder: {},
  83. payType: 2,
  84. order: null,
  85. orderId: null,
  86. payDelivery: 0,
  87. payMoney: 0,
  88. config: null,
  89. payType: 1,
  90. user: null,
  91. couponUserId: null
  92. }
  93. },
  94. computed: {
  95. formattedDate() {
  96. return this.order?.createTime ? dayjs(this.order.createTime).format('YYYY-MM-DD HH:mm:ss') : '';
  97. },
  98. payLimitTime() {
  99. return this.order?.updateTime ?
  100. dayjs(this.order.updateTime).add(2, 'day').format('YYYY-MM-DD HH:mm:ss') :
  101. '';
  102. }
  103. },
  104. onLoad(options) {
  105. // if (options.payPrice) {
  106. // this.payPrice = options.payPrice;
  107. // }
  108. if (options.couponUserId) {
  109. this.couponUserId = options.couponUserId;
  110. }
  111. console.log("支付订单是>>", options)
  112. // this.orderKey = options.orderKey;
  113. // this.liveId = options.liveId
  114. // this.productId=options.productId
  115. // console.log("支付订单",options)
  116. if (options.orderList) {
  117. try {
  118. const decoded = decodeURIComponent(options.orderList);
  119. this.order = JSON.parse(decoded) || {}; // 默认空对象
  120. } catch (e) {
  121. console.error('参数解析失败:', e);
  122. this.order = {}; // 显式赋默认值
  123. }
  124. }
  125. },
  126. // //发送给朋友
  127. // onShareAppMessage(res) {
  128. // const combinationOrderId = this.combinationOrderId ?
  129. // `&combinationOrderId=${encodeURIComponent(this.combinationOrderId)}` : ''
  130. // return {
  131. // title: "帮TA支付",
  132. // path: '/pages_user/user/otherPaymentOrder?orderId=' + this.orderId + combinationOrderId,
  133. // imageUrl: '/static/images/logo.png' //分享图标,路径可以是本地文件路径、代码包文件路径或者网络图片路径.支持PNG及JPG。显示图片长宽比是 5:4
  134. // }
  135. // },
  136. methods: {
  137. weixinPayOrder() {
  138. var data = {
  139. orderId: this.order.orderId,
  140. payType: 1
  141. // payType: this.order.payType
  142. };
  143. var that = this;
  144. uni.showLoading();
  145. weChatPayment(data).then(
  146. res => {
  147. if (res.code == 200) {
  148. console.log(res);
  149. if (res.payType == 1 || res.payType == 2) {
  150. var result = JSON.parse(res.result);
  151. uni.requestPayment({
  152. provider: 'wxpay',
  153. timeStamp: result.timeStamp,
  154. nonceStr: result.nonceStr,
  155. package: result.package,
  156. signType: result.signType,
  157. paySign: result.paySign,
  158. success: function(res) {
  159. uni.hideLoading();
  160. uni.redirectTo({
  161. url: "./success?order=" + JSON.stringify(that.newOrder)
  162. })
  163. },
  164. fail: function(err) {
  165. uni.showToast({
  166. icon: 'none',
  167. title: 'fail:' + JSON.stringify(err),
  168. });
  169. uni.hideLoading();
  170. }
  171. });
  172. }
  173. } else {
  174. uni.showToast({
  175. icon: 'none',
  176. title: res.msg,
  177. });
  178. }
  179. },
  180. rej => {}
  181. );
  182. },
  183. payOrder() {
  184. if (this.payType == 1) {
  185. // this.doWechatPay()
  186. console.log("这个order", this.order)
  187. const {
  188. itemJson,
  189. ...newOrder
  190. } = this.order;
  191. this.newOrder = newOrder;
  192. console.log("这个newOrder", this.newOrder)
  193. this.weixinPayOrder()
  194. } else if (this.payType == 2) {
  195. this.doAlipay()
  196. } else {
  197. uni.showToast({
  198. title: "暂时无可用支付",
  199. icon: 'none'
  200. })
  201. }
  202. },
  203. // 选微信支付或者支付宝支付
  204. handlePayTypeChange(e) {
  205. this.payType = e.detail.value; // 获取选中的 value
  206. console.log('当前选中:', this.payType);
  207. },
  208. getUserInfo() {
  209. getUserInfo().then(
  210. res => {
  211. if (res.code == 200) {
  212. if (res.user != null) {
  213. this.user = res.user;
  214. }
  215. } else {
  216. uni.showToast({
  217. icon: 'none',
  218. title: "请求失败",
  219. });
  220. }
  221. },
  222. rej => {}
  223. );
  224. },
  225. getStoreConfig() {
  226. getStoreConfig().then(
  227. res => {
  228. if (res.code == 200) {
  229. this.config = res.data
  230. console.log(this.config);
  231. }
  232. },
  233. rej => {}
  234. );
  235. },
  236. payTypeChange(e) {
  237. if (this.combinationOrderId) {
  238. this.editPayTypeByCombinationId(e.detail.value)
  239. } else {
  240. this.editPayType(e.detail.value)
  241. }
  242. },
  243. editPayType(payType) {
  244. var data = {
  245. orderId: this.orderId,
  246. payType: payType
  247. };
  248. var that = this;
  249. uni.showLoading();
  250. editPayType(data).then(
  251. res => {
  252. if (res.code == 200) {
  253. console.log(res);
  254. uni.hideLoading();
  255. that.order = res.order;
  256. that.order.orderCodes = that.order.orderCode ? [that.order.orderCode] : []
  257. that.orderCode = that.order.orderCode
  258. // this.payType=this.order.payType
  259. this.payMoney = this.order.payMoney;
  260. this.payDelivery = this.order.payDelivery;
  261. } else {
  262. uni.showToast({
  263. icon: 'none',
  264. title: res.msg,
  265. });
  266. }
  267. },
  268. rej => {}
  269. );
  270. },
  271. }
  272. }
  273. </script>
  274. <style lang="scss">
  275. page {
  276. height: 100%;
  277. }
  278. .content {
  279. height: 100%;
  280. display: flex;
  281. flex-direction: column;
  282. justify-content: space-between;
  283. .inner {
  284. padding: 20upx;
  285. .time-price {
  286. box-sizing: border-box;
  287. padding: 50upx 0upx;
  288. background: #FFFFFF;
  289. border-radius: 16upx;
  290. display: flex;
  291. flex-direction: column;
  292. align-items: center;
  293. .time {
  294. font-size: 32upx;
  295. font-family: PingFang SC;
  296. font-weight: 500;
  297. color: #222222;
  298. line-height: 1;
  299. text-align: center;
  300. }
  301. .desc {
  302. margin: 30upx 0upx 15upx;
  303. font-size: 26upx;
  304. font-family: PingFang SC;
  305. color: #999999;
  306. line-height: 1;
  307. text-align: center;
  308. }
  309. .price-box {
  310. display: flex;
  311. align-items: flex-end;
  312. margin-top: 28upx;
  313. .unit {
  314. font-size: 32upx;
  315. font-family: PingFang SC;
  316. font-weight: bold;
  317. color: #FF6633;
  318. line-height: 1.3;
  319. margin-right: 10upx;
  320. }
  321. .num {
  322. font-size: 56upx;
  323. font-family: PingFang SC;
  324. font-weight: bold;
  325. color: #FF6633;
  326. line-height: 1;
  327. }
  328. }
  329. }
  330. .pay-type {
  331. box-sizing: border-box;
  332. background: #FFFFFF;
  333. border-radius: 16upx;
  334. margin-top: 20upx;
  335. padding: 40upx 30upx;
  336. display: flex;
  337. flex-direction: column;
  338. justify-content: space-between;
  339. .title {
  340. font-size: 28upx;
  341. font-family: PingFang SC;
  342. font-weight: 500;
  343. color: #999999;
  344. line-height: 1;
  345. margin-bottom: 10upx;
  346. }
  347. .item {
  348. padding: 15upx 0upx;
  349. display: flex;
  350. align-items: center;
  351. justify-content: space-between;
  352. .left {
  353. display: flex;
  354. align-items: center;
  355. image {
  356. width: 44upx;
  357. height: 44upx;
  358. margin-right: 20upx;
  359. }
  360. .text {
  361. font-size: 30upx;
  362. font-family: PingFang SC;
  363. font-weight: bold;
  364. color: #222222;
  365. line-height: 1;
  366. }
  367. }
  368. }
  369. }
  370. .order-info {
  371. margin-top: 20upx;
  372. background: #FFFFFF;
  373. border-radius: 16upx;
  374. padding: 40upx 30upx;
  375. .title {
  376. font-size: 30upx;
  377. font-family: PingFang SC;
  378. font-weight: bold;
  379. color: #222222;
  380. line-height: 1;
  381. }
  382. .item {
  383. margin-top: 40upx;
  384. display: flex;
  385. align-items: center;
  386. justify-content: space-between;
  387. .label {
  388. font-size: 26upx;
  389. font-family: PingFang SC;
  390. font-weight: 500;
  391. color: #666666;
  392. line-height: 1;
  393. }
  394. .text {
  395. font-size: 26upx;
  396. font-family: PingFang SC;
  397. font-weight: 500;
  398. color: #222222;
  399. line-height: 32upx;
  400. }
  401. .cont-text {
  402. font-size: 26upx;
  403. font-family: PingFang SC;
  404. font-weight: 500;
  405. color: #666666;
  406. .bold {
  407. color: #111111;
  408. }
  409. }
  410. .sn-box {
  411. display: flex;
  412. align-items: center;
  413. .copy-btn {
  414. width: 58upx;
  415. height: 32upx;
  416. line-height: 32upx;
  417. text-align: center;
  418. font-size: 22upx;
  419. font-weight: 500;
  420. color: #222222;
  421. background: #F5F5F5;
  422. border-radius: 4upx;
  423. margin-left: 24upx;
  424. }
  425. }
  426. }
  427. .line {
  428. width: 100%;
  429. height: 1px;
  430. background: #F0F0F0;
  431. margin-top: 30upx;
  432. }
  433. }
  434. }
  435. .btn-box {
  436. height: 242upx;
  437. background: #FFFFFF;
  438. display: flex;
  439. align-items: center;
  440. justify-content: center;
  441. flex-direction: column;
  442. .btn {
  443. width: 91.73%;
  444. height: 88upx;
  445. line-height: 88upx;
  446. font-size: 30upx;
  447. font-family: PingFang SC;
  448. font-weight: bold;
  449. color: #FFFFFF;
  450. text-align: center;
  451. background: #2BC7B9;
  452. border-radius: 44upx;
  453. margin-bottom: 10rpx;
  454. }
  455. .other-btn {
  456. width: 91.73%;
  457. height: 88upx;
  458. line-height: 88upx;
  459. font-size: 30upx;
  460. font-family: PingFang SC;
  461. font-weight: bold;
  462. color: #2BC7B9;
  463. border: 1rpx solid #2BC7B9;
  464. text-align: center;
  465. background: #FFFFFF;
  466. border-radius: 44upx;
  467. margin-bottom: 10rpx;
  468. position: relative;
  469. .share {
  470. display: inline-block;
  471. position: absolute;
  472. top: 0;
  473. left: 0;
  474. width: 100%;
  475. height: 100%;
  476. opacity: 0;
  477. }
  478. }
  479. }
  480. }
  481. </style>