info.vue 9.3 KB

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