<!-- 菜单悬浮的原理: 通过给菜单添加position:sticky实现, 用法超简单, 仅APP端的低端机不兼容 https://caniuse.com/#feat=css-sticky -->
<template>
	<view>
		<view class="sticky-tabs">
			<!-- <me-tabs v-model="tabIndex" nameKey='name' :tabs="tabs" @change="tabChange"></me-tabs> -->
			<u-tabs :list="tabs" :is-scroll="false" :current="tabIndex" @change="tabChange"></u-tabs>
		</view>

		<view>
			<view class="box" v-for="(item,index) in goods" :key="index"
				@click="goNav('/my/order/pay?id='+item.postPushId)">
				<view class="flex align-center justify-between padding-lr padding-tb-sm">
					<view style="color: #82A9FE;">{{item.statusName}}</view>
					<view class="text-sm" style="color: #999999;">{{item.createTime}}</view>
				</view>
				<view style="width: 100%;height: 1rpx;background: #EEEEEE;"></view>
				<view class="padding-lr padding-tb-sm">
					<view class="flex align-center justify-between">
						<view class="text-bold" style="color: #6696FF;font-size: 38upx;">
							{{item.projectName?item.projectName:''}}
						</view>
						<view class="text-sm" style="color: #FF4A28;"><text
								class="text-lg text-bold">{{item.projectDayNum?item.projectDayNum:0}}</text>个月工期</view>
					</view>
					<view class="flex align-center margin-top-sm">
						<view class="argrtn">{{item.projectType}}
						</view>
					</view>
					<!-- <view v-if="item.status==2" class="flex align-center justify-between" style="margin: 30rpx 0 10rpx 0;">
						<view class="">
							推送进度
						</view>
						<view class="">
							{{item.num}}/{{item.counts}}
						</view>
					</view> -->
					<!-- <view class="flex align-center justify-between margin-top-sm" style="color: #666666;">
						<view class="text-bold">UI界面交互设计</view>
						<view class="text-df">西安 莲湖区</view>
					</view> -->
				</view>
				<view style="width: 100%;height: 1rpx;background: #EEEEEE;"></view>
				<view class="flex align-center padding-tb justify-between padding-lr">
					<view class="">
						<view class="" style="float: left;">
							预计<span style="color: red;padding: 0 5rpx 0 5rpx;">{{Math.ceil(dayNum / peopleNum * item.counts)}}</span>天完成
						</view>
					</view>
					<view class="flex align-center">
						<view class="btn" @click.stop="Changekefu()">联系客服</view>
						<view class="btn" v-if="item.status == 5 || item.status==6"
							@click.stop="updataServeType(item.postPushId)">修改内容</view>
						<view v-if="item.status==1" class="btn" @click.stop="cancelProject(item.postPushId)">取消项目</view>
					</view>
					
				</view>
			</view>
		</view>
		<empty v-if="goods.length==0" />
	</view>
</template>

