BindLabModal.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  1. <template>
  2. <!-- 弹窗遮罩层 -->
  3. <view class="bind-lab-modal" v-if="visible">
  4. <view class="bind-lab-content" @tap.stop>
  5. <!-- 标题栏 -->
  6. <view class="modal-header">
  7. <text class="modal-title">绑定实验室</text>
  8. <text class="modal-close" @click="$emit('close')">×</text>
  9. </view>
  10. <view class="modal-body">
  11. <!-- 搜索框区域:使用 view 包裹以兼容点击事件 -->
  12. <view class="search-box" @tap="handleFocus">
  13. <input class="search-input" type="text" placeholder="输入实验室名称、房号或楼栋关键词搜索…" v-model="keyword"
  14. @input="handleSearch" />
  15. <text class="search-icon">⌄</text>
  16. </view>
  17. <!-- 搜索提示 -->
  18. <view class="search-tip">
  19. <text>此处请选择需要后续进入的科研实验室的名称,输入实验室名称、房号或楼栋关键词,再从检索结果中选择目标实验室。</text>
  20. </view>
  21. <!-- 搜索结果下拉 -->
  22. <scroll-view v-if="showDropdown" scroll-y class="bind-lab-dropdown">
  23. <!-- 情况1:有数据,显示列表 -->
  24. <view v-if="searchList.length > 0">
  25. <view class="bind-lab-option" v-for="(lab, index) in searchList" :key="index" @click="selectLab(lab)">
  26. <text>{{ lab.deptName }}{{ lab.subName }}{{ lab.roomNum?'('+lab.roomNum+')':'' }}{{ lab.buildName }}{{ lab.floorName }}</text>
  27. </view>
  28. </view>
  29. <!-- 情况2:无数据,显示暂无数据 -->
  30. <view v-else class="bind-lab-empty">
  31. <text>暂无数据</text>
  32. </view>
  33. </scroll-view>
  34. <!-- 实验室信息表格 -->
  35. <view class="bind-lab-info" v-if="selectedLab">
  36. <view class="info-row">
  37. <view class="info-label">实验室名称</view>
  38. <view class="info-value text-bold">{{ selectedLab.labName }}</view>
  39. <view class="info-label">所在位置</view>
  40. <view class="info-value text-bold">{{ selectedLab.location }}</view>
  41. </view>
  42. <view class="info-row">
  43. <view class="info-label">负责人</view>
  44. <view class="info-value">{{ selectedLab.head }}</view>
  45. <view class="info-label">所属单位</view>
  46. <view class="info-value">{{ selectedLab.dept }}</view>
  47. </view>
  48. <view class="info-row">
  49. <view class="info-label">安全分级</view>
  50. <view class="info-value">{{ selectedLab.level }}</view>
  51. <view class="info-label">安全分类</view>
  52. <view class="info-value">{{ selectedLab.category }}</view>
  53. </view>
  54. <view class="info-row">
  55. <view class="info-label">实验室类型</view>
  56. <view class="info-value full-width">{{ selectedLab.type }}</view>
  57. </view>
  58. </view>
  59. <!-- 无需进入实验室 -->
  60. <view class="no-lab-box">
  61. <view class="checkbox-row" @click="isNoLabChecked = !isNoLabChecked">
  62. <view class="custom-checkbox" :class="{ 'checked': isNoLabChecked }"></view>
  63. <text class="no-lab-title">无需进入实验室</text>
  64. </view>
  65. <view class="no-lab-desc">
  66. <text>人文、体育等相关学院,无需进入实验室的新研究生可选择此项,选择后学时要求为4小时,需通过应知应会考试。</text>
  67. </view>
  68. </view>
  69. <!-- 阅读协议 -->
  70. <view class="agree-row" @click="isAgreeChecked = !isAgreeChecked">
  71. <view class="custom-checkbox" :class="{ 'checked': isAgreeChecked }"></view>
  72. <view class="agree-text">
  73. <text>我已阅读并同意</text>
  74. <text class="agree-link">《新生绑定实验室须知及责任说明》</text>
  75. </view>
  76. </view>
  77. <!-- 底部按钮 -->
  78. <view class="modal-footer">
  79. <view class="btn-cancel" @click="$emit('close')">取消</view>
  80. <view class="btn-confirm" @click="handleConfirm">确认绑定</view>
  81. </view>
  82. </view>
  83. </view>
  84. </view>
  85. </template>
  86. <script>
  87. import {
  88. examElLabEduRelationLabLists
  89. } from '@/pages_safetyEducationExamination/api/index.js'
  90. export default {
  91. name: 'BindLabModal',
  92. props: {
  93. visible: {
  94. type: Boolean,
  95. default: false
  96. }
  97. },
  98. data() {
  99. return {
  100. keyword: '',
  101. showDropdown: false,
  102. searchList: [],
  103. selectedLab: null,
  104. isNoLabChecked: false,
  105. isAgreeChecked: false,
  106. searchTimer: null
  107. }
  108. },
  109. watch: {
  110. visible(val) {
  111. if (val) {
  112. this.resetState();
  113. }
  114. }
  115. },
  116. methods: {
  117. resetState() {
  118. this.keyword = '';
  119. this.showDropdown = false;
  120. this.searchList = [];
  121. this.selectedLab = null;
  122. this.isNoLabChecked = false;
  123. this.isAgreeChecked = false;
  124. },
  125. // 搜索输入处理
  126. handleSearch() {
  127. clearTimeout(this.searchTimer);
  128. const trimKeyword = this.keyword.trim();
  129. // 逻辑1:少于2个字符,隐藏下拉框
  130. if (trimKeyword.length < 2) {
  131. this.showDropdown = false;
  132. return;
  133. }
  134. // 逻辑2:防抖请求
  135. this.searchTimer = setTimeout(async () => {
  136. try {
  137. const res = await examElLabEduRelationLabLists({
  138. searchValue: trimKeyword
  139. });
  140. if (res.data.code === 200) {
  141. this.searchList = res.data.data || [];
  142. // 只要有搜索结果(哪怕为空数组),都显示下拉框,由模板决定显示列表还是“暂无数据”
  143. this.showDropdown = true;
  144. } else {
  145. this.searchList = [];
  146. this.showDropdown = true; // 接口报错也显示“暂无数据”
  147. }
  148. } catch (e) {
  149. console.error('搜索失败', e);
  150. this.searchList = [];
  151. this.showDropdown = true;
  152. }
  153. }, 300);
  154. },
  155. // 搜索框聚焦/点击处理
  156. handleFocus() {
  157. // 逻辑3:点击时,如果有关键词且之前搜过有结果,直接显示列表
  158. // 注意:这里需要加一个延时,确保 input 获取焦点后再显示,避免键盘弹起冲突
  159. setTimeout(() => {
  160. if (this.keyword.trim().length >= 2 && this.searchList.length > 0) {
  161. this.showDropdown = true;
  162. }
  163. }, 100);
  164. },
  165. selectLab(lab) {
  166. this.selectedLab = lab;
  167. this.showDropdown = false;
  168. this.keyword = lab.labName;
  169. },
  170. handleConfirm() {
  171. if (!this.isAgreeChecked) {
  172. return uni.showToast({
  173. title: '请先阅读并同意协议',
  174. icon: 'none'
  175. });
  176. }
  177. if (!this.selectedLab && !this.isNoLabChecked) {
  178. return uni.showToast({
  179. title: '请选择实验室或勾选无需进入',
  180. icon: 'none'
  181. });
  182. }
  183. this.$emit('bind-success');
  184. this.$emit('close');
  185. uni.showToast({
  186. title: '绑定成功',
  187. icon: 'success'
  188. });
  189. }
  190. }
  191. }
  192. </script>
  193. <style lang="stylus" scoped>
  194. .bind-lab-modal {
  195. position: fixed;
  196. top: 0;
  197. left: 0;
  198. right: 0;
  199. bottom: 0;
  200. z-index: 800;
  201. background: rgba(0, 0, 0, 0.5);
  202. }
  203. .bind-lab-content {
  204. position: absolute;
  205. top: 50%;
  206. left: 50%;
  207. transform: translate(-50%, -50%);
  208. background: #ffffff;
  209. border-radius: 24rpx;
  210. width: 85%;
  211. max-width: 840rpx;
  212. min-height: 400rpx;
  213. max-height: 90vh;
  214. overflow-y: auto;
  215. box-shadow: 0 16rpx 64rpx rgba(0, 0, 0, 0.18);
  216. box-sizing: border-box;
  217. }
  218. .modal-header {
  219. display: flex;
  220. align-items: center;
  221. justify-content: space-between;
  222. padding: 32rpx 40rpx 24rpx;
  223. }
  224. .modal-title {
  225. font-size: 34rpx;
  226. font-weight: 700;
  227. color: #1a1a1a;
  228. }
  229. .modal-close {
  230. font-size: 40rpx;
  231. color: #999;
  232. line-height: 1;
  233. }
  234. .modal-body {
  235. padding: 0 40rpx 32rpx;
  236. }
  237. .search-box {
  238. position: relative;
  239. margin-bottom: 16rpx;
  240. /* 确保点击区域覆盖整个输入框 */
  241. z-index: 10;
  242. }
  243. .search-input {
  244. width: 100%;
  245. box-sizing: border-box;
  246. height: 80rpx;
  247. line-height: 80rpx;
  248. padding: 0 42rpx 0 24rpx;
  249. border: 1px solid #d9d9d9;
  250. border-radius: 16rpx;
  251. font-size: 26rpx;
  252. color: #333;
  253. background: #fafafa;
  254. /* 确保 input 在最上层,可点击 */
  255. position: relative;
  256. z-index: 11;
  257. }
  258. .search-icon {
  259. position: absolute;
  260. right: 20rpx;
  261. top: 40%;
  262. transform: translateY(-50%);
  263. color: #bbb;
  264. font-size: 30rpx;
  265. pointer-events: none;
  266. }
  267. .search-tip {
  268. font-size: 22rpx;
  269. color: #1677ff;
  270. margin-bottom: 24rpx;
  271. line-height: 1.5;
  272. }
  273. /* 下拉列表样式 */
  274. .bind-lab-dropdown {
  275. max-height: 600rpx;
  276. border: 1px solid #e8e8e8;
  277. border-radius: 16rpx;
  278. margin-bottom: 24rpx;
  279. background: #fff;
  280. box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.08);
  281. z-index: 99;
  282. position: relative;
  283. }
  284. .bind-lab-option {
  285. padding: 24rpx 28rpx;
  286. font-size: 26rpx;
  287. color: #333;
  288. border-bottom: 1px solid #f0f0f0;
  289. box-sizing: border-box;
  290. &:last-child {
  291. border-bottom: none;
  292. }
  293. &:active {
  294. background: #f9f9f9;
  295. }
  296. }
  297. /* 暂无数据样式 */
  298. .bind-lab-empty {
  299. padding: 30rpx 0;
  300. text-align: center;
  301. color: #999;
  302. font-size: 26rpx;
  303. }
  304. .bind-lab-info {
  305. border: 1px solid #e8e8e8;
  306. border-radius: 16rpx;
  307. overflow: hidden;
  308. margin-bottom: 28rpx;
  309. }
  310. .info-row {
  311. display: flex;
  312. border-bottom: 1px solid #f0f0f0;
  313. &:last-child {
  314. border-bottom: none;
  315. }
  316. }
  317. .info-label {
  318. padding: 18rpx 24rpx;
  319. color: #888;
  320. background: #fafafa;
  321. width: 28%;
  322. font-size: 24rpx;
  323. white-space: nowrap;
  324. }
  325. .info-value {
  326. padding: 18rpx 24rpx;
  327. color: #333;
  328. font-size: 24rpx;
  329. flex: 1;
  330. }
  331. .full-width {
  332. flex: 3;
  333. }
  334. .no-lab-box {
  335. background: #f6f8ff;
  336. border-radius: 16rpx;
  337. padding: 24rpx 28rpx;
  338. margin-bottom: 28rpx;
  339. }
  340. .checkbox-row {
  341. display: flex;
  342. align-items: flex-start;
  343. gap: 16rpx;
  344. }
  345. .custom-checkbox {
  346. position: relative;
  347. width: 32rpx;
  348. height: 32rpx;
  349. border-radius: 6rpx;
  350. border: 2rpx solid #ccc;
  351. margin-top: 4rpx;
  352. flex-shrink: 0;
  353. box-sizing: border-box;
  354. &.checked {
  355. background: #1677ff;
  356. border-color: #1677ff;
  357. &::after {
  358. content: '';
  359. position: absolute;
  360. top: 45%;
  361. left: 20%;
  362. width: 10rpx;
  363. height: 20rpx;
  364. border: solid #ffffff;
  365. border-width: 0 3rpx 3rpx 0;
  366. transform: rotate(45deg) translate(-50%, -50%);
  367. }
  368. }
  369. }
  370. .no-lab-title {
  371. font-size: 26rpx;
  372. font-weight: 600;
  373. color: #1a1a1a;
  374. }
  375. .no-lab-desc {
  376. font-size: 22rpx;
  377. color: #888;
  378. margin-top: 10rpx;
  379. line-height: 1.6;
  380. padding-left: 40rpx;
  381. }
  382. .agree-row {
  383. display: flex;
  384. align-items: center;
  385. gap: 16rpx;
  386. margin-bottom: 36rpx;
  387. }
  388. .agree-text {
  389. display: flex;
  390. font-size: 24rpx;
  391. color: #555;
  392. }
  393. .agree-link {
  394. color: #1677ff;
  395. font-weight: 500;
  396. }
  397. .modal-footer {
  398. display: flex;
  399. gap: 20rpx;
  400. justify-content: flex-end;
  401. }
  402. .btn-cancel,
  403. .btn-confirm {
  404. padding: 16rpx 44rpx;
  405. border-radius: 12rpx;
  406. font-size: 26rpx;
  407. }
  408. .btn-cancel {
  409. border: 1px solid #d9d9d9;
  410. background: #fff;
  411. color: #555;
  412. }
  413. .btn-confirm {
  414. background: #1677ff;
  415. color: #fff;
  416. font-weight: 600;
  417. }
  418. .text-bold {
  419. font-weight: 700;
  420. }
  421. </style>