二十三、小程序中的三级下拉框(下拉菜单)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | XHTML部分 < br > < view class='area'> < view class="product-list"> <!--条件选择--> < view class="choice-bar"> <!--头部--> <!--第一个--> < view bindtap="choiceItem" data-item="1" class="chioce-item" hover-class="click-once-opaque">{{name}} < image class="icon-chioce" src="{{staticImg}}maintenance/icon-go-black.png"></ image > </ view > <!--蜀山区--> < view bindtap="choiceItem" data-item="2" class="chioce-item" hover-class="click-once-opaque">{{activeSortingName}} < image class="icon-chioce" src="{{staticImg}}maintenance/icon-go-black.png"></ image > </ view > <!--默认排序--> < view bindtap="choiceItem" data-item="3" class="chioce-item" hover-class="click-once-opaque">{{ordername}} < image class="icon-chioce" src="{{staticImg}}maintenance/icon-go-black.png"></ image > </ view > <!--对应的下拉框 --> < br > <!--名字--> < view class="sorting-list{{!chioceDistrict?' chioce-list-hide':' chioce-list-show'}}"> < view wx:for="{{DjList}}" catchtap="getDistrictList" data-index="{{index}}" class="sorting-item" hover-class="click-once" bindtap='selectColor'>{{item.value}}< text >123</ text ></ view > </ view > <!--地区--> < view class="sorting-list{{!chioceSorting?' chioce-list-hide':' chioce-list-show'}}"> < view wx:for="{{sortingList}}" catchtap="selectSorting" data-index="{{index}}" class="sorting-item" hover-class="click-once" bindtap='selectColor'>{{item.value}}< text >123</ text ></ view > </ view > <!--默认排序--> < view class="filter-list{{!chioceFilter?' chioce-list-hide':' chioce-list-show'}}"> < view wx:for="{{filterList}}" catchtap="selectFilter" data-index="{{index}}" class="filter-item" hover-class="click-once" catchtap="filterButtonClick">{{item.value}} < image hidden="{{!item.selected}}" class="icon-selected" src="/pages/maintenance/img/icon-selected.png"></ image > </ view > </ view > </ view > < view bindtap="hideAllChioce" class="mask" hidden="{{!chioceDistrict&&!chioceSorting&&!chioceFilter}}"> </ view > </ view > </ view > |
WXSS样式
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 | /* pages/maintenance/maintenance.wxss */ page{ display: flex; flex-direction: column; height: 100%; background: #f0f0f0; } .navbar{ flex: none; display: flex; background: #fff; box-sizing: border-box; z-index: 9999; } .navbar .item{ position: relative; flex: auto; text-align: center; line-height: 80rpx; padding-top: 1px; font-size: 30rpx; } .navbar .item.active:after{ content: ""; display: block; position: absolute; bottom: 0; left: 0; right: 0; height: 4rpx; background: #c00; } .active { background: #c00; color: #fff; } .area { width: 100%; height: 84rpx; background: #fff; border-top: 1px solid #ccc; /* display: none; */ } .fixdd { width: 100%; height: 78rpx; background: #fff; border-top: 1px solid #ccc; box-sizing: border-box; padding-left: 43rpx; } .fixddImg { width: 40rpx; height: 40rpx; margin-top: 19rpx; display: block; float: left; } .fixddtext { font-size: 30rpx; height: 80rpx; line-height: 80rpx; margin-left: 30rpx; color: #888; } .stores { width: 100%; height: 205rpx; } .storesLi { width: 100%; height: 205rpx; background: #fff; box-sizing: border-box; padding: 30rpx; margin-top: 10rpx; } .storesL { width: 150rpx; height: 150rpx; float: left; } .storesL image { width: 150rpx; height: 150rpx; } .storesR { width: 530rpx; height: 150rpx; float: left; position: relative; box-sizing: border-box; padding-left: 20rpx; } .Ul { width: 77%; height: 150rpx; } .storestext1 { font-size: 30rpx; } .storestext2 { font-size: 24rpx; color: #888; } .storestext3 { font-size: 24rpx; color: #888; line-height: 50rpx; } .storestext3 text { color: #c00; margin-right: 30rpx; } .selt { width: 87rpx; height: 81rpx; line-height: 81rpx; border-radius: 10rpx; border: 1px solid #888; position: absolute; right: 0; top: 0; text-align: center; font-size: 24rpx; color: #888; } .dist { position: absolute; right: 0; bottom: 0;font-size: 24rpx; color: #888; } .editor { width: 100%; height: 100rpx; background: #fff; margin-top: 50rpx; box-sizing: border-box; padding-left: 56rpx; } .editortext1 { height: 100rpx; line-height: 100rpx; } .editorImg { width: 45rpx; height: 45rpx; margin-top: 28rpx; float: right; margin-right: 40rpx; } .editortext1 { font-size:30rpx; margin-right: 50rpx; } .editortext2 { display: inline-block; width: 100rpx; height: 45rpx; font-size: 24rpx; background: #c00; color: #fff; text-align: center; line-height: 45rpx; } .addEdict { width: 80%; height: 80rpx; color: #fff; line-height: 80rpx; background: #c00; margin-top: 80rpx; } /*顶部的下拉框样式*/ .product-list { min-height: 100vh; background-color: #f0f0f0; padding-top: 80rpx; box-sizing: border-box; } /*条件选择*/ .choice-bar { position: absolute; top: 80rpx; display: flex; width: 100vw; font-size: 16px; background-color: #fff; z-index: 9; } .chioce-item { background-color: #fff; /* display: flex; */ align-items: center; justify-content: space-between; padding: 0 20rpx; width: 33.3%; height: 80rpx; line-height: 80rpx; text-align: center; border-top: 1rpx solid #ddd; border-bottom: 1rpx solid #ddd; border-left: 1rpx solid #ddd; font-size: 26rpx; /*border-right: 1rpx solid #ddd;*/ } .chioce-item-last { border-right: none; } .chioce-item-first { border-left: none; } .icon-chioce { height: 25rpx; width: 25rpx; } .mask{ position: fixed; top:0; bottom: 0; right: 0; left: 0; background-color: #000; opacity: 0.5; } .district-list,.sorting-list,.filter-list { margin-top: 2rpx; position: absolute; top: 80rpx; left: 0; width: 100%; background-color: #fff; z-index: -1; font-size: 14px; border-bottom: 1rpx solid #ddd; } .chioce-list-show { top: 80rpx; animation: slide 500ms; } @keyframes slide { 0% { top: -500rpx; } 100% { top: 80rpx; } } .chioce-list-hide { display: none !important; } /*区域位置*/ .district-list { display: flex; } .district-left { flex-grow: 1; } .district-right { flex-grow: 4; } .scroll-district{ height: 500rpx; } .district-parent { height: 100rpx; line-height: 100rpx; padding: 0 40rpx; border-bottom: 1rpx solid #ddd; border-right: 1rpx solid #ddd; background-color: #f0f0f0; } .district-parent-active { background-color: #fff; } .district-children { height: 100rpx; line-height: 100rpx; padding: 0 40rpx; border-bottom: 1rpx solid #ddd; } /*综合排序*/ .sorting-item { height: 80rpx; line-height: 80rpx; padding: 0 40rpx; border-bottom: 1rpx solid #ddd; } .sorting-item text { float: right; } /*筛选*/ .filter-item { height: 80rpx; line-height: 80rpx; padding: 0 40rpx; border-bottom: 1rpx solid #ddd; display: flex; justify-content: space-between; align-items: center; } .icon-selected { height: 30rpx; width: 30rpx; } .filter-footer { display: flex; justify-content: space-between; } .filter-footer button { margin: 20rpx 80rpx; border-radius: 0 !important; } .button-reset { border: 1rpx solid #ddd !important; color: #666 !important; } .seleColor { color: #c00; } |
JS
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | // pages/maintenance/maintenance.js Page({ /** * 页面的初始数据 */ data: { staticImg: app.globalData.staticImg, curIndex: 0, currentTab: 0, // 下拉框的data值 typeID: 0, isLoading: true, loadOver: false, districtList: [], sortingList: [{ key: 1, value: "合肥市" }, { key: 2, value: "合肥市" }, { key: 3, value: "瑶海区" }, { key: 4, value: "瑶海区" }, { key: 5, value: "瑶海区" }, { key: 6, value: "瑶海区" }], filterList: [ { key: 1, value: "默认排序", selected: false }, { key: 2, value: "距离最近", selected: false }, { key: 3, value: "评分最高", selected: false }, { key: 4, value: "累计订单", selected: false }, ], DjList: [ { key: 1, value: "邓杰"}, { key: 2, value: "小明"}, { key: 3, value: "小唐"}, { key: 4, value: "小杰"}, ], // districtChioceIcon: "/pages/maintenance/img/icon-go-black.png", // sortingChioceIcon: "/pages/maintenance/img/icon-go-black.png", chioceDistrict: false, chioceSorting: false, chioceFilter: false, // activeDistrictParentIndex: -1, // activeDistrictChildrenIndex: -1, // activeDistrictName: "区域位置", // scrollTop: 0, // scrollIntoView: 0, // activeSortingIndex: -1, activeSortingName: "蜀山区", ordername: "默认排序", name:"貂蝉" }, // 下拉框的对应js //条件选择 choiceItem: function (e) { switch (e.currentTarget.dataset.item) { case "1": if (this.data.chioceDistrict) { this.setData({ districtChioceIcon: "/pages/maintenance/img/icon-go-black.png", sortingChioceIcon: "/pages/maintenance/img/icon-go-black.png", chioceDistrict: false, chioceSorting: false, chioceFilter: false, }); } else { this.setData({ districtChioceIcon: "/pages/maintenance/img/icon-go-black.png", sortingChioceIcon: "/pages/maintenance/img/icon-go-black.png", chioceDistrict: true, chioceSorting: false, chioceFilter: false, }); } break; case "2": if (this.data.chioceSorting) { this.setData({ districtChioceIcon: "/pages/maintenance/img/icon-go-black.png", sortingChioceIcon: "/pages/maintenance/img/icon-go-black.png", chioceDistrict: false, chioceSorting: false, chioceFilter: false, }); } else { this.setData({ districtChioceIcon: "/pages/maintenance/img/icon-go-black.png", sortingChioceIcon: "/pages/maintenance/img/icon-go-black.png", chioceDistrict: false, chioceSorting: true, chioceFilter: false, }); } break; case "3": if (this.data.chioceFilter) { this.setData({ districtChioceIcon: "/pages/maintenance/img/icon-go-black.png", sortingChioceIcon: "/pages/maintenance/img/icon-go-black.png", chioceDistrict: false, chioceSorting: false, chioceFilter: false, }); } else { this.setData({ districtChioceIcon: "/pages/maintenance/img/icon-go-black.png", sortingChioceIcon: "/pages/maintenance/img/icon-go-black.png", chioceDistrict: false, chioceSorting: false, chioceFilter: true, }); } break; } }, getDistrictList: function (e) { var index = e.currentTarget.dataset.index; this.setData({ sortingChioceIcon: "/pages/maintenance/img/icon-go-black.png", chioceDistrict: false, activeSortingIndex: index, name: this.data.DjList[index].value, productList: [], pageIndex: 1, loadOver: false, isLoading: true }) }, //蜀山区 selectSorting: function (e) { var index = e.currentTarget.dataset.index; this.setData({ sortingChioceIcon: "/pages/maintenance/img/icon-go-black.png", chioceSorting: false, activeSortingIndex: index, activeSortingName: this.data.sortingList[index].value, productList: [], pageIndex: 1, loadOver: false, isLoading: true }) }, //默认排序 filterButtonClick: function (e) { var index = e.currentTarget.dataset.index; this.setData({ chioceFilter: false, productList: [], pageIndex: 1, loadOver: false, isLoading: true, ordername: this.data.filterList[index].value, }) }, }) |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· AI与.NET技术实操系列(六):基于图像分类模型对图像进行分类