safeThingsType.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. // 事件类型选择
  2. <template>
  3. <view class="my-fillin-container">
  4. <title-status />
  5. <h-navbar title="事件类型选择" />
  6. <nav-button :menus="menuDatas" @itemClick="menuClick"></nav-button>
  7. <view class="search-layout">
  8. <u-search v-model="searchStr" placeholder="请输入事件标题" shape="square" :showAction="false"></u-search>
  9. </view>
  10. <scroll-view scroll-y style="flex: auto;">
  11. <u-radio-group v-model="safeThingsType" style="flex-direction: column;padding-left: 32rpx;">
  12. <u-radio
  13. v-for="(item, index) in safeThingsTypesSearch"
  14. :key="index"
  15. class="radio-item"
  16. :label="item.name"
  17. :name="item.id">
  18. </u-radio>
  19. </u-radio-group>
  20. </scroll-view>
  21. <view style="height: 160rpx;" v-if="safeThingsTypesSearch && safeThingsTypesSearch.length > 0"></view>
  22. </view>
  23. </template>
  24. <script>
  25. import { getSafeThingsTypeList } from '@/network/module/fill-in.api.js'
  26. import TitleStatus from '@/components/title-status/title-status'
  27. import HNavbar from '@/components/h-navbar/h-navbar.vue'
  28. import NavButton from '@/components/nav-bottom/nav-button.vue'
  29. export default {
  30. components: {
  31. TitleStatus,
  32. HNavbar,
  33. NavButton
  34. },
  35. data() {
  36. return {
  37. searchStr: null,
  38. menuDatas: [
  39. {
  40. title: '确定',
  41. plain: false,
  42. disabled: false,
  43. bgColor: '#4983FB'
  44. }
  45. ],
  46. safeThingsTypes: [],
  47. safeThingsTypesSearch: [],
  48. safeThingsType: null
  49. }
  50. },
  51. watch: {
  52. searchStr(nValue) {
  53. uni.$u.debounce(this.search, 700)
  54. }
  55. },
  56. onLoad(options) {
  57. if(options && options.type) {
  58. this.safeThingsType = Number(options.type)
  59. }
  60. this.getSafeThingsTypes()
  61. },
  62. methods: {
  63. // 获取事件类型列表
  64. getSafeThingsTypes() {
  65. getSafeThingsTypeList({loadingText: '正在加载...', hasMsg: true}).then(res => {
  66. if(res.data && res.data.length > 0) {
  67. this.safeThingsTypes = res.data.map(item => {
  68. return {
  69. id: item.safeThingsTypeId,
  70. name: item.safeThingsTypeName
  71. }
  72. })
  73. this.safeThingsTypesSearch = JSON.parse(JSON.stringify(this.safeThingsTypes))
  74. } else {
  75. this.safeThingsTypes = []
  76. this.safeThingsTypesSearch = []
  77. }
  78. }).catch(error => {
  79. this.safeThingsTypes = []
  80. this.safeThingsTypesSearch = []
  81. })
  82. },
  83. search() {
  84. if(!this.safeThingsTypes || this.safeThingsTypes.length <= 0) {
  85. this.safeThingsTypesSearch = []
  86. return
  87. }
  88. if(!this.searchStr || this.searchStr.trim().length <= 0) {
  89. this.safeThingsTypesSearch = this.safeThingsTypes
  90. return
  91. }
  92. // 是否需要筛选的时候清除选中的
  93. // this.safeThingsType = null
  94. this.safeThingsTypesSearch = this.safeThingsTypes.filter(item => {
  95. return item.name.includes(this.searchStr)
  96. })
  97. },
  98. menuClick() {
  99. if(!this.safeThingsType) {
  100. uni.$u.toast('未选中项!')
  101. return
  102. }
  103. const safeThingsTypeObj = this.safeThingsTypes.find(item => {
  104. return item.id === this.safeThingsType
  105. })
  106. if(!safeThingsTypeObj) {
  107. uni.$u.toast('选中项值为空,请重新选择!')
  108. return
  109. }
  110. this.getOpenerEventChannel().emit('changeSuccess', safeThingsTypeObj)
  111. this.$navigate.navigateBack()
  112. }
  113. }
  114. }
  115. </script>
  116. <style lang="scss" scoped>
  117. .my-fillin-container {
  118. display: flex;
  119. flex-direction: column;
  120. .search-layout {
  121. padding: 32rpx 30rpx;
  122. }
  123. .radio-item {
  124. margin-top: 40rpx;
  125. &:first-of-type {
  126. margin-top: 0;
  127. }
  128. }
  129. }
  130. </style>