<template>
	<view class="app-page">
		<view class="top-view">

			<view class="top-box">
				<view class="top-bar">
					<radio-group class="top-menu" @change="topMenuChange">
						<label v-for="(item,index) in topMenus" :key="index">
							<text :class="[topMenuIndex === index  ? 'active' : undefined]">{{item.label}}</text>
							<radio v-show="false" :value="index" :checked="topMenuIndex === index">
							</radio>
						</label>
					</radio-group>
				</view>
				<!-- 商单列表 -->
				<view class="good-list" v-if="topMenuIndex == 0">
					<view class="good-item-card" v-for="(item,index) in mList" :key="index" @click="toDetails(item)">
						<view class="good-item">
							<u--image width='162rpx' height='162rpx' radius="10rpx" mode="widthFix"
								:src="item.task.cover" :fade="true" duration="450"
								customStyle="margin-top:20rpx;margin-bottom:20rpx;" />
							<view class="good-item-content">
								<view class="good-name-box">
									<!-- <image mode="heightFix" :src="`${$getImgBaseUrl()}ykj.png`"></image> -->
									<text class="good-name-mode">{{item.task.task_model}}</text>
									<text class="good-name">{{item.task.task_name}}</text>
								</view>
								<text class="good-desc">{{item.task.remark}}</text>
								<view class="good-tags">
									<text class="good-tag1">{{item.task.task_model}}</text>
									<text class="good-tag2">粉丝{{item.task.fans_require}}起</text>
									<text class="good-tag2">{{item.task.show_form}}</text>
								</view>
							</view>
						</view>
						<u-line color="#E9E9E9" length="calc(100%)" customStyle="margin-bottom:0rpx;"></u-line>
						<!-- <view class="good-bottom"> -->
							<!-- <view class="good-user-box"> -->
								<!-- 	<u--image width='40rpx' height='40rpx' radius="100%" mode="heightFix"
									:src="`${$getImgBaseUrl()}nologin.png`" :fade="true" duration="450"
									customStyle="margin-left: 0rpx" /> -->
							<!-- 	<text>{{item.username}}</text>
							</view> -->
							<!-- <view class="good-btn-box"> -->
								<!-- <button class="primary-btn">修改报价</button> -->
								<!-- <button class="primary-btn">支付保证金</button> -->
								<!-- <text v-if="item.status == 2">待商家确认</text>
								<text v-if="item.status == 3">商家已确认</text>
								<button v-if="item.status == 1 || item.status == 2 || item.status == 3" class="gray-btn"
									@click="cancelTask(item)">取消合作</button> -->
							<!-- </view> -->
						<!-- </view> -->
					</view>
				</view>
				<!-- 带货列表 -->
				<view class="good-list" v-else>
					<view class="good-item-card" v-for="(item,index) in goodsList" :key="index"
						@click="toDetails(item, 2)">
						<view class="good-item">
							<image style="width: 162rpx;height: 162rpx;border-radius: 10rpx;" width='162rpx'
								:src="item.goods.cover" />
							<view class="good-item-content mt10">
								<view class="fw700 fs14">{{item.goods.name}}</view>
								<!-- <text class="good-desc">{{item.task.remark}}</text> -->
								<view class="mt5 mb5">
									售价：<text class="color-orange fs14">￥{{ item.goods.price_selling }}</text>
								</view>
								<u1-tag v-if="item.goods.rebate != '0'" :text="`佣金 ${item.goods.rebate}%`" size="mini"
									class="mr5 mb10" bg-color="#F3F1FF" border-color="#F3F1FF" color="#765AEE" />
							</view>
						</view>
						<u-line color="#E9E9E9" length="calc(100%)" customStyle="margin-bottom:0rpx;"></u-line>
						<!-- <view class="good-bottom"> -->
							<!-- 	<view class="good-user-box">
								<u--image width='40rpx' height='40rpx' radius="100%" mode="heightFix"
									:src="`${$getImgBaseUrl()}nologin.png`" :fade="true" duration="450"
									customStyle="margin-left: 0rpx" />
								<text>{{item.username}}</text>
							</view> -->
							<!-- <view class="good-btn-box"> -->
								<!-- <button class="primary-btn">修改报价</button> -->
								<!-- <button class="primary-btn">支付保证金</button> -->
								<!-- <button class="gray-btn">取消合作</button> -->
								<!-- <text class="color-orange fs14 fw600" v-if="item.status == 2">待商家确认</text>
								<text class="color-orange fs14 fw600" v-if="item.status == 3">商家已确认</text>
								<button v-if="item.status == 9" class="gray-btn">取消合作</button> -->
							<!-- </view> -->
						<!-- </view> -->
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getHistoryOne,
		getHistoryTwo
	} from "@/common/api/task.js";
	export default {
		data() {
			return {
				topData: {
					top: 0,
					height: 0
				},
				topMenus: [{
					label: '商单',
					value: '0'
				}, {
					label: '带货',
					value: '1'
				}],
				topMenuIndex: 0,
				mList: [],
				goodsList: [],
				page: 1
			}
		},
		computed: {
			taskListData() {
				return {
					limit: 20,
					page: this.page,
				}
			},
			goodsListData() {
				return {
					limit: 20,
					page: this.page,
				}
			}
		},
		//1预订单,2待支付,3支付中,4已支付,6已完成
		onLoad(options) {
			if (options.tabIndex) {
				this.topMenuIndex = 1
			}
		},
		onShow() {
			const topData = uni.getMenuButtonBoundingClientRect()
			this.topData.top = topData.top
			this.topData.height = topData.height
			this.checkList();
		},
		onReachBottom() {
			console.log("上拉加载");
		},
		methods: {
			checkList() {
				this.page = 1;
				this.mList = [];
				this.goodsList = []
				switch (this.topMenuIndex) {
					case 1:
						// 带货
						this.getHistoryTwo();
						break;
					default:
						// 商单
						this.getHistoryOne();
						break;
				}
			},
			// 0 商单 //1 带货
			topMenuChange(evt) {
				console.log(evt.detail.value);
				this.topMenuIndex = evt.detail.value - 0
				this.checkList();
			},
			toDetails(item, type = 1) {
				if (type == 1) {
					uni.navigateTo({
						url: '/pages/goodDetails/index?code=' + item.code
					})
				} else {
					uni.navigateTo({
						url: `/subPages/goodsDetail/goodsDetail?code=${item.code}&type=common`
					});
				}
			},
			getHistoryTwo() {
				uni.showLoading({

				})
				const data = this.goodsListData;
				getHistoryTwo(data)
					.then((res) => {
						uni.hideLoading();
						console.log("getTaskList==>", res.data)
						if (res.data) {
							if (this.page === 1) {
								this.goodsList = res.data.list;
							} else {
								this.goodsList = this.goodsList.concat(res.data.list);
							}
						} else {
							if (this.page != 1) {
								this.page;
							} else {
								this.goodsList = []
							}
						}
					})
					.catch(() => {
						if (this.page != 1) {
							this.page--;
						}
						uni.hideLoading();
					});
			},
			getHistoryOne() {
				uni.showLoading({

				})
				const data = this.taskListData;
				getHistoryOne(data)
					.then((res) => {
						uni.hideLoading();
						console.log("getTaskList==>", res.data)
						if (res.data) {
							if (this.page === 1) {
								this.mList = res.data.list;
							} else {
								this.mList = this.mList.concat(res.data.list);
							}
						} else {
							if (this.page != 1) {
								this.page;
							} else {
								this.mList = []
							}
						}
					})
					.catch(() => {
						if (this.page != 1) {
							this.page--;
						}
						uni.hideLoading();
					});
			},
		}
	}
