detail.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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>
  16. <view class="thr">
  17. <view class="thr_1">
  18. <view class="left">价格:</view>
  19. <view class="right"><text class="text_1" :user-select='true'>¥{{info.money||'暂无'}}</text></view>
  20. </view>
  21. <view class="thr_1">
  22. <view class="left">数量:</view>
  23. <view class="right">
  24. <text v-if="info.num==0">售罄</text>
  25. <text v-else>{{info.num||'暂无'}} 间</text>
  26. </view>
  27. </view>
  28. </view>
  29. <view class="four">
  30. <view class="four_1">简介</view>
  31. <rich-text :nodes="formatRichText(info.brief)"></rich-text>
  32. </view>
  33. <view class="foot">
  34. <view class="button" v-if="info.num==0"><text>售罄</text></view>
  35. <view class="button" v-else @click="toBuy"><text>预订</text></view>
  36. </view>
  37. </view>
  38. </view>
  39. </template>
  40. <script>
  41. export default {
  42. data() {
  43. return {
  44. id: '',
  45. user: {},
  46. info: {
  47. file: []
  48. },
  49. // 字典表
  50. typeList: []
  51. }
  52. },
  53. onLoad: async function(e) {
  54. const that = this;
  55. that.$set(that, `id`, e && e.id || '');
  56. await that.searchOther();
  57. await that.search();
  58. },
  59. onShow: async function(e) {
  60. const that = this;
  61. that.searchToken();
  62. },
  63. methods: {
  64. searchToken() {
  65. const that = this;
  66. try {
  67. const res = uni.getStorageSync('token');
  68. if (res) {
  69. that.$set(that, `user`, res);
  70. }
  71. } catch (e) {
  72. uni.showToast({
  73. title: err.errmsg,
  74. icon: 'error',
  75. duration: 2000
  76. });
  77. }
  78. },
  79. async search() {
  80. const that = this;
  81. if (that.id) {
  82. const res = await that.$api(`/room/${that.id}`, 'GET', {})
  83. if (res.errcode == '0') {
  84. const type = that.typeList.find(i => i.value == res.data.type)
  85. if (type) res.data.zhType = type.label
  86. that.$set(that, `info`, res.data)
  87. } else {
  88. uni.showToast({
  89. title: res.errmsg,
  90. });
  91. }
  92. }
  93. },
  94. // 处理富文本
  95. formatRichText(html) {
  96. // 富文本内容格式化
  97. return html && html.replace(/<img[^>]*>/gi, function(match, capture) {
  98. // 查找所有的 img 元素
  99. return match.replace(/style=".*"/gi, '').replace(/style='.*'/gi,
  100. '')
  101. // 删除找到的所有 img 元素中的 style 属性
  102. }).replace(/\<img/gi, '<img style="width:100%;"') // 对 img 元素增加 style 属性,并设置宽度为 100%
  103. },
  104. // 预订
  105. toBuy(item) {
  106. const that = this;
  107. if (that.user && that.user._id) {
  108. console.log("预订");
  109. } else {
  110. uni.navigateTo({
  111. url: `/pagesIndex/login/index`
  112. })
  113. }
  114. },
  115. // 查询其他信息
  116. async searchOther() {
  117. const that = this;
  118. let res;
  119. // 查询类型
  120. res = await that.$api(`/dictData`, 'GET', {
  121. type: 'project_type',
  122. is_use: '0',
  123. })
  124. if (res.errcode == '0') that.$set(that, `typeList`, res.data);
  125. },
  126. }
  127. }
  128. </script>
  129. <style lang="scss" scoped>
  130. .main {
  131. .one {
  132. .swiper {
  133. height: 70vw;
  134. .list {
  135. .image {
  136. width: 100%;
  137. height: 100%;
  138. }
  139. }
  140. }
  141. }
  142. .bottom {
  143. position: absolute;
  144. top: 65vw;
  145. left: 0;
  146. right: 0;
  147. background-color: var(--mainColor);
  148. border-radius: 20px;
  149. padding: 2vw 0 0 0;
  150. .two {
  151. padding: 4vw 2vw;
  152. .two_1 {
  153. padding: 1vw 0;
  154. font-weight: bold;
  155. font-size: var(--font16Size);
  156. }
  157. .two_2 {
  158. color: var(--f85Color);
  159. font-size: var(--font12Size);
  160. }
  161. }
  162. .thr {
  163. padding: 2vw;
  164. .thr_1 {
  165. display: flex;
  166. font-size: var(--font14Size);
  167. padding: 0 0 1vw 0;
  168. .left {
  169. padding: 0 1vw 0 0;
  170. font-weight: bold;
  171. }
  172. .right {
  173. color: var(--f85Color);
  174. .text_1 {
  175. font-size: var(--font14Size);
  176. color: var(--fF0Color);
  177. }
  178. }
  179. }
  180. }
  181. .four {
  182. padding: 2vw;
  183. margin: 0 0 15vw 0;
  184. .four_1 {
  185. font-weight: bold;
  186. font-size: var(--font16Size);
  187. padding: 0 0 1vw 0;
  188. }
  189. }
  190. }
  191. .foot {
  192. position: absolute;
  193. bottom: 0;
  194. left: 0;
  195. right: 0;
  196. .button {
  197. display: flex;
  198. justify-content: center;
  199. background-color: var(--f3CColor);
  200. padding: 4vw;
  201. text {
  202. font-size: var(--font16Size);
  203. color: var(--mainColor);
  204. }
  205. }
  206. }
  207. }
  208. </style>