pick-up-pay.vue 6.9 KB

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