<template>
	<view class="brief">
		<u-swiper
		height="530"
			:list="list"
			previousMargin="30"
			nextMargin="30"
			 :autoplay="false"
			 bgColor="#ffffff"
			@change="change"
			@click="click"
		></u-swiper>
	</view>
</template>

<script>
	import uSwiper from '@/uni_modules/uview-ui/components/u-swiper/u-swiper.vue'
	export default({
		components: {
			uSwiper
		},
		data() {
			return {
				list: [
					'https://xqg.zjhmit.com/xqg/handbook/brief1.jpg',
					'https://xqg.zjhmit.com/xqg/handbook/brief2.jpg',
					'https://xqg.zjhmit.com/xqg/handbook/brief3.jpg',
					'https://xqg.zjhmit.com/xqg/handbook/brief4.jpg',
				],
				downloadIng: false,
				bookList: [
					{
						title: '宁波象山县潮隐海山蟹钳港县域风貌区',
						src: '【形象手册】宁波象山县潮隐海山蟹钳港县域风貌区.pdf'
					},
					{
						title: '象山墙头-黄避岙“斑斓海岸”县域风貌区',
						src: '【宣传手册】象山墙头-黄避岙“斑斓海岸”县域风貌区.pdf'
					},
					{
						title: '象山县爵溪—石浦“东海扬帆”县域风貌区',
						src: '【宣传手册】象山县爵溪—石浦“东海扬帆”县域风貌区.pdf'
					},
					{
						title: '象山县石浦渔港古城传统风貌区',
						src: 'spyg.pdf'
					},
				]
			}
		},
		methods: {
			change() {
				
			},
			click(index) {
				if (index === 0) {
					uni.navigateTo({
						url: 'brief/xqg'
					})
				} else {
					let _this = this
					if (this.downloadIng) {
						return
					}
					uni.getSystemInfo({
						success: res => {
							if (res.platform === 'android') {
								_this.downloadIng = true
								uni.showLoading({
									title: '手册加载中，请稍后'
								})
								wx.downloadFile({
									url: 'https://xqg.zjhmit.com/xqg/handbook/' + _this.bookList[index].src,
									success: function(res) {
										_this.downloadIng = false
										uni.hideLoading()
										const filePath = res.tempFilePath;
										wx.openDocument({
											filePath: filePath,
											success: function(res) {
												console.log('打开文档成功');
											}
										});
									},
									fail: function(err) {
										uni.showToast({
											title: err
										})
									},
									complete() {
										_this.downloadIng = false
									}
								});
							} else {
								uni.navigateTo({
									url: '/pages/advertise-book/detail?src=' + _this.bookList[index].src
								})
							}
						}
					});
				}
			}
		}
	})
</script>

<style lang="scss" scoped>
	.brief{
		padding-top: 150rpx;
	}
</style>