<template>
	<view style="background-color: #FFFFFF;height: 100vh;" class="u-skeleton">
		<view class="status_bar">
			<!-- 这里是状态栏 -->
		</view>
		<view class="u-page" style="margin-bottom: 20rpx;">
			<view class="u-m-t-20">
				<u-swiper :list="bannersList" :height="310" :effect3d="true" border-radius="20" effect3d-previous-margin="20"
				 bg-color="#FFF" class="u-skeleton-fillet" v-if="bannersList.length!=0"></u-swiper>
				<u-swiper :list="list" :height="310" :effect3d="true" border-radius="20" effect3d-previous-margin="20" bg-color="#FFF"
				 class="u-skeleton-fillet" v-else></u-swiper>
			</view>
			<view class="u-flex u-m-t-20  u-m-l-20 u-m-r-20 u-skeleton-fillet" style="width:710rpx;">
				<!-- <view class="u-flex u-row-center" style="width: 150rpx; height: 70rpx;border-radius: 50rpx;background: rgba(52,140,245,0.1);font-size: 20rpx;color: #348CF5; font-size: 500;">
					<u-image width="45rpx" height="35rpx" src="../../static/sailun/speaker.png" style="margin:10rpx;"></u-image>公告
					<u-notice-bar mode="horizontal" :list="noticebarList" :volume-icon="false" bg-color="#FFF" color="#2B2B2B" padding="18rpx 12rpx" :is-circular="false"></u-notice-bar> -->
				<u-notice-bar mode="vertical" :list="noticebarList" style="width: 710rpx;" type="primary"></u-notice-bar>
			</view>
			<view class="u-flex u-m-t-20 u-row-around u-m-l-10 u-m-r-10">
				<u-image width="350rpx" src="../../static/sailun/scan_in.png" @tap="$u.throttle(inPage(0), 1000)" mode="widthFix"
				 class="u-skeleton-fillet"></u-image>
				<u-image width="350rpx" src="../../static/sailun/scan_out.png" @tap="$u.throttle(inPage(1), 1000)" mode="widthFix"
				 class="u-skeleton-fillet"></u-image>
			</view>
			<view class="u-m-t-20">
				<view class="u-m-l-30" style="font-size: 34rpx;">
					快捷服务
				</view>
				<view class="u-flex u-flex-wrap u-row-center">
					<u-image class="u-skeleton-fillet" width="350rpx" height="212rpx" src="../../static/sailun/task.png" style="margin: 10rpx;box-shadow:0rpx 0rpx 20rpx rgba(0,0,0,0.2);border-radius: 30rpx;"
					 @click="inPage(5)"></u-image>
					<u-image class="u-skeleton-fillet" width="350rpx" height="212rpx" src="../../static/sailun/2.png" style="margin: 10rpx;box-shadow:0rpx 0rpx 20rpx rgba(0,0,0,0.2);border-radius: 30rpx;"
					 @click="inPage(3)"></u-image>
					<u-image class="u-skeleton-fillet" width="350rpx" height="212rpx" src="../../static/sailun/inquire.png" style="margin: 10rpx;box-shadow:0rpx 0rpx 20rpx rgba(0,0,0,0.2);border-radius: 30rpx;"
					 @click="inPage(4)"></u-image>
					<u-image class="u-skeleton-fillet" width="350rpx" height="212rpx" src="../../static/sailun/1.png" style="margin: 10rpx;box-shadow:0rpx 0rpx 20rpx rgba(0,0,0,0.2);border-radius: 30rpx;"
					 @click="inPage(2)"></u-image>
				</view>
			</view>
			<view class="u-flex u-row-center u-m-t-30">
				<u-image class="u-skeleton-fillet" width="680rpx" src="../../static/sailun/88reward.png" mode="widthFix"></u-image>
			</view>
		</view>
		<!-- 与包裹页面所有内容的元素u-page同级，且在它的下方 -->
		<!-- <u-tabbar v-model="current" :list="list"></u-tabbar> -->
		<u-skeleton :loading="loading" :animation="true"></u-skeleton>
		<u-toast ref="ulogin" />
		<luo-version-upgrade v-if="show_s == true" version="1.0.1" :url="url" :is_force="is_force" :describe="Copywriting"></luo-version-upgrade>
	</view>
</template>

