info.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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.open_time||'暂无'}}</view>
  21. </view>
  22. <view class="thr">
  23. <view class="thr_1">
  24. <view class="left">地址:</view>
  25. <view class="right"><text :user-select='true'>{{info.address||'暂无'}}</text></view>
  26. </view>
  27. <view class="thr_1">
  28. <view class="left">类型:</view>
  29. <view class="right">
  30. <text class="text_1">#{{info.zhType||'暂无'}}</text>
  31. </view>
  32. </view>
  33. <view class="thr_1">
  34. <view class="left">人均消费:</view>
  35. <view class="money">
  36. <text>¥{{info.money||'暂无'}}</text>
  37. </view>
  38. </view>
  39. <view class="thr_1">
  40. <view class="left">联系电话:</view>
  41. <view class="right"><text :user-select='true'>{{info.phone||'暂无'}}</text></view>
  42. </view>
  43. </view>
  44. <view class="four" v-if="info.ticket">
  45. <view class="four_1">票务政策</view>
  46. <rich-text :nodes="formatRichText(info.ticket)"></rich-text>
  47. </view>
  48. <view class="four">
  49. <view class="four_1">简介</view>
  50. <rich-text :nodes="formatRichText(info.brief)"></rich-text>
  51. </view>
  52. </view>
  53. </view>
  54. </template>
  55. <script>
  56. import moment from 'moment';
  57. let innerAudioContext = uni.createInnerAudioContext();
  58. export default {
  59. data() {
  60. return {
  61. id: '',
  62. user: {},
  63. info: {
  64. file: []
  65. },
  66. // 字典表
  67. typeList: []
  68. }
  69. },
  70. onLoad: async function(e) {
  71. const that = this;
  72. that.$set(that, `id`, e && e.id || '');
  73. await that.searchOther();
  74. },
  75. onShow: async function(e) {
  76. const that = this;
  77. await that.searchToken();
  78. await that.search();
  79. },
  80. onHide: function(e) {
  81. innerAudioContext.destroy(); //销毁这个实例
  82. },
  83. methods: {
  84. searchToken() {
  85. const that = this;
  86. try {
  87. const res = uni.getStorageSync('token');
  88. if (res) that.$set(that, `user`, res);
  89. } catch (e) {
  90. uni.showToast({
  91. title: err.errmsg,
  92. icon: 'error',
  93. duration: 2000
  94. });
  95. }
  96. },
  97. async search() {
  98. const that = this;
  99. if (that.id) {
  100. const info = {}
  101. if (that.user._id) info.user = that.user._id
  102. const res = await that.$api(`/location/location/${that.id}`, 'GET', info)
  103. if (res.errcode == '0') {
  104. const type = that.typeList.find(i => i.value == res.data.type)
  105. if (type) res.data.zhType = type.label
  106. // 播放语音
  107. const voice = res.data.voice
  108. if (voice && voice.length > 0) {
  109. innerAudioContext.destroy(); //销毁这个实例
  110. innerAudioContext = uni.createInnerAudioContext();
  111. innerAudioContext.autoplay = true;
  112. innerAudioContext.sessionCategory = "soloAmbient"
  113. innerAudioContext.src = voice[0].url
  114. innerAudioContext.onPlay(() => {
  115. console.log('开始播放');
  116. });
  117. innerAudioContext.onError((res) => {
  118. uni.showToast({
  119. title: res.errMsg,
  120. icon: 'error',
  121. duration: 2000
  122. });
  123. });
  124. }
  125. that.$set(that, `info`, res.data)
  126. } else {
  127. uni.showToast({
  128. title: res.errmsg,
  129. });
  130. }
  131. }
  132. },
  133. // 处理富文本
  134. formatRichText(html) {
  135. if (html) {
  136. // 富文本内容格式化
  137. return html && html.replace(/<img[^>]*>/gi, function(match, capture) {
  138. // 查找所有的 img 元素
  139. return match.replace(/style=".*"/gi, '').replace(/style='.*'/gi,
  140. '')
  141. // 删除找到的所有 img 元素中的 style 属性
  142. }).replace(/\<img/gi, '<img style="width:100%;"') // 对 img 元素增加 style 属性,并设置宽度为 100%
  143. }
  144. },
  145. // 收藏
  146. async onClick(item) {
  147. const that = this;
  148. if (that.user && that.user._id) {
  149. let res;
  150. if (item.is_collect == false) {
  151. const form = {
  152. user: that.user._id,
  153. source: item._id,
  154. source_type: "location",
  155. type: '1',
  156. create_time: moment().format('YYYY-MM-DD HH:mm:ss'),
  157. }
  158. res = await that.$api(`/like`, 'POST', form);
  159. } else res = await that.$api(`/like/${item.collect}`, 'DELETE', {})
  160. if (res.errcode == '0') that.search()
  161. } else {
  162. uni.navigateTo({
  163. url: `/pagesIndex/login/index`
  164. })
  165. }
  166. },
  167. // 查询其他信息
  168. async searchOther() {
  169. const that = this;
  170. let res;
  171. // 查询类型
  172. res = await that.$api(`/dictData`, 'GET', {
  173. type: 'project_type',
  174. is_use: '0',
  175. })
  176. if (res.errcode == '0') that.$set(that, `typeList`, res.data);
  177. },
  178. }
  179. }
  180. </script>
  181. <style lang="scss" scoped>
  182. .main {
  183. .one {
  184. .swiper {
  185. height: 70vw;
  186. .list {
  187. .image {
  188. width: 100%;
  189. height: 100%;
  190. }
  191. }
  192. }
  193. }
  194. .bottom {
  195. position: absolute;
  196. top: 65vw;
  197. left: 0;
  198. right: 0;
  199. background-color: var(--mainColor);
  200. border-radius: 20px;
  201. padding: 2vw 0 0 0;
  202. .two {
  203. padding: 4vw 2vw;
  204. .two_1 {
  205. display: flex;
  206. justify-content: space-between;
  207. align-items: center;
  208. .name {
  209. width: 80vw;
  210. padding: 1vw 0;
  211. font-weight: bold;
  212. font-size: var(--font16Size);
  213. }
  214. }
  215. .two_2 {
  216. color: var(--f85Color);
  217. font-size: var(--font12Size);
  218. }
  219. }
  220. .thr {
  221. padding: 2vw;
  222. .thr_1 {
  223. display: flex;
  224. font-size: var(--font14Size);
  225. padding: 0 0 1vw 0;
  226. .left {
  227. padding: 0 1vw 0 0;
  228. font-weight: bold;
  229. }
  230. .money {
  231. color: var(--fF0Color);
  232. }
  233. .right {
  234. color: var(--f85Color);
  235. .text_1 {
  236. font-size: var(--font14Size);
  237. color: var(--f3CColor);
  238. }
  239. }
  240. }
  241. }
  242. .four {
  243. padding: 2vw;
  244. .four_1 {
  245. font-weight: bold;
  246. font-size: var(--font16Size);
  247. padding: 0 0 1vw 0;
  248. }
  249. }
  250. }
  251. }
  252. </style>