searchAsset.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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_get_asset, 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. asset: {
  67. downHosId:'',
  68. name: dataInfo.keyWord,
  69. }
  70. }
  71. if(dataInfo.incidentData && dataInfo.incidentData.branch){
  72. postData.asset.downHosId = dataInfo.incidentData.branch
  73. }else{
  74. if(loginUserStore.loginUser.user.currentHospital.parent){
  75. postData.asset.downHosId = loginUserStore.loginUser.user.currentHospital.parent.id
  76. }else{
  77. postData.asset.downHosId = loginUserStore.loginUser.user.currentHospital.id
  78. }
  79. }
  80. api_get_asset(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.assetDTO = data;
  102. dataInfo.incidentData.assetId = data.id;
  103. incidentBuildStore.setIncidentBuildData(dataInfo.incidentData, incidentBuildStore.incidentBuild.type, incidentBuildStore.incidentBuild.sign);
  104. uni.navigateTo({
  105. url: '/pages/buildIncident/buildIncident'
  106. })
  107. }
  108. onLoad((option) => {
  109. if(incidentBuildStore.incidentBuild.data){
  110. dataInfo.incidentData = incidentBuildStore.incidentBuild.data;
  111. }
  112. if(incidentBuildStore.incidentBuild.type === 'buildIncident' && incidentBuildStore.incidentBuild.sign === 'asset'){
  113. placeHolder.value = '请搜索资产'
  114. }
  115. getList(0);
  116. })
  117. onPullDownRefresh(() => {
  118. getList(0)
  119. })
  120. onReachBottom(() => {
  121. dataInfo.idx += 1;
  122. if (dataInfo.hasMore) {
  123. getList(); // 当触底时加载更多数据
  124. }
  125. })
  126. </script>
  127. <style lang="scss" scoped>
  128. .consumableList{
  129. display: flex;
  130. flex-direction: column;
  131. justify-content: space-between;
  132. .head{
  133. height: 88rpx;
  134. display: flex;
  135. align-items: center;
  136. justify-content: center;
  137. padding: 0 24rpx;
  138. position: fixed;
  139. z-index: 99;
  140. width: 100%;
  141. box-sizing: border-box;
  142. background: linear-gradient( 90deg, #58CF66 0%, #DDE9FC 100%);
  143. }
  144. .body{
  145. margin-bottom: 140rpx;
  146. margin-top: 88rpx;
  147. font-size: 26rpx;
  148. .body_item{
  149. border-bottom: 1rpx solid #DEDEDE;
  150. padding: 24rpx;
  151. }
  152. }
  153. .zanwu{
  154. margin-bottom: 140rpx;
  155. margin-top: 88rpx;
  156. display: flex;
  157. justify-content: center;
  158. .newicon-zanwu{
  159. font-size: 256rpx;
  160. color: #D6D6D6;
  161. margin-top: 140rpx;
  162. }
  163. }
  164. .foot_common_btns{
  165. position: fixed;
  166. left: 0;
  167. bottom: 0;
  168. background-color: #fff;
  169. }
  170. }
  171. </style>