group-pay-page.vue 6.4 KB

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