searchDept.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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="goBackPage" 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. const entranceType = ref(null);
  38. // 院区id
  39. const branchId = ref(null);
  40. // 数据
  41. const dataInfo = reactive({
  42. list: [],//工单列表
  43. idx: 0,//页码
  44. hasMore: true,//是否有更多数据
  45. incidentData: {},//事件对象
  46. keyWord: '',//搜索的关键词
  47. })
  48. // 搜索
  49. const search = debounce(getList.bind(null, 0), 500);
  50. // 获取列表信息
  51. function getList(idx){
  52. if(dataInfo.keyWord.trim() === ''){
  53. dataInfo.list = [];
  54. uni.stopPullDownRefresh();
  55. return;
  56. }
  57. uni.showLoading({
  58. title: "加载中",
  59. mask: true,
  60. });
  61. dataInfo.idx = idx === undefined ? dataInfo.idx : idx;
  62. if(dataInfo.idx === 0){
  63. dataInfo.list = [];
  64. }
  65. let postData = {
  66. idx: dataInfo.idx,
  67. sum: 20,
  68. department: {
  69. hospital:{
  70. id:''
  71. },
  72. // branch: dataInfo.incidentData.branch,
  73. // searchType: 'quickStart',
  74. // selectType: 'pinyin_qs',
  75. dept: dataInfo.keyWord,
  76. }
  77. }
  78. if(entranceType.value=='repair' || entranceType.value=='config'){
  79. if(branchId.value){
  80. postData.department.hospital.id = branchId.value
  81. }
  82. }else{
  83. if(loginUserStore.loginUser.user.currentHospital.parent){
  84. postData.department.hospital.id = loginUserStore.loginUser.user.currentHospital.parent.id
  85. }else{
  86. postData.department.hospital.id = loginUserStore.loginUser.user.currentHospital.id
  87. }
  88. }
  89. api_department(postData).then(res => {
  90. uni.hideLoading();
  91. uni.stopPullDownRefresh();
  92. if(res.status == 200){
  93. let list = res.list || [];
  94. if(list.length){
  95. dataInfo.hasMore = true;
  96. dataInfo.list = dataInfo.idx === 0 ? list : dataInfo.list.concat(list);
  97. }else{
  98. dataInfo.hasMore = false;
  99. }
  100. }else{
  101. uni.showToast({
  102. icon: 'none',
  103. title: res.msg || '请求数据失败!'
  104. });
  105. }
  106. })
  107. }
  108. function goBackPage(){
  109. // goBack()
  110. if(entranceType.value=='config'){
  111. uni.reLaunch({
  112. url: `/pages/repair/config?type=selectDept`
  113. })
  114. }else{
  115. goBack()
  116. }
  117. }
  118. // 点击
  119. function clickItem(data){
  120. if(entranceType.value=='repair'){
  121. let query = {
  122. department:null,
  123. departmentName:null,
  124. branch:branchId.value
  125. }
  126. let rapidRepNextData = uni.getStorageSync('rapidRepNext')
  127. if(rapidRepNextData){
  128. let parseData = JSON.parse(rapidRepNextData)
  129. query.department = data.id//报修科室
  130. query.departmentName = data.dept//报修科室
  131. let repairData = {
  132. ...parseData,
  133. ...query
  134. }
  135. uni.setStorageSync('rapidRepNext',JSON.stringify(repairData))
  136. }else{
  137. query.department = data.id//报修科室
  138. query.departmentName = data.dept//报修科室
  139. uni.setStorageSync('rapidRepNext',JSON.stringify(query))
  140. }
  141. uni.navigateTo({
  142. url: '/pages/repair/rapidRepNext'
  143. })
  144. }else if(entranceType.value=='config'){
  145. let query = {
  146. dept:null,
  147. departmentName:null,
  148. branch:branchId.value
  149. }
  150. let configNewData = uni.getStorageSync('configData')
  151. if(configNewData){
  152. let parseData = JSON.parse(configNewData)
  153. query.dept = data.id//报修科室
  154. query.departmentName = data.dept//报修科室
  155. // parseData.dataType = true
  156. let configData = {
  157. ...parseData,
  158. ...query
  159. }
  160. uni.setStorageSync('configData',JSON.stringify(configData))
  161. uni.reLaunch({
  162. url: `/pages/repair/config?type=selectDept`
  163. })
  164. }else{
  165. query.dept = data.id//报修科室
  166. query.departmentName = data.dept//报修科室
  167. uni.setStorageSync('configData',JSON.stringify(query))
  168. }
  169. }else{
  170. dataInfo.incidentData.department = data;
  171. incidentBuildStore.setIncidentBuildData(dataInfo.incidentData, incidentBuildStore.incidentBuild.type, incidentBuildStore.incidentBuild.sign);
  172. uni.navigateTo({
  173. url: '/pages/buildIncident/buildIncident'
  174. })
  175. }
  176. }
  177. onLoad((option) => {
  178. if(option.type){
  179. entranceType.value = option.type
  180. branchId.value = option.branchId
  181. }
  182. if(incidentBuildStore.incidentBuild.data){
  183. dataInfo.incidentData = incidentBuildStore.incidentBuild.data;
  184. }
  185. if(incidentBuildStore.incidentBuild.type === 'buildIncident' && incidentBuildStore.incidentBuild.sign === 'department'){
  186. placeHolder.value = '请搜索报修科室'
  187. }
  188. getList(0);
  189. })
  190. onPullDownRefresh(() => {
  191. getList(0)
  192. })
  193. onReachBottom(() => {
  194. dataInfo.idx += 1;
  195. if (dataInfo.hasMore) {
  196. getList(); // 当触底时加载更多数据
  197. }
  198. })
  199. </script>
  200. <style lang="scss" scoped>
  201. .consumableList{
  202. display: flex;
  203. flex-direction: column;
  204. justify-content: space-between;
  205. .head{
  206. height: 88rpx;
  207. display: flex;
  208. align-items: center;
  209. justify-content: center;
  210. padding: 0 24rpx;
  211. position: fixed;
  212. z-index: 99;
  213. width: 100%;
  214. box-sizing: border-box;
  215. background: linear-gradient( 90deg, #58CF66 0%, #DDE9FC 100%);
  216. }
  217. .body{
  218. margin-bottom: 140rpx;
  219. margin-top: 88rpx;
  220. font-size: 26rpx;
  221. .body_item{
  222. border-bottom: 1rpx solid #DEDEDE;
  223. padding: 24rpx;
  224. }
  225. }
  226. .zanwu{
  227. margin-bottom: 140rpx;
  228. margin-top: 88rpx;
  229. display: flex;
  230. justify-content: center;
  231. .newicon-zanwu{
  232. font-size: 256rpx;
  233. color: #D6D6D6;
  234. margin-top: 140rpx;
  235. }
  236. }
  237. .foot_common_btns{
  238. position: fixed;
  239. left: 0;
  240. bottom: 0;
  241. background-color: #fff;
  242. }
  243. }
  244. </style>