list.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <template>
  2. <view class="content">
  3. <view class="one">
  4. <up-list @scrolltolower="scrolltolower">
  5. <up-list-item v-for="(item, index) in list" :key="index">
  6. <view class="list">
  7. <view class="value">
  8. <view class="title">问题类型:</view>
  9. <view class="label">{{getDict(item.type,'type')}}</view>
  10. </view>
  11. <view class="value">
  12. <view class="title">问题描述:</view>
  13. <view class="label">{{item.brief||'暂无'}}</view>
  14. </view>
  15. <view class="value">
  16. <view class="title">时间:</view>
  17. <view class="label">{{item.time||'暂无'}}</view>
  18. </view>
  19. <view class="value">
  20. <view class="title">状态:</view>
  21. <view class="label" :class="[item.status=='0'?'red':'']">{{getDict(item.status,'status')}}
  22. </view>
  23. </view>
  24. </view>
  25. </up-list-item>
  26. </up-list>
  27. </view>
  28. <view class="is_bottom" v-if="is_bottom">
  29. <text>{{config.bottom_title||'没有更多了!'}}</text>
  30. </view>
  31. </view>
  32. </template>
  33. <script setup lang="ts">
  34. import { inject, computed, ref } from 'vue';
  35. //该依赖已内置不需要单独安装
  36. import { onShow, onPullDownRefresh } from "@dcloudio/uni-app";
  37. // 请求接口
  38. const $api = inject('$api');
  39. const $config = inject('$config');
  40. // 基本信息
  41. const config = ref({ logo: [], file: [] });
  42. // 列表
  43. const list = ref([]);
  44. const total = ref(0);
  45. const skip = ref(0);
  46. const limit = ref(5);
  47. const page = ref(0);
  48. // 数据是否触底
  49. const is_bottom = ref(false);
  50. // 字典表
  51. const typeList = ref([]);
  52. const statusList = ref([]);
  53. // user
  54. const user = computed(() => {
  55. return uni.getStorageSync('user');
  56. })
  57. onShow(async () => {
  58. await searchConfig();
  59. await searchOther();
  60. await search();
  61. })
  62. onPullDownRefresh(async () => {
  63. await clearPage();
  64. await search();
  65. uni.stopPullDownRefresh();
  66. })
  67. // config信息
  68. const searchConfig = async () => {
  69. config.value = uni.getStorageSync('config');
  70. };
  71. // 其他查询信息
  72. const searchOther = async () => {
  73. let res;
  74. // 问题类型
  75. res = await $api(`dictData`, 'GET', { code: 'opinionType', is_use: '0' });
  76. if (res.errcode === 0) typeList.value = res.data;
  77. // 问题状态
  78. res = await $api(`dictData`, 'GET', { code: 'opinionStatus', is_use: '0' });
  79. if (res.errcode === 0) statusList.value = res.data;
  80. };
  81. // 查询
  82. const search = async () => {
  83. const info = {
  84. skip: skip.value,
  85. limit: limit.value,
  86. user: user.value._id
  87. }
  88. const res = await $api('opinion', 'GET', info);
  89. if (res.errcode === 0) {
  90. list.value = list.value.concat(res.data)
  91. total.value = res.total
  92. } else {
  93. uni.showToast({
  94. title: res.errmsg || '',
  95. icon: 'error',
  96. });
  97. }
  98. };
  99. const getDict = (data, model) => {
  100. let res
  101. if (model == 'status') res = statusList.value.find((f) => f.value == data)
  102. else if (model == 'type') res = typeList.value.find((f) => f.value == data)
  103. return res.label || '暂无'
  104. }
  105. const scrolltolower = () => {
  106. if (total.value > list.value.length) {
  107. uni.showLoading({
  108. title: '加载中',
  109. mask: true
  110. })
  111. page.value = page.value + 1;
  112. skip.value = page.value * limit.value;
  113. search();
  114. uni.hideLoading();
  115. } else is_bottom.value = true
  116. };
  117. // 清空列表
  118. const clearPage = () => {
  119. list.value = []
  120. skip.value = 0
  121. limit.value = 6
  122. page.value = 0
  123. };
  124. </script>
  125. <style lang="scss" scoped>
  126. .content {
  127. display: flex;
  128. flex-direction: column;
  129. min-height: 100vh;
  130. background-color: var(--f1Color);
  131. .one {
  132. margin: 0 2vw;
  133. border-radius: 5px;
  134. .list {
  135. background-color: var(--mainColor);
  136. border-bottom: 1px solid var(--f5Color);
  137. margin: 2vw 0 0 0;
  138. border-radius: 4px;
  139. padding: 2vw;
  140. .value {
  141. display: flex;
  142. padding: 1vw 2vw;
  143. .title {
  144. font-size: var(--font16Size);
  145. font-weight: bold;
  146. margin: 0 2vw 0 0;
  147. }
  148. .label {
  149. width: 70%;
  150. font-size: var(--font14Size);
  151. color: var(--f85Color);
  152. }
  153. .red {
  154. color: var(--ff0Color);
  155. }
  156. }
  157. }
  158. }
  159. .is_bottom {
  160. width: 100%;
  161. text-align: center;
  162. text {
  163. padding: 2vw 0;
  164. display: inline-block;
  165. color: var(--f85Color);
  166. font-size: var(--font12Size);
  167. }
  168. }
  169. }
  170. </style>