asking.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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. return result
  104. },
  105. //获取类型列表
  106. getTypeList(){
  107. getTypeList(this.queryParams).then(res =>{
  108. this.typeList = res.rows
  109. this.loopTimes = (this.typeList.length/6).toFixed(0) *1
  110. })
  111. },
  112. //获取热门问题列表
  113. getHotQuestionList(){
  114. getHotQuestionList().then(res =>{
  115. this.hotQuestionList = res.rows
  116. })
  117. },
  118. //按类型跳转问题列表
  119. goType(id,type) {
  120. uni.setStorageSync('id', id)
  121. uni.navigateTo({
  122. url: '/pages/asking/questionlist?type='+type
  123. });
  124. },
  125. //新增问题
  126. goAddQuestion() {
  127. uni.navigateTo({
  128. url: '/pages/asking/addquestion'
  129. });
  130. },
  131. goDetails(id) {
  132. uni.navigateTo({
  133. url: '/pages/asking/questiondetails?id=' + id
  134. });
  135. },
  136. updateImg(imgList){
  137. this.imageList = imgList;
  138. }
  139. }
  140. };
  141. </script>
  142. <style lang="scss">
  143. @import '@/pages/asking/asking.css';
  144. .contain {
  145. height: 100%;
  146. display: flex;
  147. justify-content: space-between;
  148. padding: 0rpx 20rpx;
  149. box-sizing: border-box;
  150. flex-wrap: wrap;
  151. }
  152. /deep/ .wx-swiper-dots-horizontal {
  153. bottom: 0 !important;
  154. }
  155. .swiper{
  156. width: 100%;
  157. height: 324px;
  158. .swiper-item{
  159. display: flex;
  160. flex-wrap: wrap;
  161. height: 100%;
  162. justify-content: space-between;
  163. .img{
  164. width: 100%;
  165. height: 100%;
  166. }
  167. .textDesc{
  168. position: relative;
  169. height: 78%;
  170. bottom: 95%;
  171. left: 1%;
  172. }
  173. .textDesc h2{
  174. font-size: 36rpx;
  175. position: absolute;
  176. left: 30rpx;
  177. top: 40rpx;
  178. z-index: 1;
  179. font-weight: bold;
  180. opacity: .5;
  181. }
  182. .textDesc span {
  183. font-size: 30rpx;
  184. position: absolute;
  185. left: 30rpx;
  186. top: 88rpx;
  187. z-index: 1;
  188. opacity: .7;
  189. }
  190. }
  191. .swiper-item view{
  192. width: 300px;
  193. height: 30%;
  194. background-size: 100% 100%;
  195. }
  196. .swiper-item view image{
  197. width: 100%;
  198. height: 100%;
  199. }
  200. }
  201. </style>