<template>
	<view>
		<u-navbar back-text="" title="交易" title-size='36' back-icon-name='search' :title-bold='true'
			:border-bottom='false' back-icon-color='#333333' title-color='#000000'>
			<view class="slot-wrap" slot="right">
				我的关注
			</view>
		</u-navbar>
		<view class="top-warp">
			<me-tabs v-model="tabIndex" :tabs="tabs" @change="tabChange"></me-tabs>
		</view>
		<mescroll-body ref="mescrollRef" @init="mescrollInit" top="80" @down="downCallback" :up="upOption"
			@up="upCallback" @emptyclick="emptyClick">
			<!-- 数据列表 -->
			<view class="list" v-if="goods.length!=0">
				<view class="list-item" v-for="(item,index) in goods">
					<view class="row1 flex jcsb alc">
						<view class="left flex alc">
							<image src="../../static/img/face/27.png" mode="widthFix" class="head-img"></image>
							<view class="">
								<view class="title">
									中天昊元粮库
								</view>
								<view class="bottom">
									<text class="color1">采购</text>
									<text class="color2">销售</text>
									<text class="color3">5分钟前</text>
								</view>
							</view>
						</view>
						<view class="right">
							<u-icon name="plus" color="#333333" size="17"></u-icon><text class="case">关注</text>
						</view>
					</view>
				</view>
			</view>

			<!-- <good-list :list="goods"></good-list> -->
		</mescroll-body>
	</view>
</template>

<script>
	import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
	import {
		apiGoods
	} from "@/api/mock.js"

	export default {
		mixins: [MescrollMixin], // 使用mixin
		data() {
			return {
				upOption: {
					// page: {
					// 	num: 0, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
					// 	size: 10 // 每页数据的数量
					// },
					noMoreSize: 4, //如果列表已无数据,可设置列表的总数量要大于半页才显示无更多数据;避免列表数据过少(比如只有一条数据),显示无更多数据会不好看; 默认5
					empty: {
						tip: '~ 搜索无数据 ~', // 提示
						btnText: '去看看'
					}
				},
				goods: [], //列表数据
				tabs: [{
					name: '全部',
					type: 'xx'
				}, {
					name: '采购',
					type: 'xx'
				}, {
					name: '销售',
					type: 'xx'
				}, {
					name: '关注',
					type: 'xx'
				}],
				tabIndex: 0 // tab下标
			}
		},


		onShow() {
			uni.showTabBar()
			uni.hideKeyboard()
			var userInfo = uni.getStorageSync("userInfo")
			var that = this
			console.log("userInfo", userInfo)
			// setTimeout(function() {
			// 	that.$api.doRequest('get', '/appVersion/test', {
			// 		userId: "7e83070d05fc4d50aaa46e00a3ee03d8"
			// 	}).then(res => {

			// 	})
			// }, 500);
			uni.removeTabBarBadge({
				index: 4
			})
			this.$api.doRequest('get', '/newNoticeTask/query/noticeTasks').then(res => {
				if (res.data.data) {
					let name = 'myTip';
					let value = res.data.data.total;
					that.$store.commit('$uStore', {
						name,
						value
					});
					if (value != 0 && value) {
						uni.setTabBarBadge({
							index: 4,
							text: value + ""
						})
					}
					name = 'taskTip';
					value = res.data.data.total;
					that.$store.commit('$uStore', {
						name,
						value
					});
				}
			})
		},
		onLoad(options) {

		},


		methods: {
			/*上拉加载的回调: 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10 */
			upCallback(page) {
				//联网加载数据
				let curTab = this.tabs[this.tabIndex]
				let keyword = curTab.name // 具体项目中,您可能取的是tab中的type,status等字段
				apiGoods(page.num, page.size, keyword).then(res => {
					//联网成功的回调,隐藏下拉刷新和上拉加载的状态;
					this.mescroll.endSuccess(res.list.length);
					//设置列表数据
					if (page.num == 1) this.goods = []; //如果是第一页需手动制空列表
					this.goods = this.goods.concat(res.list); //追加新数据
				}).catch(() => {
					//联网失败, 结束加载
					this.mescroll.endErr();
				})
			},
			//点击空布局按钮的回调
			emptyClick() {
				uni.showToast({
					title: '点击了按钮,具体逻辑自行实现'
				})
			},

			// 切换菜单
			tabChange() {
				this.goods = [] // 先置空列表,显示加载进度
				this.mescroll.resetUpScroll() // 再刷新列表数据
			}

		}
	}
</script>

<style lang='scss'>
	page,
	.content {
		background: #F5F6FA;
	}

	.flex {
		display: flex;
	}

	.alc {
		align-items: center;
	}

	.jcse {
		justify-content: space-evenly;
	}

	.jcsb {
		justify-content: space-between;
	}

	.top-warp {
		z-index: 9990;
		position: fixed;
		top: --window-top;
		/* css变量 */
		left: 0;
		width: 100%;
		/* height: 120upx; */
		background-color: white;
	}


	.top-warp .tip {
		font-size: 28upx;
		height: 60upx;
		line-height: 60upx;
		text-align: center;
	}

	.slot-wrap {
		margin-right: 45rpx;
		font-size: 32rpx;
	}

	.list {
		margin: 0 20rpx;

		.list-item {
			padding: 26rpx 17rpx;
			background: #fff;
			margin-bottom: 20rpx;
			border-radius: 20rpx;

			.row1 {

				.head-img {
					width: 72rpx;
					background-color: red;
					border-radius: 8rpx;
					margin-right: 22rpx;
				}

				.left {
					.title {
						font-weight: 700;
						color: #333333;
					}

					.bottom {
						.color1 {
							font-size: 24rpx;
							padding: 4rpx 10rpx;
							color: #fff;
							display: inline-block;
							background: linear-gradient(180deg, #607AE0 0%, #516CDC 100%);
							border-radius: 4rpx;
						}

						.color2 {
							font-size: 24rpx;
							padding: 4rpx 10rpx;
							color: #fff;
							display: inline-block;
							background: linear-gradient(180deg, #FD714F 0%, #FD613C 100%);
							border-radius: 4rpx;
						}

						.color3 {
							font-size: 24rpx;
							color: #AFB3BF;
							margin-left: 14rpx;

						}
					}
				}

				.right {

					border: 1px solid #CDCDCD;
				}
			}
		}
	}
</style>
