orderManage.vue 14 KB

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