index.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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="special">
  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. special: {
  90. type: Boolean,
  91. default: false
  92. },
  93. title: {
  94. type: String,
  95. default: '展馆号'
  96. },
  97. data: {
  98. type: Array,
  99. default: []
  100. },
  101. children: {
  102. type: Boolean,
  103. default: false
  104. },
  105. uId: {
  106. type: String,
  107. default: 'dropdown'
  108. },
  109. value: {
  110. type: [String, Number],
  111. default: []
  112. }
  113. },
  114. watch: {
  115. data(value) {
  116. this.dataList = value
  117. this.initChildHeight()
  118. },
  119. value(value) {
  120. this.selectedList = value
  121. },
  122. selectedList(val) {
  123. this.$emit('input', val)
  124. }
  125. },
  126. data() {
  127. return {
  128. activeName: '',
  129. dataList: [],
  130. selectedList: [],
  131. height: 0,
  132. }
  133. },
  134. created() {},
  135. mounted() {
  136. this.selectedList = this.value
  137. },
  138. methods: {
  139. onChange(event) {
  140. console.log(event)
  141. this.activeName = event
  142. },
  143. initChildHeight() {
  144. if (this.children) {
  145. for (let i = 0; i < this.dataList.length; i++) {
  146. this.$set(this.dataList[i], 'height', 0)
  147. }
  148. }
  149. },
  150. handleItemChange(e) {
  151. this.selectedList = e.detail.value
  152. this.$emit('input', this.selectedList)
  153. this.$emit('change-event', this.selectedList);
  154. },
  155. getOutHeight() {
  156. this.$nextTick(() => {
  157. const query = uni.createSelectorQuery().in(this)
  158. let id = "#" + this.uId
  159. query.select(id).boundingClientRect(data => {
  160. if (data) {
  161. this.height = data.height
  162. }
  163. }).exec()
  164. })
  165. },
  166. changeStatus() {
  167. if (this.height === 0) {
  168. this.getOutHeight()
  169. } else {
  170. this.height = 0
  171. }
  172. },
  173. changeChildStatus(index) {
  174. let id = '#child' + index
  175. if (this.dataList[index].height === 0) {
  176. const query = uni.createSelectorQuery().in(this)
  177. query.select(id).boundingClientRect(data => {
  178. if (data) {
  179. this.$set(this.dataList[index], 'height', data.height)
  180. this.getOutHeight()
  181. }
  182. }).exec()
  183. } else {
  184. this.$set(this.dataList[index], 'height', 0)
  185. this.getOutHeight()
  186. }
  187. }
  188. }
  189. }
  190. </script>
  191. <style lang="scss">
  192. .u-select-container {
  193. .u-select-box {
  194. background-color: #FFFFFF;
  195. border-radius: 13rpx;
  196. border: 3rpx solid #B3B3B3;
  197. overflow: hidden;
  198. .lable-icon-box {
  199. display: flex;
  200. justify-content: space-between;
  201. grid-gap: 20rpx;
  202. align-items: center;
  203. padding: 18rpx 25rpx;
  204. .lable {
  205. font-size: 20rpx;
  206. color: #B3B3B3;
  207. &.active {
  208. color: #E57519;
  209. }
  210. }
  211. .iconfont {
  212. font-size: 24rpx;
  213. color: #333333;
  214. }
  215. }
  216. .dropdown-box {
  217. // transition: height .2s ease;
  218. .dropdown-item {
  219. border-bottom: 1px solid #e3e9f1;
  220. overflow: hidden;
  221. &:nth-last-child(1) {
  222. border-bottom: unset;
  223. }
  224. // .child-box {
  225. // transition: height .2s ease;
  226. // }
  227. .child-lable-icon-box {
  228. display: flex;
  229. grid-gap: 20rpx;
  230. align-items: center;
  231. padding: 18rpx 25rpx;
  232. .child-lable {
  233. font-size: 20rpx;
  234. color: #333333;
  235. }
  236. .iconfont {
  237. color: #333333;
  238. }
  239. }
  240. .child-custom-checkbox {
  241. checkbox {
  242. padding: 20rpx 25rpx;
  243. font-size: 24rpx;
  244. display: flex;
  245. align-items: center;
  246. }
  247. }
  248. }
  249. }
  250. }
  251. }
  252. checkbox-group {
  253. display: flex;
  254. flex-direction: column;
  255. .custom-checkbox {
  256. checkbox {
  257. padding: 20rpx 25rpx;
  258. border-bottom: 1px solid #e3e9f1;
  259. font-size: $fontSize3;
  260. display: flex;
  261. align-items: center;
  262. }
  263. &:nth-last-child(1) {
  264. checkbox {
  265. border-bottom: unset;
  266. }
  267. }
  268. }
  269. }
  270. </style>