index.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. <template>
  2. <view :style="colorStyle">
  3. <view class="px-32">
  4. <view class="fs-36 fw-500 lh-54rpx mt-44">{{ articleInfo.title }}</view>
  5. <view class="flex fs-24 text--w111-999 mt-16">
  6. <text>{{ articleInfo.catename }}</text>
  7. <text class="px-16">|</text>
  8. <text>{{ articleInfo.add_time }}</text>
  9. </view>
  10. <view class="content fs-30 text--w111-333 lh-52rpx mt-32">
  11. <jyf-parser :html="content" ref="article" :tag-style="tagStyle"></jyf-parser>
  12. </view>
  13. <view class="bg--w111-f5f5f5 rd-24rpx w-full flex-between-center p-20 mt-32" @tap="goDetail" v-if="store_info.id">
  14. <image :src="store_info.image" class="w-160 h-160 rd-16rpx" mode="aspectFill"></image>
  15. <view class="flex-1 h-160 flex-col justify-between pl-20">
  16. <view class="w-full fs-28 lh-40rpx line2">{{ store_info.store_name }}</view>
  17. <view class="flex justify-between items-end">
  18. <baseMoney :money="store_info.price" symbolSize="28" integerSize="44" decimalSize="28" weight></baseMoney>
  19. <view class="w-136 h-52 rd-30rpx flex-center fs-22 text--w111-fff bg-gradient">立即购买</view>
  20. </view>
  21. </view>
  22. </view>
  23. </view>
  24. <view class="h-200"></view>
  25. <view class="bg--w111-fff w-full z-99 fixed-lb pb-safe">
  26. <view class="w-full h-128 pr-20 flex-y-center" v-if="store_info.id">
  27. <!-- #ifdef H5 -->
  28. <text class="iconfont icon-ic_transmit1 fs-44 ml-52" @tap="listenerActionSheet"></text>
  29. <!-- #endif -->
  30. <!-- #ifdef MP -->
  31. <button open-type="share" hover-class="none">
  32. <text class="iconfont icon-ic_transmit1 fs-44 ml-52"></text>
  33. </button>
  34. <!-- #endif -->
  35. <view class="ml-80 relative">
  36. <text class="iconfont icon-ic_Eyes fs-44"></text>
  37. <text class="fs-20 fw-500 abs-num">{{ articleInfo.visit }}</text>
  38. </view>
  39. <view class="ml-80 relative" :class="{ active: articleInfo.is_like }" @tap="giveLike">
  40. <text class="iconfont icon-ic_Like fs-44"></text>
  41. <text class="fs-20 fw-500 likes-num">{{ articleInfo.likes }}</text>
  42. </view>
  43. <view class="w-300 h-72 rd-36rpx flex-center bg--w111-f5f5f5 ml-80" @tap="goDetail">
  44. <image :src="store_info.image" class="w-48 h-48 rd-8rpx"></image>
  45. <view class="pl-12">
  46. <view class="fs-22 fw-500 w-172 line1">{{ store_info.store_name }}</view>
  47. <view class="fs-20 SemiBold">¥{{ store_info.price }}</view>
  48. </view>
  49. </view>
  50. </view>
  51. <view class="w-full px-120 h-128 flex-between-center" v-else>
  52. <!-- #ifdef H5 -->
  53. <text class="iconfont icon-ic_transmit1 fs-44" @tap="listenerActionSheet"></text>
  54. <!-- #endif -->
  55. <!-- #ifdef MP -->
  56. <button open-type="share" hover-class="none">
  57. <text class="iconfont icon-ic_transmit1 fs-44"></text>
  58. </button>
  59. <!-- #endif -->
  60. <view class="relative">
  61. <text class="iconfont icon-ic_Eyes fs-44"></text>
  62. <text class="fs-20 fw-500 abs-num">{{ articleInfo.visit }}</text>
  63. </view>
  64. <view class="relative" :class="{ active: articleInfo.is_like }" @tap="giveLike">
  65. <text class="iconfont icon-ic_Like fs-44"></text>
  66. <text class="fs-20 fw-500 likes-num">{{ articleInfo.likes }}</text>
  67. </view>
  68. </view>
  69. </view>
  70. <shareInfo @setShareInfoStatus="setShareInfoStatus" :shareInfoStatus="shareInfoStatus"></shareInfo>
  71. </view>
  72. </template>
  73. <script>
  74. import { getArticleDetails } from '@/api/api.js';
  75. import { articleStarApi } from '@/api/user.js';
  76. import shareInfo from '../components/shareInfo/index.vue';
  77. import home from '@/components/home';
  78. import parser from '@/components/jyf-parser/jyf-parser';
  79. import colors from '@/mixins/color';
  80. import { mapGetters } from 'vuex';
  81. import { toLogin } from '@/libs/login.js';
  82. import { HTTP_REQUEST_URL } from '@/config/app';
  83. export default {
  84. components: {
  85. shareInfo,
  86. home,
  87. 'jyf-parser': parser
  88. },
  89. mixins: [colors],
  90. data() {
  91. return {
  92. id: 0,
  93. articleInfo: [],
  94. store_info: {},
  95. content: '',
  96. shareInfoStatus: false,
  97. tagStyle: {
  98. img: 'width:100%;display:block;border-radius:8px;',
  99. table: 'width:100%',
  100. video: 'width:100%'
  101. }
  102. };
  103. },
  104. computed: mapGetters(['isLogin']),
  105. /**
  106. * 生命周期函数--监听页面加载
  107. */
  108. onLoad: function (options) {
  109. if (options.hasOwnProperty('id')) {
  110. this.id = options.id;
  111. } else {
  112. // #ifndef H5
  113. uni.navigateBack({ delta: 1 });
  114. // #endif
  115. // #ifdef H5
  116. history.back();
  117. // #endif
  118. }
  119. },
  120. onShow: function () {
  121. uni.removeStorageSync('form_type_cart');
  122. this.getArticleOne();
  123. },
  124. methods: {
  125. getArticleOne: function () {
  126. let that = this;
  127. getArticleDetails(that.id).then((res) => {
  128. uni.setNavigationBarTitle({
  129. title: res.data.title.substring(0, 7) + '...'
  130. });
  131. that.$set(that, 'articleInfo', res.data);
  132. that.$set(that, 'store_info', res.data.store_info ? res.data.store_info : {});
  133. that.content = res.data.content;
  134. // #ifdef H5
  135. if (this.$wechat.isWeixin()) {
  136. this.setShareInfo();
  137. }
  138. // #endif
  139. });
  140. },
  141. giveLike() {
  142. if (!this.isLogin) {
  143. toLogin();
  144. } else {
  145. articleStarApi(this.id, {
  146. status: this.articleInfo.is_like ? 0 : 1
  147. }).then((res) => {
  148. let that = this;
  149. uni.showToast({
  150. title: this.articleInfo.is_like ? '取消点赞' : '点赞成功',
  151. icon: 'none',
  152. success: () => {
  153. if (this.articleInfo.is_like) {
  154. that.articleInfo.likes = that.articleInfo.likes - 1;
  155. that.articleInfo.is_like = 0;
  156. } else {
  157. that.articleInfo.likes = that.articleInfo.likes + 1;
  158. that.articleInfo.is_like = 1;
  159. }
  160. }
  161. });
  162. });
  163. }
  164. },
  165. goDetail() {
  166. uni.navigateTo({
  167. url: '/pages/goods_details/index?id=' + this.store_info.id
  168. });
  169. },
  170. listenerActionSheet() {
  171. if (this.$wechat.isWeixin()) {
  172. this.shareInfoStatus = true;
  173. } else {
  174. let that = this;
  175. uni.setClipboardData({
  176. data: HTTP_REQUEST_URL + '/pages/extension/news_details/index?id=' + that.id,
  177. success: () => {
  178. uni.showToast({
  179. title: '已复制页面链接'
  180. });
  181. }
  182. });
  183. }
  184. },
  185. setShareInfoStatus() {
  186. this.shareInfoStatus = false;
  187. },
  188. setShareInfo: function () {
  189. let href = location.href;
  190. let configAppMessage = {
  191. desc: this.articleInfo.synopsis,
  192. title: this.articleInfo.title,
  193. link: href,
  194. imgUrl: this.articleInfo.image_input.length ? this.articleInfo.image_input[0] : ''
  195. };
  196. this.$wechat.wechatEvevt(['updateAppMessageShareData', 'updateTimelineShareData'], configAppMessage);
  197. }
  198. }
  199. };
  200. </script>
  201. <style>
  202. page {
  203. background-color: #ffffff;
  204. }
  205. </style>
  206. <style lang="scss">
  207. .active {
  208. color: var(--view-theme);
  209. }
  210. .content {
  211. text-indent: 2em;
  212. }
  213. .ml-52 {
  214. margin-left: 52rpx;
  215. }
  216. .ml-80 {
  217. margin-left: 80rpx;
  218. }
  219. .abs-num {
  220. position: absolute;
  221. right: -26rpx;
  222. top: -10rpx;
  223. }
  224. .likes-num {
  225. position: absolute;
  226. right: -16rpx;
  227. top: -10rpx;
  228. }
  229. .SemiBold {
  230. font-family: 'SemiBold';
  231. }
  232. </style>