pay-page.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. <template>
  2. <view class="flex-common-css iPhone-bottom flex-common-css box-border-box">
  3. <Nav title="订单支付" bgckgroundBox='transparent'></Nav>
  4. <scroll-view :scroll-y="true" class="box-sizing-border scroll-view-css plr-30 box-border-box">
  5. <view class="fs-28 fc-121212 mb-20 p-t-40 text-align-center">
  6. 剩余时间 {{time.m}}:{{time.s}}
  7. </view>
  8. <view class="align-items-baseline flex-justify-center mb-40">
  9. <view class="fs-40 fw-500 fc-FB3D03">
  10. ¥
  11. </view>
  12. <view class="fs-64 fw-500 fc-FB3D03">
  13. {{Number(payData.pay_money).toFixed(2) || '0.00'}}
  14. </view>
  15. </view>
  16. <view class="mb-40 text-align-center">
  17. 订单编号: {{payData.order_sn}}
  18. </view>
  19. <view class="fs-32 fw-500 fc-3 mb-22">
  20. 支付方式
  21. </view>
  22. <view class="plr-16 box-border-box b-rad-20 bgc-f">
  23. <view class="align-items-center flex-justify-space p-26-0 b-t-F4" @click="setPayType(3)">
  24. <view class="align-items-center">
  25. <image class="icon-img mr-16" src="static/ye.png" mode=""></image>
  26. <view class="fs-28 fc-333">
  27. 余额支付
  28. </view>
  29. <view class="fs-28 fc-707070">
  30. (可用{{Number(payData.member_money).toFixed(2) || '0.00'}})
  31. </view>
  32. </view>
  33. <image v-if="payType === 3" class="w-h-36 mr-10" src="@/static/img/common/y-select.png" mode="">
  34. </image>
  35. <image v-else class="w-h-36 mr-10" src="@/static/img/common/n-select.png" mode=""></image>
  36. </view>
  37. <view class="align-items-center flex-justify-space p-26-0 b-t-F4" @click="setPayType(1)">
  38. <view class="align-items-center">
  39. <image class="icon-img mr-16" src="@/static/img/common/wx-zf.png" mode="scaleToFill"></image>
  40. <view class="fs-28 fc-333">
  41. 微信支付
  42. </view>
  43. </view>
  44. <image v-if="payType === 1" class="w-h-36 mr-10" src="@/static/img/common/y-select.png" mode="">
  45. </image>
  46. <image v-else class="w-h-36 mr-10" src="@/static/img/common/n-select.png" mode=""></image>
  47. </view>
  48. </view>
  49. <view class="fs-32 fw-500 fc-f text-align-center pay-but b-rad-200" @click="paySure"
  50. :class="butType === 1?'bgc-4FB3EF':'bgc-9'">
  51. 立即支付¥{{Number(payData.pay_money).toFixed(2) || '0.00'}}
  52. </view>
  53. </scroll-view>
  54. </view>
  55. </template>
  56. <script>
  57. import {
  58. orderPay
  59. } from '@/api/order.js'
  60. import {
  61. orderPayInfo
  62. } from "@/api/order.js"
  63. import tools from "@/service/tools.js"
  64. export default {
  65. data() {
  66. return {
  67. payType: 1,
  68. order_id: 0,
  69. isAJAX: false,
  70. payData: {},
  71. butType: 1,
  72. time: {
  73. day: '',
  74. h: "",
  75. m: '',
  76. s: '',
  77. },
  78. }
  79. },
  80. onLoad(data) {
  81. if (data) {
  82. this.order_id = data.orderId
  83. this.orderPayInfo()
  84. }
  85. },
  86. mounted() {},
  87. methods: {
  88. orderPayInfo() {
  89. orderPayInfo({
  90. order_id: this.order_id
  91. }).then((res) => {
  92. if (res.code === 1) {
  93. this.payData = res.data
  94. let createDate = new Date(res.data.created_at); //格式化订单创建时候的时间
  95. createDate.setMinutes(createDate.getMinutes() + 10)
  96. this.setCountDown(createDate)
  97. }
  98. })
  99. },
  100. setCountDown(sTime) {
  101. let end = new Date(sTime).getTime();
  102. let now = new Date().getTime();
  103. let msec = end - now;
  104. this.time.day = parseInt(msec / 1000 / 60 / 60 / 24);
  105. let h = parseInt(msec / 1000 / 60 / 60 % 24);
  106. let m = parseInt(msec / 1000 / 60 % 60);
  107. let s = parseInt(msec / 1000 % 60);
  108. this.time.h = h > 9 ? h : '0' + h;
  109. this.time.m = m > 9 ? m : '0' + m;
  110. this.time.s = s > 9 ? s : '0' + s;
  111. msec -= 1000;
  112. if (this.time.day >= 1) {
  113. this.showTime = true;
  114. } else {
  115. this.showTime = false;
  116. };
  117. if (msec >= 0) {
  118. setTimeout(() => {
  119. this.setCountDown(sTime);
  120. }, 1000);
  121. } else {
  122. this.isTimeEnd = true;
  123. this.bText = '活动结束';
  124. this.time.h = '--';
  125. this.time.m = '--';
  126. this.time.s = '--';
  127. };
  128. },
  129. setPayType(payType) {
  130. this.payType = payType
  131. if (payType === 3) {
  132. if (Number(this.payData.member_money) < Number(this.payData.pay_money)) {
  133. this.butType = 2
  134. } else {
  135. this.butType = 1
  136. }
  137. } else {
  138. this.butType = 1
  139. }
  140. },
  141. paySure() {
  142. if (this.butType === 2) {
  143. return
  144. }
  145. orderPay({
  146. order_id: this.order_id,
  147. pay_type: this.payType
  148. }).then((ret) => {
  149. if (ret.code === 1) {
  150. if (this.payType === 1) {
  151. uni.requestPayment({
  152. provider: "wxpay", //支付类型-固定值
  153. timeStamp: ret.data.wx_pay.timeStamp + "", // 时间戳(单位:秒)
  154. nonceStr: ret.data.wx_pay.nonceStr, // 随机字符串
  155. package: ret.data.wx_pay.package, // 固定值
  156. signType: ret.data.wx_pay.signType, //固定值
  157. paySign: ret.data.wx_pay.paySign, //签名
  158. success: (ren) => {
  159. uni.removeStorageSync('isConfirmAddressFlag')
  160. tools.success("支付成功");
  161. this.isAJAX = false;
  162. setTimeout(() => {
  163. uni.switchTab({
  164. url: '/pages/order/index'
  165. })
  166. uni.setStorageSync('orderPayType', 1)
  167. }, 1000)
  168. },
  169. fail: (err) => {
  170. uni.removeStorageSync('isConfirmAddressFlag')
  171. this.isAJAX = false;
  172. tools.error("支付失败");
  173. setTimeout(() => {
  174. uni.switchTab({
  175. url: '/pages/order/index'
  176. })
  177. uni.setStorageSync('orderPayType', 1)
  178. }, 1000)
  179. },
  180. });
  181. } else if (this.payType === 3) {
  182. uni.removeStorageSync('isConfirmAddressFlag')
  183. tools.success("支付成功");
  184. this.isAJAX = false;
  185. setTimeout(() => {
  186. uni.switchTab({
  187. url: '/pages/order/index'
  188. })
  189. uni.setStorageSync('orderPayType', 1)
  190. }, 1000)
  191. }
  192. } else {
  193. uni.removeStorageSync('isConfirmAddressFlag')
  194. this.isAJAX = false;
  195. tools.error("支付失败");
  196. setTimeout(() => {
  197. uni.switchTab({
  198. url: '/pages/order/index'
  199. })
  200. uni.setStorageSync('orderPayType', 1)
  201. }, 1000)
  202. }
  203. })
  204. }
  205. },
  206. }
  207. </script>
  208. <style lang="scss" scoped>
  209. .pop-box {
  210. width: 80vw;
  211. height: 30vh;
  212. }
  213. .p-t-40 {
  214. padding: 40rpx 0 0;
  215. }
  216. .p-12-30 {
  217. padding: 12rpx 30rpx;
  218. }
  219. .p-23-16 {
  220. padding: 23rpx 16rpx;
  221. }
  222. .plr-16 {
  223. padding: 0 16rpx;
  224. }
  225. .p-26-0 {
  226. padding: 26rpx 0;
  227. }
  228. .icon-img {
  229. width: 40rpx;
  230. height: 40rpx;
  231. }
  232. .w-h-36 {
  233. width: 36rpx;
  234. height: 36rpx;
  235. }
  236. .pay-but {
  237. width: 100%;
  238. height: 80rpx;
  239. line-height: 80rpx;
  240. margin: 30rpx auto;
  241. }
  242. .pop-but {
  243. width: 80%;
  244. padding: 24rpx 0;
  245. margin: auto;
  246. .add-card {
  247. width: 40rpx;
  248. height: 40rpx;
  249. }
  250. }
  251. </style>