wangguoyu 2 mesi fa
parent
commit
81ceeeda7e

+ 113 - 0
pages/admin/Jiazheng/common/search.vue

@@ -0,0 +1,113 @@
+<template>
+	<uni-popup ref="searchPopup" type="top" :animation="false" :is-mask-click="true"
+	 mask-background-color="rgba(0, 0, 0, 0.4)">
+	   <view class="select-search-row">
+		   <view class="select-search-body">
+			  <view class="select-jt-box" @click="toggleMenu">
+				<view class="selected-item">{{ selectedOption.label }}</view>
+				<view class="arrow" :class="{ 'arrow-up': isMenuOpen, 'arrow-down': !isMenuOpen }"></view>
+			  </view>
+			  <view class="select-list-box" v-if="isMenuOpen">
+				<view
+				  v-for="(option, index) in options"
+				  :key="option.value"
+				  class="menu-item"
+				  @click="selectOption(option)"
+				>
+				  {{ option.label }}
+				</view>
+			  </view>
+			  <input type="text" class="search-input" v-model="searchInput" :placeholder="searchPlaceholder" />
+			  <view class="search-icon" @click="handleSearch">
+			  	<uni-icons type="search" size="24" color="#fff"></uni-icons>
+			  </view>	
+			</view>
+		</view>
+		<view class="search-clear-box" v-if="searchInput" @click="searchReset">
+			<icon></icon>
+			<text>清空搜索</text>
+		</view>
+  </uni-popup>
+</template>
+
+<script setup>
+import { ref } from 'vue';
+const $emit = defineEmits(['search-btn','reset-search'])
+const searchPopup = ref(null); // 索引
+
+
+const options = ref([
+	  { label: '全部', value: 1 },
+	  { label: '姓名', value: 2 },
+	  { label: '手机号', value: 3 }
+	]);
+const searchPlaceholder= ref('请输入姓名、手机号等关键字');
+const searchInput= ref('');
+// 存储当前选中的选项对象
+const selectedOption = ref(options.value[0]);
+ 
+// 存储菜单是否打开的状态
+const isMenuOpen = ref(false);
+ 
+// 切换菜单打开/关闭状态的函数
+const toggleMenu = () => {
+  isMenuOpen.value = !isMenuOpen.value;
+};
+ 
+// 选择选项的函数
+const selectOption = (option) => {
+  selectedOption.value = option;
+  searchInput.value = '';
+  if(option.label==="全部"){
+	  searchPlaceholder.value = '请输入姓名、手机号等关键字';
+  }else{
+	  searchPlaceholder.value = '请输入'+ option.label;
+  }
+  
+  isMenuOpen.value = false; // 选择后关闭菜单
+};
+
+function validatePhoneNumber(value){
+	const phoneRegex = /^1[3-9]\d{9}$/;
+	if (phoneRegex.test(value)) {
+		return '手机号';
+	} else {
+		return '姓名';
+	}
+}
+
+// 打开弹窗
+function handleShow() {
+	searchPopup.value.open();
+}
+// 取消
+function handleClose() {
+	searchInput.value = '';
+	searchPopup.value.close();
+}
+// 确认
+function handleSearch(){
+	let searchKey = '';
+	if(selectedOption.value.label==="全部"){
+		searchKey = validatePhoneNumber(searchInput.value)
+	}else{
+		searchKey = selectedOption.value.label;
+	}
+	// 搜索 key和 data
+	$emit('search-btn',searchKey,searchInput);
+	searchPopup.value.close();
+}
+
+// 清空搜索
+function searchReset(){
+	searchInput.value = '';
+	$emit('reset-search');
+}
+
+
+defineExpose({
+	handleShow,
+	handleClose
+})
+</script>
+

+ 21 - 55
pages/admin/Jiazheng/index.vue

@@ -60,46 +60,7 @@
 				</scroll-view>
 			</view>
 			<view>
-				<!-- 普通弹窗 -->
-				<uni-popup ref="popup" background-color="#fff">
-					<view>
-						<view>
-							 <view class="container">
-							    <!-- 下拉触发按钮 -->
-							    <view class="select-box" @click="toggleDropdown">
-							      <text class="selected-label">{{ selectedOption || '请选择' }}</text>
-							      <text class="arrow" :class="{ 'rotate': isOpen }">▼</text>
-							    </view>
-							
-							    <!-- 下拉菜单 -->
-							    <view v-if="isOpenSelect" class="dropdown-menu">
-							      <view 
-							        v-for="(item, index) in options" 
-							        :key="index" 
-							        class="dropdown-item"
-							        @click="selectOption(item)"
-							      >
-							        <text>{{ item.label }}</text>
-							      </view>
-							    </view>
-							
-							    <!-- 点击外部关闭的遮罩层 -->
-							    <view v-if="isOpenSelect" class="mask" @click="isOpenSelect = false"></view>
-							  </view>
-							
-							
-							
-							
-							
-							<view class="phone-search-box">
-								<input class="search-input" placeholder="请输入职业名称" v-model="zyName" />
-								<view class="search-icon" @click="handleSearch">
-									<uni-icons type="search" size="24" color="#fff"></uni-icons>
-								</view>
-							</view>
-						</view>
-					</view>
-				</uni-popup>
+		<search-dialog ref="searchDialogRef" @search-btn="dialogSearchBtn" @reset-search="dialogSearchReset"></search-dialog>
 			</view>
 		</view>
 </template>
@@ -117,6 +78,7 @@
 		getJiazhengLeixing
 	} from "@/api/jiazheng.js"
 	import dataChecked from './common/dataChecked.vue';
+	import searchDialog from "./common/search.vue";
 	let range = ref([{
 			"value": 0,
 			"text": "篮球",
@@ -131,24 +93,11 @@
 			"text": "游泳"
 		}
 	])
+	const searchDialogRef = ref(null);
 	let allType = ref([])
 	let data = reactive({
 		zyName: '', // 职业名称
 		list: [], // 考试列表
-		list2:[
-		{
-				"value": 0,
-				"text": "全部",
-			},
-			{
-				"value": 1,
-				"text": "姓名"
-			},
-			{
-				"value": 2,
-				"text": "手机号"
-			}
-		],
 		loading: false,
 		page: 0,
 		size: 10,
@@ -176,7 +125,24 @@
 	  { label: '姓名', value: 2 },
 	  { label: '手机号', value: 3 }
 	]);
+	function dialogSearchBtn(name,searchData){
+		switch (name) {
+			case '姓名':
+				dialogSearchReset();
+			    data.realName = searchData.value;
+			    break;
+			case '手机号':
+			    data.userName = searchData.value;
+			    break;	
+		}
+		refreshData();
+		
+	}
 	
+	function dialogSearchReset(){
+		data.userName='';
+		data.realName='';
+	}
 	const clickAlltype = (data) => {
 	 isOpen.value = !isOpen.value;
 	}
@@ -197,7 +163,7 @@
 		//	allJtClass = 'select-jt-click'
 	}
 	const toggle = (data, index) => {
-		popup.value.open('top')
+	searchDialogRef.value.handleShow();	
 	}
 	const addJiazhengRenyuan = () => {
 		let pageInfo = {

+ 10 - 0
pages/admin/Jiazheng/jiazhengUserManager.vue

@@ -132,6 +132,16 @@
 
 			},
 			saveBanzhengList(data, index) {
+				jiazhengUpdate(this.allData).then(res => {
+					uni.showToast({
+						title: "保存成功!",
+						icon: 'none',
+						duration: 2000
+					})
+					uni.navigateTo({
+						url: `/pages/admin/Jiazheng/index`
+					})
+				})
 
 			},