searchDept.vue 4.6 KB

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