pay.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  1. <template>
  2. <view class="container">
  3. <uv-navbar title="确认订单" placeholder autoBack></uv-navbar>
  4. <view class="u-text-center u-plr30">
  5. <view class="mt82">
  6. <view class="u-ED3D07 u-font44 u-bold">
  7. <text class="u-ml10">{{ total_amount }}</text>
  8. </view>
  9. <view class="u-999 u-font22">付款金额</view>
  10. </view>
  11. <view class="u-bg-fff pay-select">
  12. <radio-group @change="e=>payWay(e.detail.value)">
  13. <!-- <label class="u-flex-center-sb" @click="payWay(0)">
  14. <view class="u-flex-center">
  15. <text class="iconfont3 pay">&#x100dc;</text>
  16. <view class="u-ml20 u-font28 u-181818">
  17. 余额支付<text class="u-font24 u-999"
  18. >(可用余额 ¥ {{ balance || 0 }})</text
  19. >
  20. </view>
  21. </view>
  22. <view>
  23. <radio value="0" :checked="payStatus === 0" />
  24. </view>
  25. </label> -->
  26. <label class="u-flex-center-sb u-mt30" @click.stop="payWay(1)">
  27. <view class="u-flex-center">
  28. <!-- <image class="img60" src="/static/weChat2.png"></image> -->
  29. <text class="iconfont pay weixinPay">&#xe663;</text>
  30. <view class="u-ml20 u-font28 u-181818">微信支付</view>
  31. </view>
  32. <view>
  33. <radio value="1" :checked="payStatus == 1" />
  34. </view>
  35. </label>
  36. <label
  37. class="u-flex-center-sb u-mt30"
  38. @click.stop="payWay(2)"
  39. v-if="env != 0"
  40. >
  41. <view class="u-flex-center">
  42. <text class="iconfont pay zhifuPay">&#xe663;</text>
  43. <view class="u-ml20 u-font28 u-181818">支付宝</view>
  44. </view>
  45. <view>
  46. <radio value="2" :checked="payStatus == 2" />
  47. </view>
  48. </label>
  49. </radio-group>
  50. </view>
  51. <view class="pay-btn">
  52. <button
  53. class="u-flex-center u-btn-two"
  54. @click="$throttle(submitPay, 500)"
  55. >
  56. <view class="u-flex-center">
  57. <view>去付款</view>
  58. <uni-countdown
  59. :backgroundColor="'none'"
  60. :color="'#ffffff'"
  61. :splitorColor="'#ffffff'"
  62. :show-day="time1[0] > 0"
  63. :day="time1[0]"
  64. :hour="time1[1]"
  65. :minute="time1[2]"
  66. :second="time1[3]"
  67. >
  68. </uni-countdown>
  69. </view>
  70. </button>
  71. <view class="u-flex-center u-mt20 u-999 u-font22">
  72. <view> 请在 </view>
  73. {{ payMinutes }}
  74. <view>分钟内完成付款,否则订单失效。</view>
  75. </view>
  76. </view>
  77. </view>
  78. </view>
  79. </template>
  80. <script setup>
  81. import { ref, reactive, onMounted, getCurrentInstance } from "vue";
  82. import { onLoad, onShow } from "@dcloudio/uni-app";
  83. import {
  84. shoporderInfo_Api,
  85. shopOrderGoPay_Api,
  86. shopOrderIsPay_Api,
  87. } from "@/api/order";
  88. import { totalBalance_Api } from "@/api/userInfo.js";
  89. import $mUtil from "@/util/index";
  90. // 响应式数据
  91. const total_amount = ref(null);
  92. const orderNo = ref(null);
  93. const orderId = ref(null);
  94. const loading = ref(false);
  95. const expired_pay_time = ref(null);
  96. const payStatus = ref(1);
  97. const balance = ref(null);
  98. const isGroup = ref(false);
  99. const isService = ref(false);
  100. const time1 = reactive([0, 0, 0, 0]);
  101. const payMinutes = ref(0); // 支付剩余分钟数
  102. const pagesType = ref(null); // 页面类型, 1:通知上个页面支付成功
  103. const eventChannel = ref(null);
  104. onMounted(() => {
  105. const instance = getCurrentInstance().proxy;
  106. eventChannel.value = instance.getOpenerEventChannel();
  107. });
  108. const env = ref(2);
  109. let weixinInfo = null;
  110. const orderInfo = ref({});
  111. const getOrderInfo = () => {
  112. shoporderInfo_Api(orderId.value).then((res) => {
  113. if (res && res.code == 200) {
  114. orderInfo.value = res.data || {};
  115. if (orderInfo.value.paymentMethod != null) {
  116. payStatus.value = orderInfo.value.paymentMethod;
  117. }
  118. }
  119. });
  120. };
  121. // 页面加载
  122. onLoad((options) => {
  123. // console.log(options, "options");
  124. // 微信小程序
  125. // #ifdef MP-WEIXIN
  126. env.value = 0;
  127. payStatus.value = 0;
  128. // #endif
  129. if (options.orderNo) {
  130. orderNo.value = options.orderNo;
  131. }
  132. if (options.orderId) {
  133. orderId.value = options.orderId;
  134. getOrderInfo();
  135. }
  136. if (options.total_amount) {
  137. total_amount.value = options.total_amount;
  138. }
  139. if (options.pagesType) pagesType.value = options.pagesType;
  140. if (options.expired_pay_time) {
  141. expired_pay_time.value = options.expired_pay_time;
  142. const timeArray = $mUtil
  143. .countDown(expired_pay_time.value)
  144. .split(":")
  145. .map((val) => Number(val));
  146. time1[0] = timeArray[0];
  147. time1[1] = timeArray[1];
  148. time1[2] = timeArray[2];
  149. time1[3] = timeArray[3];
  150. // console.log("支付时间:" + options.expired_pay_time);
  151. let beginTime = new Date();
  152. let time = expired_pay_time.value - beginTime;
  153. let leave1 = time % (24 * 3600 * 1000); //计算天数后剩余的毫秒数
  154. //计算相差分钟数
  155. let leave2 = leave1 % (3600 * 1000); //计算小时数后剩余的毫秒数
  156. let minutes = Math.ceil(leave2 / (60 * 1000));
  157. // payMinutes.value = minutes
  158. // console.log("分钟值:" + minutes);
  159. }
  160. if (options.type && options.type == "group") {
  161. isGroup.value = true;
  162. }
  163. if (options.type && options.type == "service") {
  164. isService.value = true;
  165. }
  166. // accountInfo();
  167. // if (options.orderId) {
  168. // returnList(options.orderId);
  169. // }
  170. // console.log("分钟" + time1[2]);
  171. if (time1[3] == "0") {
  172. payMinutes.value = time1[2];
  173. } else {
  174. payMinutes.value = time1[2] + 1;
  175. }
  176. // console.log("秒值:" + time1[3]);
  177. // #ifdef APP-PLUS
  178. plus.share.getServices(
  179. (service) => {
  180. let weixin = service.find((i) => i.id === "weixin");
  181. if (weixin) {
  182. // console.log("weixin==>", weixin);
  183. weixinInfo = weixin;
  184. } else {
  185. // 没有获取到微信分享服务
  186. console.log(weixin);
  187. }
  188. },
  189. (err) => {
  190. // 获取分享服务列表失败
  191. console.log(err);
  192. }
  193. );
  194. // #endif
  195. });
  196. const showPaying = ref(false); // 是否支付中
  197. // 订单支付状态查询
  198. const shopOrderIsPay = () => {
  199. shopOrderIsPay_Api({ orderId: orderId.value })
  200. .then((res) => {
  201. uni.hideLoading();
  202. if (res && res.code == 200) {
  203. let title = "支付成功";
  204. if (!res.data) {
  205. title = "支付失败";
  206. }
  207. uni.showToast({ title, icon: "none" });
  208. }
  209. goJump();
  210. })
  211. .catch((err) => {
  212. goJump();
  213. });
  214. };
  215. // 页面显示
  216. onShow(() => {
  217. if (showPaying.value) {
  218. uni.showLoading({ title: "加载中...", mask: true });
  219. setTimeout(() => {
  220. shopOrderIsPay();
  221. }, 500);
  222. }
  223. });
  224. // // 获取账户信息
  225. // const accountInfo = () => {
  226. // totalBalance_Api().then((res) => {
  227. // if (res && res.code == 200) {
  228. // balance.value = res.data || 0;
  229. // }
  230. // });
  231. // };
  232. // 选择支付方式
  233. const payWay = (e) => {
  234. // console.log(e, 111);
  235. payStatus.value = e;
  236. };
  237. // 跳转页面
  238. const goJump = () => {
  239. if (pagesType.value == 1 || pagesType.value == 2) {
  240. setTimeout(() => {
  241. eventChannel.value.emit("callback");
  242. uni.navigateBack();
  243. }, 500);
  244. } else {
  245. setTimeout(() => {
  246. uni.redirectTo({
  247. url: `/pages/order/mallOrder/orderList?orderType=0`,
  248. });
  249. }, 500);
  250. }
  251. };
  252. // 确认支付
  253. const confirm = () => {
  254. if (env.value == 0) {
  255. uni.navigateToMiniProgram({
  256. appId: "wxcea8ce8b537d83a5",
  257. path: `pages/order/detail?orderId=${orderId.value}&type=0`,
  258. envVersion: "release", // develop(开发版),trial(体验版),release(正式版)
  259. success: (res) => {
  260. showPaying.value = true;
  261. },
  262. fail: (res) => {
  263. console.log("取消支付:" + res);
  264. },
  265. });
  266. } else {
  267. showPaying.value = true;
  268. let isAndroid = true;
  269. // #ifdef APP-PLUS
  270. if (plus.os.name == "Android") {
  271. console.log("当前环境是安卓");
  272. isAndroid = true;
  273. } else {
  274. console.log("当前环境不是安卓");
  275. isAndroid = false;
  276. }
  277. // 微信支付
  278. if (payStatus.value == 0) {
  279. // console.log("微信支付===================");
  280. // #ifdef APP-PLUS
  281. weixinInfo.launchMiniProgram(
  282. {
  283. id: "gh_e5657eb120b6",
  284. path: `/pages/order/detail?orderId=${orderId.value}`,
  285. type: "0", // 可取值: 0-正式版; 1-测试版; 2-体验版。 默认值为0。
  286. // webUrl
  287. },
  288. (res) => {
  289. console.log("res", res);
  290. },
  291. (err) => {
  292. console.log("err", err);
  293. }
  294. );
  295. // #endif
  296. } else {
  297. // console.log("支付宝支付===================");
  298. // 支付宝支付
  299. //参数需要
  300. const query = encodeURIComponent("?orderId=" + orderId.value);
  301. const url = `${
  302. isAndroid ? "alipays" : "alipay"
  303. }://platformapi/startapp?appId=2021006116626014&page=pages/order/detail${query}`;
  304. plus.runtime.openURL(url, (e) => {
  305. console.error("未安装支付宝或无法打开");
  306. showPaying.value = false;
  307. uni.$uv.toast("未安装支付宝或无法打开");
  308. });
  309. }
  310. // #endif
  311. }
  312. };
  313. // 提交支付
  314. const submitPay = () => {
  315. if (!orderId.value) {
  316. uni.$uv.toast("未获取到订单号");
  317. return;
  318. }
  319. if (payStatus.value != orderInfo.value.paymentMethod) {
  320. uni.showLoading({ title: "支付中...", mask:true });
  321. shopOrderGoPay_Api({ orderId: orderId.value, paymentMethod: payStatus.value }).then(res => {
  322. uni.hideLoading();
  323. if (res && res.code == 200) {
  324. confirm();
  325. }
  326. })
  327. } else {
  328. confirm();
  329. }
  330. };
  331. // // 提交支付
  332. // const submitPay = () => {
  333. // //微信支付
  334. // if (
  335. // payStatus.value == 1 ||
  336. // payStatus.value == 2 ||
  337. // payStatus.value == 10 ||
  338. // payStatus.value == 12 ||
  339. // payStatus.value == 14
  340. // ) {
  341. // let data = {
  342. // orderNo: orderNo.value,
  343. // };
  344. // loading.value = true;
  345. // shoporderWxMinPay_Api(data)
  346. // .then((res) => {
  347. // if (res && res.data.code == 200) {
  348. // loading.value = false;
  349. // let target = res.data.data;
  350. // console.log("target==>>", target);
  351. // if (payStatus.value == 1) {
  352. // uni.requestPayment({
  353. // provider: "wxpay",
  354. // timeStamp: target.timeStamp,
  355. // nonceStr: target.nonceStr,
  356. // package: target.package,
  357. // signType: target.signType,
  358. // paySign: target.paySign,
  359. // success: (res) => {
  360. // uni.$uv.toast("支付成功");
  361. // uni.removeStorageSync("orderreminder");
  362. // goJump();
  363. // },
  364. // fail: function (err) {
  365. // console.log("err==>", err);
  366. // loading.value = false;
  367. // console.log("fail:" + JSON.stringify(err));
  368. // },
  369. // });
  370. // } else if (payStatus.value == 2) {
  371. // uni.requestPayment({
  372. // provider: "alipay",
  373. // orderInfo: target.prePayOrderInfo,
  374. // success: (res) => {
  375. // uni.$uv.toast("支付成功");
  376. // uni.removeStorageSync("orderreminder");
  377. // goJump();
  378. // },
  379. // fail: function (err) {
  380. // loading.value = false;
  381. // console.log("fail:" + JSON.stringify(err));
  382. // },
  383. // });
  384. // }
  385. // } else {
  386. // loading.value = false;
  387. // uni.$uv.toast("交易失败");
  388. // }
  389. // })
  390. // .catch((err) => {
  391. // loading.value = false;
  392. // // getApp().globalData.$mUtil.toast('交易失败');
  393. // });
  394. // } else if (payStatus.value == 0) {
  395. // //余额支付
  396. // loading.value = false;
  397. // uni.showModal({
  398. // title: "余额支付",
  399. // content: "确定使用余额支付吗?",
  400. // success: (res) => {
  401. // if (res.confirm) {
  402. // let data = {
  403. // orderNo: orderNo.value,
  404. // };
  405. // shoporderBalance_Api(data).then((res) => {
  406. // if (res && res.code == 200) {
  407. // uni.removeStorageSync("orderreminder");
  408. // uni.$uv.toast("支付成功");
  409. // goJump();
  410. // }
  411. // });
  412. // } else if (res.cancel) {
  413. // }
  414. // },
  415. // });
  416. // }
  417. // };
  418. </script>
  419. <style lang="scss">
  420. page {
  421. background-color: #f5f5f5;
  422. }
  423. .mt82 {
  424. margin-top: 82rpx;
  425. }
  426. radio {
  427. transform: scale(0.7);
  428. }
  429. .pay-select {
  430. margin-top: 66rpx;
  431. border-radius: 18rpx;
  432. padding: 48rpx 38rpx;
  433. .pay {
  434. font-size: 60rpx;
  435. // color: #ffa937;
  436. }
  437. .weixinPay {
  438. color: #09bb07;
  439. }
  440. .zhifuPay {
  441. color: #06b4fd;
  442. }
  443. .banks {
  444. justify-content: center;
  445. }
  446. .bank {
  447. display: flex;
  448. // flex-direction: column;
  449. justify-content: space-between;
  450. align-items: center;
  451. .box {
  452. // display: flex;
  453. // justify-content: space-between;
  454. // align-items: center;
  455. &:first-child {
  456. margin-bottom: 10rpx;
  457. }
  458. .left {
  459. display: flex;
  460. align-items: center;
  461. margin-bottom: 10rpx;
  462. }
  463. image {
  464. width: 80rpx;
  465. height: auto;
  466. margin-right: 10rpx;
  467. }
  468. .bank_name {
  469. font-size: 28rpx;
  470. margin-right: 20rpx;
  471. // font-weight: bold;
  472. }
  473. .name {
  474. text-align: left;
  475. }
  476. }
  477. }
  478. .bank-box {
  479. flex: 1;
  480. width: 0;
  481. overflow: hidden;
  482. text-overflow: ellipsis;
  483. white-space: nowrap;
  484. }
  485. .bank-icon {
  486. color: #2f77f1;
  487. font-size: 60rpx;
  488. }
  489. }
  490. .img60 {
  491. width: 50rpx;
  492. height: 50rpx;
  493. margin-left: 6rpx;
  494. }
  495. .pay-btn {
  496. margin-top: 80rpx;
  497. display: flex;
  498. flex-direction: column;
  499. align-items: center;
  500. align-content: center;
  501. button {
  502. background-color: #fa6138;
  503. color: #ffffff;
  504. justify-content: center;
  505. }
  506. }
  507. </style>