pay.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. <template>
  2. <view class="container" v-if="info">
  3. <view class="countDown">
  4. 交易剩余时间
  5. <uv-count-down :time="info.countDownTime" format="mm:ss" @finish="finish"></uv-count-down>
  6. </view>
  7. <view class="price">
  8. <text>¥</text>
  9. {{ info.houseTotalPrice }}
  10. </view>
  11. <view class="title">住房信息</view>
  12. <view class="info">
  13. <view class="info_time">
  14. {{ getTime((info.orderStartTime || '').slice(0, 19)) }}
  15. <text class="gap">{{ getWeek((info.orderStartTime || '').slice(0, 19)) }}</text>
  16. <view class="time_line"></view>
  17. <view class="time_num">{{ info.orderLiveTime }}</view>
  18. <view class="time_line"></view>
  19. <view class="gap">{{ getTime((info.orderEndTime || '').slice(0, 19)) }}</view>
  20. <text>{{ getWeek((info.orderEndTime || '').slice(0, 19)) }}</text>
  21. </view>
  22. <view class="info_msg">{{ info.houseName }}房</view>
  23. <view class="info_type">
  24. <view class="type_item">包吃住型</view>
  25. </view>
  26. <view class="info_tag">
  27. <view class="tag_item" v-if="info.hAreas">{{ info.hAreas }}㎡</view>
  28. <view class="tag_item" v-for="tag in info.houseConfigList" :key="tag.id">{{ tag.name }}</view>
  29. </view>
  30. </view>
  31. <view class="title">支付方式</view>
  32. <view class="way">
  33. <view class="way_item" @click="handleChange">
  34. <img src="../../static/index/wxPay.png" />
  35. <view class="way_text">微信支付</view>
  36. <radio class="way_radio" :checked="isChecked" />
  37. </view>
  38. </view>
  39. <!-- 提交订单区域 -->
  40. <view class="btn" @click="handleSub">确认支付</view>
  41. </view>
  42. </template>
  43. <script>
  44. export default {
  45. data() {
  46. return {
  47. // 是否选中支付方式
  48. isChecked: true,
  49. // 订单信息
  50. info: null,
  51. // 订单id
  52. id: ''
  53. }
  54. },
  55. onLoad(options) {
  56. this.id = options.id
  57. this.getData()
  58. },
  59. methods: {
  60. async getData() {
  61. const res = await this.$myRequest({
  62. url: '/mhotel/ampgetBookingById.action',
  63. data: {
  64. bookingId: this.id
  65. }
  66. })
  67. if (res.code === 200) {
  68. this.info = res.data
  69. console.log(this.info)
  70. // 计算出倒计时时间(毫秒)
  71. this.info.countDownTime = new Date(this.info.createTime.slice(0, 19)).getTime() + 15 * 60 * 1000 - new Date().getTime()
  72. }
  73. },
  74. // 点击确认支付按钮回调
  75. async handleSub() {
  76. if (this.isChecked) {
  77. const res = await this.$myRequest({
  78. url: '/mhotel/abkpay.action',
  79. data: {
  80. open_id: uni.getStorageSync('openid'),
  81. bookingId: this.info.id
  82. }
  83. })
  84. // console.log(res)
  85. if (res.code === 200) {
  86. uni.requestPayment({
  87. provider: 'wxpay',
  88. timeStamp: res.data.timeStamp,
  89. nonceStr: res.data.nonceStr,
  90. package: 'prepay_id=' + res.data.prepay_id,
  91. signType: res.data.signType,
  92. paySign: res.data.paySign,
  93. success: (res) => {
  94. if (res.errMsg == 'requestPayment:ok') {
  95. uni.navigateTo({
  96. url: '/pages/payStatus/payStatus?status=1'
  97. })
  98. } else {
  99. uni.navigateTo({
  100. url: '/pages/payStatus/payStatus?status=2'
  101. })
  102. }
  103. },
  104. fail: (err) => {
  105. if (err.errMsg === 'requestPayment:fail cancel') {
  106. uni.showToast({
  107. title: '支付已取消',
  108. icon: 'none',
  109. mask: true
  110. })
  111. }
  112. }
  113. })
  114. }
  115. } else {
  116. uni.showToast({
  117. title: '请选择支付方式',
  118. icon: 'none'
  119. })
  120. }
  121. },
  122. // 点击支付方式回调
  123. handleChange() {
  124. this.isChecked = !this.isChecked
  125. },
  126. // 倒计时结束回调
  127. finish() {
  128. uni.showModal({
  129. title: '提示',
  130. content: '订单已超过可支付时间,请重新下单',
  131. showCancel: false,
  132. success: (res) => {
  133. if (res.confirm) {
  134. uni.switchTab({
  135. url: '/pages/home/home'
  136. })
  137. }
  138. }
  139. })
  140. },
  141. getWeek(time) {
  142. let date = new Date(time)
  143. // 获取星期
  144. let week = date.getDay()
  145. let weekList = ['日', '一', '二', '三', '四', '五', '六']
  146. let res = '周' + weekList[week]
  147. return res
  148. },
  149. getTime(time) {
  150. let date = new Date(time)
  151. // 获取月份
  152. let M = date.getMonth() + 1
  153. // 获取日期
  154. let D = date.getDate()
  155. let res = M + '月' + D + '日'
  156. return res
  157. }
  158. }
  159. }
  160. </script>
  161. <style lang="scss" scoped>
  162. .container {
  163. position: relative;
  164. box-sizing: border-box;
  165. padding: 0 20rpx 160rpx;
  166. min-height: 100vh;
  167. background-color: #f2f3f5;
  168. .countDown {
  169. display: flex;
  170. justify-content: center;
  171. align-items: center;
  172. height: 70rpx;
  173. color: #808080;
  174. font-size: 24rpx;
  175. }
  176. .price {
  177. display: flex;
  178. justify-content: center;
  179. align-items: center;
  180. height: 65rpx;
  181. font-size: 50rpx;
  182. font-weight: bold;
  183. text {
  184. font-size: 28rpx;
  185. }
  186. }
  187. .title {
  188. margin-top: 14rpx;
  189. color: #808080;
  190. font-size: 24rpx;
  191. }
  192. .info {
  193. display: flex;
  194. flex-direction: column;
  195. box-sizing: border-box;
  196. padding: 0 30rpx;
  197. margin-top: 18rpx;
  198. width: 100%;
  199. border-radius: 15rpx;
  200. background-color: #fff;
  201. .info_time {
  202. display: flex;
  203. align-items: center;
  204. margin-top: 20rpx;
  205. font-size: 32rpx;
  206. font-weight: bold;
  207. .time_line {
  208. width: 17rpx;
  209. height: 1rpx;
  210. background-color: #096562;
  211. }
  212. .time_num {
  213. box-sizing: border-box;
  214. padding: 0 15rpx;
  215. height: 46rpx;
  216. line-height: 46rpx;
  217. font-size: 24rpx;
  218. font-weight: 400;
  219. border-radius: 66rpx;
  220. border: 1rpx solid #096562;
  221. background-color: #f0f2f5;
  222. }
  223. .gap {
  224. margin: 0 10rpx;
  225. }
  226. text {
  227. font-size: 24rpx;
  228. font-weight: 400;
  229. }
  230. }
  231. .info_msg {
  232. margin-top: 15rpx;
  233. font-size: 28rpx;
  234. font-weight: bold;
  235. }
  236. .info_type {
  237. display: flex;
  238. flex-wrap: wrap;
  239. margin-top: 15rpx;
  240. .type_item {
  241. box-sizing: border-box;
  242. padding: 0 15rpx;
  243. margin-right: 20rpx;
  244. height: 41rpx;
  245. line-height: 41rpx;
  246. font-size: 24rpx;
  247. color: #fff;
  248. border-radius: 34rpx;
  249. background-color: #096562;
  250. }
  251. }
  252. .info_tag {
  253. display: flex;
  254. flex-wrap: wrap;
  255. margin: 18rpx 0 30rpx;
  256. color: #808080;
  257. font-size: 24rpx;
  258. .tag_item {
  259. margin-right: 20rpx;
  260. }
  261. }
  262. }
  263. .way {
  264. .way_item {
  265. display: flex;
  266. align-items: center;
  267. box-sizing: border-box;
  268. padding: 0 30rpx;
  269. margin-top: 18rpx;
  270. height: 100rpx;
  271. font-size: 28rpx;
  272. border-radius: 15rpx;
  273. background-color: #fff;
  274. img {
  275. width: 40rpx;
  276. height: 40rpx;
  277. }
  278. .way_text {
  279. margin-left: 18rpx;
  280. }
  281. .way_radio {
  282. margin-left: auto;
  283. transform: scale(0.9);
  284. }
  285. }
  286. }
  287. .btn {
  288. position: fixed;
  289. bottom: 40rpx;
  290. display: flex;
  291. justify-content: center;
  292. align-items: center;
  293. width: 710rpx;
  294. height: 96rpx;
  295. color: #fff;
  296. font-size: 32rpx;
  297. border-radius: 64rpx;
  298. background-color: #096562;
  299. }
  300. }
  301. </style>