index.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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. this.activeName = event
  141. },
  142. initChildHeight() {
  143. if (this.children) {
  144. for (let i = 0; i < this.dataList.length; i++) {
  145. this.$set(this.dataList[i], 'height', 0)
  146. }
  147. }
  148. },
  149. handleItemChange(e) {
  150. this.selectedList = e.detail.value
  151. this.$emit('input', this.selectedList)
  152. this.$emit('change-event', this.selectedList);
  153. },
  154. getOutHeight() {
  155. this.$nextTick(() => {
  156. const query = uni.createSelectorQuery().in(this)
  157. let id = "#" + this.uId
  158. query.select(id).boundingClientRect(data => {
  159. if (data) {
  160. this.height = data.height
  161. }
  162. }).exec()
  163. })
  164. },
  165. changeStatus() {
  166. if (this.height === 0) {
  167. this.getOutHeight()
  168. } else {
  169. this.height = 0
  170. }
  171. },
  172. changeChildStatus(index) {
  173. let id = '#child' + index
  174. if (this.dataList[index].height === 0) {
  175. const query = uni.createSelectorQuery().in(this)
  176. query.select(id).boundingClientRect(data => {
  177. if (data) {
  178. this.$set(this.dataList[index], 'height', data.height)
  179. this.getOutHeight()
  180. }
  181. }).exec()
  182. } else {
  183. this.$set(this.dataList[index], 'height', 0)
  184. this.getOutHeight()
  185. }
  186. }
  187. }
  188. }
  189. </script>
  190. <style lang="scss">
  191. .u-select-container {
  192. .u-select-box {
  193. background-color: #FFFFFF;
  194. border-radius: 13rpx;
  195. border: 3rpx solid #B3B3B3;
  196. overflow: hidden;
  197. .lable-icon-box {
  198. display: flex;
  199. justify-content: space-between;
  200. grid-gap: 20rpx;
  201. align-items: center;
  202. padding: 18rpx 25rpx;
  203. .lable {
  204. font-size: 20rpx;
  205. color: #B3B3B3;
  206. &.active {
  207. color: #E57519;
  208. }
  209. }
  210. .iconfont {
  211. font-size: 24rpx;
  212. color: #333333;
  213. }
  214. }
  215. .dropdown-box {
  216. // transition: height .2s ease;
  217. .dropdown-item {
  218. border-bottom: 1px solid #e3e9f1;
  219. overflow: hidden;
  220. &:nth-last-child(1) {
  221. border-bottom: unset;
  222. }
  223. // .child-box {
  224. // transition: height .2s ease;
  225. // }
  226. .child-lable-icon-box {
  227. display: flex;
  228. grid-gap: 20rpx;
  229. align-items: center;
  230. padding: 18rpx 25rpx;
  231. .child-lable {
  232. font-size: 20rpx;
  233. color: #333333;
  234. }
  235. .iconfont {
  236. color: #333333;
  237. }
  238. }
  239. .child-custom-checkbox {
  240. checkbox {
  241. padding: 20rpx 25rpx;
  242. font-size: 24rpx;
  243. display: flex;
  244. align-items: center;
  245. }
  246. }
  247. }
  248. }
  249. }
  250. }
  251. checkbox-group {
  252. display: flex;
  253. flex-direction: column;
  254. .custom-checkbox {
  255. checkbox {
  256. padding: 20rpx 25rpx;
  257. border-bottom: 1px solid #e3e9f1;
  258. font-size: $fontSize1;
  259. display: flex;
  260. align-items: center;
  261. }
  262. &:nth-last-child(1) {
  263. checkbox {
  264. border-bottom: unset;
  265. }
  266. }
  267. }
  268. }
  269. </style>