paymentOrder.vue 12 KB

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