paymentOrder.vue 12 KB

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