selectLei.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. <template>
  2. <u-popup v-model="show" mode="left" width="100%">
  3. <view class="box">
  4. <view class="top">
  5. <!-- <view class="top-text">
  6. 分类选择
  7. </view> -->
  8. <view class="top_search">
  9. <view class="search">
  10. <u-search shape="round" bgColor='#fff' searchIconColor='#ccc' clearabled :show-action="false"
  11. searchIconSize="28" placeholderColor="#BDBDBD" height="80" placeholder="请输入分类名称"
  12. v-model="search_name" @clear="clear" />
  13. <view class="search-button" @click="search">搜索</view>
  14. </view>
  15. </view>
  16. </view>
  17. <view class="list-content" v-if="list.length>0">
  18. <view class="list" v-for="(item,_) in list" :key='item.id'>
  19. <view class="list-item">
  20. <view class="text" @click="select(item)">
  21. <view class="text-name"> {{item.name}}</view>
  22. <view class="select1" v-if="currentId==item.id">
  23. <u-icon name="checkbox-mark" color="#DE2E27"></u-icon>
  24. </view>
  25. <view class="select" v-else>
  26. </view>
  27. </view>
  28. <view class="" v-if="item.children">
  29. <view class="list-1" v-for="(item1) in item.children" :key="item1.id">
  30. <view class="list-item-1">
  31. <view class="text-1" @click="select(item1)">
  32. <view class="text-name"> {{item1.name}}</view>
  33. <view class="select1" v-if="currentId == item1.id">
  34. <u-icon name="checkbox-mark" color="#DE2E27"></u-icon>
  35. </view>
  36. <view class="select" v-else>
  37. </view>
  38. </view>
  39. <view class="" v-if="item1.children">
  40. <view class="list-2" v-for="(item2) in item1.children" :key="item2.id">
  41. <view class="list-item-2">
  42. <view class="text-2" @click="select(item2)">
  43. <view class="text-name"> {{item2.name}}</view>
  44. <view class="select1" v-if="currentId==item2.id">
  45. <u-icon name="checkbox-mark" color="#DE2E27"></u-icon>
  46. </view>
  47. <view class="select" v-else>
  48. </view>
  49. </view>
  50. <view class="" v-if="item2.children">
  51. <view class="list-3" v-for="item3 in item2.children"
  52. :key="item3.id">
  53. <view class="list-item-3">
  54. <view class="text-3" @click="select(item3)">
  55. <view class="text-name"> {{item3.name}}</view>
  56. <view class="select1" v-if="currentId == item3.id">
  57. <u-icon name="checkbox-mark" color="#DE2E27">
  58. </u-icon>
  59. </view>
  60. <view class="select" v-else>
  61. </view>
  62. </view>
  63. </view>
  64. </view>
  65. </view>
  66. </view>
  67. </view>
  68. </view>
  69. </view>
  70. </view>
  71. </view>
  72. </view>
  73. </view>
  74. </view>
  75. <view class="buttom-list">
  76. <view class="bottom-left" @click="cancel">
  77. 取消
  78. </view>
  79. <view class="bottom-right" @click="confirm">
  80. 确定
  81. </view>
  82. </view>
  83. </view>
  84. </u-popup>
  85. </template>
  86. <script>
  87. export default {
  88. data() {
  89. return {
  90. show: false,
  91. list: [],
  92. currentId: '',
  93. currentName: '',
  94. search_name: '',
  95. list_init: []
  96. }
  97. },
  98. methods: {
  99. showEdit(row) {
  100. this.show = true
  101. this.list = row
  102. this.list_init = row
  103. console.log(row, '分类数据')
  104. },
  105. select(item) {
  106. this.currentId = item.id
  107. this.currentName = item.name
  108. },
  109. confirm() {
  110. if (!this.currentId && !this.currentName) {
  111. this.$u.toast('请选择数据!')
  112. } else {
  113. this.show = false
  114. const data = {
  115. id: this.currentId,
  116. name: this.currentName
  117. };
  118. this.$emit('fetch-data', data);
  119. }
  120. },
  121. search() {
  122. if (this.search_name) {
  123. this.list = this.list_init
  124. this.list = this.searchByName(this.list, this.search_name);
  125. } else {
  126. this.list = this.list_init
  127. }
  128. },
  129. searchByName(data, keyword) {
  130. const result = [];
  131. const searchKeyword = keyword.trim();
  132. function searchInArray(arr) {
  133. for (const item of arr) {
  134. if (item.name.includes(searchKeyword)) {
  135. result.push(item);
  136. }
  137. if (item.children) {
  138. searchInArray(item.children);
  139. }
  140. }
  141. }
  142. searchInArray(data);
  143. return result;
  144. },
  145. clear() {
  146. this.search_name = ''
  147. this.list = this.list_init
  148. },
  149. cancel() {
  150. this.show = false
  151. this.currentId = ''
  152. this.currentName = ''
  153. }
  154. }
  155. }
  156. </script>
  157. <style lang="scss">
  158. .buttom-list {
  159. height: 50px;
  160. line-height: 50px;
  161. position: fixed;
  162. bottom: 0;
  163. width: 80vw;
  164. left: 10vw;
  165. display: flex;
  166. justify-content: space-between;
  167. .bottom-left {
  168. width: 35vw;
  169. height: 40px;
  170. line-height: 40px;
  171. text-align: center;
  172. background-color: #a5a6a8;
  173. border-radius: 12px;
  174. }
  175. .bottom-right {
  176. width: 35vw;
  177. height: 40px;
  178. line-height: 40px;
  179. text-align: center;
  180. background-color: #DE2E27;
  181. color: #fff;
  182. border-radius: 12px;
  183. }
  184. }
  185. .top {
  186. background: #f7f7f7;
  187. padding: 0 32upx 0 32upx;
  188. box-sizing: border-box;
  189. position: fixed;
  190. top: 0;
  191. left: 0;
  192. height: 140rpx;
  193. z-index: 2;
  194. width: 100%;
  195. }
  196. .top-text {
  197. height: 80px;
  198. line-height: 80px;
  199. font-weight: 550;
  200. font-size: 32upx;
  201. text-align: center;
  202. }
  203. .top_search {
  204. margin-top: 24rpx;
  205. .search {
  206. display: flex;
  207. align-items: center;
  208. justify-content: space-between;
  209. background-color: #fff;
  210. border-radius: 40upx;
  211. height: 80upx;
  212. width: 100%;
  213. }
  214. .search-button {
  215. width: 60px;
  216. height: 32px;
  217. background: #DE2E27;
  218. border-radius: 32px;
  219. font-size: 14px;
  220. margin-right: 5px;
  221. color: #fff;
  222. text-align: center;
  223. line-height: 32px;
  224. }
  225. u-search {
  226. width: 83%;
  227. }
  228. .chongzhi {
  229. background: #2F54EB;
  230. padding: 14rpx;
  231. font-family: PingFangSCMedium-Medium;
  232. font-size: 28rpx;
  233. font-weight: normal;
  234. color: #FFFFFF;
  235. }
  236. }
  237. .box {
  238. padding: 15px;
  239. }
  240. .list-content {
  241. padding-top: 140rpx;
  242. padding-bottom: 55px;
  243. }
  244. .list-item {
  245. // padding:10px;
  246. .list-item-1 {
  247. // border-top: dashed 1px #b9b9b9;
  248. .list-item-2 {
  249. .list-item-3 {
  250. // border-top: dashed 1px #b9b9b9;
  251. }
  252. }
  253. }
  254. .text {
  255. padding: 10px;
  256. // border-left: dashed 1px #b9b9b9;
  257. border-bottom: dashed 1px #b9b9b9;
  258. display: flex;
  259. align-item: center;
  260. .text-name {
  261. flex: 1
  262. }
  263. .select {
  264. height: 18px;
  265. width: 18px;
  266. border-radius: 50%;
  267. border: solid 1px #b9b9b9;
  268. text-align: center;
  269. line-height: 15px;
  270. }
  271. .select1 {
  272. height: 18px;
  273. width: 18px;
  274. border-radius: 50%;
  275. border: solid 1px #DE2E27;
  276. text-align: center;
  277. line-height: 15px;
  278. }
  279. }
  280. .text-1 {
  281. padding: 10px;
  282. margin-left: 20px;
  283. // border-left: dashed 1px #b9b9b9;
  284. border-bottom: dashed 1px #b9b9b9;
  285. display: flex;
  286. align-item: center;
  287. .text-name {
  288. flex: 1
  289. }
  290. .select {
  291. height: 18px;
  292. width: 18px;
  293. border-radius: 50%;
  294. border: solid 1px #b9b9b9;
  295. text-align: center;
  296. line-height: 15px;
  297. }
  298. .select1 {
  299. height: 15px;
  300. width: 15px;
  301. border-radius: 50%;
  302. border: solid 1px #DE2E27;
  303. text-align: center;
  304. line-height: 15px;
  305. }
  306. }
  307. .text-2 {
  308. padding: 10px;
  309. margin-left: 30px;
  310. // border-left: dashed 1px #b9b9b9;
  311. border-bottom: dashed 1px #b9b9b9;
  312. display: flex;
  313. align-item: center;
  314. .text-name {
  315. flex: 1
  316. }
  317. .select {
  318. height: 18px;
  319. width: 18px;
  320. border-radius: 50%;
  321. border: solid 1px #b9b9b9;
  322. text-align: center;
  323. line-height: 15px;
  324. }
  325. .select1 {
  326. height: 18px;
  327. width: 18px;
  328. border-radius: 50%;
  329. border: solid 1px #DE2E27;
  330. text-align: center;
  331. line-height: 15px;
  332. }
  333. }
  334. .text-3 {
  335. padding: 10px;
  336. margin-left: 40px;
  337. // border-left: dashed 1px #b9b9b9;
  338. border-bottom: dashed 1px #b9b9b9;
  339. display: flex;
  340. align-item: center;
  341. .text-name {
  342. flex: 1
  343. }
  344. .select {
  345. height: 18px;
  346. width: 18px;
  347. border-radius: 50%;
  348. border: solid 1px #b9b9b9;
  349. text-align: center;
  350. line-height: 15px;
  351. }
  352. .select1 {
  353. height: 18px;
  354. width: 18px;
  355. border-radius: 50%;
  356. border: solid 1px #DE2E27;
  357. text-align: center;
  358. line-height: 15px;
  359. }
  360. }
  361. }
  362. </style>