<template>
	<view class="content">

		<view class="content_top">
			<!--选项卡滑动切换-->
			<cxNavTitle :tabs="tabs" :activeItem="activeItem" :show="false" @tabClick="tabClick"></cxNavTitle>
		</view>
		<!-- 审核通过 打折有拒绝、同意功能 ,调货不需要功能 -->
		<view class="content-content">
			<view class="" v-for="(item,i) in orderList" :key='i'
				style="	border-radius: 14rpx 14rpx 14rpx 14rpx;margin-bottom:  23rpx;background-color: #FFFFFF; padding: 28rpx 46rpx;">

				<view   @click="detail(item)"
					:class="tabTitle=='tabTwo'?'content-onea':'content-one'&&(tabTitle=='tabFive'&&item.resale_type==1)?'content-onea':'content-one'">
					<view class="content-one-img">

						<image :src="item.image.indexOf(',')>-1?item.image.split(',')[0]:item.image" mode="aspectFit">
						</image>
					</view>
					<view class="content-one-txt" v-if="tabTitle=='tabFive'">
						<view class="one-txt-a">
							{{item.title}}
						</view>
						<view class="one-txt-b" style="margin-top: 5px;">
							<view class="txt-b-a">
								¥ {{item.total_price}}
							</view>
							<view v-if="item.resale_type!=1" class="txt-b-b"
								style="font-size: 28rpx;font-family: SF Pro Display-Regular, SF Pro Display;font-weight: 400;color: #999999;">
								结算价:¥{{item.discount_price}}
							</view>
						</view>


						<view class="txt-b-b" style="margin-top: 5px;" v-if="item.resale_type==1">
							类型:调货
						</view>
						<view class="txt-b-b" style="margin-top: 5px;" v-else>
							类型:打折
						</view>
					</view>
					<view class="content-one-txt" v-else>
						<view class="one-txt-a">
							{{item.title}}
						</view>
						<view class="one-txt-b">
							<view class="txt-b-a">
								¥ {{item.discount_price}}
							</view>
							<view class="txt-b-b" v-if="item.resale_type==1">
								类型:调货
							</view>
							<view class="txt-b-b" v-else>
								类型:打折
							</view>
						</view>



					</view>
				</view>
				<view class="content-two_one" v-if='tabTitle=="tabOne"'>
					<view class="content-two-edit" @click="soldEdit(item) ">
						编辑
					</view>

				</view>
				<view class="content-two-two" v-if='tabTitle=="tabTwo"'>
					<!-- <view class="content-two-delete">
						删除
					</view>
					<view class="content-two-edit">
						编辑
					</view>
				   -->
				</view>
				<view class="content-two-three" v-if='tabTitle=="tabThree"'>
					<view class="content-two-delete" @click="pendingDeletion(item)">
						删除
					</view>
					<view class="content-two-edit" @click="editReviewe(item)">
						编辑
					</view>

				</view>
				<view class="content-two-four" v-if='tabTitle=="tabFour"'>
					<view class="content-two-delete" @click="auditDelete(item)">
						删除
					</view>
					<view class="content-two-edit" @click="auditEdit(item)">
						编辑
					</view>

				</view>
				<view class="content-two-five" v-if='tabTitle=="tabFive"&&item.resale_type==2'>
					<view class="" v-if="item.mer_status==0">
						<view class="content-two-delete" @click="passDelete(item)">
							拒绝
						</view>

						<view class="content-two-agree" @click="passagree(item)">
							同意
						</view>
					</view>
					<view class="" v-else>
						<view :class="item.mer_status==1?'content-two-deletea':'content-two-delete'"
							@click="passDelete(item)" v-if="item.mer_status==1">
							拒绝
						</view>

						<view class="content-two-agree" @click="passagree(item)" v-else>
							同意
						</view>
					</view>
				</view>

			</view>



		</view>

		<view v-if="orderList.length == 0 ">
			<emptyPage title="暂无订单~"></emptyPage>
		</view>

	</view>
</template>

