pay-page.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. <template>
  2. <view class="flex-common-css iPhone-bottom flex-common-css box-border-box">
  3. <Nav title="订单支付" bgckgroundBox='transparent' :letTap='true' @goBack='goBack'></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. goBack() {
  101. setTimeout(() => {
  102. uni.switchTab({
  103. url: '/pages/order/index'
  104. })
  105. uni.setStorageSync('orderPayType', 1)
  106. }, 1000)
  107. },
  108. setCountDown(sTime) {
  109. let end = new Date(sTime).getTime();
  110. let now = new Date().getTime();
  111. let msec = end - now;
  112. this.time.day = parseInt(msec / 1000 / 60 / 60 / 24);
  113. let h = parseInt(msec / 1000 / 60 / 60 % 24);
  114. let m = parseInt(msec / 1000 / 60 % 60);
  115. let s = parseInt(msec / 1000 % 60);
  116. this.time.h = h > 9 ? h : '0' + h;
  117. this.time.m = m > 9 ? m : '0' + m;
  118. this.time.s = s > 9 ? s : '0' + s;
  119. msec -= 1000;
  120. if (this.time.day >= 1) {
  121. this.showTime = true;
  122. } else {
  123. this.showTime = false;
  124. };
  125. if (msec >= 0) {
  126. setTimeout(() => {
  127. this.setCountDown(sTime);
  128. }, 1000);
  129. } else {
  130. this.isTimeEnd = true;
  131. this.bText = '活动结束';
  132. this.time.h = '--';
  133. this.time.m = '--';
  134. this.time.s = '--';
  135. };
  136. },
  137. setPayType(payType) {
  138. this.payType = payType
  139. if (payType === 3) {
  140. if (Number(this.payData.member_money) < Number(this.payData.pay_money)) {
  141. this.butType = 2
  142. } else {
  143. this.butType = 1
  144. }
  145. } else {
  146. this.butType = 1
  147. }
  148. },
  149. paySure() {
  150. if (this.butType === 2) {
  151. return
  152. }
  153. orderPay({
  154. order_id: this.order_id,
  155. pay_type: this.payType
  156. }).then((ret) => {
  157. if (ret.code === 1) {
  158. if (this.payType === 1) {
  159. uni.requestPayment({
  160. provider: "wxpay", //支付类型-固定值
  161. timeStamp: ret.data.wx_pay.timeStamp + "", // 时间戳(单位:秒)
  162. nonceStr: ret.data.wx_pay.nonceStr, // 随机字符串
  163. package: ret.data.wx_pay.package, // 固定值
  164. signType: ret.data.wx_pay.signType, //固定值
  165. paySign: ret.data.wx_pay.paySign, //签名
  166. success: (ren) => {
  167. uni.removeStorageSync('isConfirmAddressFlag')
  168. tools.success("支付成功");
  169. this.isAJAX = false;
  170. setTimeout(() => {
  171. uni.switchTab({
  172. url: '/pages/order/index'
  173. })
  174. uni.setStorageSync('orderPayType', 1)
  175. }, 1000)
  176. },
  177. fail: (err) => {
  178. uni.removeStorageSync('isConfirmAddressFlag')
  179. this.isAJAX = false;
  180. tools.error("支付失败");
  181. setTimeout(() => {
  182. uni.switchTab({
  183. url: '/pages/order/index'
  184. })
  185. uni.setStorageSync('orderPayType', 1)
  186. }, 1000)
  187. },
  188. });
  189. } else if (this.payType === 3) {
  190. uni.removeStorageSync('isConfirmAddressFlag')
  191. tools.success("支付成功");
  192. this.isAJAX = false;
  193. setTimeout(() => {
  194. uni.switchTab({
  195. url: '/pages/order/index'
  196. })
  197. uni.setStorageSync('orderPayType', 1)
  198. }, 1000)
  199. }
  200. } else {
  201. uni.removeStorageSync('isConfirmAddressFlag')
  202. this.isAJAX = false;
  203. tools.error("支付失败");
  204. setTimeout(() => {
  205. uni.switchTab({
  206. url: '/pages/order/index'
  207. })
  208. uni.setStorageSync('orderPayType', 1)
  209. }, 1000)
  210. }
  211. })
  212. }
  213. },
  214. }
  215. </script>
  216. <style lang="scss" scoped>
  217. .pop-box {
  218. width: 80vw;
  219. height: 30vh;
  220. }
  221. .p-t-40 {
  222. padding: 40rpx 0 0;
  223. }
  224. .p-12-30 {
  225. padding: 12rpx 30rpx;
  226. }
  227. .p-23-16 {
  228. padding: 23rpx 16rpx;
  229. }
  230. .plr-16 {
  231. padding: 0 16rpx;
  232. }
  233. .p-26-0 {
  234. padding: 26rpx 0;
  235. }
  236. .icon-img {
  237. width: 40rpx;
  238. height: 40rpx;
  239. }
  240. .w-h-36 {
  241. width: 36rpx;
  242. height: 36rpx;
  243. }
  244. .pay-but {
  245. width: 100%;
  246. height: 80rpx;
  247. line-height: 80rpx;
  248. margin: 30rpx auto;
  249. }
  250. .pop-but {
  251. width: 80%;
  252. padding: 24rpx 0;
  253. margin: auto;
  254. .add-card {
  255. width: 40rpx;
  256. height: 40rpx;
  257. }
  258. }
  259. </style>