checkboxPage.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. // 查获位置/简要情况 多选页面
  2. <template>
  3. <view class="checkbox-container">
  4. <title-status />
  5. <h-navbar :title="title" />
  6. <nav-button :menus="menuDatas" @itemClick="menuClick"></nav-button>
  7. <scroll-view scroll-y style="flex: auto;">
  8. <view style="padding: 30rpx;">
  9. <view>{{ subTitle }}</view>
  10. <u-checkbox-group v-model="checkboxValue" style="flex-direction: column;">
  11. <template v-for="(item, index) in checkboxList">
  12. <u-checkbox
  13. class="radio-item"
  14. :label="item.value"
  15. :name="item.key">
  16. </u-checkbox>
  17. <u-input
  18. v-if="item.hasOwnProperty('extra') && checkboxValue.includes(item.key)"
  19. v-model="item.extra"
  20. :customStyle="{margin: '20rpx 0 0 50rpx'}"
  21. placeholder="请输入其他项的内容"/>
  22. </template>
  23. </u-checkbox-group>
  24. </view>
  25. </scroll-view>
  26. <view style="height: 160rpx;" v-if="checkboxList && checkboxList.length > 0"></view>
  27. </view>
  28. </template>
  29. <script>
  30. import { getSafeThingsTypeList } from '@/network/module/fill-in.api.js'
  31. import TitleStatus from '@/components/title-status/title-status'
  32. import HNavbar from '@/components/h-navbar/h-navbar.vue'
  33. import NavButton from '@/components/nav-bottom/nav-button.vue'
  34. export default {
  35. components: {
  36. TitleStatus,
  37. HNavbar,
  38. NavButton
  39. },
  40. data() {
  41. return {
  42. title: null,
  43. subTitle: null,
  44. menuDatas: [
  45. {
  46. title: '确定',
  47. plain: false,
  48. disabled: false,
  49. bgColor: '#4983FB'
  50. }
  51. ],
  52. checkboxValue: [],
  53. checkboxList: []
  54. }
  55. },
  56. onLoad(options) {
  57. if(options) {
  58. this.title = options.title || ''
  59. this.subTitle = decodeURIComponent(options.subTitle || '')
  60. if(options.checkboxList) {
  61. this.checkboxList = JSON.parse(decodeURIComponent(options.checkboxList))
  62. for(let i = 0; i < this.checkboxList.length; i++) {
  63. if(this.checkboxList[i].checked) {
  64. this.checkboxValue.push(this.checkboxList[i].key)
  65. }
  66. }
  67. }
  68. }
  69. },
  70. methods: {
  71. menuClick() {
  72. if(!this.checkboxValue || this.checkboxValue.length <= 0) {
  73. uni.$u.toast('未选中项!')
  74. return
  75. }
  76. const callBackList = this.checkboxList.map(item => {
  77. if(this.checkboxValue.includes(item.key)) {
  78. item.checked = true
  79. } else {
  80. item.checked = false
  81. }
  82. return item
  83. })
  84. const checkedCheckboxs = callBackList.filter(item => {
  85. return item.checked && item.hasOwnProperty('extra')
  86. })
  87. if(checkedCheckboxs && checkedCheckboxs.length > 0) {
  88. const success = checkedCheckboxs.every(item => {
  89. return item.extra && item.extra.trim().length > 0
  90. })
  91. if(!success) {
  92. uni.$u.toast('补充项不能为空!')
  93. return
  94. }
  95. }
  96. this.getOpenerEventChannel().emit('changeSuccess', callBackList)
  97. this.$navigate.navigateBack()
  98. }
  99. }
  100. }
  101. </script>
  102. <style lang="scss" scoped>
  103. .checkbox-container {
  104. display: flex;
  105. flex-direction: column;
  106. .radio-item {
  107. margin-top: 40rpx;
  108. }
  109. /deep/ .u-checkbox {
  110. align-items: flex-start !important;
  111. }
  112. /deep/ .u-checkbox uni-text {
  113. line-height: 40rpx !important;
  114. }
  115. }
  116. </style>