paymentOrder.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  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. const {
  225. itemJson,
  226. ...newOrder
  227. } = this.order;
  228. uni.redirectTo({
  229. url: "./success?order=" + JSON.stringify(newOrder)
  230. })
  231. } else {
  232. uni.showToast({
  233. icon: 'none',
  234. title: "请求失败",
  235. });
  236. }
  237. },
  238. rej => {}
  239. );
  240. },
  241. getUserInfo() {
  242. getUserInfo().then(
  243. res => {
  244. if (res.code == 200) {
  245. if (res.user != null) {
  246. this.user = res.user;
  247. }
  248. } else {
  249. uni.showToast({
  250. icon: 'none',
  251. title: "请求失败",
  252. });
  253. }
  254. },
  255. rej => {}
  256. );
  257. },
  258. getStoreConfig() {
  259. getStoreConfig().then(
  260. res => {
  261. if (res.code == 200) {
  262. this.config = res.data
  263. console.log(this.config);
  264. }
  265. },
  266. rej => {}
  267. );
  268. },
  269. payTypeChange(e) {
  270. if (this.combinationOrderId) {
  271. this.editPayTypeByCombinationId(e.detail.value)
  272. } else {
  273. this.editPayType(e.detail.value)
  274. }
  275. },
  276. editPayType(payType) {
  277. var data = {
  278. orderId: this.orderId,
  279. payType: payType
  280. };
  281. var that = this;
  282. uni.showLoading();
  283. editPayType(data).then(
  284. res => {
  285. if (res.code == 200) {
  286. console.log(res);
  287. uni.hideLoading();
  288. that.order = res.order;
  289. that.order.orderCodes = that.order.orderCode ? [that.order.orderCode] : []
  290. that.orderCode = that.order.orderCode
  291. // this.payType=this.order.payType
  292. this.payMoney = this.order.payMoney;
  293. this.payDelivery = this.order.payDelivery;
  294. } else {
  295. uni.showToast({
  296. icon: 'none',
  297. title: res.msg,
  298. });
  299. }
  300. },
  301. rej => {}
  302. );
  303. },
  304. }
  305. }
  306. </script>
  307. <style lang="scss">
  308. page {
  309. height: 100%;
  310. }
  311. .content {
  312. height: 100%;
  313. display: flex;
  314. flex-direction: column;
  315. justify-content: space-between;
  316. .inner {
  317. padding: 20upx;
  318. .time-price {
  319. box-sizing: border-box;
  320. padding: 50upx 0upx;
  321. background: #FFFFFF;
  322. border-radius: 16upx;
  323. display: flex;
  324. flex-direction: column;
  325. align-items: center;
  326. .time {
  327. font-size: 32upx;
  328. font-family: PingFang SC;
  329. font-weight: 500;
  330. color: #222222;
  331. line-height: 1;
  332. text-align: center;
  333. }
  334. .desc {
  335. margin: 30upx 0upx 15upx;
  336. font-size: 26upx;
  337. font-family: PingFang SC;
  338. color: #999999;
  339. line-height: 1;
  340. text-align: center;
  341. }
  342. .price-box {
  343. display: flex;
  344. align-items: flex-end;
  345. margin-top: 28upx;
  346. .unit {
  347. font-size: 32upx;
  348. font-family: PingFang SC;
  349. font-weight: bold;
  350. color: #FF6633;
  351. line-height: 1.3;
  352. margin-right: 10upx;
  353. }
  354. .num {
  355. font-size: 56upx;
  356. font-family: PingFang SC;
  357. font-weight: bold;
  358. color: #FF6633;
  359. line-height: 1;
  360. }
  361. }
  362. }
  363. .pay-type {
  364. box-sizing: border-box;
  365. background: #FFFFFF;
  366. border-radius: 16upx;
  367. margin-top: 20upx;
  368. padding: 40upx 30upx;
  369. display: flex;
  370. flex-direction: column;
  371. justify-content: space-between;
  372. .title {
  373. font-size: 28upx;
  374. font-family: PingFang SC;
  375. font-weight: 500;
  376. color: #999999;
  377. line-height: 1;
  378. margin-bottom: 10upx;
  379. }
  380. .item {
  381. padding: 15upx 0upx;
  382. display: flex;
  383. align-items: center;
  384. justify-content: space-between;
  385. .left {
  386. display: flex;
  387. align-items: center;
  388. image {
  389. width: 44upx;
  390. height: 44upx;
  391. margin-right: 20upx;
  392. }
  393. .text {
  394. font-size: 30upx;
  395. font-family: PingFang SC;
  396. font-weight: bold;
  397. color: #222222;
  398. line-height: 1;
  399. }
  400. }
  401. }
  402. }
  403. .order-info {
  404. margin-top: 20upx;
  405. background: #FFFFFF;
  406. border-radius: 16upx;
  407. padding: 40upx 30upx;
  408. .title {
  409. font-size: 30upx;
  410. font-family: PingFang SC;
  411. font-weight: bold;
  412. color: #222222;
  413. line-height: 1;
  414. }
  415. .item {
  416. margin-top: 40upx;
  417. display: flex;
  418. align-items: center;
  419. justify-content: space-between;
  420. .label {
  421. font-size: 26upx;
  422. font-family: PingFang SC;
  423. font-weight: 500;
  424. color: #666666;
  425. line-height: 1;
  426. }
  427. .text {
  428. font-size: 26upx;
  429. font-family: PingFang SC;
  430. font-weight: 500;
  431. color: #222222;
  432. line-height: 32upx;
  433. }
  434. .cont-text {
  435. font-size: 26upx;
  436. font-family: PingFang SC;
  437. font-weight: 500;
  438. color: #666666;
  439. .bold {
  440. color: #111111;
  441. }
  442. }
  443. .sn-box {
  444. display: flex;
  445. align-items: center;
  446. .copy-btn {
  447. width: 58upx;
  448. height: 32upx;
  449. line-height: 32upx;
  450. text-align: center;
  451. font-size: 22upx;
  452. font-weight: 500;
  453. color: #222222;
  454. background: #F5F5F5;
  455. border-radius: 4upx;
  456. margin-left: 24upx;
  457. }
  458. }
  459. }
  460. .line {
  461. width: 100%;
  462. height: 1px;
  463. background: #F0F0F0;
  464. margin-top: 30upx;
  465. }
  466. }
  467. }
  468. .btn-box {
  469. height: 242upx;
  470. background: #FFFFFF;
  471. display: flex;
  472. align-items: center;
  473. justify-content: center;
  474. flex-direction: column;
  475. .btn {
  476. width: 91.73%;
  477. height: 88upx;
  478. line-height: 88upx;
  479. font-size: 30upx;
  480. font-family: PingFang SC;
  481. font-weight: bold;
  482. color: #FFFFFF;
  483. text-align: center;
  484. background: #2BC7B9;
  485. border-radius: 44upx;
  486. margin-bottom: 10rpx;
  487. }
  488. .other-btn {
  489. width: 91.73%;
  490. height: 88upx;
  491. line-height: 88upx;
  492. font-size: 30upx;
  493. font-family: PingFang SC;
  494. font-weight: bold;
  495. color: #2BC7B9;
  496. border: 1rpx solid #2BC7B9;
  497. text-align: center;
  498. background: #FFFFFF;
  499. border-radius: 44upx;
  500. margin-bottom: 10rpx;
  501. position: relative;
  502. .share {
  503. display: inline-block;
  504. position: absolute;
  505. top: 0;
  506. left: 0;
  507. width: 100%;
  508. height: 100%;
  509. opacity: 0;
  510. }
  511. }
  512. }
  513. }
  514. </style>