pay-page.vue 7.0 KB

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