<script>
	import meTabs from "@/components/mescroll-uni/me-tabs/me-tabs.vue";
	import empty from '@/components/empty.vue'

	export default {
		components: {
			meTabs,
			empty
		},
		data() {
			return {
				statustab:'',
				count: 0,
				statuss: 'loadmore',
				iconType: 'flower',
				loadText: {
					loadmore: '轻轻上拉',
					loading: '努力加载中',
					nomore: '实在没有了'
				},
				goods: [], // 数据列表
				game: [],
				tabs: [{
					name: '全部',
					status: ''
				}, {
					name: '进行中',
					status: 2
				}, {
					name: '已解冻',
					status: 3
				}],
				tabIndex: 0, // tab下标
				page: 1,
				limit: 10,
				userId: 0,
				status: 1,
				nickName: '',
				avatar: '',
				customStyle: {
					color: '#999999',
					border: '2rpx solid #999999',
					// backgroundColor: '#1E1F31',
					border: "8rpx",
					width: '180rpx',
					height: '54rpx',
					margin: "0 0 0 20rpx"
				},
				customStyle1: {
					color: '#557EFD',
					border: '2rpx solid #557EFD',
					// backgroundColor: '#1E1F31',
					border: "8rpx",
					width: '180rpx',
					height: '54rpx',
					margin: "0 0 0 20rpx"
				}
			}
		},
		onLoad(option) {
			this.$queue.showLoading("加载中...");
			this.gettype1();
			this.gettype2();
			this.getlist()
			this.userId = uni.getStorageSync('userId')
			this.nickName = uni.getStorageSync('nickName')
		},
		onShow() {
			this.getlist()
		},
		methods: {
			//获取估计人数
			gettype1(){
				this.$Request.get('/app/common/type/276').then(res => {
					if (res.code == 0) {
						this.peopleNum = parseInt(res.data.value)
					}
				})
			},
			//获取估计天数
			gettype2(){
				this.$Request.get('/app/common/type/277').then(res => {
					if (res.code == 0) {
						this.dayNum = parseInt(res.data.value)
					}
				})
			},
			//修改项目
			updataServeType(postPushId) {
				uni.navigateTo({
					url: '/my/publish/updataServeTypes?postPushId=' + postPushId
				})
			},
			//取消项目
			cancelProject(postPushId) {
				let that = this
				uni.showModal({
					content: '确认取消该项目？',
					title: '提示',
					confirmColor:'#016BF6',
					success(iet) {
						if (iet.confirm) {
							let data = {
								postPushId: postPushId
							}
							that.$Request.post('/app/postPush/cleanPostPush', data).then(res => {
								if (res.code == 0) {
									uni.showToast({
										title: '取消成功',
										duration: 1500,
										complete() {
											that.page = 1
											that.getlist()
										}
									})
								} else {
									uni.showToast({
										title: res.msg,
										icon: 'none'
									})
								}
								uni.hideLoading()
							})
						}
					}
				})
			},
			//联系客服
			Changekefu() {
				// let that = this
				// // #ifdef MP-WEIXIN
				// wx.openCustomerServiceChat({
				// 	extInfo: {
				// 		url: that.$queue.getData('kefu')
				// 	},
				// 	corpId: that.$queue.getData('kefuAppid'),
				// 	success(res) {}
				// })
				// // #endif
				// // #ifdef H5
				// window.location.href = that.$queue.getData('kefu');
				// // #endif
				// // #ifdef APP
				// let kefu = that.$queue.getData('kefu')
				// console.log(kefu)
				// plus.runtime.openURL(kefu, function(res) {});
				// // #endif
				uni.navigateTo({
					url:'/my/setting/chat'
				})
			},
			getlist() {
				let data = {
					status: this.statustab,
					classify:1,
					page: this.page,
					limit: this.limit
				}
				this.$Request.get('/app/postPush/selectPostPushListByUserId', data).then(res => {
					if (res.code == 0) {
						if (this.page == 1) this.goods = []; //如果是第一页需手动制空列表
						res.data.records.forEach(ret => {
							if (ret.status == 1) {
								ret.statusName = '待审核'
							} else if (ret.status == 2) {
								ret.statusName = '进行中'
							} else if (ret.status == 3) {
								ret.statusName = '已完成'
							} else if (ret.status == 4) {
								ret.statusName = '未完成'
							} else if (ret.status == 5) {
								ret.statusName = '已取消'
							} else if (ret.status == 6) {
								ret.statusName = '已拒绝'
							}

							this.goods.push(ret)
						})
						this.count = res.data.total
					}
					uni.hideLoading()
				})

			},
			// 切换菜单
			tabChange(e) {
				console.log(e)
				this.tabIndex = e
				this.tabs.map((item,index)=>{
					if(e==index){
						this.statustab = item.status
					}
				})
				this.goods = []; // 置空列表,显示加载进度条
				this.getlist()
			},
			goNav(url) {
				uni.navigateTo({
					url
				})
			}
		},
		onReachBottom: function() {
			if (this.goods.length == this.count) {
				uni.showToast({
					title: '已经到底了',
					icon: 'none'
				})
			} else {
				this.page = this.page + 1;
				this.getlist()
			}
		},
		onPullDownRefresh: function() {
			this.page = 1;
			this.getlist()
		}
	}
</script>

<style lang="scss">
	/*
	sticky生效条件：
	1、父元素不能overflow:hidden或者overflow:auto属性。(mescroll-body设置:sticky="true"即可, mescroll-uni本身没有设置overflow)
	2、必须指定top、bottom、left、right4个值之一，否则只会处于相对定位
	3、父元素的高度不能低于sticky元素的高度
	4、sticky元素仅在其父元素内生效,所以父元素必须是 mescroll
	*/
	.sticky-tabs {
		z-index: 990;
		position: sticky;
		top: var(--window-top);
		// background-color: #fff;
	}

	page {
		background-color: #F7F7F7;
	}

	.bg {
		background-color: #FFFFFF;
	}

	.box {
		background: #FFFFFF;
		border-radius: 24upx;
		margin: 30upx;
	}

	.argrtn {
		background: #F6F6F6;
		color: #666666;
		font-size: 24upx;
		border-radius: 8upx;
		padding: 5upx 20upx;
		margin-right: 20upx;
	}

	.btn {
		border: 1px solid #82A9FE;
		border-radius: 30px;
		color: #82A9FE;
		padding: 14upx 35upx;
		margin-left: 20upx;
	}
</style>
