searchUser.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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:'',
  71. name: dataInfo.keyWord,
  72. userTypeIds:String(userTypes.value.map(v => v.id))
  73. }
  74. }
  75. if(loginUserStore.loginUser.user.currentHospital.parent){
  76. postData.user.hospital = loginUserStore.loginUser.user.currentHospital.parent.id
  77. }else{
  78. postData.user.hospital = loginUserStore.loginUser.user.currentHospital.id
  79. }
  80. api_user(postData).then(res => {
  81. uni.hideLoading();
  82. uni.stopPullDownRefresh();
  83. if(res.status == 200){
  84. let list = res.list || [];
  85. if(list.length){
  86. dataInfo.hasMore = true;
  87. dataInfo.list = dataInfo.idx === 0 ? list : dataInfo.list.concat(list);
  88. }else{
  89. dataInfo.hasMore = false;
  90. }
  91. }else{
  92. uni.showToast({
  93. icon: 'none',
  94. title: res.msg || '请求数据失败!'
  95. });
  96. }
  97. })
  98. }
  99. // 点击
  100. function clickItem(data){
  101. dataInfo.incidentData.requester = data;
  102. incidentBuildStore.setIncidentBuildData(dataInfo.incidentData, incidentBuildStore.incidentBuild.type, incidentBuildStore.incidentBuild.sign);
  103. uni.navigateTo({
  104. url: '/pages/buildIncident/buildIncident'
  105. })
  106. }
  107. function getUserType(){
  108. let postData = {
  109. "key": 'usertype',
  110. "type": "list",
  111. };
  112. api_getDictionary(postData).then((data) => {
  113. userTypes.value = data;
  114. getList(0);
  115. });
  116. }
  117. onLoad((option) => {
  118. if(incidentBuildStore.incidentBuild.data){
  119. dataInfo.incidentData = incidentBuildStore.incidentBuild.data;
  120. }
  121. if(incidentBuildStore.incidentBuild.type === 'buildIncident' && incidentBuildStore.incidentBuild.sign === 'requester'){
  122. placeHolder.value = '请搜索报修人'
  123. }
  124. getUserType()
  125. })
  126. onPullDownRefresh(() => {
  127. getList(0)
  128. })
  129. onReachBottom(() => {
  130. dataInfo.idx += 1;
  131. if (dataInfo.hasMore) {
  132. getList(); // 当触底时加载更多数据
  133. }
  134. })
  135. </script>
  136. <style lang="scss" scoped>
  137. .consumableList{
  138. display: flex;
  139. flex-direction: column;
  140. justify-content: space-between;
  141. .head{
  142. height: 88rpx;
  143. display: flex;
  144. align-items: center;
  145. justify-content: center;
  146. padding: 0 24rpx;
  147. position: fixed;
  148. z-index: 99;
  149. width: 100%;
  150. box-sizing: border-box;
  151. background: linear-gradient( 90deg, #58CF66 0%, #DDE9FC 100%);
  152. }
  153. .body{
  154. margin-bottom: 140rpx;
  155. margin-top: 88rpx;
  156. font-size: 26rpx;
  157. .body_item{
  158. border-bottom: 1rpx solid #DEDEDE;
  159. padding: 24rpx;
  160. }
  161. }
  162. .zanwu{
  163. margin-bottom: 140rpx;
  164. margin-top: 88rpx;
  165. display: flex;
  166. justify-content: center;
  167. .newicon-zanwu{
  168. font-size: 256rpx;
  169. color: #D6D6D6;
  170. margin-top: 140rpx;
  171. }
  172. }
  173. .foot_common_btns{
  174. position: fixed;
  175. left: 0;
  176. bottom: 0;
  177. background-color: #fff;
  178. }
  179. }
  180. </style>