<script>
	import versionUpgrade from "../../components/luo-version-upgrade/luo-version-upgrade.vue";
	import {
		mapState,
		mapMutations
	} from 'vuex'
	import {
		request
	} from '../../common/request/request'
	require("promise.prototype.finally").shim()
	import axios from 'axios'
	export default {
		components: {
			versionUpgrade
		},
		data() {
			return {
				bannersList: [],
				noticebarList: [],
				loading: true, // 是否显示骨架屏组件
				list: [
					'../../static/sailun/swiper1.png'
				],
				show_s: false,
				url: '',
				is_force: false,
				Copywriting: '',
			}
		},
		onLoad() {
			uni.$on('login', (data) => {
				this.loginStatus = data.msg
			})
		},
		onReady() {
			if (this.loginStatus == "登录成功") {
				this.$refs.ulogin.show({
					title: "登录成功",
				})
			}
		},
		created() {
			if (this.hasLogin) {
				uni.showLoading({
					title: '加载中...'
				});
				axios.all([this.getBanners(), this.getTiceList()])
					.then(axios.spread((one, two) => {
						this.bannersList = one.data.data.map(t => t.imgPath)
						this.noticebarList = two.data.data.map(t => t.msgContent)
					}))
					.catch(err => {

					})
					.finally(() => {
						this.loading = false;
						uni.hideLoading();
					})
			}
		},
		onShow() {
			this.system()
		},
		computed: {
			...mapState(['hasLogin'])
		},
		methods: {
			system() {
				uni.getSystemInfo({
					success: res => {
						// 
					},
					complete: err => {
						if (err.platform == 'android') {
							this.onLaunch_s()
						} else if (err.platform == 'ios') {
							// 
							this.iosstartup()
						}
					}
				});
			},
			iosstartup() {
				request({
						url: '/baseReq/apkUpgrade',
						method: 'get',
						params: {
							osType: 1
						}
					}).then(res => {
						// 
						// 
						//  //最低版本
						//  //更新文案
						//  //最新版本

						plus.runtime.getProperty(plus.runtime.appid, (wgtinfo) => {
							// 
							//版本号
							if (wgtinfo.version == res.data.version) {
								this.show_s = true
								// uni.showToast({
								// 	icon: 'none',
								// 	title: '已是最新版本',
								// 	position: "bottom"
								// })
								// 
							} else if (wgtinfo.version != res.data.forceVersion) {
								// 
								res.data.msg = res.data.msg.replace(/\\n/g, "\n")
								uni.showModal({
									title: "发现新版本",
									content: res.data.msg,
									showCancel: false,
									confirmText: "立即去AppStore更新",
									success: function(res) {
										if (res.confirm) {
											// 
											let appleId = 1518555723
											plus.runtime.launchApplication({
												action: `itms-apps://itunes.apple.com/cn/app/id${appleId}?mt=8`
											}, function(e) {

											});
										} else if (res.cancel) {

										}
									}
								})
							} else if (wgtinfo.version == res.data.forceVersion) {

								res.data.msg = res.data.msg.replace(/\\n/g, "\n")
								uni.showModal({
									title: "发现新版本",
									content: res.data.msg,
									showCancel: true,
									confirmText: "立即去AppStore更新",
									success: function(res) {
										if (res.confirm) {

											let appleId = 1518555723
											plus.runtime.launchApplication({
												action: `itms-apps://itunes.apple.com/cn/app/id${appleId}?mt=8`
											}, function(e) {

											});
										} else if (res.cancel) {

										}
									}
								})
							}

						})

					}).catch(err => {

					})
					.finally(() => {
						// Loading.close()
					})
			},
			//升级调用的接口
			onLaunch_s() {
				request({
						url: '/baseReq/apkUpgrade',
						method: 'get',
						params: {
							osType: 0
						}
					}).then(res => {

						//最低版本
						//更新文案
						//下载最新版地址
						//最新版本

						plus.runtime.getProperty(plus.runtime.appid, (wgtinfo) => {

							//版本号
							if (wgtinfo.version == res.data.version) {
								this.show_s = false
								// uni.showToast({
								// 	icon: 'none',
								// 	title: '已是最新版本',
								// 	position: "bottom"
								// })

							} else if (wgtinfo.version != res.data.forceVersion) {

								this.Copywriting = res.data.msg

								this.show_s = true

								this.url = res.data.url
								this.is_force = true
							} else if (wgtinfo.version == res.data.forceVersion) {

								this.Copywriting = res.data.msg


								this.is_force = false
								this.show_s = true
								this.url = res.data.url
							}

						})

					}).catch(err => {

					})
					.finally(() => {
						// Loading.close()
					})
			},
			//轮播图
			getBanners() {
				return request({
					url: '/homepage/getBanners',
					method: 'post',
					data: {
						"storeId": this.$store.state.storeInfo.storeId,
						"showPosition": 0, //门店0
					}
				})
			},
			//消息文字跑马灯
			getTiceList() {
				return request({
					url: '/homepage/noticeList',
					method: 'post',
					data: {
						"storeId": this.$store.state.storeInfo.storeId,
						"contentType": "1" //门店1
					}
				})
			},
			inPage(index) {
				switch (index) {
					case 0:
						{
							this.$u.route({
								url: 'pages/home/scancode/index',
							})
							break;
						}
					case 1:
						{
							this.$u.route({
								url: 'pages/home/scancode/scancodeout',
							})
							break;
						}
					case 2:
						{
							this.$u.route({
								url: 'pages/home/my-stock/my-stock',
							})
							break;
						}
					case 3:
						{
							this.$u.route({
								url: 'pages/home/monthly-policy/monthly-policy',
							})
							break;
						}
					case 4:
						{
							this.$u.route({
								url: 'pages/home/scancodequery/result',
							})
							break;
						}
					case 5:
						{
							this.$u.route({
								url: 'pages/home/Statistical-task/index',
							})
							break;
						}
				}
			},
			inInlineshop() {
				this.$u.toast('线上订货暂不开放');
				// this.$u.route({
				// 	url: 'pages/home/inline-shop/inline_shop',
				// })
			},
			inIntegral() {
				this.$u.toast('积分商城暂不开放');
				// this.$u.route({
				// 	url: 'pages/home/integral-mall/integral_mall',
				// })
			}
		},
	}
</script>

<style lang="scss" scoped>
	.status_bar {
		height: var(--status-bar-height);
		width: 100%;
		background-color: #FFF;
	}
</style>
