pay.vue 7.1 KB

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