down.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <template>
  2. <div class="down-item" ref="layout">
  3. <h3 @click="parentClickHandle" :class="{active: showContent}" v-show="!key">
  4. <div>
  5. <span :class="{aactive: aaaactive}">{{title}}</span>
  6. <a>{{children.length}}</a>
  7. </div>
  8. <span>
  9. <i class="iconfont" :class="showContent ? 'icon-shouqi' : 'icon-xl'"></i>
  10. </span>
  11. </h3>
  12. <ul v-show="showContent && children.length > 0">
  13. <li v-for="(item, key) in children" :key="key" @click.stop="clickHandle(item)" :class="{active: item.name === active}">
  14. <p>• {{item.name}} <i class="iconfont icon-wancheng1" v-if="item.link || item.data"></i> </p>
  15. </li>
  16. </ul>
  17. </div>
  18. </template>
  19. <script>
  20. export default {
  21. props: ['setting', 'keyword', 'show', 'aaaactive'],
  22. data () {
  23. return {
  24. key: this.keyword,
  25. showAll: false,
  26. title: this.setting.title,
  27. showContent: false,
  28. active: null,
  29. isReq: false
  30. }
  31. },
  32. methods: {
  33. clickHandle (item) {
  34. this.$emit('checkItem', item)
  35. },
  36. parentClickHandle () {
  37. this.showContent = !this.showContent
  38. if (this.showContent) {
  39. this.$emit('showcontent')
  40. }
  41. }
  42. },
  43. computed: {
  44. children () {
  45. let children = [...this.setting.children]
  46. let title = this.setting.title
  47. if (title === '全部' && this.key) {
  48. return []
  49. }
  50. if (this.key) {
  51. children = children.filter(item => {
  52. return ~item.name.indexOf(this.keyword)
  53. })
  54. }
  55. return children
  56. }
  57. },
  58. watch: {
  59. show (newVal) {
  60. if (newVal === this.title) {
  61. this.showContent = true
  62. // this.parentClickHandle()
  63. }
  64. },
  65. '$route': {
  66. deep: true,
  67. immediate: true,
  68. handler (newVal) {
  69. this.active = newVal.params.show
  70. }
  71. },
  72. keyword (newVal) {
  73. this.key = newVal
  74. this.showContent = !!this.key
  75. },
  76. async showAll (newVal) {
  77. if (newVal) {
  78. if (!this.isReq) {
  79. await this.getData()
  80. }
  81. this.content.forEach(item => {
  82. if (!~this.actives.indexOf(item)) {
  83. this.actives.push(item)
  84. this.$emit('selected', item)
  85. }
  86. })
  87. } else {
  88. this.actives.forEach(item => {
  89. this.$emit('cancel', item)
  90. })
  91. this.actives = []
  92. }
  93. },
  94. showContent: {
  95. immediate: true,
  96. handler: function (newVal) {
  97. if (newVal) {
  98. setTimeout(() => {
  99. this.$refs.layout.parentNode.scrollTop = this.$refs.layout.offsetTop
  100. }, 50)
  101. }
  102. }
  103. }
  104. },
  105. mounted () {
  106. this.quxiaoHandle = () => {
  107. this.showAll = false
  108. }
  109. this.$bus.$on('quxiao', this.quxiaoHandle)
  110. this.$bus.$on('closeitem', (data) => {
  111. this.showContent = false
  112. })
  113. },
  114. beforeDestroy () {
  115. this.$bus.$off('quxiao', this.quxiaoHandle)
  116. }
  117. }
  118. </script>
  119. <style scoped>
  120. .down-item {
  121. margin-top: 10px;
  122. }
  123. .down-item > h3 {
  124. background-color: #ffffff;
  125. /* padding: 8px 20px; */
  126. height: 30px;
  127. display: flex;
  128. color: #fff;
  129. font-size: 16px;
  130. align-items: center;
  131. font-weight: normal;
  132. cursor: pointer;
  133. }
  134. .down-item > h3 input {
  135. -webkit-appearance: checkbox;
  136. cursor: pointer;
  137. }
  138. .down-item > h3 div {
  139. flex: 1;
  140. color: #2b2521;
  141. font-size: 14px;
  142. flex: 0 0 'auto';
  143. }
  144. .down-item > h3 i {
  145. color: #eac1a3;
  146. font-size: 16px;
  147. }
  148. .down-item > h3 div span {
  149. font-weight: bold;
  150. }
  151. .down-item > ul > li {
  152. margin: 16px 0;
  153. display: flex;
  154. align-items: center;
  155. cursor: pointer;
  156. }
  157. .down-item > ul > li img {
  158. flex: 0 0 auto;
  159. height: 20px;
  160. margin-right: 10px;
  161. }
  162. .down-item > ul > li p {
  163. flex: 1;
  164. color: #2b2521;
  165. font-size: 14px;
  166. }
  167. .down-item > ul > li.active p {
  168. color: #f13800;
  169. }
  170. .aactive {
  171. color: #f13800 !important;
  172. }
  173. .down-item > h3 a {
  174. background-color: #f13800;
  175. color: #fff;
  176. font-size: 12px;
  177. text-align: center;
  178. border-radius: 9px;
  179. width: 24px;
  180. height: 18px;
  181. line-height: 18px;
  182. display: inline-block;
  183. margin-left: 5px;
  184. }
  185. </style>