修改心身量表选择城市的展现形式
This commit is contained in:
@@ -8,11 +8,7 @@
|
||||
<view class="scale_des"><text style="font-weight: bold;">题目数量:</text>{{data.num}}</view>
|
||||
<view class="scale_des"><text style="font-weight: bold;">测试说明:</text>{{data.tip}}</view>
|
||||
</view>
|
||||
|
||||
<!-- Picker 组件 -->
|
||||
<picker mode="multiSelector" :range="multiArray" @change="bindMultiPickerChange" @columnchange="bindMultiPickerColumnChange">
|
||||
<u-button class="scale_btn">进入测试</u-button>
|
||||
</picker>
|
||||
<u-button class="scale_btn" @click="startTest">进入测试</u-button>
|
||||
</view>
|
||||
<view class="scale_block" v-show="status==1">
|
||||
<view class="test_block">
|
||||
@@ -29,7 +25,7 @@
|
||||
<text class="result_title">{{data.title}}-测试结果</text>
|
||||
<text class="result_total">{{resultTotal}}分</text>
|
||||
<text class="result_content">{{resultContent}}</text>
|
||||
<u-button class="result_btn" @click="back">回到首页</u-button>
|
||||
<u-button class="result_btn" @click="back">回到测试页</u-button>
|
||||
|
||||
<view class="result_border">
|
||||
<text class="result_con">结果解释:</text>
|
||||
@@ -74,117 +70,13 @@ export default {
|
||||
name: item,
|
||||
value: index+1
|
||||
}));
|
||||
this.getCityList();
|
||||
this.getTestData();
|
||||
//radioHeight
|
||||
this.radioHeight = this.checkList.length*42 +20;
|
||||
},
|
||||
methods: {
|
||||
//获取国家-一级
|
||||
getCountryList() {
|
||||
$http.request({
|
||||
url: "common/baseArea/getAllBaseArea",
|
||||
method: "POST",
|
||||
data: {},
|
||||
header: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
})
|
||||
.then(res => {
|
||||
if (res.code == 0) {
|
||||
this.countries = res.baseAreas;
|
||||
this.countries.forEach((country, index)=>{
|
||||
if(country.code=='86'){
|
||||
this.countries[index].cities = this.cityList;
|
||||
}
|
||||
})
|
||||
|
||||
//初始化 picker 数据
|
||||
this.initPickerData();
|
||||
}
|
||||
}).catch(e => {
|
||||
|
||||
});
|
||||
},
|
||||
//获取城市-二级
|
||||
getCityList() {
|
||||
$http.request({
|
||||
url: "common/province/getProvinceList",
|
||||
method: "POST",
|
||||
data: {},
|
||||
header: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
})
|
||||
.then(res => {
|
||||
if (res.code == 0) {
|
||||
const newCityList = res.provinceList.map( city => {
|
||||
return city.provName;
|
||||
});
|
||||
this.cityList = newCityList;
|
||||
this.getCountryList();
|
||||
}
|
||||
}).catch(e => {
|
||||
|
||||
});
|
||||
},
|
||||
//展示城市数据
|
||||
initPickerData() {
|
||||
//第一列是国家名
|
||||
const countryNames = this.countries.map(item => item.title);
|
||||
this.multiArray[0] = countryNames;
|
||||
//默认选择中国,并加载其省份
|
||||
if (this.countries[0].cities) {
|
||||
this.multiArray[1] = Object.keys(this.countries[0].cities).map(key => this.countries[0].cities[key]);
|
||||
} else {
|
||||
this.multiArray[1] = [];
|
||||
}
|
||||
},
|
||||
//picker修改值
|
||||
bindMultiPickerChange(e) {
|
||||
this.value = e.detail.value;
|
||||
this.updateCurrentSelection();
|
||||
},
|
||||
//修改动作
|
||||
bindMultiPickerColumnChange(e) {
|
||||
let data = {
|
||||
multiArray: this.multiArray,
|
||||
value: this.value
|
||||
};
|
||||
|
||||
if (e.detail.column === 0) {
|
||||
// 如果是第一列(国家)改变了,则需要更新第二列(城市)
|
||||
const selectedCountry = this.countries[e.detail.value];
|
||||
if (selectedCountry.cities) {
|
||||
// 如果选择了中国,加载省份
|
||||
data.multiArray[1] = Object.keys(selectedCountry.cities).map(key => selectedCountry.cities[key]);
|
||||
data.value = [e.detail.value, 0];
|
||||
} else {
|
||||
// 否则清空第二列
|
||||
data.multiArray[1] = [];
|
||||
data.value = [e.detail.value, 0];
|
||||
}
|
||||
}
|
||||
|
||||
this.multiArray = data.multiArray;
|
||||
this.value = data.value;
|
||||
//this.updateCurrentSelection();
|
||||
},
|
||||
updateCurrentSelection() {
|
||||
const countryIndex = this.value[0];
|
||||
this.countryIndex = countryIndex; //判断抑郁结果 标准的定义文字显示
|
||||
const cityIndex = this.value[1];
|
||||
const selectedCountry = this.multiArray[0][countryIndex];
|
||||
const selectedCity = this.multiArray[1][cityIndex];
|
||||
|
||||
this.selectedData = {
|
||||
country: selectedCountry
|
||||
}
|
||||
if(selectedCity){
|
||||
this.selectedData.city = selectedCity
|
||||
}else{
|
||||
this.selectedData.city = ''
|
||||
}
|
||||
//开始测试
|
||||
startTest(){
|
||||
//切换界面,进入测试
|
||||
this.status = 1;
|
||||
this.title = '开始测试题';
|
||||
@@ -265,10 +157,9 @@ export default {
|
||||
},
|
||||
//回到首页
|
||||
back(){
|
||||
uni.switchTab({
|
||||
url: '/pages/peanut/home'
|
||||
uni.navigateBack({
|
||||
delta: 1
|
||||
})
|
||||
uni.setStorageSync('fixed',true)
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -306,8 +197,8 @@ export default {
|
||||
padding: 5rpx 0;
|
||||
}
|
||||
.scale_btn{
|
||||
width: 500rpx;
|
||||
height: 70rpx;
|
||||
width: 80%;
|
||||
height: 85rpx;
|
||||
margin: 60rpx auto 0;
|
||||
color: #fff;
|
||||
font-size: 30rpx;
|
||||
|
||||
Reference in New Issue
Block a user