personList.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <template>
  2. <view class="page_body">
  3. <!-- 头部 -->
  4. <nav-bar height="220" :title="pageTitle" :tabBtns="state.tabBtns" :onlyTitle="false" :showHeadSearchInput="false" :showFilterPicker="false" :showTabs="false" :showTabBtns="false" rightWidth="0rpx" @GoBack="GoBack">
  5. <template #tabs_bottom_content>
  6. <!-- 搜索框单独一行 -->
  7. <view class="nav_head row_search_box">
  8. <uni-easyinput class="search_box" v-model="state.searchWord" trim="all" :styles="state.searchInputStyles"
  9. :placeholderStyle="state.searchInputPlaceholderStyle" placeholder="请输入关键字搜索" @input="HandleSearchInput">
  10. <template #left>
  11. <image src="@/static/image/overview/search.png" class="search_icon"></image>
  12. </template>
  13. </uni-easyinput>
  14. </view>
  15. </template>
  16. </nav-bar>
  17. <view class="person_list">
  18. <view class="list_item" v-for="(item,index) in state.listData" :key="item.id">
  19. <view class="item_name">{{item.label}}</view>
  20. <view :class="['btn_del',{'disabled':item.disabled}]" @click="handleDel(item.disabled,index,item.id,item.targetName)">删除</view>
  21. </view>
  22. </view>
  23. <!-- 删除确认框 -->
  24. <popupDialog ref="popupDelDialogRef" :showFootBorder="true" :content="state.popupDelDialog.content" @DialogConfirm="DialogDelConfirm" />
  25. </view>
  26. </template>
  27. <script setup>
  28. import navBar from '@/components/navBar.vue';
  29. import {onLoad} from '@dcloudio/uni-app';
  30. import {reactive,ref,onUnmounted, computed} from 'vue';
  31. import popupDialog from '@/components/popupDialog.vue';
  32. const state = reactive({
  33. listData:[],
  34. allListData:[],
  35. popupDelDialog:{//删除确认框
  36. content:'',
  37. index:'',
  38. id:'',
  39. targetName:''
  40. }
  41. });
  42. const targetType = ref('');//采集对象 1-按部门,2-按学科,3-按年级,4-按权限,5-按学生
  43. const popupDelDialogRef = ref('');
  44. onLoad((option) => {
  45. const taskTargetsTreeData = uni.getStorageSync('taskTargetsTreeData');
  46. targetType.value = taskTargetsTreeData.targetType;
  47. const listData = taskTargetsTreeData?.taskTargets || [];
  48. state.listData = listData;
  49. state.allListData = listData;
  50. })
  51. const pageTitle = computed(() => {
  52. const num = state.allListData?.length || 0;
  53. if(targetType.value == 1){
  54. return `按部门 已选${num}人`
  55. }else if(targetType.value == 2){
  56. return `按学科 已选${num}人`
  57. }else if(targetType.value == 3){
  58. return `按年级 已选${num}人`
  59. }else if(targetType.value == 4){
  60. return `按权限 已选${num}人`
  61. }else{
  62. return ''
  63. }
  64. });
  65. onUnmounted(()=>{
  66. uni.removeStorageSync('taskTargetsTreeData');//移除缓存
  67. })
  68. //搜索
  69. const HandleSearchInput = (e) => {
  70. const searchWord = (e || '').trim();
  71. if (!searchWord) {
  72. state.listData = [...state.allListData]; // 清空恢复全量
  73. return;
  74. }
  75. state.listData = state.allListData.filter(item=>item.label.indexOf(searchWord) > -1)
  76. }
  77. //删除
  78. const handleDel = (disabled,index,id,targetName) => {
  79. if(disabled){
  80. return false
  81. }
  82. state.popupDelDialog.index = id;
  83. state.popupDelDialog.id = id;
  84. state.popupDelDialog.targetName = targetName;
  85. state.popupDelDialog.content = `确定要删除【${targetName}】吗?`;
  86. popupDelDialogRef.value.OpenDialog();
  87. }
  88. const DialogDelConfirm = () => {
  89. state.listData.splice(state.popupDelDialog.index,1);
  90. const key = state.allListData.findIndex(item=>item.id==state.popupDelDialog.id);
  91. if (key !== -1) {
  92. state.allListData.splice(key, 1);
  93. }
  94. uni.setStorageSync('taskTargetsTreeData',{
  95. targetType:Number(targetType.value),
  96. taskTargets:state.allListData,//已选中
  97. });
  98. }
  99. //返回
  100. const GoBack = () => {
  101. uni.navigateBack({
  102. delta: 1
  103. });
  104. }
  105. </script>
  106. <style scoped lang="scss">
  107. .page_body{
  108. display: flex;
  109. flex-direction: column;
  110. height: 100%;
  111. min-width: auto;
  112. .row_search_box{
  113. height: 96rpx;
  114. align-items: flex-start;
  115. }
  116. .person_list{
  117. display: flex;
  118. flex-direction: column;
  119. width: 100%;
  120. padding: 0 24rpx;
  121. box-sizing: border-box;
  122. flex:1;
  123. overflow: auto;
  124. align-items: flex-start;
  125. .list_item{
  126. display: flex;
  127. width: 100%;
  128. justify-content: space-between;
  129. padding: 24rpx 0;
  130. border-bottom: 2rpx solid #F3F3F3;
  131. .item_name{
  132. font-weight: 400;
  133. font-size: 28rpx;
  134. color: #666666;
  135. flex:1;
  136. white-space: nowrap;
  137. overflow: hidden;
  138. text-overflow: ellipsis;
  139. }
  140. .btn_del{
  141. font-weight: 400;
  142. font-size: 28rpx;
  143. color: #F56C6C;
  144. &.disabled{
  145. color: #C0C4CC;
  146. }
  147. }
  148. }
  149. }
  150. }
  151. </style>