pay.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  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. // 计算出倒计时时间(毫秒)
  70. let temLockTime = this.info.lockTime ? this.info.lockTime * 1 : 15
  71. this.info.countDownTime = new Date(this.info.createTime.slice(0, 19)).getTime() + temLockTime * 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. } else {
  115. uni.showToast({
  116. title: res.message,
  117. icon: 'none',
  118. mask: true
  119. })
  120. setTimeout(() => {
  121. uni.reLaunch({
  122. url: '/pages/orderManage/orderManage'
  123. })
  124. }, 1500)
  125. }
  126. } else {
  127. uni.showToast({
  128. title: '请选择支付方式',
  129. icon: 'none'
  130. })
  131. }
  132. },
  133. // 点击支付方式回调
  134. handleChange() {
  135. this.isChecked = !this.isChecked
  136. },
  137. // 倒计时结束回调
  138. finish() {
  139. uni.showModal({
  140. title: '提示',
  141. content: '订单已超过可支付时间,请重新下单',
  142. showCancel: false,
  143. success: (res) => {
  144. if (res.confirm) {
  145. uni.switchTab({
  146. url: '/pages/home/home'
  147. })
  148. }
  149. }
  150. })
  151. },
  152. getWeek(time) {
  153. let date = new Date(time)
  154. // 获取星期
  155. let week = date.getDay()
  156. let weekList = ['日', '一', '二', '三', '四', '五', '六']
  157. let res = '周' + weekList[week]
  158. return res
  159. },
  160. getTime(time) {
  161. let date = new Date(time)
  162. // 获取月份
  163. let M = date.getMonth() + 1
  164. // 获取日期
  165. let D = date.getDate()
  166. let res = M + '月' + D + '日'
  167. return res
  168. }
  169. }
  170. }
  171. </script>
  172. <style lang="scss" scoped>
  173. .container {
  174. position: relative;
  175. box-sizing: border-box;
  176. padding: 0 20rpx 160rpx;
  177. min-height: 100vh;
  178. background-color: #f2f3f5;
  179. .countDown {
  180. display: flex;
  181. justify-content: center;
  182. align-items: center;
  183. height: 70rpx;
  184. color: #808080;
  185. font-size: 24rpx;
  186. }
  187. .price {
  188. display: flex;
  189. justify-content: center;
  190. align-items: center;
  191. height: 65rpx;
  192. font-size: 50rpx;
  193. font-weight: bold;
  194. text {
  195. font-size: 28rpx;
  196. }
  197. }
  198. .title {
  199. margin-top: 14rpx;
  200. color: #808080;
  201. font-size: 24rpx;
  202. }
  203. .info {
  204. display: flex;
  205. flex-direction: column;
  206. box-sizing: border-box;
  207. padding: 0 30rpx;
  208. margin-top: 18rpx;
  209. width: 100%;
  210. border-radius: 15rpx;
  211. background-color: #fff;
  212. .info_time {
  213. display: flex;
  214. align-items: center;
  215. margin-top: 20rpx;
  216. font-size: 32rpx;
  217. font-weight: bold;
  218. .time_line {
  219. width: 17rpx;
  220. height: 1rpx;
  221. background-color: #096562;
  222. }
  223. .time_num {
  224. box-sizing: border-box;
  225. padding: 0 15rpx;
  226. height: 46rpx;
  227. line-height: 46rpx;
  228. font-size: 24rpx;
  229. font-weight: 400;
  230. border-radius: 66rpx;
  231. border: 1rpx solid #096562;
  232. background-color: #f0f2f5;
  233. }
  234. .gap {
  235. margin: 0 10rpx;
  236. }
  237. text {
  238. font-size: 24rpx;
  239. font-weight: 400;
  240. }
  241. }
  242. .info_msg {
  243. margin-top: 15rpx;
  244. font-size: 28rpx;
  245. font-weight: bold;
  246. }
  247. .info_type {
  248. display: flex;
  249. flex-wrap: wrap;
  250. margin-top: 15rpx;
  251. .type_item {
  252. box-sizing: border-box;
  253. padding: 0 15rpx;
  254. margin-right: 20rpx;
  255. height: 41rpx;
  256. line-height: 41rpx;
  257. font-size: 24rpx;
  258. color: #fff;
  259. border-radius: 34rpx;
  260. background-color: #096562;
  261. }
  262. }
  263. .info_tag {
  264. display: flex;
  265. flex-wrap: wrap;
  266. margin: 18rpx 0 30rpx;
  267. color: #808080;
  268. font-size: 24rpx;
  269. .tag_item {
  270. margin-right: 20rpx;
  271. }
  272. }
  273. }
  274. .way {
  275. .way_item {
  276. display: flex;
  277. align-items: center;
  278. box-sizing: border-box;
  279. padding: 0 30rpx;
  280. margin-top: 18rpx;
  281. height: 100rpx;
  282. font-size: 28rpx;
  283. border-radius: 15rpx;
  284. background-color: #fff;
  285. img {
  286. width: 40rpx;
  287. height: 40rpx;
  288. }
  289. .way_text {
  290. margin-left: 18rpx;
  291. }
  292. .way_radio {
  293. margin-left: auto;
  294. transform: scale(0.9);
  295. }
  296. }
  297. }
  298. .btn {
  299. position: fixed;
  300. bottom: 40rpx;
  301. display: flex;
  302. justify-content: center;
  303. align-items: center;
  304. width: 710rpx;
  305. height: 96rpx;
  306. color: #fff;
  307. font-size: 32rpx;
  308. border-radius: 64rpx;
  309. background-color: #096562;
  310. }
  311. }
  312. </style>