info.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  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) {
  89. that.$set(that, `user`, res);
  90. }
  91. } catch (e) {
  92. uni.showToast({
  93. title: err.errmsg,
  94. icon: 'error',
  95. duration: 2000
  96. });
  97. }
  98. },
  99. async search() {
  100. const that = this;
  101. if (that.id) {
  102. const info = {}
  103. if (that.user._id) info.user = that.user._id
  104. const res = await that.$api(`/location/location/${that.id}`, 'GET', info)
  105. if (res.errcode == '0') {
  106. const type = that.typeList.find(i => i.value == res.data.type)
  107. if (type) res.data.zhType = type.label
  108. // 播放语音
  109. const voice = res.data.voice
  110. if (voice && voice.length > 0) {
  111. innerAudioContext.destroy(); //销毁这个实例
  112. innerAudioContext = uni.createInnerAudioContext();
  113. innerAudioContext.autoplay = true;
  114. innerAudioContext.sessionCategory = "soloAmbient"
  115. innerAudioContext.src = voice[0].url
  116. innerAudioContext.onPlay(() => {
  117. console.log('开始播放');
  118. });
  119. innerAudioContext.onError((res) => {
  120. uni.showToast({
  121. title: res.errMsg,
  122. icon: 'error',
  123. duration: 2000
  124. });
  125. });
  126. }
  127. that.$set(that, `info`, res.data)
  128. } else {
  129. uni.showToast({
  130. title: res.errmsg,
  131. });
  132. }
  133. }
  134. },
  135. // 处理富文本
  136. formatRichText(html) {
  137. if (html) {
  138. // 富文本内容格式化
  139. return html && html.replace(/<img[^>]*>/gi, function(match, capture) {
  140. // 查找所有的 img 元素
  141. return match.replace(/style=".*"/gi, '').replace(/style='.*'/gi,
  142. '')
  143. // 删除找到的所有 img 元素中的 style 属性
  144. }).replace(/\<img/gi, '<img style="width:100%;"') // 对 img 元素增加 style 属性,并设置宽度为 100%
  145. }
  146. },
  147. // 收藏
  148. async onClick(item) {
  149. const that = this;
  150. if (that.user && that.user._id) {
  151. let res;
  152. if (item.is_collect == false) {
  153. const form = {
  154. user: that.user._id,
  155. source: item._id,
  156. source_type: "location",
  157. type: '1',
  158. create_time: moment().format('YYYY-MM-DD HH:mm:ss'),
  159. }
  160. res = await that.$api(`/like`, 'POST', form);
  161. } else res = await that.$api(`/like/${item.collect}`, 'DELETE', {})
  162. if (res.errcode == '0') that.search()
  163. } else {
  164. uni.navigateTo({
  165. url: `/pagesIndex/login/index`
  166. })
  167. }
  168. },
  169. // 查询其他信息
  170. async searchOther() {
  171. const that = this;
  172. let res;
  173. // 查询类型
  174. res = await that.$api(`/dictData`, 'GET', {
  175. type: 'project_type',
  176. is_use: '0',
  177. })
  178. if (res.errcode == '0') that.$set(that, `typeList`, res.data);
  179. },
  180. }
  181. }
  182. </script>
  183. <style lang="scss" scoped>
  184. .main {
  185. .one {
  186. .swiper {
  187. height: 70vw;
  188. .list {
  189. .image {
  190. width: 100%;
  191. height: 100%;
  192. }
  193. }
  194. }
  195. }
  196. .bottom {
  197. position: absolute;
  198. top: 65vw;
  199. left: 0;
  200. right: 0;
  201. background-color: var(--mainColor);
  202. border-radius: 20px;
  203. padding: 2vw 0 0 0;
  204. .two {
  205. padding: 4vw 2vw;
  206. .two_1 {
  207. display: flex;
  208. justify-content: space-between;
  209. align-items: center;
  210. .name {
  211. width: 80vw;
  212. padding: 1vw 0;
  213. font-weight: bold;
  214. font-size: var(--font16Size);
  215. }
  216. }
  217. .two_2 {
  218. color: var(--f85Color);
  219. font-size: var(--font12Size);
  220. }
  221. }
  222. .thr {
  223. padding: 2vw;
  224. .thr_1 {
  225. display: flex;
  226. font-size: var(--font14Size);
  227. padding: 0 0 1vw 0;
  228. .left {
  229. padding: 0 1vw 0 0;
  230. font-weight: bold;
  231. }
  232. .money {
  233. color: var(--fF0Color);
  234. }
  235. .right {
  236. color: var(--f85Color);
  237. .text_1 {
  238. font-size: var(--font14Size);
  239. color: var(--f3CColor);
  240. }
  241. }
  242. }
  243. }
  244. .four {
  245. padding: 2vw;
  246. .four_1 {
  247. font-weight: bold;
  248. font-size: var(--font16Size);
  249. padding: 0 0 1vw 0;
  250. }
  251. }
  252. }
  253. }
  254. </style>