asking.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <template>
  2. <!-- pages/fuwu/fuwu.wxml -->
  3. <view class="contain">
  4. <!-- 问答类别 -->
  5. <swiper :indicator-dots="true" :autoplay="false" class="swiper">
  6. <swiper-item v-for="(e,idx) in loopTimes" style="padding: 1% 2% 0 0;">
  7. <view class="swiper-item">
  8. <view v-for="(v,index) in imgListExcuted(idx)" style="width: 48%;height: 27%;" @tap="goType(v.id,v.type)">
  9. <image :src="loadImgSrcLocalhost(v.path)" class="img"></image>
  10. <view class="textDesc">
  11. <h2>{{v.type}}</h2>
  12. <span>{{v.questionNum}}</span>
  13. </view>
  14. </view>
  15. </view>
  16. </swiper-item>
  17. </swiper>
  18. <!-- 问答列表 -->
  19. <view class="rnwdList" v-for="(item, index) in hotQuestionList" :key="index" @tap="goDetails(item.id)">
  20. <span class="lb">{{ item.type }}</span>
  21. <view class="list">
  22. <span class="listTitle">{{ item.title }}</span>
  23. <view class="jlSj">
  24. <span class="jf">
  25. {{ item.score }}
  26. <em class="iconfont icon-jifen"></em>
  27. </span>
  28. <view class="ck">
  29. <span>
  30. <em class="iconfont icon-pinglun"></em>
  31. {{ item.comment }}
  32. </span>
  33. <span>
  34. <em class="iconfont icon-chakan"></em>
  35. {{ item.browse }}
  36. </span>
  37. <span>
  38. <em class="iconfont icon-shoucang"></em>
  39. {{ item.collect }}
  40. </span>
  41. </view>
  42. </view>
  43. </view>
  44. <em class="iconfont icon-xiangyoujiantou"></em>
  45. </view>
  46. <button type="primary" @click="goAddQuestion()" v-if="form.id==null">新增</button>
  47. </view>
  48. </template>
  49. <script>
  50. import upload from '@/components/upload/index.vue'
  51. import {getTypeList,getHotQuestionList} from '@/api/asking/asking.js'
  52. export default {
  53. components: {
  54. upload
  55. },
  56. data() {
  57. return {
  58. imageList:[
  59. '/profile/upload/2024/03/02/D5hjxYkldNxIef093ae65b2128b1293b86a7b537ed98_20240302170757A001.png',
  60. '/profile/upload/2024/03/02/D5hjxYkldNxIef093ae65b2128b1293b86a7b537ed98_20240302170757A001.png'
  61. ],
  62. typeList: [
  63. {
  64. type: null,
  65. path: null
  66. }
  67. ],
  68. hotQuestionList: [{}],
  69. // 查询参数
  70. queryParams: {
  71. pageNum: 1,
  72. pageSize: 6,
  73. },
  74. loopTimes:null
  75. };
  76. }
  77. /**
  78. * 生命周期函数--监听页面加载
  79. */,
  80. onLoad(options) {
  81. this.getTypeList();
  82. this.getHotQuestionList();
  83. },
  84. methods: {
  85. imgListExcuted(idx){
  86. let result = []
  87. let pageNum = 6
  88. if(idx == 0){
  89. result = this.typeList.slice(0,6)
  90. } else {
  91. this.typeList.filter(e => {
  92. if(this.typeList.length - pageNum * (idx +1) < pageNum){
  93. console.log(this.typeList.slice(idx*6,this.typeList.length))
  94. // 剩余信息不够6条 全部返回
  95. result = this.typeList.slice(idx*6,this.typeList.length)
  96. } else {
  97. result = this.typeList.slice(idx*6,idx*6 +6 )
  98. }
  99. })
  100. }
  101. console.log('加工后result',idx,result)
  102. return result
  103. },
  104. //获取类型列表
  105. getTypeList(){
  106. getTypeList(this.queryParams).then(res =>{
  107. this.typeList = res.rows
  108. this.typeList = this.typeList.concat(this.typeList)
  109. this.loopTimes = (this.typeList.length/6).toFixed(0) *1
  110. console.log('loopTimes',this.loopTimes)
  111. })
  112. },
  113. //获取热门问答列表
  114. getHotQuestionList(){
  115. getHotQuestionList().then(res =>{
  116. this.hotQuestionList = res.rows
  117. })
  118. },
  119. //按类型跳转问题列表
  120. goType(id,type) {
  121. uni.setStorageSync('id', id)
  122. uni.navigateTo({
  123. url: '/pages/asking/questionlist?type='+type
  124. });
  125. },
  126. //新增问题
  127. goAddQuestion() {
  128. uni.navigateTo({
  129. url: '/pages/asking/addquestion'
  130. });
  131. },
  132. goDetails(id) {
  133. uni.navigateTo({
  134. url: '/pages/asking/questiondetails?id=' + id
  135. });
  136. },
  137. updateImg(imgList){
  138. this.imageList = imgList;
  139. }
  140. }
  141. };
  142. </script>
  143. <style lang="scss">
  144. @import '@/pages/asking/asking.css';
  145. .contain {
  146. height: 100%;
  147. display: flex;
  148. justify-content: space-between;
  149. padding: 0rpx 20rpx;
  150. box-sizing: border-box;
  151. flex-wrap: wrap;
  152. }
  153. /deep/ .wx-swiper-dots-horizontal {
  154. bottom: 0 !important;
  155. }
  156. .swiper{
  157. width: 100%;
  158. height: 324px;
  159. .swiper-item{
  160. display: flex;
  161. flex-wrap: wrap;
  162. height: 100%;
  163. justify-content: space-between;
  164. .img{
  165. width: 100%;
  166. height: 100%;
  167. }
  168. .textDesc{
  169. position: relative;
  170. height: 78%;
  171. bottom: 95%;
  172. left: 1%;
  173. }
  174. .textDesc h2{
  175. font-size: 36rpx;
  176. position: absolute;
  177. left: 30rpx;
  178. top: 40rpx;
  179. z-index: 1;
  180. font-weight: bold;
  181. }
  182. .textDesc span {
  183. font-size: 30rpx;
  184. position: absolute;
  185. left: 30rpx;
  186. top: 88rpx;
  187. z-index: 1;
  188. }
  189. }
  190. .swiper-item view{
  191. width: 300px;
  192. height: 30%;
  193. background-size: 100% 100%;
  194. }
  195. .swiper-item view image{
  196. width: 100%;
  197. height: 100%;
  198. }
  199. }
  200. </style>