paymentOrder.vue 12 KB

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