pay.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. <template>
  2. <view class="container" v-if="info">
  3. <view class="countDown">
  4. 交易剩余时间
  5. <uv-count-down v-if="info.countDownTime" :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. {{ getTimes((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">{{ getTimes((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">{{ info.hotelType }}</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. onUnload() {
  60. uni.$emit('choose', { data: {} })
  61. },
  62. methods: {
  63. async getData() {
  64. const res = await this.$myRequest({
  65. url: '/mhotel/ampgetBookingById.action',
  66. data: {
  67. bookingId: this.id
  68. }
  69. })
  70. if (res.code === 200) {
  71. this.info = res.data
  72. // 计算出倒计时时间(毫秒)
  73. let temLockTime = this.info.lockTime ? this.info.lockTime * 1 : 15
  74. // 兼容ios部分系统转换时间格式
  75. let createTime = this.info.createTime.slice(0, 19).replace(/-/g, '/')
  76. this.info.countDownTime = new Date(createTime).getTime() + temLockTime * 60 * 1000 - new Date().getTime()
  77. }
  78. },
  79. // 点击确认支付按钮回调
  80. async handleSub() {
  81. if (this.isChecked) {
  82. const res = await this.$myRequest({
  83. url: '/mhotel/abkpay.action',
  84. data: {
  85. open_id: uni.getStorageSync('openid'),
  86. bookingId: this.info.id
  87. }
  88. })
  89. // console.log(res)
  90. if (res.code === 200) {
  91. uni.requestPayment({
  92. provider: 'wxpay',
  93. timeStamp: res.data.timeStamp,
  94. nonceStr: res.data.nonceStr,
  95. package: 'prepay_id=' + res.data.prepay_id,
  96. signType: res.data.signType,
  97. paySign: res.data.paySign,
  98. success: (res) => {
  99. if (res.errMsg == 'requestPayment:ok') {
  100. uni.navigateTo({
  101. url: `/pages/payStatus/payStatus?status=1&id=${this.info.id}`
  102. })
  103. } else {
  104. uni.navigateTo({
  105. url: `/pages/payStatus/payStatus?status=2`
  106. })
  107. }
  108. },
  109. fail: (err) => {
  110. if (err.errMsg === 'requestPayment:fail cancel') {
  111. uni.showToast({
  112. title: '支付已取消',
  113. icon: 'none',
  114. mask: true
  115. })
  116. }
  117. }
  118. })
  119. } else {
  120. uni.showToast({
  121. title: res.message,
  122. icon: 'none',
  123. mask: true
  124. })
  125. setTimeout(() => {
  126. uni.reLaunch({
  127. url: '/pages/orderManage/orderManage'
  128. })
  129. }, 1500)
  130. }
  131. } else {
  132. uni.showToast({
  133. title: '请选择支付方式',
  134. icon: 'none'
  135. })
  136. }
  137. },
  138. // 点击支付方式回调
  139. handleChange() {
  140. this.isChecked = !this.isChecked
  141. },
  142. // 倒计时结束回调
  143. finish() {
  144. uni.showModal({
  145. title: '提示',
  146. content: '订单已超过可支付时间,请重新下单',
  147. showCancel: false,
  148. success: (res) => {
  149. if (res.confirm) {
  150. uni.switchTab({
  151. url: '/pages/home3/home3'
  152. })
  153. }
  154. }
  155. })
  156. },
  157. getWeek(time) {
  158. // 兼容ios部分系统转换时间格式
  159. let rgTime = time.replace(/-/g, '/')
  160. let date = new Date(rgTime)
  161. // 获取星期
  162. let week = date.getDay()
  163. let weekList = ['日', '一', '二', '三', '四', '五', '六']
  164. let res = '周' + weekList[week]
  165. return res
  166. },
  167. getTimes(time) {
  168. // 兼容ios部分系统转换时间格式
  169. let rgTime = time.replace(/-/g, '/')
  170. let date = new Date(rgTime)
  171. // 获取月份
  172. let M = date.getMonth() + 1
  173. // 获取日期
  174. let D = date.getDate()
  175. let res = M + '月' + D + '日'
  176. return res
  177. }
  178. }
  179. }
  180. </script>
  181. <style lang="scss" scoped>
  182. .container {
  183. position: relative;
  184. box-sizing: border-box;
  185. padding: 0 20rpx 160rpx;
  186. min-height: 100vh;
  187. background-color: #f2f3f5;
  188. .countDown {
  189. display: flex;
  190. justify-content: center;
  191. align-items: center;
  192. height: 70rpx;
  193. color: #808080;
  194. font-size: 24rpx;
  195. }
  196. .price {
  197. display: flex;
  198. justify-content: center;
  199. align-items: center;
  200. height: 65rpx;
  201. font-size: 50rpx;
  202. font-weight: bold;
  203. text {
  204. font-size: 28rpx;
  205. }
  206. }
  207. .title {
  208. margin-top: 14rpx;
  209. color: #808080;
  210. font-size: 24rpx;
  211. }
  212. .info {
  213. display: flex;
  214. flex-direction: column;
  215. box-sizing: border-box;
  216. padding: 0 30rpx;
  217. margin-top: 18rpx;
  218. width: 100%;
  219. border-radius: 15rpx;
  220. background-color: #fff;
  221. .info_time {
  222. display: flex;
  223. align-items: center;
  224. margin-top: 20rpx;
  225. font-size: 32rpx;
  226. font-weight: bold;
  227. .time_line {
  228. width: 17rpx;
  229. height: 1rpx;
  230. background-color: #096562;
  231. }
  232. .time_num {
  233. box-sizing: border-box;
  234. padding: 0 15rpx;
  235. height: 46rpx;
  236. line-height: 46rpx;
  237. font-size: 24rpx;
  238. font-weight: 400;
  239. border-radius: 66rpx;
  240. border: 1rpx solid #096562;
  241. background-color: #f0f2f5;
  242. }
  243. .gap {
  244. margin: 0 10rpx;
  245. }
  246. text {
  247. font-size: 24rpx;
  248. font-weight: 400;
  249. }
  250. }
  251. .info_msg {
  252. margin-top: 15rpx;
  253. font-size: 28rpx;
  254. font-weight: bold;
  255. }
  256. .info_type {
  257. display: flex;
  258. flex-wrap: wrap;
  259. margin-top: 15rpx;
  260. .type_item {
  261. box-sizing: border-box;
  262. padding: 0 15rpx;
  263. margin-right: 20rpx;
  264. height: 41rpx;
  265. line-height: 41rpx;
  266. font-size: 24rpx;
  267. color: #fff;
  268. border-radius: 34rpx;
  269. background-color: #096562;
  270. }
  271. }
  272. .info_tag {
  273. display: flex;
  274. flex-wrap: wrap;
  275. margin: 18rpx 0 30rpx;
  276. color: #808080;
  277. font-size: 24rpx;
  278. .tag_item {
  279. margin-right: 20rpx;
  280. }
  281. }
  282. }
  283. .way {
  284. .way_item {
  285. display: flex;
  286. align-items: center;
  287. box-sizing: border-box;
  288. padding: 0 30rpx;
  289. margin-top: 18rpx;
  290. height: 100rpx;
  291. font-size: 28rpx;
  292. border-radius: 15rpx;
  293. background-color: #fff;
  294. img {
  295. width: 40rpx;
  296. height: 40rpx;
  297. }
  298. .way_text {
  299. margin-left: 18rpx;
  300. }
  301. .way_radio {
  302. margin-left: auto;
  303. transform: scale(0.9);
  304. }
  305. }
  306. }
  307. .btn {
  308. position: fixed;
  309. bottom: 40rpx;
  310. display: flex;
  311. justify-content: center;
  312. align-items: center;
  313. width: 710rpx;
  314. height: 96rpx;
  315. color: #fff;
  316. font-size: 32rpx;
  317. border-radius: 64rpx;
  318. background-color: #096562;
  319. }
  320. }
  321. </style>