index.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. <template>
  2. <view>
  3. <view v-if="children === false">
  4. <checkbox-group @change="handleItemChange" :id="uId">
  5. <label class="custom-checkbox" v-for="(item, index) in dataList" :key="index">
  6. <checkbox :value="item.label" v-if="title === '展馆号'">
  7. {{item.label}}
  8. </checkbox>
  9. <checkbox :value="item.value" v-else>
  10. {{item.label}}
  11. </checkbox>
  12. </label>
  13. </checkbox-group>
  14. </view>
  15. <view v-else>
  16. <checkbox-group class="child_collapse" @change="handleItemChange" :id="uId">
  17. <van-collapse :value="activeName" @change="onChange" :name="item.label" v-for="(item, index) in dataList" :key="index">
  18. <van-collapse-item :title="item.label" :name="item.label">
  19. <label class="custom-checkbox" v-for="(children_item, index) in item.children" :key="index">
  20. <checkbox :value="children_item.value">
  21. {{children_item.label}}
  22. </checkbox>
  23. </label>
  24. </van-collapse-item>
  25. </van-collapse>
  26. </checkbox-group>
  27. </view>
  28. </view>
  29. <!-- <view class="u-select-container">
  30. <view class="u-select-box">
  31. <view class="lable-icon-box" @click="changeStatus()">
  32. <view class="lable" :class="{'active': selectedList.length>0}">
  33. {{title}}
  34. </view>
  35. <i class="iconfont icon-Down"></i>
  36. </view>
  37. <view class="dropdown-box" :style="{ height: height + 'px' }" v-if="children === false">
  38. <checkbox-group @change="handleItemChange" :id="uId" v-if="title === '展馆号'">
  39. <label class="custom-checkbox" v-for="(item, index) in dataList" :key="index">
  40. <checkbox :class="{ 'open': selectedList.includes(String(item.label)) }" :value="item.label">
  41. {{item.label}}
  42. </checkbox>
  43. </label>
  44. </checkbox-group>
  45. <checkbox-group @change="handleItemChange" :id="uId" v-else>
  46. <label class="custom-checkbox" v-for="(item, index) in dataList" :key="index">
  47. <checkbox :class="{ 'open': selectedList.includes(String(item.value)) }" :value="item.value">
  48. {{item.label}}
  49. </checkbox>
  50. </label>
  51. </checkbox-group>
  52. </view>
  53. <view class="dropdown-box" :style="{ height: height + 'px' }" v-else>
  54. <checkbox-group @change="handleItemChange" :id="uId">
  55. <view class="dropdown-item" v-for="(item, index) in dataList" :key="index">
  56. <template>
  57. <view class="child-lable-icon-box" @click="changeChildStatus(index)">
  58. <view class="child-lable">
  59. {{item.label}}
  60. </view>
  61. <i class="iconfont icon-DownSmall"></i>
  62. </view>
  63. <view class="child-box" :style="{ height: item.height + 'px' }">
  64. <view class="inner-box" :id="'child' + index">
  65. <label class="child-custom-checkbox" v-for="(childItem, index) in item.children" :key="index">
  66. <checkbox :class="{ 'open': selectedList.includes(String(childItem.value)) }"
  67. :value="childItem.value">
  68. {{childItem.label}}
  69. </checkbox>
  70. </label>
  71. </view>
  72. </view>
  73. </template>
  74. </view>
  75. </checkbox-group>
  76. </view>
  77. </view>
  78. </view>-->
  79. </template>
  80. <script>
  81. import vanCollapse from '@/wxcomponents/vant/collapse/index'
  82. import vanCollapseItem from '@/wxcomponents/vant/collapse-item/index'
  83. export default {
  84. components: {
  85. vanCollapse,
  86. vanCollapseItem
  87. },
  88. props: {
  89. title: {
  90. type: String,
  91. default: '展馆号'
  92. },
  93. data: {
  94. type: Array,
  95. default: []
  96. },
  97. children: {
  98. type: Boolean,
  99. default: false
  100. },
  101. uId: {
  102. type: String,
  103. default: 'dropdown'
  104. },
  105. value: {
  106. type: [String, Number],
  107. default: []
  108. }
  109. },
  110. watch: {
  111. data(value) {
  112. this.dataList = value
  113. this.initChildHeight()
  114. },
  115. value(value) {
  116. this.selectedList = value
  117. },
  118. selectedList(val) {
  119. this.$emit('input', val)
  120. }
  121. },
  122. data() {
  123. return {
  124. activeName: '',
  125. dataList: [],
  126. selectedList: [],
  127. height: 0,
  128. }
  129. },
  130. created() {},
  131. mounted() {
  132. this.selectedList = this.value
  133. },
  134. methods: {
  135. onChange(event) {
  136. console.log(event)
  137. this.activeName = event
  138. },
  139. initChildHeight() {
  140. if (this.children) {
  141. for (let i = 0; i < this.dataList.length; i++) {
  142. this.$set(this.dataList[i], 'height', 0)
  143. }
  144. }
  145. },
  146. handleItemChange(e) {
  147. this.selectedList = e.detail.value
  148. this.$emit('input', this.selectedList)
  149. this.$emit('change-event', this.selectedList);
  150. },
  151. getOutHeight() {
  152. this.$nextTick(() => {
  153. const query = uni.createSelectorQuery().in(this)
  154. let id = "#" + this.uId
  155. query.select(id).boundingClientRect(data => {
  156. if (data) {
  157. this.height = data.height
  158. }
  159. }).exec()
  160. })
  161. },
  162. changeStatus() {
  163. if (this.height === 0) {
  164. this.getOutHeight()
  165. } else {
  166. this.height = 0
  167. }
  168. },
  169. changeChildStatus(index) {
  170. let id = '#child' + index
  171. if (this.dataList[index].height === 0) {
  172. const query = uni.createSelectorQuery().in(this)
  173. query.select(id).boundingClientRect(data => {
  174. if (data) {
  175. this.$set(this.dataList[index], 'height', data.height)
  176. this.getOutHeight()
  177. }
  178. }).exec()
  179. } else {
  180. this.$set(this.dataList[index], 'height', 0)
  181. this.getOutHeight()
  182. }
  183. }
  184. }
  185. }
  186. </script>
  187. <style lang="scss">
  188. .u-select-container {
  189. .u-select-box {
  190. background-color: #FFFFFF;
  191. border-radius: 13rpx;
  192. border: 3rpx solid #B3B3B3;
  193. overflow: hidden;
  194. .lable-icon-box {
  195. display: flex;
  196. justify-content: space-between;
  197. grid-gap: 20rpx;
  198. align-items: center;
  199. padding: 18rpx 25rpx;
  200. .lable {
  201. font-size: 20rpx;
  202. color: #B3B3B3;
  203. &.active {
  204. color: #E57519;
  205. }
  206. }
  207. .iconfont {
  208. font-size: 24rpx;
  209. color: #333333;
  210. }
  211. }
  212. .dropdown-box {
  213. // transition: height .2s ease;
  214. .dropdown-item {
  215. border-bottom: 1px solid #e3e9f1;
  216. overflow: hidden;
  217. &:nth-last-child(1) {
  218. border-bottom: unset;
  219. }
  220. // .child-box {
  221. // transition: height .2s ease;
  222. // }
  223. .child-lable-icon-box {
  224. display: flex;
  225. grid-gap: 20rpx;
  226. align-items: center;
  227. padding: 18rpx 25rpx;
  228. .child-lable {
  229. font-size: 20rpx;
  230. color: #333333;
  231. }
  232. .iconfont {
  233. color: #333333;
  234. }
  235. }
  236. .child-custom-checkbox {
  237. checkbox {
  238. padding: 20rpx 25rpx;
  239. font-size: 24rpx;
  240. display: flex;
  241. align-items: center;
  242. }
  243. }
  244. }
  245. }
  246. }
  247. }
  248. checkbox-group {
  249. display: flex;
  250. flex-direction: column;
  251. .custom-checkbox {
  252. checkbox {
  253. padding: 20rpx 25rpx;
  254. border-bottom: 1px solid #e3e9f1;
  255. font-size: $fontSize3;
  256. display: flex;
  257. align-items: center;
  258. }
  259. &:nth-last-child(1) {
  260. checkbox {
  261. border-bottom: unset;
  262. }
  263. }
  264. }
  265. }
  266. </style>