asking.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. <uni-fab ref="fab" horizontal="right"
  47. @fabClick="goAddQuestion()"/>
  48. <!-- <button type="primary" @click="goAddQuestion()" v-if="form.id==null">新增</button> -->
  49. </view>
  50. </template>
  51. <script>
  52. import upload from '@/components/upload/index.vue'
  53. import {getTypeList,getHotQuestionList} from '@/api/asking/asking.js'
  54. export default {
  55. components: {
  56. upload
  57. },
  58. data() {
  59. return {
  60. imageList:[
  61. '/profile/upload/2024/03/02/D5hjxYkldNxIef093ae65b2128b1293b86a7b537ed98_20240302170757A001.png',
  62. '/profile/upload/2024/03/02/D5hjxYkldNxIef093ae65b2128b1293b86a7b537ed98_20240302170757A001.png'
  63. ],
  64. typeList: [
  65. {
  66. type: null,
  67. path: null
  68. }
  69. ],
  70. hotQuestionList: [{}],
  71. // 查询参数
  72. queryParams: {
  73. pageNum: 1,
  74. pageSize: 6,
  75. },
  76. loopTimes:null
  77. };
  78. }
  79. /**
  80. * 生命周期函数--监听页面加载
  81. */,
  82. onLoad(options) {
  83. this.getTypeList();
  84. this.getHotQuestionList();
  85. },
  86. methods: {
  87. imgListExcuted(idx){
  88. let result = []
  89. let pageNum = 6
  90. if(idx == 0){
  91. result = this.typeList.slice(0,6)
  92. } else {
  93. this.typeList.filter(e => {
  94. if(this.typeList.length - pageNum * (idx +1) < pageNum){
  95. console.log(this.typeList.slice(idx*6,this.typeList.length))
  96. // 剩余信息不够6条 全部返回
  97. result = this.typeList.slice(idx*6,this.typeList.length)
  98. } else {
  99. result = this.typeList.slice(idx*6,idx*6 +6 )
  100. }
  101. })
  102. }
  103. console.log('加工后result',idx,result)
  104. return result
  105. },
  106. //获取类型列表
  107. getTypeList(){
  108. getTypeList(this.queryParams).then(res =>{
  109. this.typeList = res.rows
  110. this.loopTimes = (this.typeList.length/6).toFixed(0) *1
  111. console.log('loopTimes',this.loopTimes)
  112. })
  113. },
  114. //获取热门问题列表
  115. getHotQuestionList(){
  116. getHotQuestionList().then(res =>{
  117. this.hotQuestionList = res.rows
  118. })
  119. },
  120. //按类型跳转问题列表
  121. goType(id,type) {
  122. uni.setStorageSync('id', id)
  123. uni.navigateTo({
  124. url: '/pages/asking/questionlist?type='+type
  125. });
  126. },
  127. //新增问题
  128. goAddQuestion() {
  129. uni.navigateTo({
  130. url: '/pages/asking/addquestion'
  131. });
  132. },
  133. goDetails(id) {
  134. uni.navigateTo({
  135. url: '/pages/asking/questiondetails?id=' + id
  136. });
  137. },
  138. updateImg(imgList){
  139. this.imageList = imgList;
  140. }
  141. }
  142. };
  143. </script>
  144. <style lang="scss">
  145. @import '@/pages/asking/asking.css';
  146. .contain {
  147. height: 100%;
  148. display: flex;
  149. justify-content: space-between;
  150. padding: 0rpx 20rpx;
  151. box-sizing: border-box;
  152. flex-wrap: wrap;
  153. }
  154. /deep/ .wx-swiper-dots-horizontal {
  155. bottom: 0 !important;
  156. }
  157. .swiper{
  158. width: 100%;
  159. height: 324px;
  160. .swiper-item{
  161. display: flex;
  162. flex-wrap: wrap;
  163. height: 100%;
  164. justify-content: space-between;
  165. .img{
  166. width: 100%;
  167. height: 100%;
  168. }
  169. .textDesc{
  170. position: relative;
  171. height: 78%;
  172. bottom: 95%;
  173. left: 1%;
  174. }
  175. .textDesc h2{
  176. font-size: 36rpx;
  177. position: absolute;
  178. left: 30rpx;
  179. top: 40rpx;
  180. z-index: 1;
  181. font-weight: bold;
  182. opacity: .5;
  183. }
  184. .textDesc span {
  185. font-size: 30rpx;
  186. position: absolute;
  187. left: 30rpx;
  188. top: 88rpx;
  189. z-index: 1;
  190. opacity: .7;
  191. }
  192. }
  193. .swiper-item view{
  194. width: 300px;
  195. height: 30%;
  196. background-size: 100% 100%;
  197. }
  198. .swiper-item view image{
  199. width: 100%;
  200. height: 100%;
  201. }
  202. }
  203. </style>