orderManage.vue 15 KB

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