<script>
	import cxNavTitle from '@/components/cx-navTitle.vue'
	import emptyPage from '@/components/emptyPage.vue';

	import {
		getResaleid,
		getResalecheck,
		getResaledelete,
		getResale
	} from '@/api/release.js'
	export default {
		components: {
			cxNavTitle,
			emptyPage
		},
		data() {
			return {
				activeItem: "tabOne",
				tabTitle: "",
				orderList: [],

				where: {
					page: 1,
					limit: 10,
					status: 1
				},
				tabs: [{
						name: "tabOne",
						label: '在售',
						value: 1,
					},
					{
						name: "tabTwo",
						label: '已售出',
						value: 2,
					},
					{
						name: "tabThree",
						label: '待审核',
						value: 3,
					},
					{
						name: "tabFour",
						label: '审核未通过',
						value: 4,
					},
					{
						name: "tabFive",
						label: '审核通过',
						value: 5,
					},
				],
			}
		},
		onLoad(num) {
			this.tabTitle = this.tabs[0].name
			if (num.key == '2') {
				this.activeItem = 'tabThree',
					this.where.status = 3
			}
			this.orderList = []
			this.list()
		},
		methods: {
			tabClick(e) { //点击获取当前标签数据 

				this.activeItem = e.name; //当前class类名 
				this.tabTitle = e.name; //当前选的标签名
				this.where.status = e.value
				this.orderList = []
				this.list()

			},
			list() {
				getResale(this.where).then(res => {
					if (res.status = 200) {
						this.orderList.push(...res.data.list)
					}
				})
			},
			//售出 编辑
			soldEdit(item) {
				if (item.resale_type == 1) {
					uni.navigateTo({
						url: '/pages/trading_hall/transfer_goods/index?id=' + item.community_id +
							'&gtype=' + 'edit'
					})
				} else {
					uni.navigateTo({
						url: '/pages/trading_hall/adddiscounts/index?id=' + item.community_id +
							'&gtype=' + 'edit'
					})
				}

			},
			//审核未通过 删除
			pendingDeletion(item) {

				getResaledelete(item.community_id).then(res => {
					this.$util.Tips({
						title: res.message,
						icon: 'success'
					})
					this.orderList = []
					this.list()
					this.tabTitle = 'tabThree'
				})
			},
			//待审核 编辑
			editReviewe(item) {
				if (item.resale_type == 1) {
					uni.navigateTo({
						url: '/pages/trading_hall/transfer_goods/index?id=' + item.community_id +
							'&gtype=' + 'edit'
					})
				} else {
					uni.navigateTo({
						url: '/pages/trading_hall/adddiscounts/index?id=' + item.community_id +
							'&gtype=' + 'edit'
					})
				}
			},
			// 审核未通过 删除
			auditDelete(item) {
				getResaledelete(item.community_id).then(res => {
					this.$util.Tips({
						title: res.message,
						icon: 'success'
					})
					this.orderList = []
					this.list()
					this.tabTitle = 'tabFour'
				})
			},

			// 审核未通过 编辑
			auditEdit(item) {
				if (item.resale_type == 1) {
					uni.navigateTo({
						url: '/pages/trading_hall/transfer_goods/index?id=' + item.community_id +
							'&gtype=' + 'edit'
					})
				} else {
					uni.navigateTo({
						url: '/pages/trading_hall/adddiscounts/index?id=' + item.community_id +
							'&gtype=' + 'edit'
					})
				}
			},
			//审核通过 拒绝
			passDelete(item) {
				getResalecheck(item.community_id, {
					"status": 2
				}).then(res => {
					this.$util.Tips({
						title: res.message,
						icon: 'success'
					})
					this.orderList = []
					this.list()
					this.tabTitle = 'tabFive'
				})
			},
			//详情
			detail(item) {

				uni.navigateTo({
					url: '/pages/releaseManagement/details/index?key=' + item.community_id
				})
			},
			//审核通过 同意
			passagree(item) {
				getResalecheck(item.community_id, {
					"status": 1
				}).then(res => {
					this.$util.Tips({
						title: res.message,
						icon: 'success'
					})
					this.orderList = []
					this.list()
					this.tabTitle = 'tabFive'
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content_top {
		background-color: #FFFFFF;
	}

	.content_top {

		width: 100%;
	}

	.content-content {
		margin-top: 21rpx;
		margin-left: 28rpx;
		margin-right: 28rpx;
		padding-top: 28rpx;
		opacity: 1;
		position: relative;

		.content-onea {
			display: flex;
			padding-bottom: 23rpx;
			background-color: #FFFFFF;

			.content-one-img {
				width: 148rpx;
				height: 148rpx;
				margin-right: 28rpx;

				image {
					width: 100%;
					height: 100%;
				}
			}

			.content-one-txt {
				margin-bottom: 23rpx;

				.txt-b-a {
					font-size: 32rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #333333;
				}

				.one-txt-b {
					display: flex;
					margin-top: 30rpx;

					.txt-b-a {
						font-size: 32rpx;
						font-family: SF Pro Display-Medium, SF Pro Display;
						font-weight: 500;
						color: #F84221;
						margin-right: 74rpx;
					}

					.txt-b-b {
						font-size: 28rpx;
						font-family: PingFang SC;
						font-weight: 400;
						color: #333333
					}
				}

			}

		}

		.content-one {
			display: flex;
			border-bottom: 1px solid #CCCCCC;
			padding-bottom: 23rpx;


			.content-one-img {
				width: 148rpx;
				height: 148rpx;
				margin-right: 28rpx;


				image {
					width: 100%;
					height: 100%;
				}
			}

			.content-one-txt {


				.txt-b-a {
					font-size: 32rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #333333;
				}

				.one-txt-b {
					display: flex;
					margin-top: 30rpx;

					.txt-b-a {
						font-size: 32rpx;
						font-family: SF Pro Display-Medium, SF Pro Display;
						font-weight: 500;
						color: #F84221;
						margin-right: 74rpx;
					}

					.txt-b-b {
						font-size: 28rpx;
						font-family: PingFang SC;
						font-weight: 400;
						color: #333333
					}
				}

			}

		}

		.content-two_one {
			height: 110rpx;
			position: relative;

			.content-two-edit {
				width: 168rpx;
				height: 60rpx;
				line-height: 60rpx;
				text-align: center;
				font-size: 28rpx;
				font-family: PingFang SC;
				font-weight: 400;
				color: #FFFFFF;
				background: linear-gradient(90deg, #F98649 0%, #F34E45 100%);
				border-radius: 32rpx 32rpx 32rpx 32rpx;
				position: absolute;
				right: 28rpx;
				bottom: 20rpx;
			}
		}

		.content-two-three {
			height: 110rpx;
			position: relative;

			.content-two-edit {
				width: 168rpx;
				height: 60rpx;
				line-height: 60rpx;
				text-align: center;
				font-size: 28rpx;
				font-family: PingFang SC;
				font-weight: 400;
				color: #FFFFFF;
				background: linear-gradient(90deg, #F98649 0%, #F34E45 100%);
				border-radius: 32rpx 32rpx 32rpx 32rpx;
				position: absolute;
				right: 28rpx;
				bottom: 23rpx;
			}

			.content-two-delete {
				width: 168rpx;
				height: 60rpx;
				line-height: 60rpx;
				text-align: center;
				font-size: 28rpx;
				font-family: PingFang SC;
				font-weight: 400;
				color: #999999;
				border: 2rpx solid #999999;
				position: absolute;
				right: 228rpx;
				bottom: 23rpx;
				border-radius: 32rpx 32rpx 32rpx 32rpx;
			}
		}

		.content-two-four {
			height: 110rpx;
			position: relative;

			.content-two-edit {
				width: 168rpx;
				height: 60rpx;
				line-height: 60rpx;
				text-align: center;
				font-size: 28rpx;
				font-family: PingFang SC;
				font-weight: 400;
				color: #FFFFFF;
				background: linear-gradient(90deg, #F98649 0%, #F34E45 100%);
				border-radius: 32rpx 32rpx 32rpx 32rpx;
				position: absolute;
				right: 28rpx;
				bottom: 23rpx;
			}

			.content-two-delete {
				width: 168rpx;
				height: 60rpx;
				line-height: 60rpx;
				text-align: center;
				font-size: 28rpx;
				font-family: PingFang SC;
				font-weight: 400;
				color: #999999;
				border: 2rpx solid #999999;
				position: absolute;
				right: 228rpx;
				bottom: 23rpx;
				border-radius: 32rpx 32rpx 32rpx 32rpx;
			}
		}


		.content-two-five {
			height: 110rpx;
			position: relative;

			.content-two-agree {
				width: 168rpx;
				height: 60rpx;
				line-height: 60rpx;
				text-align: center;
				font-size: 28rpx;
				font-family: PingFang SC;
				font-weight: 400;
				color: #FFFFFF;
				background: linear-gradient(90deg, #F98649 0%, #F34E45 100%);
				border-radius: 32rpx 32rpx 32rpx 32rpx;
				position: absolute;
				right: 28rpx;
				bottom: 23rpx;
			}

			.content-two-deletea {
				width: 168rpx;
				height: 60rpx;
				line-height: 60rpx;
				text-align: center;
				font-size: 28rpx;
				font-family: PingFang SC;
				font-weight: 400;
				color: #999999;
				border: 2rpx solid #999999;
				position: absolute;
				right: 28rpx;
				bottom: 23rpx;
				border-radius: 32rpx 32rpx 32rpx 32rpx;
			}

			.content-two-delete {
				width: 168rpx;
				height: 60rpx;
				line-height: 60rpx;
				text-align: center;
				font-size: 28rpx;
				font-family: PingFang SC;
				font-weight: 400;
				color: #999999;
				border: 2rpx solid #999999;
				position: absolute;
				right: 228rpx;
				bottom: 23rpx;
				border-radius: 32rpx 32rpx 32rpx 32rpx;
			}
		}

	}
</style>