<template>
	<view class="main">
		<navbar :config="config" backColor="#666"></navbar>
		<swiper class="swiper" :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000"
			circular=false>
			<swiper-item v-for="item in bannerList" :key="item.id">
				<view class="swiper-item" @click="
		        imgLink(item.model_type, item.model_id, item.url, item.shop_id)
		      ">
					<image class="cover" :src="item.cover" mode="aspectFill"></image>
				</view>
			</swiper-item>
		</swiper>
		<image @click="goToRegisterAndAudit()" class="settle" src="/static/entrepreneurshipZone/settle.png"></image>
		<view class="service-sys-moudle">
			<view class="title-box">服务体系</view>
			<view class="content">
				<view class="item" v-for="(item,index) in serviceListData" :key="index" @click="goServiceDetail(item)">
					<image class="cover" :src="item.cover" mode="aspectFill"></image>
					<view class="title">{{item.title}}</view>
					<view class="new-price">
						<text class="company">¥</text>
						<text class="num">{{formatPrice(item.min_sale_price,'int')}}.</text>
							<text class="float-num">{{formatPrice(item.min_sale_price,'float')}}</text>
						</view>
					<view class="old-price">¥ {{item.min_market_price}}</view>
				</view>
			</view>
		</view>
		<view class="project-list">
			<view class="list-title">
				创业政策
			</view>
			<view class="list">
				<view class="item" v-for="(item,index) in listData" :key="index" @click="policyDetail(item)">
					<image class="cover" mode="aspectFill" :src="item.thumbnail"></image>
					<view class="right">
						<view class="desc">
							{{item.header}}
						</view>
					</view>
				</view>
			</view>
		</view>
		<u-loadmore :status="loadStatus" />
	</view>
</template>

<script>
	export default{
		data(){
			return {
				config: {
					back: true,
					title: '创业专区',
					color: '#1a1a1a',
					backgroundColor: [1, '#fff'],
					statusBarFontColor: 'black'
				},
				bannerList: [],
				pageParams:{
					page: 1,
					limit: 10
				},
				listData: [],
				loadStatus: 'loadmore',//loading / nomore
				serviceListData: []
			}
		},
		onLoad() {
			this.getBanner();
			this.getList(true);
			this.getServiceList();
		},
		onPullDownRefresh() {
			this.getBanner();
			this.getList(true);
			this.getServiceList();
			uni.stopPullDownRefresh();
		},
		methods:{
			getBanner() {
				this.$http.get(`/ad/ad/getShopAdByAdL/0/entrepreneurshipzone-banner`, {}, false)
				.then((res) => {
					this.loading = false;
					if (res && res.code == 200) {
						this.bannerList = res.list;
					}
				})
			},
			/**
			 * @param {Object} type int或float
			 */
			formatPrice(price,type){
				let str = ''
				if(type=='int'){
					str = String(price).split('.')[0]
				}
				if(type=='float'){
					str = String(price).split('.').length <= 1?'00':(String(price).split('.')[1])
				}
				return str;
			},
			//跳转成为商家
			goToRegisterAndAudit(){
				let token = uni.getStorageSync("apiToken")
				if(!token){
					uni.navigateTo({
						url:"/pages/login/index"
					})
				}else{
					this.$http.get("/yxt/shopapply/shopApplyInfo").then(res=>{
						if(res&&res.code==200){
							if(res.data==null){
								uni.navigateTo({
									url: "/pages/user/merchant/registerAndAudit"
								})
							}else{
								uni.navigateTo({
									url:"/pages/user/merchant/audit"
								})
							}
						}
					})
				}
			},
			getList(isRefresh,needLoading = false) {
				let that = this;
				if (!isRefresh && this.loadStatus == 'nomore') {
					return false;
				}
				this.pageParams.page = isRefresh ? 1 : this.pageParams.page + 1;
				this.listData = isRefresh ? [] : this.listData;
				if(needLoading){
					uni.showLoading({
						title: '努力加载中...',
						mask: true
					});
				}
				this.loadStatus = 'loading';
				// this.$http.get('/workpolicy/list',this.pageParams)
				// .then(res=>{
				// 	if (res.code == 200) {
				// 		let listData = that.listData;
				// 		listData.push(...res.page.list);
				// 		that.listData = listData;
				// 		that.loadStatus = that.listData.length >= res.page.totalCount?'nomore':'loadmore';
				// 	}
				// })
				// .finally(()=>{
				// 	if(needLoading){
				// 		uni.hideLoading();
				// 	}
				// })
			},
			policyDetail(item){
				uni.navigateTo({
					url: '/pages/entrepreneurshipZone/policyDetail?id='+item.id
				})
			},
			getServiceList(){
				this.$http.get('/goodsareafeature/page',{
						page: 1,
						limit: 100,
						order_type: 1,
						order_mode: '',
						area_feature: 1
					})
				.then(res=>{
					if (res.code == 200) {
						this.serviceListData = res.page.list;
					}
				})
			},
			goServiceDetail(item){
				uni.navigateTo({
					url: `/pages/product/goods/goods?id=${item.goods_id}`
				})
			},
			/**轮播图跳转 */
			imgLink(type, id, url, shopid) {
				if (type == "goods") {
					uni.navigateTo({
						url: "/pages/product/goods/goods?id=" + id + "&shopid=" + shopid,
					});
				} else if (type == "service") {
					// uni.navigateTo({
					// 	url: "/pages/product/goods/serviceGood?id=" + id
					// });
				} else if (type == "point_goods") {
					// uni.navigateTo({
					// 	url: "/pages/product/goods/IntegralGood?id=" + id
					// });
				} else if (type == "url") {
					if(/^http/.test(url)){
						uni.navigateTo({
							url: "/pages/index/webView?linkUrl=" + url,
						});
					}else{
						uni.navigateTo({
							url
						});
					}
				}
			}
		},
		onReachBottom(){
			this.getList();
		}
	}
