info.vue 10 KB

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