info.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. <template>
  2. <view class="main">
  3. <view class="top">
  4. <view class="left">
  5. <image v-if="info.file.length>0" class="image" :src="info.file&&info.file.length>0?info.file[0].url:''"
  6. mode="aspectFill">
  7. <image v-else class="image" :src="config.file&&config.file.length>0?config.file[0].url:''"
  8. mode="aspectFill">
  9. </view>
  10. <view class="right">
  11. <view class="right_1 textOver">{{info.name||'暂无'}}</view>
  12. <view class="right_2">已售 {{info.buy_num||0}}</view>
  13. <view class="right_3">
  14. <uni-fav :checked="info.is_collect" @tap.stop="onClick(info)" />
  15. </view>
  16. </view>
  17. </view>
  18. <view class="center">
  19. <scroll-view scroll-y="true" class="scroll-view">
  20. <view class="list-scroll-view">
  21. <view class="center_1" v-if="info.buy_explain">
  22. <view class="name">购买须知</view>
  23. <view class="cotent">
  24. <rich-text :nodes="formatRichText(info.buy_explain)"></rich-text>
  25. </view>
  26. </view>
  27. <view class="center_1" v-if="info.use_explain">
  28. <view class="name">使用说明</view>
  29. <view class="cotent">
  30. <rich-text :nodes="formatRichText(info.use_explain)"></rich-text>
  31. </view>
  32. </view>
  33. <view class="center_1" v-if="info.money_explain">
  34. <view class="name">费用说明</view>
  35. <view class="cotent">
  36. <rich-text :nodes="formatRichText(info.money_explain)"></rich-text>
  37. </view>
  38. </view>
  39. <view class="center_1" v-if="info.other_explain">
  40. <view class="name">其他说明</view>
  41. <view class="cotent">
  42. <rich-text :nodes="formatRichText(info.other_explain)"></rich-text>
  43. </view>
  44. </view>
  45. </view>
  46. </scroll-view>
  47. </view>
  48. <view class="foot">
  49. <view class="money">
  50. <text>¥{{info.original_price||'暂无'}}</text>
  51. <text>¥{{info.money||'暂无'}}起</text>
  52. </view>
  53. <view class="button">
  54. <button type="warn" @tap.stop="toBuy(info)">预订</button>
  55. </view>
  56. </view>
  57. </view>
  58. </template>
  59. <script>
  60. import moment from 'moment';
  61. export default {
  62. data() {
  63. return {
  64. id: '',
  65. user: {},
  66. config: {},
  67. info: {
  68. file: []
  69. },
  70. // 字典表
  71. typeList: []
  72. }
  73. },
  74. onLoad: async function(e) {
  75. const that = this;
  76. that.$set(that, `id`, e && e.id || '');
  77. that.searchConfig();
  78. },
  79. onShow: async function(e) {
  80. const that = this;
  81. await that.searchToken();
  82. await that.searchOther();
  83. await that.search();
  84. },
  85. methods: {
  86. searchToken() {
  87. const that = this;
  88. try {
  89. const res = uni.getStorageSync('token');
  90. if (res) {
  91. that.$set(that, `user`, res);
  92. }
  93. } catch (e) {
  94. uni.showToast({
  95. title: err.errmsg,
  96. icon: 'error',
  97. duration: 2000
  98. });
  99. }
  100. },
  101. searchConfig() {
  102. const that = this;
  103. try {
  104. const res = uni.getStorageSync('config');
  105. if (res) that.$set(that, `config`, res);
  106. } catch (e) {
  107. uni.showToast({
  108. title: err.errmsg,
  109. icon: 'error',
  110. duration: 2000
  111. });
  112. }
  113. },
  114. async search() {
  115. const that = this;
  116. if (that.id) {
  117. const info = {}
  118. if (that.user._id) info.user = that.user._id
  119. const res = await that.$api(`/ticket/ticket/${that.id}`, 'GET', info)
  120. if (res.errcode == '0') {
  121. const type = that.typeList.find(i => i.value == res.data.type)
  122. if (type) res.data.zhType = type.label
  123. that.$set(that, `info`, res.data)
  124. } else {
  125. uni.showToast({
  126. title: res.errmsg,
  127. });
  128. }
  129. }
  130. },
  131. // 处理富文本
  132. formatRichText(html) {
  133. if (html) {
  134. // 富文本内容格式化
  135. return html && html.replace(/<img[^>]*>/gi, function(match, capture) {
  136. // 查找所有的 img 元素
  137. return match.replace(/style=".*"/gi, '').replace(/style='.*'/gi,
  138. '')
  139. // 删除找到的所有 img 元素中的 style 属性
  140. }).replace(/\<img/gi, '<img style="width:100%;"') // 对 img 元素增加 style 属性,并设置宽度为 100%
  141. }
  142. },
  143. // 收藏
  144. async onClick(item) {
  145. const that = this;
  146. if (that.user && that.user._id) {
  147. let res;
  148. if (item.is_collect == false) {
  149. const form = {
  150. user: that.user._id,
  151. source: item._id,
  152. source_type: "ticket",
  153. type: '1',
  154. create_time: moment().format('YYYY-MM-DD HH:mm:ss'),
  155. }
  156. res = await that.$api(`/like`, 'POST', form);
  157. } else res = await that.$api(`/like/${item.collect}`, 'DELETE', {})
  158. if (res.errcode == '0') that.search()
  159. } else {
  160. uni.navigateTo({
  161. url: `/pagesIndex/login/index`
  162. })
  163. }
  164. },
  165. // 预订
  166. toBuy(item) {
  167. const that = this;
  168. if (that.user && that.user._id) {
  169. uni.navigateTo({
  170. url: `/pagesIndex/order/order?id=${item.id||item._id}`
  171. })
  172. } else {
  173. uni.navigateTo({
  174. url: `/pagesIndex/login/index`
  175. })
  176. }
  177. },
  178. // 查询其他信息
  179. async searchOther() {
  180. const that = this;
  181. let res;
  182. // 查询类型
  183. res = await that.$api(`/dictData`, 'GET', {
  184. type: 'project_type',
  185. is_use: '0',
  186. })
  187. if (res.errcode == '0') that.$set(that, `typeList`, res.data);
  188. },
  189. }
  190. }
  191. </script>
  192. <style lang="scss" scoped>
  193. .main {
  194. display: flex;
  195. flex-direction: column;
  196. width: 100vw;
  197. height: 100vh;
  198. .top {
  199. display: flex;
  200. padding: 1vw;
  201. border-radius: 5px;
  202. border: 1px solid var(--f9Color);
  203. .left {
  204. width: 25vw;
  205. .image {
  206. width: 100%;
  207. height: 25vw;
  208. }
  209. }
  210. .right {
  211. padding: 2vw;
  212. width: 65vw;
  213. margin: 0 0 0 2vw;
  214. .right_1 {
  215. font-size: var(--font18Size);
  216. font-weight: bold;
  217. padding: 0 0 2px 0;
  218. }
  219. .right_2 {
  220. padding: 0 0 2px 0;
  221. font-size: var(--font14Size);
  222. color: var(--f85Color);
  223. }
  224. .right_3 {
  225. display: flex;
  226. justify-content: flex-end;
  227. }
  228. }
  229. }
  230. .center {
  231. position: relative;
  232. flex-grow: 1;
  233. .center_1 {
  234. padding: 2vw;
  235. .name {
  236. padding: 3vw 0;
  237. font-size: var(--font18Size);
  238. font-weight: bold;
  239. }
  240. .content {
  241. padding: 2vw;
  242. }
  243. }
  244. }
  245. .foot {
  246. display: flex;
  247. justify-content: space-between;
  248. align-items: center;
  249. padding: 2vw;
  250. background-color: var(--mainColor);
  251. .money {
  252. text-align: right;
  253. color: var(--fF0Color);
  254. font-size: var(--font16Size);
  255. font-weight: bold;
  256. text:first-child {
  257. text-decoration: line-through;
  258. color: var(--f69Color);
  259. font-size: var(--font12Size);
  260. font-weight: 400;
  261. }
  262. }
  263. .button {
  264. button {
  265. width: 30vw;
  266. font-size: var(--font14Size);
  267. border-radius: 40px;
  268. background: linear-gradient(to right, #00BFFF, #007AFF);
  269. }
  270. }
  271. }
  272. }
  273. .scroll-view {
  274. position: absolute;
  275. top: 0;
  276. left: 0;
  277. right: 0;
  278. bottom: 0;
  279. .list-scroll-view {
  280. display: flex;
  281. flex-direction: column;
  282. }
  283. }
  284. .is_bottom {
  285. width: 100%;
  286. text-align: center;
  287. text {
  288. padding: 2vw 0;
  289. display: inline-block;
  290. color: var(--f85Color);
  291. font-size: var(--font14Size);
  292. }
  293. }
  294. </style>