orderManage.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  1. <template>
  2. <view class="container">
  3. <!-- 每一个订单区域 -->
  4. <uni-swipe-action>
  5. <uni-swipe-action-item v-for="item in orderList" :key="item.id">
  6. <!-- 右侧选项内容区域 -->
  7. <template v-slot:right>
  8. <view class="order_right" @click="handleDelete(item)">
  9. <img class="img" src="../../static/my/delete.png" />
  10. </view>
  11. </template>
  12. <view class="order_box" @click="goPageOrderDetail(item)">
  13. <!-- 标题区域 -->
  14. <view class="box_header">
  15. <img class="img" src="../../static/my/hotel.png" />
  16. <view class="title">{{ item.hotelName }}</view>
  17. <view class="type type2" v-if="item.orderStatus === '1'">
  18. 待支付,剩余
  19. <uv-count-down v-if="item.countDownTime" :time="item.countDownTime" format="mm:ss" @finish="finish(item)"></uv-count-down>
  20. </view>
  21. <view class="type" v-if="item.orderStatus === '2'">已支付</view>
  22. <view class="type" v-if="item.orderStatus === '3'">待入住</view>
  23. <view class="type" v-if="item.orderStatus === '4'">已入住</view>
  24. <view class="type" v-if="item.orderStatus === '5'">已消费</view>
  25. <view class="type" v-if="item.orderStatus === '6'">支付超时</view>
  26. <view class="type" v-if="item.orderStatus === '7'">已取消</view>
  27. <view class="type" v-if="item.orderStatus === '8'">已退单</view>
  28. <view class="type" v-if="item.orderStatus === '9'">已退款</view>
  29. <view class="type" v-if="item.orderStatus === '10'">退款中</view>
  30. </view>
  31. <!-- 酒店信息区域 -->
  32. <view class="box_info">
  33. <img class="img" mode="aspectFill" :src="item.houseFileInfoList[0].url" />
  34. <view class="info_right">
  35. <view class="info_right_item">{{ item.houseOrderNumber }}间,{{ item.houseName }}</view>
  36. <view class="info_right_item">{{ (item.orderStartTime || '').slice(0, 10) }} - {{ (item.orderEndTime || '').slice(0, 10) }}</view>
  37. <view class="info_right_item">总价:¥{{ item.houseTotalPrice }}</view>
  38. </view>
  39. </view>
  40. <!-- 按钮区域 -->
  41. <view class="box_btn" v-if="item.orderStatus === '1' || item.orderStatus === '6'">
  42. <view class="btn_item pay" v-if="item.orderStatus === '1'" @click.stop="goPagePay(item)">去支付</view>
  43. <view class="btn_item" v-if="item.orderStatus === '6'" @click.stop="goPageDetail(item)">再次预定</view>
  44. </view>
  45. </view>
  46. </uni-swipe-action-item>
  47. </uni-swipe-action>
  48. <view class="noData" v-if="!orderList.length">
  49. <img src="../../static/images/noData.png" />
  50. 暂无数据
  51. </view>
  52. </view>
  53. </template>
  54. <script>
  55. export default {
  56. data() {
  57. return {
  58. // 订单列表
  59. orderList: [],
  60. // 倒计时时间(毫秒)
  61. countDownTime: 1000 * 60 * 15,
  62. // 当前页
  63. page: 1,
  64. // 每页多少条数据
  65. rows: 6,
  66. // 一共多少条数据
  67. total: '',
  68. // 是否显示距离差
  69. showdDistance: false,
  70. // 用户定位经度
  71. myLng: 0,
  72. // 用户定位纬度
  73. myLat: 0
  74. }
  75. },
  76. onLoad() {
  77. this.getLocation()
  78. },
  79. // onShow() {
  80. // this.page = 1
  81. // this.orderList = []
  82. // this.getLocation()
  83. // },
  84. // 下拉刷新
  85. onPullDownRefresh() {
  86. setTimeout(() => {
  87. this.orderList = []
  88. this.page = 1
  89. this.getLocation()
  90. uni.stopPullDownRefresh()
  91. }, 2000)
  92. },
  93. // 上拉加载
  94. onReachBottom() {
  95. if (this.orderList.length < this.total) {
  96. this.page++
  97. this.getOrderList()
  98. } else {
  99. uni.showToast({
  100. title: '没有更多数据了',
  101. icon: 'none',
  102. mask: true
  103. })
  104. }
  105. },
  106. methods: {
  107. // 获取用户当前位置
  108. getLocation() {
  109. uni.getSetting({
  110. success: (res) => {
  111. if (!res.authSetting['scope.userLocation']) {
  112. uni.authorize({
  113. scope: 'scope.userLocation',
  114. success: (res) => {
  115. // 授权成功
  116. uni.getLocation({
  117. type: 'gcj02',
  118. success: (res) => {
  119. this.myLat = res.latitude
  120. this.myLng = res.longitude
  121. this.showdDistance = true
  122. this.getOrderList()
  123. }
  124. })
  125. },
  126. fail: () => {
  127. uni.showModal({
  128. content: '获取定位权限失败将会影响使用部分功能,是否去设置打开?',
  129. confirmText: '确认',
  130. cancelText: '取消',
  131. success: (res) => {
  132. if (res.confirm) {
  133. uni.openSetting({
  134. success: (res) => {
  135. console.log(res)
  136. this.getLocation()
  137. }
  138. })
  139. } else {
  140. this.showdDistance = false
  141. this.getOrderList()
  142. uni.showToast({
  143. title: '获取定位权限失败',
  144. icon: 'none'
  145. })
  146. }
  147. }
  148. })
  149. }
  150. })
  151. } else {
  152. uni.getLocation({
  153. type: 'gcj02',
  154. success: (res) => {
  155. this.myLat = res.latitude
  156. this.myLng = res.longitude
  157. this.showdDistance = true
  158. this.getOrderList()
  159. }
  160. })
  161. }
  162. }
  163. })
  164. },
  165. // 获取订单列表数据
  166. async getOrderList() {
  167. const res = await this.$myRequest({
  168. url: '/mhotel/ampgetBookingList.action',
  169. data: {
  170. userId: uni.getStorageSync('userInfo').id,
  171. page: this.page,
  172. rows: this.rows
  173. }
  174. })
  175. // console.log(res)
  176. if (res.code === 200) {
  177. this.total = res.data.total
  178. this.orderList = [...this.orderList, ...res.data.pageList]
  179. // 如果是待支付状态,算出剩余支付时间
  180. this.orderList.forEach((ele) => {
  181. if (ele.orderStatus === '1') {
  182. let temLockTime = ele.lockTime ? ele.lockTime * 1 : 15
  183. // 兼容ios部分系统转换时间格式
  184. let createTime = ele.createTime.slice(0, 19).replace(/-/g, '/')
  185. ele.countDownTime = new Date(createTime).getTime() + temLockTime * 60 * 1000 - new Date().getTime()
  186. }
  187. })
  188. // 如果定位成功则获取和民宿之间的距离
  189. if (this.showdDistance && this.orderList.length) {
  190. this.orderList.forEach((ele) => {
  191. let lat = ele.hotelHpositionWens.split(',')[0]
  192. let lng = ele.hotelHpositionWens.split(',')[1]
  193. ele.distance = this.calculateDistance(lat, lng)
  194. })
  195. }
  196. }
  197. },
  198. // 倒计时结束回调
  199. async finish(item) {
  200. const res = await this.$myRequest({
  201. url: '/mhotel/abkupdateOrderStatus.action',
  202. data: {
  203. bookingId: item.id
  204. }
  205. })
  206. // console.log(res)
  207. if (res.code === 200) {
  208. item.orderStatus = '6'
  209. }
  210. // uni.showModal({
  211. // title: '提示',
  212. // content: '订单已超过可支付时间',
  213. // showCancel: false,
  214. // success: async (res) => {
  215. // if (res.confirm) {
  216. // const res = await this.$myRequest({
  217. // url: '/mhotel/abkupdateOrderStatus.action',
  218. // data: {
  219. // bookingId: item.id
  220. // }
  221. // })
  222. // // console.log(res)
  223. // if (res.code === 200) {
  224. // uni.switchTab({
  225. // url: '/pages/my/my'
  226. // })
  227. // }
  228. // }
  229. // }
  230. // })
  231. },
  232. // 点击预定按钮回调
  233. goPagePay(item) {
  234. console.log(item.countDownTime)
  235. if (item.countDownTime <= 0) {
  236. uni.showModal({
  237. title: '提示',
  238. content: '订单已超过可支付时间',
  239. showCancel: false,
  240. success: async (res) => {
  241. if (res.confirm) {
  242. const res = await this.$myRequest({
  243. url: '/mhotel/abkupdateOrderStatus.action',
  244. data: {
  245. bookingId: item.id
  246. }
  247. })
  248. // console.log(res)
  249. if (res.code === 200) {
  250. this.page = 1
  251. this.orderList = []
  252. this.getOrderList()
  253. }
  254. }
  255. }
  256. })
  257. } else {
  258. uni.navigateTo({
  259. url: `/pages/pay/pay?id=${item.id}`
  260. })
  261. }
  262. },
  263. // 点击再次预定按钮回调
  264. goPageDetail(item) {
  265. uni.navigateTo({
  266. url: `/pages/detail/detail?id=${item.hotelId}&distance=${item.distance}`
  267. })
  268. // if (item.hstatus === 1 && item.hotelStatus === 1) {
  269. // uni.showModal({
  270. // title: '提示',
  271. // content: '确定再次预定吗?',
  272. // success: async (res) => {
  273. // if (res.confirm) {
  274. // const result = await this.$myRequest({
  275. // url: '/mhotel/abkcreateOrder.action',
  276. // data: {
  277. // houseId: item.houseId,
  278. // startTime: item.orderStartTime.slice(0, 10),
  279. // endTime: item.orderEndTime.slice(0, 10),
  280. // houseOrderNumber: item.houseOrderNumber,
  281. // userName: item.userName,
  282. // userPhone: item.userPhone,
  283. // userId: uni.getStorageSync('userInfo').id
  284. // }
  285. // })
  286. // if (result.code === 200) {
  287. // uni.navigateTo({
  288. // url: `/pages/pay/pay?id=${result.data}`
  289. // })
  290. // }
  291. // }
  292. // }
  293. // })
  294. // } else {
  295. // uni.showToast({
  296. // title: '该民宿暂时无法预定',
  297. // icon: 'none',
  298. // mask: true
  299. // })
  300. // }
  301. },
  302. // 点击每一个订单回调
  303. goPageOrderDetail(item) {
  304. // console.log(item)
  305. uni.navigateTo({
  306. url: `/pages/orderDetail/orderDetail?id=${item.id}&distance=${item.distance}`
  307. })
  308. },
  309. // 右侧选项内容删除按钮回调
  310. handleDelete(item) {
  311. // console.log(item)
  312. if (
  313. item.orderStatus === '1' ||
  314. item.orderStatus === '5' ||
  315. item.orderStatus === '6' ||
  316. item.orderStatus === '7' ||
  317. item.orderStatus === '8' ||
  318. item.orderStatus === '9'
  319. ) {
  320. uni.showModal({
  321. title: '提示',
  322. content: '确定删除吗?删除后不可恢复',
  323. success: async (res) => {
  324. if (res.confirm) {
  325. const res = await this.$myRequest({
  326. url: '/mhotel/abkdelBooking.action',
  327. data: {
  328. bookingId: item.id
  329. }
  330. })
  331. // console.log(res)
  332. if (res.code === 200) {
  333. uni.showToast({
  334. title: '删除成功',
  335. icon: 'success',
  336. mask: true
  337. })
  338. setTimeout(() => {
  339. this.orderList = []
  340. this.page = 1
  341. this.getOrderList()
  342. }, 1500)
  343. }
  344. }
  345. }
  346. })
  347. } else {
  348. uni.showToast({
  349. title: '当前状态订单不可删除',
  350. icon: 'none',
  351. mask: true
  352. })
  353. }
  354. },
  355. // 计算两个点之间的距离
  356. calculateDistance(lat, lng) {
  357. let centerLat = lat
  358. let centerLng = lng
  359. let red1 = (this.myLat * Math.PI) / 180.0
  360. let red2 = (centerLat * Math.PI) / 180.0
  361. let a = red1 - red2
  362. let b = (this.myLng * Math.PI) / 180.0 - (centerLng * Math.PI) / 180.0
  363. let R = 6378137
  364. let distance = R * 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(red1) * Math.cos(red2) * Math.pow(Math.sin(b / 2), 2)))
  365. let res = (distance / 1000).toFixed(2) * 1
  366. return res
  367. }
  368. }
  369. }
  370. </script>
  371. <style lang="scss" scoped>
  372. .container {
  373. box-sizing: border-box;
  374. padding: 0 20rpx 40rpx;
  375. min-height: 100vh;
  376. background-color: #f2f3f5;
  377. overflow-y: auto;
  378. .order_right {
  379. display: flex;
  380. justify-content: center;
  381. align-items: center;
  382. margin-top: 20rpx;
  383. width: 126rpx;
  384. background-color: #d43030;
  385. .img {
  386. width: 50rpx;
  387. height: 50rpx;
  388. }
  389. }
  390. .order_box {
  391. margin-top: 20rpx;
  392. box-sizing: border-box;
  393. padding: 0 22rpx;
  394. width: 710rpx;
  395. border-radius: 15rpx;
  396. background-color: #fff;
  397. .box_header {
  398. display: flex;
  399. align-items: center;
  400. height: 94rpx;
  401. .img {
  402. width: 47rpx;
  403. height: 47rpx;
  404. }
  405. .title {
  406. margin-left: 16rpx;
  407. width: 350rpx;
  408. font-size: 32rpx;
  409. font-weight: bold;
  410. overflow: hidden;
  411. white-space: nowrap;
  412. text-overflow: ellipsis;
  413. }
  414. .type {
  415. display: flex;
  416. justify-content: flex-end;
  417. align-items: center;
  418. margin-left: auto;
  419. width: 285rpx;
  420. color: #808080;
  421. font-size: 28rpx;
  422. }
  423. .type2 {
  424. color: #ff5733;
  425. }
  426. }
  427. .box_info {
  428. display: flex;
  429. height: 140rpx;
  430. .img {
  431. width: 100rpx;
  432. height: 100rpx;
  433. border-radius: 9rpx;
  434. }
  435. .info_right {
  436. display: flex;
  437. flex-direction: column;
  438. justify-content: space-around;
  439. margin-top: -5rpx;
  440. margin-left: 18rpx;
  441. height: 120rpx;
  442. color: #808080;
  443. font-size: 28rpx;
  444. .info_right_item {
  445. flex: 1;
  446. }
  447. }
  448. }
  449. .box_btn {
  450. display: flex;
  451. justify-content: flex-end;
  452. margin-top: -10rpx;
  453. height: 100rpx;
  454. .btn_item {
  455. display: flex;
  456. justify-content: center;
  457. align-items: center;
  458. margin-left: 20rpx;
  459. width: 178rpx;
  460. height: 68rpx;
  461. border-radius: 64rpx;
  462. color: #808080;
  463. font-size: 28rpx;
  464. border: 1rpx solid #808080;
  465. }
  466. .pay {
  467. color: #fff;
  468. border: none;
  469. background-color: #096562;
  470. }
  471. }
  472. }
  473. .noData {
  474. display: flex;
  475. flex-direction: column;
  476. justify-content: center;
  477. align-items: center;
  478. img {
  479. margin-top: 150rpx;
  480. width: 600rpx;
  481. height: 600rpx;
  482. }
  483. }
  484. }
  485. // 修改倒计时字体颜色
  486. ::v-deep .uv-count-down .uv-count-down__text {
  487. color: #ff5733;
  488. }
  489. </style>