pay-page.vue 6.8 KB

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