info.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. <template>
  2. <view class="main">
  3. <view class="one" v-if="info.file.length>0">
  4. <swiper class="swiper" circular :indicator-dots="true" indicator-color="#F5F5F5"
  5. indicator-active-color="#ffffff" :autoplay="true" :interval="3000" :duration="1000">
  6. <swiper-item class="list" v-for="(item,index) in info.file" :key="index">
  7. <image class="image" :src="item.url" mode="">
  8. </image>
  9. </swiper-item>
  10. </swiper>
  11. </view>
  12. <view class="bottom">
  13. <view class="two">
  14. <view class="two_1">
  15. <view class="name textOne">{{info.name||'暂无'}}</view>
  16. <view class="collect">
  17. <uni-fav :checked="info.is_collect" @click="onClick(info)" />
  18. </view>
  19. </view>
  20. <view class="two_2">入住时间:{{info.start_time||'暂无'}}</view>
  21. <view class="two_2">退房时间:{{info.end_time||'暂无'}}</view>
  22. </view>
  23. <view class="thr">
  24. <view class="thr_1">
  25. <view class="left">地址:</view>
  26. <view class="right"><text :user-select='true'>{{info.address||'暂无'}}</text></view>
  27. </view>
  28. <view class="thr_1">
  29. <view class="left">总客房数:</view>
  30. <view class="right">
  31. <text>{{info.num||'暂无'}}间</text>
  32. </view>
  33. </view>
  34. <view class="thr_1">
  35. <view class="left">联系电话:</view>
  36. <view class="right"><text :user-select='true'>{{info.phone||'暂无'}}</text></view>
  37. </view>
  38. </view>
  39. <view class="four">
  40. <uni-collapse>
  41. <uni-collapse-item title="酒店民宿简介">
  42. <view class="content">
  43. <view class="four" v-if="info.prompt">
  44. <view class="four_1">接待提示</view>
  45. <rich-text :nodes="formatRichText(info.prompt)"></rich-text>
  46. </view>
  47. <view class="four" v-if="info.children">
  48. <view class="four_1">儿童及加床</view>
  49. <rich-text :nodes="formatRichText(info.children)"></rich-text>
  50. </view>
  51. <view class="four">
  52. <view class="four_1">简介</view>
  53. <rich-text :nodes="formatRichText(info.brief)"></rich-text>
  54. </view>
  55. </view>
  56. </uni-collapse-item>
  57. </uni-collapse>
  58. </view>
  59. <view class="five">
  60. <scroll-view scroll-y="true" class="scroll-view" @scrolltolower="toPage" @scroll="toScroll">
  61. <view class="list-scroll-view">
  62. <view class="list" v-for="(item, index) in list" :key="index" @tap="toInfo(item)">
  63. <image class="image" :src="item.file&&item.file.length>0?item.file[0].url:''"
  64. mode="aspectFill">
  65. </image>
  66. <view class="list_1">
  67. <view class="name textOne">{{ item.name ||'暂无'}}</view>
  68. <view class="other other_1">¥{{ item.money ||'暂无'}}</view>
  69. <view v-if="item.num==0" class="other other_2"><text>当天剩余房量:</text>售罄</view>
  70. <view v-else class="other other_2"><text>当天剩余房量:</text>
  71. {{ item.num||'暂无' }} 间
  72. </view>
  73. <view class="button">
  74. <button v-if="item.num==0" size="mini" type="primary">售罄</button>
  75. <button v-else @tap.stop="toBuy(item)" size="mini" type="primary">预订</button>
  76. </view>
  77. </view>
  78. </view>
  79. <view class="is_bottom" v-if="is_bottom">
  80. <text>{{config.bottom_title}}</text>
  81. </view>
  82. </view>
  83. </scroll-view>
  84. </view>
  85. </view>
  86. </view>
  87. </template>
  88. <script>
  89. export default {
  90. data() {
  91. return {
  92. id: '',
  93. user: {},
  94. info: {
  95. file: []
  96. },
  97. config: {},
  98. list: [],
  99. total: 0,
  100. skip: 0,
  101. limit: 10,
  102. page: 0,
  103. // 数据是否触底
  104. is_bottom: false,
  105. scrollTop: 0,
  106. }
  107. },
  108. onLoad: async function(e) {
  109. const that = this;
  110. that.$set(that, `id`, e && e.id || '');
  111. that.searchConfig();
  112. that.search();
  113. },
  114. onShow: async function(e) {
  115. const that = this;
  116. that.searchToken();
  117. },
  118. methods: {
  119. searchToken() {
  120. const that = this;
  121. try {
  122. const res = uni.getStorageSync('token');
  123. if (res) {
  124. that.$set(that, `user`, res);
  125. }
  126. } catch (e) {
  127. uni.showToast({
  128. title: err.errmsg,
  129. icon: 'error',
  130. duration: 2000
  131. });
  132. }
  133. },
  134. searchConfig() {
  135. const that = this;
  136. try {
  137. const res = uni.getStorageSync('config');
  138. if (res) that.$set(that, `config`, res);
  139. } catch (e) {
  140. uni.showToast({
  141. title: err.errmsg,
  142. icon: 'error',
  143. duration: 2000
  144. });
  145. }
  146. },
  147. async search() {
  148. const that = this;
  149. if (that.id) {
  150. const res = await that.$api(`/hotel/${that.id}`, 'GET', {})
  151. if (res.errcode == '0') {
  152. that.$set(that, `info`, res.data)
  153. } else {
  154. uni.showToast({
  155. title: res.errmsg,
  156. });
  157. }
  158. let info = {
  159. skip: that.skip,
  160. limit: that.limit,
  161. is_use: '0',
  162. hotel: res.data._id
  163. }
  164. const room = await that.$api(`/room`, 'GET', {
  165. ...info
  166. })
  167. if (room.errcode == '0') {
  168. let list = [...that.list, ...room.data];
  169. that.$set(that, `list`, list)
  170. that.$set(that, `total`, room.total)
  171. } else {
  172. uni.showToast({
  173. title: room.errmsg,
  174. });
  175. }
  176. }
  177. },
  178. // 处理富文本
  179. formatRichText(html) {
  180. if (html) {
  181. // 富文本内容格式化
  182. return html && html.replace(/<img[^>]*>/gi, function(match, capture) {
  183. // 查找所有的 img 元素
  184. return match.replace(/style=".*"/gi, '').replace(/style='.*'/gi,
  185. '')
  186. // 删除找到的所有 img 元素中的 style 属性
  187. }).replace(/\<img/gi, '<img style="width:100%;"') // 对 img 元素增加 style 属性,并设置宽度为 100%
  188. }
  189. },
  190. // 详情
  191. toInfo(e) {
  192. uni.navigateTo({
  193. url: `/pagesHome/hotel/detail?id=${e.id||e._id}`
  194. })
  195. },
  196. // 预订
  197. toBuy(item) {
  198. const that = this;
  199. if (that.user && that.user._id) {
  200. console.log(item);
  201. } else {
  202. uni.navigateTo({
  203. url: `/pagesIndex/login/index`
  204. })
  205. }
  206. },
  207. // 收藏
  208. onClick() {
  209. const that = this;
  210. console.log("收藏");
  211. },
  212. // 分页
  213. toPage(e) {
  214. const that = this;
  215. let list = that.list;
  216. let limit = that.limit;
  217. if (that.total > list.length) {
  218. uni.showLoading({
  219. title: '加载中',
  220. mask: true
  221. })
  222. let page = that.page + 1;
  223. that.$set(that, `page`, page)
  224. let skip = page * limit;
  225. that.$set(that, `skip`, skip)
  226. that.searchComment();
  227. uni.hideLoading();
  228. } else that.$set(that, `is_bottom`, true)
  229. },
  230. // 触底
  231. toScroll(e) {
  232. const that = this;
  233. let up = that.scrollTop;
  234. that.$set(that, `scrollTop`, e.detail.scrollTop);
  235. let num = Math.sign(up - e.detail.scrollTop);
  236. if (num == 1) that.$set(that, `is_bottom`, false);
  237. },
  238. // 清空列表
  239. clearPage() {
  240. const that = this;
  241. that.$set(that, `list`, [])
  242. that.$set(that, `skip`, 0)
  243. that.$set(that, `limit`, 10)
  244. that.$set(that, `page`, 0)
  245. },
  246. }
  247. }
  248. </script>
  249. <style lang="scss" scoped>
  250. .main {
  251. .one {
  252. .swiper {
  253. height: 70vw;
  254. .list {
  255. .image {
  256. width: 100%;
  257. height: 100%;
  258. }
  259. }
  260. }
  261. }
  262. .bottom {
  263. position: absolute;
  264. top: 65vw;
  265. left: 0;
  266. right: 0;
  267. background-color: var(--mainColor);
  268. border-radius: 20px;
  269. padding: 2vw 0 0 0;
  270. display: flex;
  271. flex-direction: column;
  272. width: 100vw;
  273. height: 100vh;
  274. .two {
  275. padding: 4vw 2vw;
  276. .two_1 {
  277. display: flex;
  278. justify-content: space-between;
  279. align-items: center;
  280. .name {
  281. width: 80vw;
  282. padding: 1vw 0;
  283. font-weight: bold;
  284. font-size: var(--font16Size);
  285. }
  286. }
  287. .two_2 {
  288. color: var(--f85Color);
  289. font-size: var(--font12Size);
  290. }
  291. }
  292. .thr {
  293. padding: 2vw;
  294. .thr_1 {
  295. display: flex;
  296. font-size: var(--font14Size);
  297. padding: 0 0 1vw 0;
  298. .left {
  299. padding: 0 1vw 0 0;
  300. font-weight: bold;
  301. }
  302. .right {
  303. color: var(--f85Color);
  304. .text_1 {
  305. font-size: var(--font14Size);
  306. color: var(--f3CColor);
  307. }
  308. }
  309. }
  310. }
  311. .four {
  312. padding: 2vw;
  313. /deep/.uni-collapse-item__title-box {
  314. padding: 0 !important;
  315. }
  316. .four_1 {
  317. font-weight: bold;
  318. font-size: var(--font16Size);
  319. padding: 0 0 1vw 0;
  320. }
  321. }
  322. .five {
  323. position: relative;
  324. flex-grow: 1;
  325. background-color: var(--f9Color);
  326. margin: 2vw 0 0 0;
  327. .list {
  328. display: flex;
  329. background-color: var(--mainColor);
  330. border: 1px solid var(--f5Color);
  331. padding: 2vw;
  332. margin: 2vw 2vw 0 2vw;
  333. border-radius: 5px;
  334. .image {
  335. width: 25vw;
  336. height: 25vw;
  337. border-radius: 5px;
  338. }
  339. .list_1 {
  340. width: 63vw;
  341. padding: 0 0 0 2vw;
  342. .name {
  343. font-size: var(--font14Size);
  344. font-weight: bold;
  345. padding: 0 0 1vw 0;
  346. }
  347. .other {
  348. font-size: var(--font12Size);
  349. padding: 0 0 2px 0;
  350. text {
  351. color: #000;
  352. }
  353. }
  354. .other_1 {
  355. color: red;
  356. }
  357. .other_2 {
  358. color: var(--f85Color);
  359. }
  360. .button {
  361. text-align: right;
  362. button {
  363. font-size: var(--font12Size);
  364. background-color: var(--f3CColor);
  365. }
  366. }
  367. }
  368. }
  369. }
  370. }
  371. }
  372. .scroll-view {
  373. position: absolute;
  374. top: 0;
  375. left: 0;
  376. right: 0;
  377. bottom: 0;
  378. .list-scroll-view {
  379. display: flex;
  380. flex-direction: column;
  381. }
  382. }
  383. .is_bottom {
  384. width: 100%;
  385. text-align: center;
  386. text {
  387. padding: 2vw 0;
  388. display: inline-block;
  389. color: var(--f85Color);
  390. font-size: var(--font14Size);
  391. }
  392. }
  393. </style>