AuditorSelector.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <template>
  2. <u-popup :show="show" @close="handleClose" mode="bottom" round="10">
  3. <view class="auditor-selector">
  4. <view style="flex:1">
  5. <!-- Title -->
  6. <view class="header">
  7. <text class="title">绑定审核员</text>
  8. </view>
  9. <!-- Search Box -->
  10. <view class="search-box">
  11. <u-search :inputStyle="{ 'height': '80rpx', 'font-size': '16px' }"
  12. :actionStyle="{ 'font-size': '16px', color: '#22ac38' }" v-model="searchKeyword"
  13. placeholder="搜索审核员" :show-action="true" action-text="搜索" @search="handleSearch"
  14. @custom="handleSearch" />
  15. </view>
  16. <!-- Search Results -->
  17. <view class="search-result" v-if="searchResults.length > 0">
  18. <text class="section-title">搜索结果</text>
  19. <view class="tag-group">
  20. <u-tag v-for="item in searchResults" :key="item" :text="item.userName"
  21. :plain="checkUserId!==item.userId" shape="circle" @click="selectAuditor(item)"
  22. size="large" />
  23. </view>
  24. </view>
  25. <!-- History -->
  26. <view class="history-section" v-if="historyAuditors.length>0">
  27. <text class="section-title">历史绑定</text>
  28. <view class="tag-group">
  29. <u-tag v-for="item in historyAuditors" :key="item" :text="item.userName"
  30. :plain="checkUserId!==item.userId" shape="circle" @click="selectAuditor(item)"
  31. size="large" />
  32. </view>
  33. </view>
  34. </view>
  35. <!-- Footer Buttons -->
  36. <view class="footer">
  37. <u-button @click="handleClose" text="取消" plain shape="circle" />
  38. <u-button type="primary" @click="handleConfirm" text="确定" shape="circle" />
  39. </view>
  40. </view>
  41. </u-popup>
  42. </template>
  43. <script setup>
  44. import { ref, onMounted } from 'vue'
  45. const props = defineProps({
  46. show: {
  47. type: Boolean,
  48. default: false
  49. }
  50. })
  51. const emit = defineEmits(['update:show', 'auditor-selected'])
  52. const searchKeyword = ref('')
  53. const searchResults = ref([])
  54. const historyAuditors = ref(uni.getStorageSync('historyAuditors') || [])
  55. const checkUserId = ref('')
  56. // Auditor search
  57. const auditorSearch = (name) => {
  58. console.log(name)
  59. uni.$u.http.get('/app/appUser/getCheckUser?name=' + name).then(res => {
  60. if (res.code == 200) {
  61. searchResults.value = res.data
  62. }
  63. })
  64. }
  65. const handleSearch = () => {
  66. auditorSearch(searchKeyword.value)
  67. }
  68. const selectItem = ref({})
  69. const selectAuditor = (item) => {
  70. checkUserId.value = item.userId
  71. selectItem.value = item
  72. }
  73. const handleClose = () => {
  74. emit('update:show', false)
  75. searchKeyword.value = ''
  76. }
  77. const handleConfirm = () => {
  78. if (checkUserId.value) {
  79. emit('auditor-selected', selectItem.value)
  80. uni.setStorageSync('checkUserInfo', selectItem.value)
  81. addToHistory(selectItem.value)
  82. handleClose()
  83. }
  84. }
  85. const addToHistory = (item) => {
  86. const existingIndex = historyAuditors.value.findIndex(auditor => auditor.userId === item.userId)
  87. if (existingIndex !== -1) {
  88. historyAuditors.value.splice(existingIndex, 1)
  89. }
  90. historyAuditors.value.unshift(item)
  91. if (historyAuditors.value.length > 10) {
  92. historyAuditors.value.pop()
  93. }
  94. uni.setStorageSync('historyAuditors', historyAuditors.value)
  95. }
  96. onMounted(() => {
  97. const storedHistory = uni.getStorageSync('historyAuditors') || []
  98. historyAuditors.value = storedHistory
  99. })
  100. </script>
  101. <style lang="scss" scoped>
  102. .auditor-selector {
  103. padding: 30rpx;
  104. min-height: 35vh;
  105. max-height: 80vh;
  106. overflow: auto;
  107. background-color: #fff;
  108. display: flex;
  109. flex-direction: column;
  110. }
  111. .header {
  112. text-align: center;
  113. margin-bottom: 20px;
  114. .title {
  115. font-size: 18px;
  116. font-weight: 500;
  117. }
  118. }
  119. .search-box {
  120. margin-bottom: 30rpx;
  121. }
  122. .section-title {
  123. font-size: 16px;
  124. color: #666;
  125. margin-bottom: 10px;
  126. display: block;
  127. }
  128. .tag-group {
  129. display: flex;
  130. flex-wrap: wrap;
  131. gap: 10px;
  132. margin-bottom: 20px;
  133. }
  134. .footer {
  135. position: sticky;
  136. bottom: 0;
  137. padding: 20px 0;
  138. padding-bottom: 0;
  139. display: flex;
  140. justify-content: center;
  141. gap: 30rpx;
  142. }
  143. </style>