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. var that = this;
  162. uni.showLoading();
  163. weChatPayment(data).then(
  164. res => {
  165. if (res.code == 200) {
  166. console.log(res);
  167. if (res.payType == 1 || res.payType == 2) {
  168. var result = res.result;
  169. uni.requestPayment({
  170. provider: 'wxpay',
  171. timeStamp: result.timeStamp,
  172. nonceStr: result.nonceStr,
  173. package: result.package,
  174. signType: result.signType,
  175. paySign: result.paySign,
  176. success: function(res) {
  177. uni.hideLoading();
  178. uni.redirectTo({
  179. url: "./success?order=" + JSON.stringify(that.newOrder)
  180. })
  181. },
  182. fail: function(err) {
  183. uni.showToast({
  184. icon: 'none',
  185. title: 'fail:' + JSON.stringify(err),
  186. });
  187. uni.hideLoading();
  188. }
  189. });
  190. }
  191. } else {
  192. uni.showToast({
  193. icon: 'none',
  194. title: res.msg,
  195. });
  196. }
  197. },
  198. rej => {}
  199. );
  200. },
  201. payOrder() {
  202. if (this.type == 'win') {
  203. this.toPayConfirmReward()
  204. } else {
  205. if (this.payType == 1) {
  206. console.log("这个order", this.order)
  207. const {
  208. itemJson,
  209. ...newOrder
  210. } = this.order;
  211. this.newOrder = newOrder;
  212. console.log("这个newOrder", this.newOrder)
  213. this.weixinPayOrder()
  214. } else {
  215. uni.showToast({
  216. title: "暂时无可用支付",
  217. icon: 'none'
  218. })
  219. }
  220. }
  221. },
  222. // 选微信支付或者支付宝支付
  223. handlePayTypeChange(e) {
  224. this.payType = e.detail.value; // 获取选中的 value
  225. console.log('当前选中:', this.payType);
  226. },
  227. toPayConfirmReward() {
  228. let data = {
  229. orderId: this.order.orderId
  230. }
  231. payConfirmReward(data).then(
  232. res => {
  233. if (res.code == 200) {
  234. uni.showToast({
  235. icon: 'none',
  236. title: res.msg,
  237. });
  238. const {
  239. itemJson,
  240. ...newOrder
  241. } = this.order;
  242. uni.redirectTo({
  243. url: "./success?order=" + JSON.stringify(newOrder)
  244. })
  245. } else {
  246. uni.showToast({
  247. icon: 'none',
  248. title: "请求失败",
  249. });
  250. }
  251. },
  252. rej => {}
  253. );
  254. },
  255. getUserInfo() {
  256. getUserInfo().then(
  257. res => {
  258. if (res.code == 200) {
  259. if (res.user != null) {
  260. this.user = res.user;
  261. }
  262. } else {
  263. uni.showToast({
  264. icon: 'none',
  265. title: "请求失败",
  266. });
  267. }
  268. },
  269. rej => {}
  270. );
  271. },
  272. getStoreConfig() {
  273. getStoreConfig().then(
  274. res => {
  275. if (res.code == 200) {
  276. this.config = res.data
  277. console.log(this.config);
  278. }
  279. },
  280. rej => {}
  281. );
  282. },
  283. payTypeChange(e) {
  284. if (this.combinationOrderId) {
  285. this.editPayTypeByCombinationId(e.detail.value)
  286. } else {
  287. this.editPayType(e.detail.value)
  288. }
  289. },
  290. editPayType(payType) {
  291. var data = {
  292. orderId: this.orderId,
  293. payType: payType
  294. };
  295. this.payParams = data
  296. var that = this;
  297. uni.showLoading();
  298. editPayType(data).then(
  299. res => {
  300. if (res.code == 200) {
  301. console.log(res);
  302. uni.hideLoading();
  303. that.order = res.order;
  304. that.order.orderCodes = that.order.orderCode ? [that.order.orderCode] : []
  305. that.orderCode = that.order.orderCode
  306. // this.payType=this.order.payType
  307. this.payMoney = this.order.payMoney;
  308. this.payDelivery = this.order.payDelivery;
  309. } else {
  310. uni.showToast({
  311. icon: 'none',
  312. title: res.msg,
  313. });
  314. }
  315. },
  316. rej => {}
  317. );
  318. },
  319. }
  320. }
  321. </script>
  322. <style lang="scss">
  323. page {
  324. height: 100%;
  325. }
  326. .content {
  327. height: 100%;
  328. display: flex;
  329. flex-direction: column;
  330. justify-content: space-between;
  331. .inner {
  332. padding: 20upx;
  333. .time-price {
  334. box-sizing: border-box;
  335. padding: 50upx 0upx;
  336. background: #FFFFFF;
  337. border-radius: 16upx;
  338. display: flex;
  339. flex-direction: column;
  340. align-items: center;
  341. .time {
  342. font-size: 32upx;
  343. font-family: PingFang SC;
  344. font-weight: 500;
  345. color: #222222;
  346. line-height: 1;
  347. text-align: center;
  348. }
  349. .desc {
  350. margin: 30upx 0upx 15upx;
  351. font-size: 26upx;
  352. font-family: PingFang SC;
  353. color: #999999;
  354. line-height: 1;
  355. text-align: center;
  356. }
  357. .price-box {
  358. display: flex;
  359. align-items: flex-end;
  360. margin-top: 28upx;
  361. .unit {
  362. font-size: 32upx;
  363. font-family: PingFang SC;
  364. font-weight: bold;
  365. color: #FF6633;
  366. line-height: 1.3;
  367. margin-right: 10upx;
  368. }
  369. .num {
  370. font-size: 56upx;
  371. font-family: PingFang SC;
  372. font-weight: bold;
  373. color: #FF6633;
  374. line-height: 1;
  375. }
  376. }
  377. }
  378. .pay-type {
  379. box-sizing: border-box;
  380. background: #FFFFFF;
  381. border-radius: 16upx;
  382. margin-top: 20upx;
  383. padding: 40upx 30upx;
  384. display: flex;
  385. flex-direction: column;
  386. justify-content: space-between;
  387. .title {
  388. font-size: 28upx;
  389. font-family: PingFang SC;
  390. font-weight: 500;
  391. color: #999999;
  392. line-height: 1;
  393. margin-bottom: 10upx;
  394. }
  395. .item {
  396. padding: 15upx 0upx;
  397. display: flex;
  398. align-items: center;
  399. justify-content: space-between;
  400. .left {
  401. display: flex;
  402. align-items: center;
  403. image {
  404. width: 44upx;
  405. height: 44upx;
  406. margin-right: 20upx;
  407. }
  408. .text {
  409. font-size: 30upx;
  410. font-family: PingFang SC;
  411. font-weight: bold;
  412. color: #222222;
  413. line-height: 1;
  414. }
  415. }
  416. }
  417. }
  418. .order-info {
  419. margin-top: 20upx;
  420. background: #FFFFFF;
  421. border-radius: 16upx;
  422. padding: 40upx 30upx;
  423. .title {
  424. font-size: 30upx;
  425. font-family: PingFang SC;
  426. font-weight: bold;
  427. color: #222222;
  428. line-height: 1;
  429. }
  430. .item {
  431. margin-top: 40upx;
  432. display: flex;
  433. align-items: center;
  434. justify-content: space-between;
  435. .label {
  436. font-size: 26upx;
  437. font-family: PingFang SC;
  438. font-weight: 500;
  439. color: #666666;
  440. line-height: 1;
  441. }
  442. .text {
  443. font-size: 26upx;
  444. font-family: PingFang SC;
  445. font-weight: 500;
  446. color: #222222;
  447. line-height: 32upx;
  448. }
  449. .cont-text {
  450. font-size: 26upx;
  451. font-family: PingFang SC;
  452. font-weight: 500;
  453. color: #666666;
  454. .bold {
  455. color: #111111;
  456. }
  457. }
  458. .sn-box {
  459. display: flex;
  460. align-items: center;
  461. .copy-btn {
  462. width: 58upx;
  463. height: 32upx;
  464. line-height: 32upx;
  465. text-align: center;
  466. font-size: 22upx;
  467. font-weight: 500;
  468. color: #222222;
  469. background: #F5F5F5;
  470. border-radius: 4upx;
  471. margin-left: 24upx;
  472. }
  473. }
  474. }
  475. .line {
  476. width: 100%;
  477. height: 1px;
  478. background: #F0F0F0;
  479. margin-top: 30upx;
  480. }
  481. }
  482. }
  483. .btn-box {
  484. height: 242upx;
  485. background: #FFFFFF;
  486. display: flex;
  487. align-items: center;
  488. justify-content: center;
  489. flex-direction: column;
  490. .btn {
  491. width: 91.73%;
  492. height: 88upx;
  493. line-height: 88upx;
  494. font-size: 30upx;
  495. font-family: PingFang SC;
  496. font-weight: bold;
  497. color: #FFFFFF;
  498. text-align: center;
  499. background: #2BC7B9;
  500. border-radius: 44upx;
  501. margin-bottom: 10rpx;
  502. }
  503. .other-btn {
  504. width: 91.73%;
  505. height: 88upx;
  506. line-height: 88upx;
  507. font-size: 30upx;
  508. font-family: PingFang SC;
  509. font-weight: bold;
  510. color: #2BC7B9;
  511. border: 1rpx solid #2BC7B9;
  512. text-align: center;
  513. background: #FFFFFF;
  514. border-radius: 44upx;
  515. margin-bottom: 10rpx;
  516. position: relative;
  517. .share {
  518. display: inline-block;
  519. position: absolute;
  520. top: 0;
  521. left: 0;
  522. width: 100%;
  523. height: 100%;
  524. opacity: 0;
  525. }
  526. }
  527. }
  528. }
  529. </style>