<template>
|
<view class="box">
|
<view class="box1" v-for="(item, index) in yyList" @click="gokeshi(item)" :key="index">
|
<img
|
:src="item.imgUrl || fallbackImg"
|
mode="scaleToFill"
|
alt=""
|
class="bgimg"
|
@error="handleImageError($event, index)"
|
@load="handleImageLoad($event, index)"
|
>
|
<view class="yuan">{{item.hospAreaName}}</view>
|
<view class="box2">
|
<div class="address">
|
<div class="img"></div>
|
<div class="txt">{{item.areaName}}</div>
|
</div>
|
<div class="address">
|
<div class="phone"></div>
|
<div class="txt">{{item.phone}}</div>
|
</div>
|
</view>
|
</view>
|
</view>
|
</template>
|
|
<script>
|
import { list } from "@/api/system/people.js";
|
|
export default {
|
data() {
|
return {
|
yyList: [],
|
canshu: '',
|
fallbackImg: '/static/images/pic1.png', // 默认本地图片
|
}
|
},
|
onLoad(options) {
|
this.getList();
|
if (options.id) {
|
this.canshu = options.canshu + "?" + "id=" + options.id;
|
} else {
|
this.canshu = options.canshu;
|
}
|
},
|
methods: {
|
getList() {
|
list().then(res => {
|
console.log(res, res.data)
|
// 为每项添加动态图片 URL
|
this.yyList = res.data.map(item => ({
|
...item,
|
imgUrl: item.code && typeof item.code === 'string' && item.code.trim()
|
? `http://47.109.86.30:5902/img/${item.code}.png`
|
: this.fallbackImg
|
}));
|
}).catch((err) => {
|
console.log(err);
|
});
|
},
|
gokeshi(item) {
|
console.log(item);
|
uni.setStorageSync('hospId', item.code); // 存储 hospId
|
uni.setStorageSync('hospName', item.hospName); // 存储医院名称
|
uni.navigateTo({
|
url: `/pages/login` //?code=${item.code} 传递 item.code
|
});
|
},
|
// 处理图片加载失败
|
handleImageError(event, index) {
|
this.$set(this.yyList, index, {
|
...this.yyList[index],
|
imgUrl: this.fallbackImg // 加载失败时切换到默认图片
|
});
|
},
|
// 处理图片加载成功
|
handleImageLoad(event, index) {
|
// 图片加载成功,无需额外操作
|
}
|
}
|
}
|
</script>
|
|
<style scoped lang="scss">
|
.box {
|
padding: 20rpx 20rpx 20rpx 24rpx;
|
}
|
|
.box1 {
|
width: 702rpx;
|
height: 348rpx;
|
background: linear-gradient(180deg, rgba(65, 159, 253, 0.9) 0%, rgba(33, 80, 127, 0.38) 100%);
|
border-radius: 12rpx 12rpx 12rpx 12rpx;
|
padding-top: 65rpx;
|
margin-bottom: 32rpx;
|
position: relative;
|
|
.yuan {
|
height: 44rpx;
|
font-weight: bold;
|
font-size: 44rpx;
|
color: #FFFFFF;
|
line-height: 62rpx;
|
text-align: center;
|
font-style: normal;
|
text-transform: none;
|
}
|
|
.bgimg {
|
width: 702rpx;
|
height: 348rpx;
|
position: absolute;
|
z-index: -1;
|
margin-top: -65rpx;
|
}
|
|
.box2 {
|
display: flex;
|
flex-direction: column;
|
position: absolute;
|
bottom: 27rpx;
|
|
.address {
|
display: flex;
|
padding: 0 100rpx 0 35rpx;
|
|
.img {
|
width: 32rpx;
|
height: 32rpx;
|
background-image: url("/static/images/address.png");
|
background-size: 100% 100%;
|
background-position: center center;
|
background-repeat: no-repeat;
|
flex: 0 0 auto;
|
margin-top: 4rpx;
|
margin-right: 12rpx;
|
color: white;
|
}
|
|
.phone {
|
width: 32rpx;
|
height: 32rpx;
|
background-size: 100% 100%;
|
background-position: center center;
|
background-repeat: no-repeat;
|
flex: 0 0 auto;
|
margin-top: 4rpx;
|
margin-right: 12rpx;
|
background-image: url("/static/images/phone.png");
|
}
|
|
.txt {
|
font-family: Source Han Sans CN, Source Han Sans CN;
|
font-size: 28rpx;
|
color: #FFFFFF;
|
line-height: 44rpx;
|
text-align: left;
|
font-style: normal;
|
text-transform: none;
|
display: -webkit-box;
|
-webkit-box-orient: vertical;
|
-webkit-line-clamp: 2;
|
overflow: hidden;
|
text-overflow: ellipsis;
|
}
|
}
|
}
|
}
|
</style>
|