<template>
	<view style="background: #F1F2F8;min-height: 100vh;" v-cloak>
		<tn-nav-bar :isBack="false" backTitle="" :bottomShadow="false" backgroundColor="#FFFFFF">
			<view class="custom-nav tn-flex tn-flex-col-center tn-flex-row-left">
				<view style="padding-left: 15rpx;" @click="goBack()">
					<text class="tn-icon-left" style="font-size: 40rpx;"></text>
				</view>
				<view style="width: 83%;font-weight: bold;">
					<text>我的发布</text>
				</view>
			</view>
		</tn-nav-bar>
		<view :style="{paddingTop: vuex_custom_bar_height + 'px'}" style="padding-bottom: 10rpx;">
			<view style="background-color: #FFFFFF;">
				<tn-tabs :list="tab_list" :current="current" :isScroll="false" name="name" activeColor="#000000"
					inactiveColor="#E6E6E6" :barWidth="25" @change="change"></tn-tabs>
			</view>
			<view style="padding: 30rpx;">

				<view style="background-color: #FFFFFF;border-radius: 20rpx;">
					<view v-for="(item,index) in list">
						<view v-if="current==1"
							style="padding-left: 20rpx;border-radius: 20rpx 20rpx 0rpx 0rpx;color: #FF6D66;background: rgba(255,109,102,0.1);height: 100rpx;line-height: 100rpx">
							拒绝原因：{{item.remark}}</view>
						<view style="padding:30rpx;">
							<view class="tn-text-ellipsis-2"
								style="font-size: 32rpx;font-weight: bold;margin-top: 20rpx;">
								{{item.title}}
							</view>
							<view class="tn-text-ellipsis-2" style="font-size: 28rpx;color: #666666;margin-top: 20rpx;">
								{{item.content}}
							</view>
							<view class="tn-flex tn-flex-center tn-flex-col-center tn-flex-row-between"
								style="margin-top: 20rpx;">
								<view style="color: #AAAAAA;font-size: 24rpx;">
									发布于:{{item.createtime}}
								</view>
							</view>
							<view v-if="item.files.length>0" style="margin-top: 30rpx;">
								<view class="tn-flex tn-flex-center tn-flex-col-center tn-flex-wrap">
									<view class="tn-flex-basic-xs" v-for="(img,img_i) in item.files"
										style="text-align: center;">
										<view style="padding-right: 10rpx;">
											<image :src="apiImgUrl+img" @click="openImg(item,img_i)"
												style="width: 200rpx;height: 200rpx;border-radius:20rpx;">
											</image>
										</view>
									</view>
								</view>
							</view>
							<view style="margin-top: 30rpx;padding:30rpx;">
								<view class="tn-flex tn-flex-center tn-flex-col-center tn-flex-row-between">
									<view style="text-align: center;font-size: 28rpx;">
										<text class="tn-icon-send" style="font-size: 32rpx;"></text>
										<text style="margin-left: 10rpx;">分享</text>
									</view>
									<view style="text-align: center;font-size: 28rpx;">
										<text v-if="item.is_like==1" class="tn-icon-praise-fill tn-color-red"
											style="font-size: 32rpx;"></text>
										<text v-if="item.is_like==0" class="tn-icon-praise"
											style="font-size: 32rpx;"></text>
										<text style="margin-left: 10rpx;">{{item.like_num>0?item.like_num:'点赞'}}</text>
									</view>
									<view style="text-align: center;font-size: 28rpx;">
										<text v-if="item.is_fav==1" class="tn-icon-star-fill tn-color-orangeyellow"
											style="font-size: 32rpx;"></text>
										<text v-if="item.is_fav==0" class="tn-icon-star"
											style="font-size: 32rpx;"></text>
										<text style="margin-left: 10rpx;">{{item.fav_num>0?item.fav_num:'收藏'}}</text>
									</view>
									<view style="text-align: center;font-size: 28rpx;">
										<text class="tn-icon-comment" style="font-size: 32rpx;"></text>
										<text style="margin-left: 10rpx;">评论</text>
									</view>
								</view>

							</view>
							<view @click="del(item)" style="text-align: right;font-size: 24rpx;color: #AAAAAA">删除
							</view>
						</view>

						<view v-if="index<list.length-1" style="height: 1px;border-top: #BABDC7 1px dashed;"></view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		tweetsList,
		tweetsDel
	} from '@/util/api.js';
	import store from '@/store/index.js'

	export default {
		data() {
			return {
				list: [],
				apiImgUrl: this.$store.state.imgUrl,
				current: 0,
				tab_list: [{
					name: '发布成功'
				}, {
					name: '发布失败'
				}],
				page: 1,
			}
		},
		mounted() {
			this.getTweetsList();
		},
		methods: {
			del(item) {
				var that = this;
				uni.showModal({
					title: '提示',
					content: '确定要删除吗？',
					success: function(res) {
						if (res.confirm) {
							that.delShow(item);
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			delShow(item) {
				tweetsDel({
						id: item.id
					})
					.then(res => {
						console.log(res);
						if (res.code == 1) {
							uni.showToast({
								title: '删除成功！',
								icon: 'none',
								duration: 2000
							});
							this.page = 1;
							this.list = [];
							this.getTweetsList();
						} else {
							uni.showToast({
								title: res.msg,
								icon: 'none',
								duration: 2000
							});
						}
					})
					.catch(error => {
						uni.showToast({
							title: error,
							icon: 'none',
							duration: 2000
						});
					})
			},
			change(index) {
				this.current = index;
				this.page = 1;
				this.list = [];
				this.getTweetsList();
			},
			openImg(item, index) {
				console.log(index);
				console.log(item.files);
				uni.previewImage({
					current: index,
					urls: item.files,
				});
			},
			switchTabbar(d) {
				console.log(d);
				store.commit('$tStore', {
					name: 'Gid',
					value: d.id
				})
				uni.setStorageSync('Gid', d.id);
				uni.$emit('getGid', {
					gid: d.id
				})
				uni.$emit('depId', {
					index: 0
				})
			},
			onsubmit() {
				this.page = 1;
				this.list = [];
				this.getAssociationIndex();
			},
			getTweetsList() {
				tweetsList({
						me: 1,
						association_name: 1,
						page: this.page,
						state: this.current == 0 ? 2 : 3,
						size: 10
					})
					.then(res => {
						console.log(res);
						if (res.code == 1) {
							this.list.push(...res.data.data);
						}
					})
					.catch(error => {
						uni.showToast({
							title: error,
							icon: 'none',
							duration: 2000
						});
					})
			},
			tn(e) {
				uni.navigateTo({
					url: e
				})
			},
			goBack() {
				if (getCurrentPages().length > 1) {
					uni.navigateBack()
				} else {
					uni.redirectTo({
						url: '/pages/index/index'
					})

				}
			}
		}
	}
</script>

<style>
	.triangle {
		width: 0;
		height: 0;
		border-top: 20rpx solid #13C296;
		border-right: 20rpx solid transparent;
		border-left: 20rpx solid transparent;
		position: absolute;
		left: 0;
		right: 0;
		margin: 0 auto;
		bottom: -12rpx;
		z-index: 100;
	}
</style>