<template>
	<view class="pad-x180">
		<!-- 状态栏 -->
		<status-nav :titleVal="'我的日记'" :statusTitle="true"></status-nav>
		<view :style="{paddingTop: statusHeight+'px'}" class="pad-zy30" style="padding-bottom: 160rpx;">
			<view v-if="dataList.length!=0" class="mar-s30 bacf pad20" v-for="(item,index) in dataList" :key="index" style="border-radius: 28rpx;">
				<view class="clips1">{{item.title}}</view>
				<view class="mar-s20 fon24 col9">{{item.content}}</view>
				<view class="disac fw mar-s20">
					<image lazy-load class="diary-img mar-x10" @tap="preImg(index,index1)" :src="item1" v-for="(item1,index1) in item.imgArr" :key="index1" mode="aspectFill"></image>
				</view>
				<view class="disjbac mar-s20">
					<view class="fon28 pcol bold">{{item.doctorName}}</view>
					<view class="fon24 col9">{{item.creatTime}}</view>
				</view>
				<view @tap="delDiaryEv(item.id,index)" class="disac mar-s20 pad-s20" style="border-top: 2rpx solid #E6E6E6;">
					<image src="../../static/public/del-diary.png" style="width: 20px;height: 20px;vertical-align: bottom;" mode=""></image>
					<view class="fon28 colf8 bold" style="margin-top: -4rpx;">删除</view>
				</view>
			</view>
			<nothing-page v-if="dataList.length==0" :content="'暂无日记'"></nothing-page>
		</view>
		<!-- 底部按钮 -->
		<view class="posixzy pad-sx25" style="bottom:140rpx;">
			<view @tap="goAddDiary" class="fon30 radius20 tc colf bold" style="margin: 0 83rpx;height: 90rpx;line-height: 90rpx;" :style="{background:publicColor}">添加日记</view>
		</view>
		<!-- 底部客服 -->
		<public-customer></public-customer>
		<!-- 用户信息授权，手机号授权 -->
		<auth-userInfo-mobileInfo></auth-userInfo-mobileInfo>
		<!-- 底部导航 -->
		<view class="posixzy">
			<bottom-tab></bottom-tab>
		</view>
	</view>
</template>

<script>
	import {base64ToPath} from '@/jsFile/base64-src.js';
	import {checkBanner} from '@/jsFile/publicAPI.js';
	import bottomTab from '@/components/bottom-tab.vue';
	export default {
		components: {
			bottomTab,
		},
		data() {
			return {
				optionObj:'',
				dataList:[],
				page:1,
				size:20,
				total:'',//总数
				isZanw:true,
			}
		},
		computed: {
			// 主题颜色
			publicColor() {
				return this.$store.state.publicColor
			},
			statusHeight() {
				return this.$store.state.statusHeight
			}
		},
		onReachBottom() {
			if(this.total!=this.dataList.length){
				this.page++
				this.checkDiaryEv()//调用自主预约列表事件
			} else {
				if(this.isZanw) this.$toolAll.tools.showToast('暂无更多日记','none',1000)
				this.isZanw = false
			}
		},
		onUnload: function() {
			
		},
		onShow() {
			if(uni.getStorageSync('phone_active')!=0 && uni.getStorageSync('is_active')!=0){
				this.checkDiaryEv();
			}
		},
		onLoad() {
			
		},
		methods: {
			goAddDiary(){
				uni.navigateTo({
					url:'/pagesA/my-diary-edit/my-diary-edit'
				})
			},
			checkDiaryEv(){
				this.$requst.get('user/diary',{page:this.page,size:this.size}).then(res=>{
					if(res.code==0){
						if(this.page==1) this.dataList = [];
						this.total = res.data.total;
						if(res.data.list.length){
							res.data.list.forEach(item=>{
								let obj = {
									id:item.id,
									title:item.title,
									content:item.content,
									imgArr:item.images.split(','),
									doctorName:item.doctor_name,
									creatTime:item.created_at,
								}
								this.dataList.push(obj);
							})
						}
					} else this.$toolAll.tools.showToast(res.msg);
				},error=>{})
			},
			delDiaryEv(id,index){
				this.$requst.get('user/diary-del',{id:id}).then(res=>{
					if(res.code==0){
						this.$toolAll.tools.showToast('删除成功');
						this.dataList.splice(index,1);
					} else this.$toolAll.tools.showToast(res.msg);
				},error=>{})
			},
			preImg(index,num){
				console.log(this.dataList[index]);
				uni.previewImage({
					current:this.dataList[index].imgArr[num],
					urls:this.dataList[index].imgArr
				})
			}
		}
	}
</script>

<style>

</style>
