<template>
<gracePage :customHeader="false">
<!-- 页面主体 -->
<view slot="gBody">
<view class="grace-nowrap grace-flex-vcenter grace-border-b"
style="margin-top:50rpx; background:#F6F7F8;">
<view class="graceSelectMenuItem">
<graceSelectMenu
:show="show1" :items="selectMenu1" @showMenu="showMenu1" @close="closeMenu1" @select="select1"></graceSelectMenu>
</view>
<view class="graceSelectMenuItem">
<!-- 此处演示数据来自后端 api,将后端的复杂数组转换为简单数组使用并适配 -->
<graceSelectMenu
:show="show2" :height="300" :selectIndex="selectIndex2" :items="selectMenu2"
@showMenu="showMenu2" @close="closeMenu2" @select="select2"></graceSelectMenu>
</view>
<!-- 可自定义输入 -->
<view class="graceSelectMenuItem">
<graceSelectMenu :show="show3" :items="selectMenu3" :isInput="true"
@submit="submit" :selectIndex="selectIndex3" placeholder="填写自定义分类"
@showMenu="showMenu3" @close="closeMenu3" @select="select3"></graceSelectMenu>
</view>
</view>
</view>
</gracePage>
</template>
<script>
import gracePage from "../../graceUI/components/gracePage.vue";
import graceSelectMenu from "../../graceUI/components/graceSelectMenu.vue";
export default {
data(){
return {
// 第 1 个菜单
show1 : false,
selectMenu1 : ['全部分类', '精选优品', '价格较低', '只买贵的', '其他方式'],
selectIndex1 : 0,
// 第 2 个菜单
show2 : false,
selectIndex2 : 1,
selectMenu2FromApi : [],
selectMenu2 : [],
// 第 3 个菜单
show3 : false,
selectMenu3 : ['全部语言', 'php', 'java', 'c#', 'nodejs'],
selectIndex3 : 0,
}
},
onLoad : function () {
setTimeout(()=>{
// 默认二个菜单的数据来自api请求
// 请求的原本数据格式 :
this.selectMenu2FromApi = [
{key:1, value:'大专'},
{key:2, value:'本科'},
{key:3, value:'硕士'},
{key:4, value:'博士'}
];
// 将后端的复杂数组转换为索引关系一致的简单数组
this.selectMenu2 = [];
for(var i = 0; i < this.selectMenu2FromApi.length; i++){
this.selectMenu2.push(this.selectMenu2FromApi[i].value);
}
this.selectIndex2 = 3
}, 1000)
},
components:{
gracePage, graceSelectMenu
},
methods:{
showMenu1 : function () {this.show1 = true;},
closeMenu1 : function () {this.show1 = false;},
select1 : function (index) {
console.log("选择了 " + this.selectMenu1[index]);
},
showMenu2 : function () {this.show2 = true;},
closeMenu2 : function () {this.show2 = false;},
select2 : function (index) {
console.log("选择了 " + this.selectMenu2[index]);
// 如何对应获取后端 api 的值
console.log(this.selectMenu2FromApi[index]);
},
// 第三个菜单
// 客户自定义输入
submit : function (e) {
var len = this.selectMenu3.push(e);
this.selectIndex3 = len - 1;
this.closeMenu3();
console.log("选择了 " + e);
},
showMenu3 : function () {this.show3 = true;},
closeMenu3 : function () {this.show3 = false;},
select3 : function (index) {
console.log("选择了 " + this.selectMenu3[index]);
}
}
}
</script>
<style>
.graceSelectMenuItem{width:200rpx; line-height:90rpx;}
</style>
<template>
<gracePage :customHeader="false">
<!-- 页面主体 -->
<view slot="gBody">
<view class="grace-nowrap grace-flex-vcenter grace-border-b" style="background-color:#F6F7F8;">
<view class="graceSelectMenuItem">
<graceSelectMenu :show="show1" :items="selectMenu1" @showMenu="showMenu1" @close="closeMenu1" @select="select1"></graceSelectMenu>
</view>
<view class="graceSelectMenuItem">
<graceSelectMenu
:show="show2" :height="300" :selectIndex="selectIndex2" :items="selectMenu2"
@showMenu="showMenu2" @close="closeMenu2" @select="select2"></graceSelectMenu>
</view>
<!-- 可自定义输入 -->
<view class="graceSelectMenuItem">
<graceSelectMenu :show="show3" :items="selectMenu3" :isInput="true"
@submit="submit" :selectIndex="selectIndex3" placeholder="填写自定义分类"
@showMenu="showMenu3" @close="closeMenu3" @select="select3"></graceSelectMenu>
</view>
</view>
</view>
</gracePage>
</template>
<script>
import gracePage from "../../graceUI/weexComponents/gracePage.nvue";
import graceSelectMenu from "../../graceUI/weexComponents/graceSelectMenu.nvue";
export default {
data(){
return {
// 第1个菜单
show1 : false,
selectMenu1 : ['全部分类', '精选优品', '价格较低', '只买贵的', '其他方式'],
// 第2个菜单
show2 : false,
selectIndex2 : 1,
selectMenu2 : ['学历', '大专', '本科', '硕士', '博士'],
// 第 3 个菜单
show3 : false,
selectMenu3 : ['全部语言', 'php', 'java', 'c#', 'nodejs'],
selectIndex3 : 0,
}
},
onLoad : function () {
setTimeout(()=>{
this.selectIndex2 = 3
}, 2000)
},
components:{
gracePage, graceSelectMenu
},
methods:{
showMenu1 : function () {this.show1 = true;},
closeMenu1 : function () {this.show1 = false;},
select1 : function (index) {
console.log("选择了 " + this.selectMenu1[index]);
},
showMenu2 : function () {this.show2 = true;},
closeMenu2 : function () {this.show2 = false;},
select2 : function (index) {
console.log("选择了 " + this.selectMenu2[index]);
},
// 第三个菜单
// 客户自定义输入
submit : function (e) {
var len = this.selectMenu3.push(e);
this.selectIndex3 = len - 1;
this.closeMenu3();
console.log("选择了 " + e);
},
showMenu3 : function () {this.show3 = true;},
closeMenu3 : function () {this.show3 = false;},
select3 : function (index) {
console.log("选择了 " + this.selectMenu3[index]);
}
}
}
</script>
<style>
.graceSelectMenuItem{width:200rpx; line-height:90rpx;}
</style>
.wxml
<gracePage customHeader="{{false}}">
<!-- 页面主体 -->
<view slot="gBody">
<view class="grace-nowrap grace-flex-vcenter grace-border-b" style="margin-top:50rpx; background:#F6F7F8;">
<view class="graceSelectMenuItem">
<graceSelectMenu show="{{show1}}" items="{{selectMenu1}}" bind:showMenu="showMenu1"
bind:close="closeMenu1" bind:select="select1"></graceSelectMenu>
</view>
<view class="graceSelectMenuItem">
<graceSelectMenu
show="{{show2}}" height="500" selectIndex="2" items="{{selectMenu2}}" selectIndex="{{selectIndex2}}"
bind:showMenu="showMenu2" bind:close="closeMenu2" bind:select="select2"></graceSelectMenu>
</view>
<!-- 可自定义输入 -->
<view class="graceSelectMenuItem">
<graceSelectMenu show="{{show3}}" items="{{selectMenu3}}" isInput="{{true}}"
bind:submit="submit" selectIndex="{{selectIndex3}}" placeholder="填写自定义分类"
bind:showMenu="showMenu3" bind:close="closeMenu3" bind:select="select3"></graceSelectMenu>
</view>
</view>
</view>
</gracePage>.json
{
"usingComponents": {
"gracePage": "../../graceUI/components/gracePage",
"graceSelectMenu": "../../graceUI/components/graceSelectMenu"
}
}.js
Page({
data: {
// 第1个菜单
show1: false,
selectMenu1: ['全部分类', '精选优品', '价格较低', '只买贵的', '其他方式'],
// 第2个菜单
show2: false,
selectMenu2: ['学历', '大专', '本科', '硕士', '博士'],
selectIndex2: 0,
// 第 3 个菜单
show3 : false,
selectMenu3 : ['全部语言', 'php', 'java', 'c#', 'nodejs'],
selectIndex3 : 0
},
onLoad : function () {
setTimeout(() => {
this.setData({selectIndex2 : 3});
}, 2000)
},
showMenu1: function () { this.setData({ show1: true }); },
closeMenu1: function () { this.setData({ show1: false }); },
select1: function (index) {
index = index.detail;
console.log("选择了 " + this.data.selectMenu1[index]);
},
showMenu2: function () { this.setData({ show2: true }); },
closeMenu2: function () { this.setData({ show2: false }); },
select2: function (index) {
index = index.detail;
console.log("选择了 " + this.data.selectMenu2[index]);
},
// 第三个菜单
// 客户自定义输入
submit : function (e) {
var len = this.data.selectMenu3.push(e.detail);
this.setData({selectMenu3 : this.data.selectMenu3, selectIndex3 : len - 1});
this.closeMenu3();
console.log("选择了 " + e.detail);
},
showMenu3 : function () {this.setData({ show3: true });},
closeMenu3 : function () {this.setData({ show3: false });},
select3 : function (index) {
index = index.detail;
console.log("选择了 " + this.data.selectMenu3[index]);
}
}).wxss
.graceSelectMenuItem{width:200rpx; line-height:90rpx; background:#F6F7F8;}