detail.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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. if (html) {
  97. // 富文本内容格式化
  98. return html && html.replace(/<img[^>]*>/gi, function(match, capture) {
  99. // 查找所有的 img 元素
  100. return match.replace(/style=".*"/gi, '').replace(/style='.*'/gi,
  101. '')
  102. // 删除找到的所有 img 元素中的 style 属性
  103. }).replace(/\<img/gi, '<img style="width:100%;"') // 对 img 元素增加 style 属性,并设置宽度为 100%
  104. }
  105. },
  106. // 预订
  107. toBuy(item) {
  108. const that = this;
  109. if (that.user && that.user._id) {
  110. console.log("预订");
  111. } else {
  112. uni.navigateTo({
  113. url: `/pagesIndex/login/index`
  114. })
  115. }
  116. },
  117. // 查询其他信息
  118. async searchOther() {
  119. const that = this;
  120. let res;
  121. // 查询类型
  122. res = await that.$api(`/dictData`, 'GET', {
  123. type: 'project_type',
  124. is_use: '0',
  125. })
  126. if (res.errcode == '0') that.$set(that, `typeList`, res.data);
  127. },
  128. }
  129. }
  130. </script>
  131. <style lang="scss" scoped>
  132. .main {
  133. .one {
  134. .swiper {
  135. height: 70vw;
  136. .list {
  137. .image {
  138. width: 100%;
  139. height: 100%;
  140. }
  141. }
  142. }
  143. }
  144. .bottom {
  145. position: absolute;
  146. top: 65vw;
  147. left: 0;
  148. right: 0;
  149. background-color: var(--mainColor);
  150. border-radius: 20px;
  151. padding: 2vw 0 0 0;
  152. .two {
  153. padding: 4vw 2vw;
  154. .two_1 {
  155. padding: 1vw 0;
  156. font-weight: bold;
  157. font-size: var(--font16Size);
  158. }
  159. .two_2 {
  160. color: var(--f85Color);
  161. font-size: var(--font12Size);
  162. }
  163. }
  164. .thr {
  165. padding: 2vw;
  166. .thr_1 {
  167. display: flex;
  168. font-size: var(--font14Size);
  169. padding: 0 0 1vw 0;
  170. .left {
  171. padding: 0 1vw 0 0;
  172. font-weight: bold;
  173. }
  174. .right {
  175. color: var(--f85Color);
  176. .text_1 {
  177. font-size: var(--font14Size);
  178. color: var(--fF0Color);
  179. }
  180. }
  181. }
  182. }
  183. .four {
  184. padding: 2vw;
  185. margin: 0 0 15vw 0;
  186. .four_1 {
  187. font-weight: bold;
  188. font-size: var(--font16Size);
  189. padding: 0 0 1vw 0;
  190. }
  191. }
  192. }
  193. .foot {
  194. position: absolute;
  195. bottom: 0;
  196. left: 0;
  197. right: 0;
  198. .button {
  199. display: flex;
  200. justify-content: center;
  201. background-color: var(--f3CColor);
  202. padding: 4vw;
  203. text {
  204. font-size: var(--font16Size);
  205. color: var(--mainColor);
  206. }
  207. }
  208. }
  209. }
  210. </style>