FenXiNspUniapp/pages/index/index.vue

703 lines
17 KiB
Vue

<template>
<view class="container">
<uni-nav-bar :fixed="true" leftWidth="00rpx" rightWidth="0rpx" background-color="transparent" status-bar title="武乡县农业面源污染在线监测小程序" />
<image src="../../static/home_top_bg.png" mode="" class="bgimg"></image>
<scroll-view class="content" scroll-y="true" :style="{height:contentheight + 'rpx'}">
<view class="top_address">
<view class="address_left" v-if="city">
<image src="../../static/home_icon_dingwei.png" mode=""></image>
<view class="left_shi">
{{ city }}
</view>
</view>
<view class="address_right" v-if="weather">
<view class="right_tq">
{{ weather }}
</view>
<image :src="weatherimg" mode=""></image>
</view>
</view>
<!-- 顶部banner轮播图 -->
<view class="pic">
<swiper class="pics" circular :indicator-dots="true" indicator-color="rgba(199, 199, 199, 0.3)"
indicator-active-color="rgba(197, 197, 197, 1)" :autoplay="autoplay" interval="3000"
:duration="duration">
<swiper-item class="swiper_items" v-for="(item,index) in bigswiperList" :key="index">
<image class="siwper_imgs" :src="baseUrl + '/applet/common/static/' + item.detailPics" mode="" @click="banlick(index)">
</image>
</swiper-item>
</swiper>
</view>
<view class="jgg">
<uni-grid :column="4" class="uni-grid" :showBorder="false" :highlight="false">
<uni-grid-item class="uni-grid-item" v-for="(item,index) in menuList" :key="index">
<view class="grid-item-box" @click="toList(item,index)">
<image :src="item.img" mode=""></image>
<text class="text" v-if="item.name">{{ item.name }}</text>
<view class="numberbj" v-if="index == 1 && bjnumber">
{{ cutMoneyFiter(bjnumber) }}
</view>
</view>
</uni-grid-item>
</uni-grid>
</view>
<view class="bottom_box">
<view class="bottom_top">
<view class="bottom_left">
<image src="../../static/home_title_img.png" mode=""></image>
</view>
<view class="bottom_right">
累计
<span class="num">{{ cutMoneyFiter(numbers) }}</span>
</view>
</view>
<view class="line"></view>
<swiper class="liebiao" next-margin="570rpx" :vertical="true" circular :autoplay="autoplay"
:indicator-dots="false" interval="3000" :duration="duration">
<swiper-item class="item" v-for="(item,index) in list" :key="index" @click="todetail(item,index)">
<view class="topline" :class="{'toplines':index == 0}"></view>
<view class="List">
<image class="imgs" src="../../static/home_img_zhuangshi_yuan.png" mode=""></image>
<view class="list_left">
<image src="../../static/home_zhuangshi_img.png" mode=""></image>
</view>
<view class="list_right">
<view class="list_right_top">
<view class="rit_top_lef" v-if="item.stationName">
{{ item.stationName }}
</view>
<view class="rit_top_rig" v-if="item.times">
{{ item.times[1] }}
</view>
</view>
<view class="list_right_bot">
<block>
<view class="bot_lef" :style="{background:item.color}">
{{ item.name }}
</view>
</block>
<view class="bot_mid">
<view class="bot_mid_left"
:class="{'bot_mid_lefts':item.type == 2 || item.type == 0}">
{{ item.value }}{{ item.unit }}
</view>
<!-- <image v-if="item.type == 1" src="../../static/home_shuju_shang.png" mode=""></image>
<image v-if="item.type == 2" src="../../static/home_shuju_xia.png" mode=""></image>
<view v-if="item.type == 0" class="" style="width: 42rpx;"> </view> -->
</view>
<view class="bot_rig" v-if="item.times">
{{ item.times[0] }}
</view>
</view>
</view>
</view>
</swiper-item>
</swiper>
</view>
<view class="pagebot"></view>
</scroll-view>
</view>
</template>
<script>
import api from "@/api/api"
import configService from '@/common/service/config.service.js';
import indexData from './indexData';
//高德SDKjs
// import amap from '@/common/amap-wx.130.js'; //自己js的所在的位置
export default {
data() {
return {
contentheight: 0,
pageheight: 0,
height: 0,
indicatorDots: true,
autoplay: true,
interval: 2000,
baseUrl: configService.apiUrl,
duration: 500,
pagelogin: '',
city: '',
numbers: 0,
wrwlist: [],
wrwcode: [],
colorList: ['#22BB8A', '#EE701C', '#52AC2A', '#2BADB9', '#D75A28', '#AD8F49', '#26A3CC', '#6C48C7',
'#22BB8A', '#415FBE', '#52AC2A', '#EE701C'
],
colorList1: ['#22BB8A', '#EE701C', '#52AC2A', '#2BADB9', '#D75A28', '#AD8F49', '#26A3CC', '#6C48C7',
'#22BB8A'
],
bigswiperList: [
// {
// img:require('../../static/banner1.png')
// },
// {
// img:require('../../static/banner.jpg')
// }
],
menuList: indexData.menu,
list: [],
weather: '',
weatherimg: '',
bjnumber: '',
lastClickTime: 0,
throttleDelay: 1000 // 节流时间1秒
}
},
onLoad() {
// this.wrwlist = uni.getStorageSync('wrwlist')
uni.getSystemInfo({
success: res => {
console.log("getSystemInfo", res)
var pxToRpxScale = 750 / res.windowWidth
var ktxStatusHeight = res.statusBarHeight * pxToRpxScale
var navigationHeight = 44 * pxToRpxScale
this.height = res.windowHeight * pxToRpxScale //将px 转换rpx
this.contentheight = this.height - ktxStatusHeight - navigationHeight
this.pageheight = this.height - ktxStatusHeight - navigationHeight - 98
}
});
// var QQMapWX = require('@/static/qqmap-wx-jssdk.min.js');
var amapFile = require('@/common/amap-wx.130.js')
// 实例化API核心类
// var qqmapsdk = new QQMapWX({
// key: 'WVDBZ-FGPRZ-JQMXB-ZIGM3-YADQV-NSF44' // 必填
// });
var myAmapFun = new amapFile.AMapWX({key: 'e1dc41b2d5363e7768023cdb6aaddb01'});
var that = this
myAmapFun.getWeather({
type: 'live',
success: function(data) {
that.weather = data.temperature.data + '℃'
that.city = data.liveData.city;
var twtype = data.weather.data
if (twtype.indexOf('云') != -1) {
that.weatherimg = '/static/tianqi_icon_duoyun.png'
} else if (twtype == '晴') {
that.weatherimg = '/static/tianqi_icon_qingtian.png'
} else if (twtype == '小雨') {
that.weatherimg = '/static/tianqi_icon_xiaoyu.png'
} else if (twtype == '阴') {
that.weatherimg = '/static/tianqi_icon_yintian.png'
} else if (twtype == '中雨') {
that.weatherimg = '/static/tianqi_icon_zhongyu.png'
} else if (twtype == '大雨') {
that.weatherimg = '/static/tianqi_icon_dayu.png'
} else if (twtype == '雷阵雨') {
that.weatherimg = '/static/tianqi_icon_leizhengyu.png'
} else if (twtype.indexOf('雪') != -1) {
that.weatherimg = '/static/tianqi_icon_xuetian.png'
} else if (twtype.indexOf('暴雨') != -1) {
that.weatherimg = '/static/tianqi_icon_dayu.png'
} else if (twtype.indexOf('阵雨') != -1) {
that.weatherimg = '/static/tianqi_icon_dayu.png'
} else if (twtype.indexOf('雨') != -1) {
that.weatherimg = '/static/tianqi_icon_zhongyu.png'
} else if (twtype.indexOf('雷') != -1) {
that.weatherimg = '/static/tianqi_icon_leizhengyu.png'
} else if (twtype.indexOf('雾') != -1) {
that.weatherimg = '/static/tianqi_icon_wu.png'
} else if (twtype.indexOf('霾') != -1) {
that.weatherimg = '/static/tianqi_icon_wu.png'
} else if (twtype.indexOf('风') != -1) {
that.weatherimg = '/static/tianqi_icon_duoyun.png'
} else if (twtype.indexOf('沙') != -1 || twtype.indexOf('尘') != -1) {
that.weatherimg = '/static/tianqi_icon_duoyun.png'
}
},
fail: function(info) {
//失败回调
console.log(info)
},
complete: function(resa) {
console.log(resa)
}
})
},
onShow() {
var that = this
api.checkLogin(() => {
that.getzdInfo()
that.getsssj()
that.getnumber()
that.getpicinfo()
}, () => {
that.bigswiperList = indexData.bigswiperList;
that.wrwlist = indexData.wrwlist;
that.list = indexData.list;
if (that.list) {
for (var i = 0; i < that.list.length; i++) {
that.list[i].wrwcode = []
for (var j = 0; j < that.wrwlist.length; j++) {
// Object.keys 获取字段名
for (var k = 0; k < Object.keys(that.list[i]).length; k++) {
if (that.wrwlist[j].code == Object.keys(that.list[
i])[k]) {
this.list[i].wrwcode.push({
name: that.wrwlist[j].description,
icon: that.wrwlist[j].icon,
unit: that.wrwlist[j].unit,
color: that.wrwlist[j].color,
code: that.wrwlist[j].code
})
}
}
}
if (that.list[i].dataDateTime) {
that.list[i].times = null
}
}
that.numbers = that.list[0].dataCounts
}
})
},
methods: {
isAathorize(url) {
var that = this
api.checkLogin(()=>{
uni.navigateTo({
url: url
})
}, () => {
uni.reLaunch({
url: '/packDetail/pages/login/login'
})
});
},
onstoptouchmove() {
return false;
},
todetail(item, index) {
const now = Date.now();
// 如果距离上次点击时间小于节流时间,则忽略此次点击
if (now - this.lastClickTime < this.throttleDelay) {
return;
}
// 更新最后点击时间
this.lastClickTime = now;
// 执行原逻辑
this.isAathorize('/packDetail/pages/Site/detail?item=' + encodeURIComponent(JSON.stringify(item)));
},
tologin() {
uni.reLaunch({
url: '/packDetail/pages/login/login'
})
},
getzdInfo() {
this.$http.get('/applet/wxclient/getPollutionDict').then(res => {
this.wrwlist = res.data.data
uni.setStorageSync('wrwlist', res.data.data)
})
},
getpicinfo() {
var infoType = 'applet_roll'
this.$http.post('/applet/wxclient/displayInfo?infoType=' + infoType).then(res => {
if(res.data.data){this.bigswiperList = res.data.data.effect_assess.detailList}
})
},
getnumber() {
this.$http.get('/applet/survPestlightAlert/getLightAlertCount').then(res => {
if(res.data.data){this.bjnumber = res.data.data.alertCount}
})
},
getsssj() {
this.$http.post('/applet/wxclient/getNewestData').then(res => {
this.list = res.data.data
if (this.list && this.list.length > 0) {
for (var i = 0; i < this.list.length; i++) {
this.list[i].wrwcode = []
for (var j = 0; j < this.wrwlist.length; j++) {
// Object.keys 获取字段名
for (var k = 0; k < Object.keys(this.list[i]).length; k++) {
if (this.wrwlist[j].code == Object.keys(this.list[i])[k]) {
this.list[i].wrwcode.push({
name: this.wrwlist[j].description,
icon: this.wrwlist[j].icon,
unit: this.wrwlist[j].unit,
color: this.wrwlist[j].color,
code: this.wrwlist[j].code
})
}
}
}
if (this.list[i].dataDateTime) {
this.list[i].times = this.list[i].dataDateTime.split(" ")
}
}
this.numbers = this.list[0].dataCounts
}
})
},
toList(item, index) {
this.isAathorize(item.path)
},
// banner跳转
banlick(index){
if (index==0) {
uni.navigateTo({
url: '/packDetail/pages/vidio/soilindex'
})
} else {
uni.navigateTo({
url: '/packDetail/pages/Site/index'
})
}
}
}
}
</script>
<style lang="scss">
page {
background-color: #F4F5F9;
height: 100%;
}
.container {
height: 100%;
}
.uni-nav-bar {
background-color: transparent;
border-color: transparent;
height: 44px;
}
.uni-nav-bar-text {
font-size: 32rpx !important;
font-family: Source Han Sans SC;
font-weight: bold;
color: #FFFFFF !important;
}
.uni-nav-bar__left,
.uni-nav-bar__right {
color: #FFFFFF;
}
.uni-navbar__content {
border: 0 none !important;
}
.bgimg {
position: fixed;
top: 0;
left: 0;
width: 100%;
z-index: -99;
}
.content {
padding: 0 29rpx;
box-sizing: border-box;
}
.top_address {
display: flex;
justify-content: space-between;
margin-bottom: 30rpx;
}
.address_left {
display: flex;
align-items: center;
}
.address_left image {
width: 32rpx;
height: 32rpx;
margin-right: 6rpx;
}
.left_shi {
font-size: 28rpx;
font-family: Source Han Sans SC;
color: #FFFFFF;
}
.address_right {
font-size: 28rpx;
font-family: Source Han Sans SC;
color: #FFFFFF;
display: flex;
align-items: center;
}
.address_right image {
width: 38rpx;
height: 38rpx;
margin-left: 14rpx;
}
.pic {
width: 100%;
height: 342rpx;
background: #DFE6E8;
background: rgba(223, 230, 232, 0.4);
border-radius: 28rpx;
overflow: hidden;
transform: translateY(0);
}
.pics {
width: 100%;
height: 100%;
overflow: hidden;
border-radius: 28rpx;
transform: translateY(0);
}
.swiper_items image {
width: 100%;
height: 100%;
border-radius: 28rpx;
}
.jgg {
background: #FFFFFF;
border-radius: 36rpx;
margin-top: 40rpx;
padding: 37rpx 20rpx;
padding-bottom: 0;
box-sizing: border-box;
margin-bottom: 32rpx;
}
.uni-grid-item {
height: 200rpx;
}
.uni-grid-item image {
width: 124rpx;
height: 124rpx;
}
.text {
font-size: 24rpx;
font-family: Source Han Sans SC;
font-weight: 400;
color: #333333;
margin-top: 14rpx;
}
.grid-item-box {
flex: 1;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
position: relative;
}
.numberbj {
height: 40rpx;
min-width: 40rpx;
padding: 0 12rpx;
background-color: red;
border: 2rpx solid #fff;
border-radius: 40rpx;
z-index: 99;
position: absolute;
color: #fff;
font-size: 20rpx;
line-height: 40rpx;
text-align: center;
top: -5rpx;
right: 5rpx;
}
.grid-item-box-row {
flex: 1;
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
}
.grid-dot {
position: absolute;
top: 5px;
right: 15px;
}
.bottom_box {
background: #FFFFFF;
border-radius: 36rpx;
padding: 0 30rpx;
box-sizing: border-box;
padding-bottom: 28rpx;
}
.bottom_top {
height: 94rpx;
display: flex;
justify-content: space-between;
align-items: center;
}
.bottom_left image {
width: 358rpx;
height: 32rpx;
}
.bottom_right {
font-size: 24rpx;
font-family: Source Han Sans SC;
color: #B3C1D1;
}
.num {
font-size: 34rpx;
font-family: DIN Next LT Pro;
color: #2AC166;
margin: 0 9rpx;
}
.line {
height: 2rpx;
background: #EBF2FB;
}
.topline {
margin-left: 24rpx;
height: 24rpx;
border-left: 1rpx solid #EBF2FB;
}
.List {
margin-left: 24rpx;
box-sizing: border-box;
border-left: 1rpx solid #EBF2FB;
position: relative;
display: flex;
align-items: center;
padding-left: 20rpx;
height: 120rpx;
}
.imgs {
width: 37rpx;
height: 37rpx;
position: absolute;
top: 44%;
left: -20rpx;
transform: translateY(-44%);
}
.list_left {
height: 100%;
}
.list_left image {
width: 13rpx;
height: 100%;
}
.list_right {
height: 100%;
background-color: #F6F6F6;
border-radius: 0rpx 12rpx 12rpx 0rpx;
padding-left: 24rpx;
padding-right: 24rpx;
width: 100%;
padding-top: 6rpx;
display: flex;
flex-direction: column;
justify-content: space-between;
padding-bottom: 18rpx;
}
.list_right_top {
display: flex;
justify-content: space-between;
}
.rit_top_lef {
font-size: 28rpx;
font-family: Source Han Sans SC;
color: #333333;
width: 85%;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.rit_top_rig {
font-size: 25rpx;
font-family: DIN Next LT Pro;
font-weight: 400;
color: #999999;
}
.list_right_bot {
display: flex;
align-items: center;
justify-content: space-between;
}
.bot_lef {
padding: 6rpx 22rpx 6rpx 21rpx;
// background: #22BB8A;
border-radius: 4rpx;
font-size: 24rpx;
font-family: Source Han Sans SC;
color: #FFFFFF;
}
.bot_mid {
display: flex;
align-items: center;
flex: 1;
justify-content: flex-end;
}
.bot_mid_left {
font-size: 28rpx;
font-family: DIN Next LT Pro;
font-weight: 400;
color: #FF4242;
}
.bot_mid_lefts {
color: #2FCD81;
}
.gg {
font-size: 24rpx;
font-family: DIN Next LT Pro;
font-weight: 500;
color: #308DFF;
margin-left: 10rpx;
}
.bot_mid image {
width: 32rpx;
height: 32rpx;
margin-left: 10rpx;
}
.bot_rig {
font-size: 25rpx;
font-family: DIN Next LT Pro;
font-weight: 400;
color: #999999;
margin-left: 39rpx;
}
.toplines {
border: none;
}
.pagebot {
height: 59rpx;
}
.liebiao {
height: 713rpx;
}
</style>