orderManage.vue 14 KB

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