paymentOrder.vue 12 KB

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