select-inst.vue 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <!--
  2. * @Author: wanglj wanglijie@dashoo.cn
  3. * @Date: 2025-03-11 18:02:10
  4. * @LastEditors: wanglj wanglijie@dashoo.cn
  5. * @LastEditTime: 2025-04-16 16:19:33
  6. * @FilePath: \vant-demo-master\vant\vue3-ts\src\view\login\index.vue
  7. * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
  8. -->
  9. <template>
  10. <van-popup v-model:show="state.showPicker" round position="bottom" :style="{ height: '60%' }">
  11. <div class="flex">
  12. <van-search class="search-input" v-model="state.params.instName" placeholder="请输入仪器名称" shape="round" @search="getDataList" />
  13. <van-button style="" class="search-btn" type="success" size="small" round @click="getDataList">搜索</van-button>
  14. </div>
  15. <van-picker
  16. title="选择仪器"
  17. :loading="state.loading"
  18. show-toolbar
  19. :columns="state.columns"
  20. :columns-field-names="{ text: 'instName', value: 'id' }"
  21. @confirm="onConfirm"
  22. @cancel="onCancel"
  23. visible-item-count="8"
  24. />
  25. </van-popup>
  26. </template>
  27. <script name="selectInst" lang="ts" setup>
  28. import { reactive } from 'vue'
  29. import { useInstrApi } from '/@/api/instr/index'
  30. import to from 'await-to-js'
  31. const emit = defineEmits(['selectInst'])
  32. const instrApi = useInstrApi()
  33. const state = reactive({
  34. showPicker: false,
  35. searchValue: '',
  36. columns: [],
  37. loading: false,
  38. params: {
  39. instStatus: '10',
  40. pageNum: 1,
  41. pageSize: 9999,
  42. instName: ''
  43. }
  44. })
  45. const openPopup = () => {
  46. state.showPicker = true
  47. state.columns = []
  48. getDataList()
  49. }
  50. const getDataList = async () => {
  51. state.loading = true
  52. const [err, res]: ToResponse = await to(instrApi.getList({ ...state.params }))
  53. state.loading = false
  54. if (err) return
  55. state.columns = res.data.list
  56. }
  57. const onConfirm = ({ selectedOptions }: { selectedOptions: any[] }) => {
  58. state.showPicker = false
  59. const selectedOption = selectedOptions[selectedOptions.length - 1]
  60. emit('selectInst', selectedOption)
  61. }
  62. const onCancel = () => {
  63. state.showPicker = false
  64. }
  65. // 暴露变量
  66. defineExpose({
  67. openPopup
  68. })
  69. </script>
  70. <style lang="scss" scoped>
  71. .search-input {
  72. flex: 1;
  73. }
  74. .search-btn {
  75. width: 70px;
  76. height: 30px;
  77. margin: 0 10px;
  78. font-size: 14px;
  79. }
  80. </style>