</script>

<style lang="scss" scoped>
	.main{
		padding-bottom: 30px;
		.swiper{
			height: 340rpx;
			width: 100%;
			.cover{
				height: 340rpx;
				width: 100%;
			}
		}
		.settle{
			height: 156rpx;
			width: 690rpx;
			margin: 50rpx 30rpx;
		}
		.project-list{
			width: 690rpx;
			margin: 0 auto 60rpx auto;
			background: #ffffff;
			border-radius: 16rpx;
			padding: 23rpx 20rpx 0 20rpx;
			box-sizing: border-box;
			filter: drop-shadow(1px 2px 4px rgba(26,58,70,0.1));
			.list-title{
				font-size: 36rpx;
				font-family: PingFang SC, PingFang SC-Bold;
				font-weight: 700;
				text-align: left;
				color: #1a1a1a;
				display: flex;
				justify-content: space-between;
				align-items: baseline;
				padding: 0 0 23rpx 10rpx;
				box-sizing: border-box;
				border-bottom: 1px solid #e6e6e6;
			}
			.list{
				padding: 15rpx 0;
				box-sizing: border-box;
				.item{
					padding: 45rpx 0;
					border-top: 1px solid #e6e6e6;
					&:nth-child(1){
						border-top: none;
					}
					.right{
						display: inline-block;
						.desc{
							font-size: 26rpx;
							font-family: PingFang SC, PingFang SC-Regular;
							font-weight: 400;
							text-align: left;
							color: #1A1A1A;
							line-height: 39rpx;
							margin-top: 15rpx;
							overflow: hidden;
							text-overflow: ellipsis;
							display: -webkit-box;
							-webkit-box-orient: vertical;
							-webkit-line-clamp: 3;
							word-break: break-word;
							width: 480rpx;
						}
					}
					.cover{
						width: 136rpx;
						height: 136rpx;
						background: rgba(0,0,0,0.00);
						border-radius: 10rpx;
						margin-right: 34rpx;
						vertical-align: top;
					}
				}
			}
		}
	}
</style>