info.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  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. import moment from 'moment';
  90. export default {
  91. data() {
  92. return {
  93. id: '',
  94. user: {},
  95. info: {
  96. file: []
  97. },
  98. config: {},
  99. list: [],
  100. total: 0,
  101. skip: 0,
  102. limit: 10,
  103. page: 0,
  104. // 数据是否触底
  105. is_bottom: false,
  106. scrollTop: 0,
  107. }
  108. },
  109. onLoad: async function(e) {
  110. const that = this;
  111. that.$set(that, `id`, e && e.id || '');
  112. that.searchConfig();
  113. that.search();
  114. },
  115. onShow: async function(e) {
  116. const that = this;
  117. that.searchToken();
  118. },
  119. methods: {
  120. searchToken() {
  121. const that = this;
  122. try {
  123. const res = uni.getStorageSync('token');
  124. if (res) {
  125. that.$set(that, `user`, res);
  126. }
  127. } catch (e) {
  128. uni.showToast({
  129. title: err.errmsg,
  130. icon: 'error',
  131. duration: 2000
  132. });
  133. }
  134. },
  135. searchConfig() {
  136. const that = this;
  137. try {
  138. const res = uni.getStorageSync('config');
  139. if (res) that.$set(that, `config`, res);
  140. } catch (e) {
  141. uni.showToast({
  142. title: err.errmsg,
  143. icon: 'error',
  144. duration: 2000
  145. });
  146. }
  147. },
  148. async search() {
  149. const that = this;
  150. if (that.id) {
  151. const res = await that.$api(`/hotel/${that.id}`, 'GET', {})
  152. if (res.errcode == '0') {
  153. that.$set(that, `info`, res.data)
  154. } else {
  155. uni.showToast({
  156. title: res.errmsg,
  157. });
  158. }
  159. let info = {
  160. skip: that.skip,
  161. limit: that.limit,
  162. is_use: '0',
  163. hotel: res.data._id
  164. }
  165. const room = await that.$api(`/room`, 'GET', {
  166. ...info
  167. })
  168. if (room.errcode == '0') {
  169. let list = [...that.list, ...room.data];
  170. that.$set(that, `list`, list)
  171. that.$set(that, `total`, room.total)
  172. } else {
  173. uni.showToast({
  174. title: room.errmsg,
  175. });
  176. }
  177. }
  178. },
  179. // 处理富文本
  180. formatRichText(html) {
  181. if (html) {
  182. // 富文本内容格式化
  183. return html && html.replace(/<img[^>]*>/gi, function(match, capture) {
  184. // 查找所有的 img 元素
  185. return match.replace(/style=".*"/gi, '').replace(/style='.*'/gi,
  186. '')
  187. // 删除找到的所有 img 元素中的 style 属性
  188. }).replace(/\<img/gi, '<img style="width:100%;"') // 对 img 元素增加 style 属性,并设置宽度为 100%
  189. }
  190. },
  191. // 详情
  192. toInfo(e) {
  193. uni.navigateTo({
  194. url: `/pagesHome/hotel/detail?id=${e.id||e._id}`
  195. })
  196. },
  197. // 预订
  198. toBuy(item) {
  199. const that = this;
  200. if (that.user && that.user._id) {
  201. console.log(item);
  202. } else {
  203. uni.navigateTo({
  204. url: `/pagesIndex/login/index`
  205. })
  206. }
  207. },
  208. // 收藏
  209. async onClick(item) {
  210. const that = this;
  211. let res;
  212. if (item.is_collect == false) {
  213. const form = {
  214. user: that.user._id,
  215. source: item._id,
  216. source_type: "hotel",
  217. type: '1',
  218. create_time: moment().format('YYYY-MM-DD HH:mm:ss'),
  219. }
  220. res = await that.$api(`/like`, 'POST', form);
  221. } else res = await that.$api(`/like/${item.like}`, 'DELETE', {})
  222. if (res.errcode == '0') that.search()
  223. },
  224. // 分页
  225. toPage(e) {
  226. const that = this;
  227. let list = that.list;
  228. let limit = that.limit;
  229. if (that.total > list.length) {
  230. uni.showLoading({
  231. title: '加载中',
  232. mask: true
  233. })
  234. let page = that.page + 1;
  235. that.$set(that, `page`, page)
  236. let skip = page * limit;
  237. that.$set(that, `skip`, skip)
  238. that.searchComment();
  239. uni.hideLoading();
  240. } else that.$set(that, `is_bottom`, true)
  241. },
  242. // 触底
  243. toScroll(e) {
  244. const that = this;
  245. let up = that.scrollTop;
  246. that.$set(that, `scrollTop`, e.detail.scrollTop);
  247. let num = Math.sign(up - e.detail.scrollTop);
  248. if (num == 1) that.$set(that, `is_bottom`, false);
  249. },
  250. // 清空列表
  251. clearPage() {
  252. const that = this;
  253. that.$set(that, `list`, [])
  254. that.$set(that, `skip`, 0)
  255. that.$set(that, `limit`, 10)
  256. that.$set(that, `page`, 0)
  257. },
  258. }
  259. }
  260. </script>
  261. <style lang="scss" scoped>
  262. .main {
  263. .one {
  264. .swiper {
  265. height: 70vw;
  266. .list {
  267. .image {
  268. width: 100%;
  269. height: 100%;
  270. }
  271. }
  272. }
  273. }
  274. .bottom {
  275. position: absolute;
  276. top: 65vw;
  277. left: 0;
  278. right: 0;
  279. background-color: var(--mainColor);
  280. border-radius: 20px;
  281. padding: 2vw 0 0 0;
  282. display: flex;
  283. flex-direction: column;
  284. width: 100vw;
  285. height: 100vh;
  286. .two {
  287. padding: 4vw 2vw;
  288. .two_1 {
  289. display: flex;
  290. justify-content: space-between;
  291. align-items: center;
  292. .name {
  293. width: 80vw;
  294. padding: 1vw 0;
  295. font-weight: bold;
  296. font-size: var(--font16Size);
  297. }
  298. }
  299. .two_2 {
  300. color: var(--f85Color);
  301. font-size: var(--font12Size);
  302. }
  303. }
  304. .thr {
  305. padding: 2vw;
  306. .thr_1 {
  307. display: flex;
  308. font-size: var(--font14Size);
  309. padding: 0 0 1vw 0;
  310. .left {
  311. padding: 0 1vw 0 0;
  312. font-weight: bold;
  313. }
  314. .right {
  315. color: var(--f85Color);
  316. .text_1 {
  317. font-size: var(--font14Size);
  318. color: var(--f3CColor);
  319. }
  320. }
  321. }
  322. }
  323. .four {
  324. padding: 2vw;
  325. /deep/.uni-collapse-item__title-box {
  326. padding: 0 !important;
  327. }
  328. .four_1 {
  329. font-weight: bold;
  330. font-size: var(--font16Size);
  331. padding: 0 0 1vw 0;
  332. }
  333. }
  334. .five {
  335. position: relative;
  336. flex-grow: 1;
  337. background-color: var(--f9Color);
  338. margin: 2vw 0 0 0;
  339. .list {
  340. display: flex;
  341. background-color: var(--mainColor);
  342. border: 1px solid var(--f5Color);
  343. padding: 2vw;
  344. margin: 2vw 2vw 0 2vw;
  345. border-radius: 5px;
  346. .image {
  347. width: 25vw;
  348. height: 25vw;
  349. border-radius: 5px;
  350. }
  351. .list_1 {
  352. width: 63vw;
  353. padding: 0 0 0 2vw;
  354. .name {
  355. font-size: var(--font14Size);
  356. font-weight: bold;
  357. padding: 0 0 1vw 0;
  358. }
  359. .other {
  360. font-size: var(--font12Size);
  361. padding: 0 0 2px 0;
  362. text {
  363. color: #000;
  364. }
  365. }
  366. .other_1 {
  367. color: red;
  368. }
  369. .other_2 {
  370. color: var(--f85Color);
  371. }
  372. .button {
  373. text-align: right;
  374. button {
  375. font-size: var(--font12Size);
  376. background-color: var(--f3CColor);
  377. }
  378. }
  379. }
  380. }
  381. }
  382. }
  383. }
  384. .scroll-view {
  385. position: absolute;
  386. top: 0;
  387. left: 0;
  388. right: 0;
  389. bottom: 0;
  390. .list-scroll-view {
  391. display: flex;
  392. flex-direction: column;
  393. }
  394. }
  395. .is_bottom {
  396. width: 100%;
  397. text-align: center;
  398. text {
  399. padding: 2vw 0;
  400. display: inline-block;
  401. color: var(--f85Color);
  402. font-size: var(--font14Size);
  403. }
  404. }
  405. </style>