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