searchUser.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <template>
  2. <view class="consumableList">
  3. <view class="head">
  4. <uni-search-bar v-model="dataInfo.keyWord" :placeholder="placeHolder" bgColor="#F8F8F8" @input="search" cancelButton="none" focus :radius="18" />
  5. </view>
  6. <view class="body" v-if="dataInfo.list.length">
  7. <view class="body_item ellipsis" v-for="data in dataInfo.list" :key="data.id" @click="clickItem(data)">
  8. {{data.name}}<template v-if="data.account">({{data.account}})</template>
  9. </view>
  10. </view>
  11. <view class="zanwu" v-else>
  12. <text class="newicon newicon-zanwu"></text>
  13. </view>
  14. <view class="foot_common_btns">
  15. <button @click="goBack" type="default" class="primaryButton btn">返回</button>
  16. </view>
  17. </view>
  18. </template>
  19. <script setup>
  20. import { debounce } from 'lodash-es'
  21. import { ref, reactive} from 'vue'
  22. import { onLoad, onPullDownRefresh, onReachBottom } from '@dcloudio/uni-app'
  23. import { api_user } from "@/http/api.js"
  24. import { defaultColor } from '@/static/js/theme.js'
  25. import { useSetTitle } from '@/share/useSetTitle.js'
  26. import { useLoginUserStore } from '@/stores/loginUser'
  27. import { useIncidentBuildStore } from '@/stores/incidentBuild'
  28. import { useGoBack } from '@/share/useGoBack.js'
  29. useSetTitle();
  30. const loginUserStore = useLoginUserStore();
  31. const incidentBuildStore = useIncidentBuildStore();
  32. const { goBack } = useGoBack();
  33. // 主题颜色
  34. const primaryColor = ref(defaultColor)
  35. // placeHolder
  36. const placeHolder = ref('');
  37. // 数据
  38. const dataInfo = reactive({
  39. list: [],//工单列表
  40. idx: 0,//页码
  41. hasMore: true,//是否有更多数据
  42. incidentData: {},//事件对象
  43. keyWord: '',//搜索的关键词
  44. })
  45. // 搜索
  46. const search = debounce(getList.bind(null, 0), 500);
  47. // 获取列表信息
  48. function getList(idx){
  49. if(dataInfo.keyWord.trim() === ''){
  50. dataInfo.list = [];
  51. uni.stopPullDownRefresh();
  52. return;
  53. }
  54. uni.showLoading({
  55. title: "加载中",
  56. mask: true,
  57. });
  58. dataInfo.idx = idx === undefined ? dataInfo.idx : idx;
  59. if(dataInfo.idx === 0){
  60. dataInfo.list = [];
  61. }
  62. let postData = {
  63. idx: dataInfo.idx,
  64. sum: 20,
  65. user: {
  66. simple: true,
  67. engineer: undefined,
  68. selectType: "pinyin_all",
  69. name: dataInfo.keyWord,
  70. }
  71. }
  72. api_user(postData).then(res => {
  73. uni.hideLoading();
  74. uni.stopPullDownRefresh();
  75. if(res.status == 200){
  76. let list = res.list || [];
  77. if(list.length){
  78. dataInfo.hasMore = true;
  79. dataInfo.list = dataInfo.idx === 0 ? list : dataInfo.list.concat(list);
  80. }else{
  81. dataInfo.hasMore = false;
  82. }
  83. }else{
  84. uni.showToast({
  85. icon: 'none',
  86. title: res.msg || '请求数据失败!'
  87. });
  88. }
  89. })
  90. }
  91. // 点击
  92. function clickItem(data){
  93. dataInfo.incidentData.requester = data;
  94. incidentBuildStore.setIncidentBuildData(dataInfo.incidentData, incidentBuildStore.incidentBuild.type, incidentBuildStore.incidentBuild.sign);
  95. uni.navigateTo({
  96. url: '/pages/buildIncident/buildIncident'
  97. })
  98. }
  99. onLoad((option) => {
  100. if(incidentBuildStore.incidentBuild.data){
  101. dataInfo.incidentData = incidentBuildStore.incidentBuild.data;
  102. }
  103. if(incidentBuildStore.incidentBuild.type === 'buildIncident' && incidentBuildStore.incidentBuild.sign === 'requester'){
  104. placeHolder.value = '请搜索报修人'
  105. }
  106. getList(0);
  107. })
  108. onPullDownRefresh(() => {
  109. getList(0)
  110. })
  111. onReachBottom(() => {
  112. dataInfo.idx += 1;
  113. if (dataInfo.hasMore) {
  114. getList(); // 当触底时加载更多数据
  115. }
  116. })
  117. </script>
  118. <style lang="scss" scoped>
  119. .consumableList{
  120. display: flex;
  121. flex-direction: column;
  122. justify-content: space-between;
  123. .head{
  124. height: 88rpx;
  125. display: flex;
  126. align-items: center;
  127. justify-content: center;
  128. padding: 0 24rpx;
  129. position: fixed;
  130. z-index: 99;
  131. width: 100%;
  132. box-sizing: border-box;
  133. background: linear-gradient( 90deg, #58CF66 0%, #DDE9FC 100%);
  134. }
  135. .body{
  136. margin-bottom: 140rpx;
  137. margin-top: 88rpx;
  138. font-size: 26rpx;
  139. .body_item{
  140. border-bottom: 1rpx solid #DEDEDE;
  141. padding: 24rpx;
  142. }
  143. }
  144. .zanwu{
  145. margin-bottom: 140rpx;
  146. margin-top: 88rpx;
  147. display: flex;
  148. justify-content: center;
  149. .newicon-zanwu{
  150. font-size: 256rpx;
  151. color: #D6D6D6;
  152. margin-top: 140rpx;
  153. }
  154. }
  155. .foot_common_btns{
  156. position: fixed;
  157. left: 0;
  158. bottom: 0;
  159. background-color: #fff;
  160. }
  161. }
  162. </style>