searchUser.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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, api_getDictionary } 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. const userTypes = ref([])
  36. // placeHolder
  37. const placeHolder = ref('');
  38. // 数据
  39. const dataInfo = reactive({
  40. list: [],//工单列表
  41. idx: 0,//页码
  42. hasMore: true,//是否有更多数据
  43. incidentData: {},//事件对象
  44. keyWord: '',//搜索的关键词
  45. })
  46. // 搜索
  47. const search = debounce(getList.bind(null, 0), 500);
  48. // 获取列表信息
  49. function getList(idx){
  50. if(dataInfo.keyWord.trim() === ''){
  51. dataInfo.list = [];
  52. uni.stopPullDownRefresh();
  53. return;
  54. }
  55. uni.showLoading({
  56. title: "加载中",
  57. mask: true,
  58. });
  59. dataInfo.idx = idx === undefined ? dataInfo.idx : idx;
  60. if(dataInfo.idx === 0){
  61. dataInfo.list = [];
  62. }
  63. let postData = {
  64. idx: dataInfo.idx,
  65. sum: 20,
  66. user: {
  67. // simple: true,
  68. // engineer: undefined,
  69. // selectType: "pinyin_all",
  70. hospital:loginUserStore.loginUser.user.currentHospital.id,
  71. name: dataInfo.keyWord,
  72. userTypeIds:String(userTypes.value.map(v => v.id))
  73. }
  74. }
  75. api_user(postData).then(res => {
  76. uni.hideLoading();
  77. uni.stopPullDownRefresh();
  78. if(res.status == 200){
  79. let list = res.list || [];
  80. if(list.length){
  81. dataInfo.hasMore = true;
  82. dataInfo.list = dataInfo.idx === 0 ? list : dataInfo.list.concat(list);
  83. }else{
  84. dataInfo.hasMore = false;
  85. }
  86. }else{
  87. uni.showToast({
  88. icon: 'none',
  89. title: res.msg || '请求数据失败!'
  90. });
  91. }
  92. })
  93. }
  94. // 点击
  95. function clickItem(data){
  96. dataInfo.incidentData.requester = data;
  97. incidentBuildStore.setIncidentBuildData(dataInfo.incidentData, incidentBuildStore.incidentBuild.type, incidentBuildStore.incidentBuild.sign);
  98. uni.navigateTo({
  99. url: '/pages/buildIncident/buildIncident'
  100. })
  101. }
  102. function getUserType(){
  103. let postData = {
  104. "key": 'usertype',
  105. "type": "list",
  106. };
  107. api_getDictionary(postData).then((data) => {
  108. userTypes.value = data;
  109. getList(0);
  110. });
  111. }
  112. onLoad((option) => {
  113. if(incidentBuildStore.incidentBuild.data){
  114. dataInfo.incidentData = incidentBuildStore.incidentBuild.data;
  115. }
  116. if(incidentBuildStore.incidentBuild.type === 'buildIncident' && incidentBuildStore.incidentBuild.sign === 'requester'){
  117. placeHolder.value = '请搜索报修人'
  118. }
  119. getUserType()
  120. })
  121. onPullDownRefresh(() => {
  122. getList(0)
  123. })
  124. onReachBottom(() => {
  125. dataInfo.idx += 1;
  126. if (dataInfo.hasMore) {
  127. getList(); // 当触底时加载更多数据
  128. }
  129. })
  130. </script>
  131. <style lang="scss" scoped>
  132. .consumableList{
  133. display: flex;
  134. flex-direction: column;
  135. justify-content: space-between;
  136. .head{
  137. height: 88rpx;
  138. display: flex;
  139. align-items: center;
  140. justify-content: center;
  141. padding: 0 24rpx;
  142. position: fixed;
  143. z-index: 99;
  144. width: 100%;
  145. box-sizing: border-box;
  146. background: linear-gradient( 90deg, #58CF66 0%, #DDE9FC 100%);
  147. }
  148. .body{
  149. margin-bottom: 140rpx;
  150. margin-top: 88rpx;
  151. font-size: 26rpx;
  152. .body_item{
  153. border-bottom: 1rpx solid #DEDEDE;
  154. padding: 24rpx;
  155. }
  156. }
  157. .zanwu{
  158. margin-bottom: 140rpx;
  159. margin-top: 88rpx;
  160. display: flex;
  161. justify-content: center;
  162. .newicon-zanwu{
  163. font-size: 256rpx;
  164. color: #D6D6D6;
  165. margin-top: 140rpx;
  166. }
  167. }
  168. .foot_common_btns{
  169. position: fixed;
  170. left: 0;
  171. bottom: 0;
  172. background-color: #fff;
  173. }
  174. }
  175. </style>