</script>

<style lang="scss" scoped>
	.app-page {
		width: 100%;
		display: flex;
		align-items: center;
		flex-direction: column;
	}


	.top-view {
		width: 100%;
		position: relative;
		display: flex;
		flex-direction: column;
	}

	.top-box {
		display: flex;
		flex-direction: column;
	}

	.top-bar {
		display: flex;
		margin-top: 40rpx;
		align-items: center;
		justify-content: center;
		flex-direction: row;
	}

	.top-menu {
		height: 60rpx;
		background: rgba(235, 218, 240, 0.54);
		border-radius: 28rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		flex-direction: row;

		text {
			margin: 0 6rpx;
			padding: 6rpx 32rpx;
			font-size: 28rpx;
			font-family: PingFang SC-Medium, PingFang SC;
			font-weight: 500;
			color: #222222;
		}

		.active {

			margin: 0 6rpx;
			padding: 6rpx 32rpx;
			background: #FCFFFE;
			border-radius: 28rpx;
			font-size: 28rpx;
			font-family: PingFang SC-Bold, PingFang SC;
			font-weight: bold;
			color: #765AEE;
		}
	}

	.menu-box {
		width: 100%;
		height: 90rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		flex-direction: row;

		text {
			height: 90rpx;
			line-height: 90rpx;
			padding: 6rpx 32rpx;
			font-size: 26rpx;
			font-family: PingFang SC-Medium, PingFang SC;
			font-weight: 500;
			color: #444041;
		}

		.active {
			font-weight: bold;
			color: #000005;
		}
	}

	.good-list {
		width: 100%;
		display: flex;
		margin-top: 40rpx;
		align-items: center;
		flex-direction: column;

		.good-item-card {
			border-radius: 20rpx 20rpx 20rpx 20rpx;
			background: white;
			margin-bottom: 20rpx;
			width: calc(100% - 40rpx);
			display: flex;
			align-items: center;
			flex-direction: column;
		}

		.good-item {
			width: calc(100% - 40rpx);
			display: flex;
			flex-direction: row;
			align-items: center
		}

		.good-item-content {
			flex: 1;
			margin-left: 20rpx;
			display: flex;
			flex-direction: column;
		}

		.good-name-box {
			display: flex;
			// margin-top: 20rpx;
			flex-direction: row;
			align-items: center;

			image {
				width: 81rpx;
				height: 31rpx;
				display: block;
			}

			.good-name-mode {
				font-size: 26rpx;
				white-space: nowrap;
				color: white;
				background: rgb(89, 213, 195);
				padding: 0 6rpx;
				border-radius: 4rpx;
			}

			.good-name {
				font-size: 32rpx;
				font-family: PingFang SC-Bold, PingFang SC;
				font-weight: bold;
				color: #1D161F;
				margin-left: 10rpx;
				overflow: hidden;
				text-overflow: ellipsis;
				-webkit-line-clamp: 1;
				display: -webkit-box;
				-webkit-box-orient: vertical;
			}
		}

		.good-desc {
			font-size: 22rpx;
			font-family: PingFang SC-Medium, PingFang SC;
			font-weight: 500;
			color: #2C2C2C;
			margin-top: 8rpx;
		}

		.good-tags {
			display: flex;
			flex-direction: row;
			margin-top: 15rpx;
			align-items: center;

			.good-tag1 {
				font-size: 22rpx;
				font-family: PingFang SC-Medium, PingFang SC;
				font-weight: 500;
				margin-right: 10rpx;
				color: #765AEE;
				padding: 3rpx 12rpx;
				background: #F3F1FF;
				border-radius: 5rpx 5rpx 5rpx 5rpx;
				opacity: 1;
			}

			.good-tag2 {
				font-size: 22rpx;
				font-family: PingFang SC-Medium, PingFang SC;
				font-weight: 500;
				color: #5E5E5E;
				margin-right: 10rpx;
				padding: 3rpx 12rpx;
				background: #F8F8F8;
				border-radius: 5rpx 5rpx 5rpx 5rpx;
				opacity: 1;
			}
		}

		.good-bottom {
			width: calc(100% - 40rpx);
			display: flex;
			flex-direction: row;
			align-items: center;
			height: 88rpx;
			justify-content: space-between;

			.good-user-box {

				display: flex;
				flex-direction: row;
				justify-content: center;
				align-items: center;


				text {
					font-size: 22rpx;
					font-family: PingFang SC-Medium, PingFang SC;
					font-weight: 500;
					margin-left: 10rpx;
					color: #2C2C2C;
				}
			}

			.good-btn-box {

				display: flex;
				flex-direction: row;
				align-items: center;
				justify-content: flex-end;

				text {
					font-size: 26rpx;
					font-family: PingFang SC-Medium, PingFang SC;
					font-weight: 500;
					color: #FF7400;
				}

				.primary-btn {
					height: 52rpx;
					line-height: 52rpx;
					background: #815BFF;
					border-radius: 42rpx 42rpx 42rpx 42rpx;
					opacity: 1;
					font-size: 26rpx;
					font-family: PingFang SC-Medium, PingFang SC;
					font-weight: 500;
					color: #FFFFFF;
				}

				.gray-btn {
					height: 52rpx;
					margin-left: 20rpx;
					line-height: 52rpx;
					background: #EFF1F3;
					border-radius: 42rpx 42rpx 42rpx 42rpx;
					opacity: 1;
					font-size: 26rpx;
					font-family: PingFang SC-Medium, PingFang SC;
					font-weight: 500;
					color: #1D161F;

				}

				button::after {
					height: 52rpx;
					line-height: 52rpx;
				}

				.gray-btn:active {
					opacity: 0.7;
				}

				.primary-btn:active {
					opacity: 0.7;
				}
			}
		}
	}
</style>
