修改心身量表选择城市的展现形式

This commit is contained in:
liuyuan
2025-02-05 10:08:25 +08:00
parent b24119a549
commit 1cbc7f96cd
6 changed files with 224 additions and 132 deletions

View File

@@ -12,10 +12,10 @@
"src" : "图片路径"
}
],
"versionName" : "1.0.40",
"versionCode" : 1040,
"versionName" : "1.0.42",
"versionCode" : 1042,
"app-plus" : {
"nvueCompiler" : "weex",
"nvueCompiler" : "uni-app",
"compatible" : {
"ignoreVersion" : true
},

View File

@@ -3,6 +3,12 @@
// "^u-(.*)": "uview-ui/components/u-$1/u-$1.vue"
// },
"pages": [
{
"path": "pages/peanut/home",
"style": {
"navigationBarTitleText": "首页"
}
},
{
"path": "pages/user/login",
"style": {
@@ -10,12 +16,6 @@
"enablePullDownRefresh": false // 禁止下拉刷新
}
},
{
"path": "pages/peanut/home",
"style": {
"navigationBarTitleText": "首页"
}
},
{
"path": "pages/mine/vip/index",
"style": {

View File

@@ -2,7 +2,19 @@
<view class="courseWrap">
<!-- 公共组件-每个页面必须引入 -->
<public-module></public-module>
<z-nav-bar :title="pageTitle" @back='handleBack'><view class="curseSet" slot="right" @click="shuomingPage('/pages/course/courseSet',tagId,pid)"><uni-icons type="info" size="24"></uni-icons> 课程说明</view></z-nav-bar>
<z-nav-bar :title="pageTitle" @back='handleBack'>
<view class="curseSet" slot="right"
v-if="tagId!='71'"
@click="shuomingPage('/pages/course/courseSet',tagId,pid)">
<uni-icons type="info" size="24"></uni-icons> 课程说明
</view>
<view class="curseSet" slot="right" v-else>
<uni-icons type="location" size="18"></uni-icons>
<picker class="picker" mode="multiSelector" :range="multiArray" @change="bindMultiPickerChange" @columnchange="bindMultiPickerColumnChange">
<text @click="changeCountry">{{countryText}}</text>
</picker>
</view>
</z-nav-bar>
<view class="tabsBox" :class="[fixed ? 'fixed' : '' ]">
<u-tabs v-if="tabList.length > 0" :class="['tabList']" @click="fatherClick" :current="curTagId"
:activeStyle="activeStyle" :scrollable="scrollable" :list="tabList"
@@ -54,11 +66,13 @@
<text class="form_title">{{item.title}}</text>
<view class="form_solid">
<view class="form_des">{{item.des}}</view>
<u-button class="form_btn" @click="test(item)">进入测试</u-button>
<picker mode="multiSelector" :range="multiArray" @change="bindMultiPickerChange" @columnchange="bindMultiPickerColumnChange" v-show="countryText=='城市'">
<u-button class="form_btn">进入测试</u-button>
</picker>
<u-button v-show="countryText!='城市'" class="form_btn" @click="test(item)">进入测试</u-button>
</view>
</view>
<public-module></public-module>
<z-navigation></z-navigation>
</view>
</view>
@@ -104,7 +118,16 @@ export default {
page: 1,
flag: true, // 函数是否执行完
//心身量表
formList: []
formList: [],
//选择城市弹窗
cityList: [],
isPicker: false,
countries: [],
multiArray: [[], []],
value: [0, 0],
selectedData: {}, //城市
countryIndex: 0, //抑郁症文字区分国家展示
countryText: ''
};
},
//第一次加载
@@ -119,6 +142,20 @@ export default {
if(this.tagId=='71'){
this.getFormList();
}
//显示城市数据
this.getCityList();
let countryData = uni.getStorageSync('countryData');
let text= '';
if(countryData&&countryData.country){
text = countryData.country
if(countryData.city){
text = text + countryData.city
}
}else{
text= '城市';
}
this.countryText = text;
},
onPageScroll(e) {
this.scrollTop = e.scrollTop;
@@ -157,6 +194,119 @@ export default {
},
//方法
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.value[0]==0) { //如果默认显示的是第一个-中国,则显示城市列
this.multiArray[1] = Object.keys(this.countries[0].cities).map(key => this.countries[0].cities[key]);
} else {
this.multiArray[1] = [];
}
//强制更新视图
this.$set(this, 'multiArray', [...this.multiArray]);
},
//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.$set(this, 'multiArray', [...data.multiArray]);
this.value = data.value;
},
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
}
this.countryText = selectedCountry;
if(selectedCity){
this.selectedData.city = selectedCity;
this.countryText = selectedCountry + selectedCity;
}else{
this.selectedData.city = ''
}
uni.setStorageSync('countryData', this.selectedData)
},
//点击地理位置修改城市
changeCountry(){
this.initPickerData();
},
handleBack(){
uni.setStorageSync('fixed',true)
},
@@ -339,7 +489,7 @@ export default {
padding: 0 20rpx;
}
.curseSet{margin-right: 20rpx; font-size: 28rpx; display: flex; align-items: center;}
.curseSet{margin-right: 12rpx; font-size: 28rpx; display: flex; align-items: center;}
.fixed {
position: fixed;
z-index: 1; width: 100%; background-color: #fff;
@@ -514,4 +664,56 @@ export default {
background: #258feb;
border-radius: 10rpx;
}
.popup_mark{
width: 100%;
height: 100%;
background: #000;
opacity: 0.5;
position: fixed;
top: 0;
left: 0;
z-index: 99;
}
.popup_block{
width: 580rpx;
height: 360rpx;
position: fixed;
top: 50%;
left: 50%;
margin-top: -180rpx;
margin-left: -290rpx;
background: #fff;
z-index: 999;
border-radius: 5px;
}
.popup_title{
display: block;
height: 90rpx;
line-height: 90rpx;
font-size: 32rpx;
color: #333;
text-align: center;
border-bottom: 1rpx solid #f0f0f0;
}
.popup_con{
font-size: 28rpx;
padding-top: 50rpx;
text-align: center;
}
.popup_picker{
position: absolute;
bottom: 0;
width: 100%;
}
.scale_btn{
width: 100%;
height: 80rpx;
line-height: 80rpx;
color: #fff;
font-size: 28rpx;
background: #258feb;
border: none;
border-radius: 0 0 5px 5px;
}
</style>

View File

@@ -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;

View File

@@ -502,7 +502,6 @@
},
})
.then(async (res) => {
console.log("res at line 615:", res);
if (res.code == 0 && res.list && res.list.length > 0) {
this.advertisementList = res.list;

Binary file not shown.