index.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. <template>
  2. <view class="main">
  3. <view class="info">
  4. <scroll-view scroll-y="true" :scroll-top="scrollTop" class="scroll-view">
  5. <view class="list-scroll-view">
  6. <view class="one">
  7. <swiperImg :imgsList='info.file'></swiperImg>
  8. </view>
  9. <view class="two">
  10. <view class="two_1">{{info.title||'暂无标题'}}</view>
  11. <view class="two_2">#{{info.zhType||'暂无类型'}}</view>
  12. <view class="two_3">
  13. <rich-text :nodes="info.content"></rich-text>
  14. </view>
  15. <view class="two_4">发布时间:{{info.create_time}}</view>
  16. </view>
  17. <view class="thr">
  18. <view class="thr_1">评论 {{total}}</view>
  19. <scroll-view scroll-y="true" class="scroll-view" @scrolltolower="toPage" @scroll="toScroll">
  20. <view class="list-scroll-view">
  21. <view class="thr_2">
  22. <view class="list" v-for="(item,index) in list" :key="index">
  23. <image class="image"
  24. :src="item.user_file&&item.user_file.length>0?item.user_file[0].url:'../../static/my.png'"
  25. mode="aspectFill">
  26. </image>
  27. <view class="other">
  28. <view class="name textOver">{{item.user_name||'暂无'}}</view>
  29. <view class="content">{{item.content||'暂无'}}</view>
  30. </view>
  31. </view>
  32. </view>
  33. <view class="is_bottom" v-if="is_bottom">
  34. <text>{{config.bottom_title}}</text>
  35. </view>
  36. </view>
  37. </scroll-view>
  38. </view>
  39. </view>
  40. </scroll-view>
  41. </view>
  42. <view class="foot">
  43. <view class="foot_1">
  44. <view class="left">
  45. <uni-easyinput confirmType="send" prefixIcon="chatbubble" v-model="content" placeholder="说点什么..."
  46. @confirm="toSend">
  47. </uni-easyinput>
  48. </view>
  49. <view class="right">
  50. <view class="right_1"><text class="iconfont icon-aixin"></text>{{like}}</view>
  51. <view class="right_1"><text class="iconfont icon-shoucang1"></text>{{collect}}</view>
  52. <view class="right_1" @click="pageScroll"><text class="iconfont icon-pinglun"></text>{{total}}
  53. </view>
  54. </view>
  55. </view>
  56. </view>
  57. </view>
  58. </view>
  59. </template>
  60. <script>
  61. import swiperImg from '../../components/swiper/index.vue';
  62. export default {
  63. components: {
  64. swiperImg
  65. },
  66. data() {
  67. return {
  68. id: '',
  69. config: {},
  70. user: {},
  71. info: {},
  72. // 评论数量
  73. list: [],
  74. total: 0,
  75. skip: 0,
  76. limit: 15,
  77. page: 0,
  78. // 数据是否触底
  79. is_bottom: false,
  80. scrollTop: 0,
  81. // 评论
  82. content: '',
  83. // 点赞
  84. like: 0,
  85. // 收藏
  86. collect: 0,
  87. // 字典表
  88. typeList: []
  89. }
  90. },
  91. onLoad: async function(e) {
  92. const that = this;
  93. that.$set(that, `id`, e && e.id || '');
  94. that.searchConfig();
  95. that.searchToken();
  96. await that.searchOther();
  97. await that.search();
  98. },
  99. methods: {
  100. searchConfig() {
  101. const that = this;
  102. try {
  103. const res = uni.getStorageSync('config');
  104. if (res) that.$set(that, `config`, res);
  105. } catch (e) {
  106. uni.showToast({
  107. title: err.errmsg,
  108. icon: 'error',
  109. duration: 2000
  110. });
  111. }
  112. },
  113. searchToken() {
  114. const that = this;
  115. try {
  116. const res = uni.getStorageSync('token');
  117. if (res) that.$set(that, `user`, res);
  118. } catch (e) {
  119. uni.showToast({
  120. title: err.errmsg,
  121. icon: 'error',
  122. duration: 2000
  123. });
  124. }
  125. },
  126. // 查询
  127. async search() {
  128. const that = this;
  129. if (that.id) {
  130. let res;
  131. res = await that.$api(`/article/${that.id}`, 'GET', {})
  132. if (res.errcode == '0') {
  133. res.data.content = res.data.content.replace(/\<img/gi, '<img class="rich-img"');
  134. res.data.zhType = that.searchDict(res.data.type, 'type')
  135. that.$set(that, `info`, res.data)
  136. uni.setNavigationBarTitle({
  137. title: res.data.contact_name
  138. });
  139. } else {
  140. uni.showToast({
  141. title: res.errmsg,
  142. });
  143. }
  144. // 查看评论
  145. that.searchComment();
  146. }
  147. },
  148. // 查看评论
  149. async searchComment() {
  150. const that = this;
  151. let res;
  152. let info = {
  153. skip: that.skip,
  154. limit: that.limit,
  155. is_use: '0',
  156. status: '1',
  157. }
  158. res = await that.$api(`/comment`, 'GET', {
  159. ...info,
  160. });
  161. if (res.errcode == '0') {
  162. let list = [...that.list, ...res.data];
  163. that.$set(that, `list`, list);
  164. that.$set(that, `total`, res.total)
  165. } else {
  166. uni.showToast({
  167. title: res.errmsg,
  168. icon: 'none'
  169. })
  170. }
  171. },
  172. // 查询字典表
  173. searchDict(e, model) {
  174. const that = this;
  175. let data
  176. if (model == 'type') {
  177. data = that.typeList.find((i) => i.value == e);
  178. if (data) return data.label
  179. else return '暂无'
  180. }
  181. },
  182. // 滑动到评论专区
  183. pageScroll() {
  184. this.$set(this, `scrollTop`, 0);
  185. this.$nextTick(() => {
  186. setTimeout(() => {
  187. uni.createSelectorQuery().in(this).select(`.thr`).boundingClientRect(res => {
  188. this.$set(this, `scrollTop`, res.top);
  189. }).exec();
  190. }, 100);
  191. });
  192. },
  193. // 发送
  194. async toSend(item) {
  195. if (that.user && that.user._id) {
  196. console.log(item);
  197. } else {
  198. uni.navigateTo({
  199. url: `/pagesIndex/login/index`
  200. })
  201. }
  202. },
  203. // 分页
  204. toPage(e) {
  205. const that = this;
  206. let list = that.list;
  207. let limit = that.limit;
  208. if (that.total > list.length) {
  209. uni.showLoading({
  210. title: '加载中',
  211. mask: true
  212. })
  213. let page = that.page + 1;
  214. that.$set(that, `page`, page)
  215. let skip = page * limit;
  216. that.$set(that, `skip`, skip)
  217. that.searchComment();
  218. uni.hideLoading();
  219. } else that.$set(that, `is_bottom`, true)
  220. },
  221. // 触底
  222. toScroll(e) {
  223. const that = this;
  224. let up = that.scrollTop;
  225. that.$set(that, `scrollTop`, e.detail.scrollTop);
  226. let num = Math.sign(up - e.detail.scrollTop);
  227. if (num == 1) that.$set(that, `is_bottom`, false);
  228. },
  229. // 清空列表
  230. clearPage() {
  231. const that = this;
  232. that.$set(that, `list`, [])
  233. that.$set(that, `skip`, 0)
  234. that.$set(that, `limit`, 15)
  235. that.$set(that, `page`, 0)
  236. },
  237. // 查询其他信息
  238. async searchOther() {
  239. const that = this;
  240. let res;
  241. // 查询类型
  242. res = await that.$api(`/dictData`, 'GET', {
  243. type: 'home_tabs',
  244. is_use: '0',
  245. })
  246. if (res.errcode == '0') that.$set(that, `typeList`, res.data);
  247. },
  248. }
  249. }
  250. </script>
  251. <style lang="scss" scoped>
  252. .main {
  253. display: flex;
  254. flex-direction: column;
  255. box-sizing: border-box;
  256. width: 100vw;
  257. height: 100vh;
  258. .info {
  259. position: relative;
  260. flex-grow: 1;
  261. .two {
  262. padding: 0 2vw;
  263. .two_1 {
  264. font-weight: bold;
  265. font-size: var(--font16Size);
  266. }
  267. .two_2 {
  268. padding: 1vw;
  269. font-size: var(--font14Size);
  270. color: var(--f3CColor);
  271. }
  272. .two_3 {
  273. .rich-img {
  274. width: 100% !important;
  275. display: block;
  276. }
  277. }
  278. .two_4 {
  279. padding: 3vw 0;
  280. font-size: var(--font12Size);
  281. color: var(--f99Color);
  282. border-bottom: 1px solid var(--f9Color);
  283. }
  284. }
  285. .thr {
  286. .thr_1 {
  287. padding: 2vw 4vw;
  288. font-weight: 500;
  289. font-size: var(--font15Size);
  290. border-bottom: 1px solid var(--f9Color);
  291. }
  292. }
  293. }
  294. .foot {
  295. padding: 2vw;
  296. background-color: var(--mainColor);
  297. .foot_1 {
  298. display: flex;
  299. justify-content: space-between;
  300. align-items: center;
  301. .left {
  302. .is-input-border {
  303. border-radius: 45px;
  304. }
  305. }
  306. .right {
  307. width: 45%;
  308. display: flex;
  309. justify-content: space-around;
  310. .right_1 {
  311. display: flex;
  312. align-items: center;
  313. font-size: var(--font17Szie);
  314. .iconfont {
  315. padding: 0 1vw;
  316. font-size: 21px;
  317. }
  318. }
  319. }
  320. }
  321. }
  322. }
  323. .scroll-view {
  324. position: absolute;
  325. top: 0;
  326. left: 0;
  327. right: 0;
  328. bottom: 0;
  329. .list-scroll-view {
  330. display: flex;
  331. flex-direction: column;
  332. }
  333. }
  334. .is_bottom {
  335. width: 100%;
  336. text-align: center;
  337. text {
  338. padding: 2vw 0;
  339. display: inline-block;
  340. color: var(--f85Color);
  341. font-size: var(--font14Size);
  342. }
  343. }
  344. </style>