list.vue 4.4 KB

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