index.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. <template>
  2. <view>
  3. <view class="cu-bar search bg-white">
  4. <view class="search-form round">
  5. <text class="cuIcon-search"></text>
  6. <input @input="inputSearch" @confirm="search()" :adjust-position="false" type="text"
  7. placeholder="请输入题目关键词进行搜索" confirm-type="search"></input>
  8. </view>
  9. <view class="action">
  10. <button class="cu-btn bg-primary shadow-blur round" @click="search()">搜索</button>
  11. </view>
  12. </view>
  13. <view class="question-list">
  14. <view class="question-card" v-for="(item, index) in list" :key="index">
  15. <tui-card :title="{text: item.cates.name, size: 30, color: '#7A7A7A'}"
  16. :tag="{text: item.kind_text, size: 24}" :header="item.title">
  17. <template v-slot:body>
  18. <view class="m-lr-20">
  19. <view class="m-t-20" v-if="item.is_material_child && item.material_question_id && item.material_parent">
  20. <text>材料题干:</text>
  21. <rich-text :nodes="formatRichtext(item.material_parent.title)" style="font-size: 36rpx; font-weight: bold;"></rich-text>
  22. </view>
  23. <view class="m-t-20">
  24. <text>{{item.kind_text}}:</text>
  25. <rich-text :nodes="formatRichtext(item.title)" style="font-size: 36rpx; font-weight: bold;"></rich-text>
  26. </view>
  27. <view class="options">
  28. <view v-if="item.kind == 'FILL'" v-html="getFillAnswer(item)"></view>
  29. <view v-for="(option, i) in item.options_json"
  30. :key="i"
  31. :class="item.answer.indexOf(option.key) > -1 ? ['text-green'] : []"
  32. v-else
  33. >
  34. {{ option.key }}:{{ option.value }}
  35. <block v-if="item.options_img && item.options_img[i]">
  36. <image :src="item.options_img[i].value" @click="previewOptionImage(item.options_img[i].value)" class="option-img"></image>
  37. </block>
  38. </view>
  39. </view>
  40. </view>
  41. </template>
  42. <template v-slot:footer>
  43. <text class="margin-left-sm">解析:</text>
  44. <view class="explain" v-if="item.explain" v-html="item.explain">
  45. <rich-text :nodes="formatRichtext(item.explain)" style="border-top: solid 1px #ccc;width: 100%;display: block;" v-if="item.explain"></rich-text>
  46. </view>
  47. <view class="explain" v-else>无</view>
  48. </template>
  49. </tui-card>
  50. </view>
  51. <!-- 加载状态条 -->
  52. <view class="cu-load bg-grey" :class="loadFlag" v-show="has_more || loadFlag == 'over'"></view>
  53. </view>
  54. <tui-loading v-if="showLoading"></tui-loading>
  55. <tui-no-data imgUrl="/static/img/img_noorder_3x.png" v-if="showNodata">暂无数据</tui-no-data>
  56. <!--流量主组件-->
  57. <!-- #ifdef MP-WEIXIN -->
  58. <view :class="showNodata ? ['margin-top-100'] : ['margin-top-10']" v-show="false">
  59. <kz-ad ref="adSearch" kind="BANNER" :config="ad" field="question_search_banner"></kz-ad>
  60. <kz-ad ref="adSearch" kind="VIDEO" :config="ad" field="question_search_video"></kz-ad>
  61. <kz-ad ref="adSearch" kind="VIDEO_PATCH" :config="ad" field="question_search_video_patch"></kz-ad>
  62. </view>
  63. <!-- #endif -->
  64. <login ref="login"></login>
  65. <tabbar></tabbar>
  66. </view>
  67. </template>
  68. <script>
  69. export default {
  70. data() {
  71. return {
  72. showLoading: false,
  73. showNodata: true,
  74. keyword: '',
  75. list: [],
  76. loadFlag: 'loading',
  77. current_page: 1,
  78. has_more: false,
  79. ad: {}
  80. }
  81. },
  82. computed: {
  83. // 显示填空题答案
  84. getFillAnswer(item) {
  85. return function(item) {
  86. let answer = ''
  87. if (item.answer && item.kind == 'FILL') {
  88. try {
  89. answer = '';
  90. for (let i = 0; i < item.answer.length; i++) {
  91. answer += '填空位' + (i + 1) + ':' + item.answer[i].answers.join('、') + '<br>';
  92. }
  93. } catch (e) {
  94. console.log('answer', answer, e);
  95. return value;
  96. }
  97. }
  98. return answer
  99. }
  100. },
  101. },
  102. onLoad(e) {
  103. this.ad = this.utils.getData('ad')
  104. console.log('ad data', this.ad)
  105. // 插屏广告
  106. if (this.ad.question_search_cp_open == 1) {
  107. this.adUtils.interstitial.load(this.ad.question_search_cp)
  108. this.adUtils.interstitial.show()
  109. }
  110. if (e.keyword) {
  111. this.keyword = e.keyword
  112. }
  113. },
  114. async onReachBottom() {
  115. console.log("onReachBottom")
  116. if (this.has_more) {
  117. this.current_page++
  118. this.search()
  119. }
  120. },
  121. methods: {
  122. search() {
  123. if (!this.keyword) {
  124. uni.showToast({
  125. title: '请输入关键词',
  126. icon: 'none'
  127. })
  128. return
  129. }
  130. this.loadFlag = 'loading'
  131. this.has_more = true
  132. this.http('question/search', {
  133. keyword: this.keyword,
  134. page: this.current_page
  135. }, 'post').then(res => {
  136. console.log('search res', res)
  137. if (res.code == 0) {
  138. uni.showToast({
  139. title: res.msg,
  140. icon: 'none'
  141. })
  142. return
  143. } else {
  144. this.list = res.data.list.data //this.list.concat(res.data.list.data)
  145. this.current_page = res.data.list.current_page
  146. this.has_more = res.data.list.has_more
  147. this.loadFlag = !this.has_more ? 'over' : ''
  148. this.showNodata = !this.list.length
  149. }
  150. })
  151. },
  152. inputSearch(e) {
  153. console.log('input e', e)
  154. this.keyword = e.detail.value
  155. },
  156. // 试题标题
  157. formatRichtext(text) {
  158. if (text) {
  159. return this.utils.formatRichText(text)
  160. }
  161. return '无'
  162. },
  163. // 选项图片yulan
  164. previewOptionImage(src) {
  165. if (!src) {
  166. return
  167. }
  168. uni.previewImage({
  169. current: 0,
  170. urls: [src]
  171. });
  172. }
  173. }
  174. }
  175. </script>
  176. <style>
  177. .question-list {
  178. padding-bottom: 20rpx;
  179. }
  180. .question-card {
  181. margin: 20rpx 0;
  182. }
  183. .options {
  184. margin: 20rpx 0;
  185. line-height: 50rpx;
  186. }
  187. .explain {
  188. margin: 20rpx 0;
  189. padding: 15rpx;
  190. padding-top: 0rpx;
  191. }
  192. .margin-top-10 {
  193. margin-top: 10px;
  194. }
  195. .margin-top-100 {
  196. margin-top: 100%;
  197. }
  198. .option-img {
  199. width: 100rpx;
  200. height: 100rpx;
  201. }
  202. </style>