<!--  -->
<template>
	<view class="content">
			<view style="width: 100%; height: 44px;"></view>
			<view class="top-heder">
				<view class="t-left" @click="getfan()">
					<uni-icons type="left" size="18"></uni-icons>
				</view>
				<view class="t-input">
					<uni-icons type="search" color="#BCBCBC" size="22"></uni-icons>
					<input type="text" v-model="goodsTitle" placeholder="搜索商品.....">
				</view>
				<view class="sou" @click="getindex()">搜索</view>
			</view>
			<view class="top-tap">
				<view class="tap-box" v-for="(item,index) in taplist" :key="index" @click="gettapindex(index,item.id)">
					<text :class="{'lan':isListing == item.id}">{{item.Text}}</text>
					<view class="gang" v-if="isListing == item.id"></view>
				</view>
				<!-- <view class="tap-box">
					<text>待上架</text>
					<view class="gang"></view>
				</view> -->
			</view>
			<view class="mub">
			<view class="top-ail">
				<view class="jsy" v-if="goodsList.length == 0">
						<image src="http://www.nuoyunr.com/lananRsc/detection/qs.png" mode=""></image>
				</view>
				<view class="a-box" v-for="(item,index) in goodsList" :key="index">
					<view class="t-box">
						<view class="s-img">
							<image :src="item.goodsImage" mode=""></image>
						</view>
						<view class="s-right">
							<view class="s-title">{{item.goodsTitle}}</view>
							<view class="s-hui">销量 {{item.salesNum}}</view>
							<view class="s-ju">￥{{item.price / 100}}</view>
						</view>
					</view>
					<view class="d-bottom">
						<view v-if="isListing ==0">
							<view class="" style="color: #afafaff6; margin-right: 50px;" v-if="item.listingStatus == 0" >
								<text>待提交</text>
							</view>
							<view class="" style="color: #E6A23C; margin-right: 50px;" v-if="item.listingStatus == 1" >
								<text>审核中</text>
							</view>
							<view class="" style="color: #F56C6C;  margin-right: 50px;" v-if="item.listingStatus == 3"  @click="weitongg(item.rejectReason)">
									<text>未通过</text>
							</view>
						</view>
					
						<view class="bottom-box" @click="getedit(item.goodsId,item.listingStatus)">
							<text>编辑</text>
						</view>
						<view class="bottom-box" @click="getxia(item.goodsId,item.listingStatus)">
							<text v-if="isListing == 0">上架</text>
							<text v-if="isListing == 1">下架</text>
						</view>
						<view class="bottom-box" @click="getdelete(item.goodsId)">
							<text>删除</text>
						</view>
						<view class="box-bottom" @click="editPrice(item.goodsId)">
							<text>价格</text>
						</view>
					</view>
				</view>
			</view>
			</view>

		<!-- 底部 -->
		<u-modal :show="show" :content='content' :title="title"  @confirm="confirms" :closeOnClickOverlay="true"></u-modal>
		
	</view>
</template>

<script>
	import config from '@/config'
	import request from '../../utils/request';
	export default {
		data() {
			return {
				show:false,
				msg:'3',
			    goodsList:[],
				baseUrl:this.$baseUrl,
				partnerId:'',
				title:'未通过原因',
				isListing:1,
				goodsTitle:"",
				content:'',
				taplist:[
					{Text:'已发布',id:1},
					{Text:'待上架',id:0},
				],
				pageNum: 1,//第几页
				pageSize: 10,//一页多少张
				totalPages: 0,//总数
			}
		},
		onLoad() {

		},
		onPullDownRefresh() {
					uni.showLoading()
					setTimeout(() => {
						uni.hideLoading()
						uni.stopPullDownRefresh()
					}, 500)
				},
		onReachBottom() {
					console.log(111)
					if (this.pageNum >= this.totalPages) {
						uni.showToast({
							title: '没有下一页数据',
							icon: 'none'
						})
		
					} else {
						this.pageNum++
						console.log(222)
						this.getindex()
					}
				},
		onShow() {
			// this.baseUrl = this.$baseUrl
			this.partnerId = uni.getStorageSync('partnerId')
			this.getindex()
		},
		methods: {
			confirms(){
					this.show = false
			},
			weitongg(text){
				this.show = true
				this.content = text
			},
			async getindex(){
				// 首页信息
				let data = {
					partnerId:this.partnerId,
					isListing:this.isListing,
					goodsTitle:this.goodsTitle,
					pageSize:this.pageSize,
					pageNum:this.pageNum
				}
				let res = await request({
					
					url:'/partnerOwn/partner/goodsList',
					method: 'get',
					params: data
				})	
				if(res.code == 200){
						this.goodsList = res.rows
						let total =  res.total
						this.totalPages = Math.ceil(total / this.pageSize);
				}
				
			},
			// 编辑价格
			editPrice(id){
				console.log('1');
				uni.navigateTo({
					url:'/pages/order/editPrice?id='+id
				})
			},
			// 去编辑
			getedit(id,e){
				if(e == 1){
					uni.showToast({
						title:'待审核状态不能编辑',
						icon:'none'
					})
					return
				}
				if(this.isListing == 1){
					uni.showToast({
						title:'需下架后方可编辑',
						icon:'none'
					})
					return
				}
							
				uni.navigateTo({
					url:'/pages/order/editorder?id='+id
				})
			},
			// 下架
			
			async getxia(id,e){
			
				
				let data ={
					goodsId :id
				}
				let res = await request({
					url:'/partnerOwn/partner/changeListing',
					method: 'post',
					params: data
				})
				if(res.code == 200){
					uni.showToast({
						title:res.msg,
						
					})
					this.getindex()
				}
			},
			// 删除
			async getdelete(id){
				if(this.isListing == 1){
					uni.showToast({
						title:'需下架后方可删除',
						icon:'none'
					})
					return
				}
				let data ={
					goodsId :id
				}
				let res = await request({
					url:'/partnerOwn/partner/delGoods',
					method: 'post',
					params: data
				})
				if(res.code == 200){
					uni.showToast({
						title:"操作成功",
						
					})
					this.getindex()
				}
			},
			gettapindex(index,id){
				this.isListing = id
				this.getindex()
			},
			
			getfan(){
				uni.navigateBack()
			}
		}
	}
</script>

<style scoped lang="scss">
	.content {
		box-sizing: border-box;
		width: 100%;
		height: calc(100vh);
		background: white;
	}
	
	.top-heder{
		width: 100%;
		height: 46px;
		background: white;
		display: flex;
		justify-content: space-between;
		align-items: center;
		box-sizing: border-box;
		padding: 5px 15px;
	}
	.t-left{
		width: 10%;
	}
	.t-input{
		width: 75%;
		height: 36px;
		background: #F0F0F0;
		border-radius: 50px;
		box-sizing: border-box;
		padding: 0 15px;
		display: flex;
		align-items: center;
		
	}
	.top-ail{
		width: 100%;
		box-sizing: border-box;
		padding: 15px;
		background-color: #F4F4F4;
		
	}
	.sou{
		width: 10%;
		margin-left: 5px;
	}
	.mub{
		background-color: #F4F4F4;
		height: calc(100vh);
	}
	.dix{
		display: flex;
		align-items: center;
	}
	.top-tap{
		width: 100%;
		height: 44px;
		display: flex;
		justify-content: space-between;
		align-items: center;
		
	}
	.tap-box{
		width: 50%;
		height: 100%;
		text-align: center;
		font-size: 16px;
		font-weight: 400;
		color: #606266;
		box-sizing: border-box;
		padding-top: 10px;
	}
	.gang{
		width: 30px;
		height: 4px;
		background: #0D2E8D;
		border-radius: 4px;
		margin: 4px auto;
	}
	.a-box{
		width: 100%;
		border-radius: 8px;
		background-color: white;
		box-sizing: border-box;
		padding: 15px;
		margin-bottom: 10px;
		position: relative;
	}
	.box-bottom{
		width: 45px;
		height: 45px;
		border-radius: 50%;
		display: flex;
		align-items: center;
		justify-content: center;
		overflow: hidden;
		color: white;
		background: #0D2E8D;
		position: absolute;
		bottom: 75px;
		right: 30px;
	}
	.t-box{
		width: 100%;
		box-sizing: border-box;
		padding-bottom: 15px;
		display: flex;
		border-bottom:  1px solid #EEEEEE;
	}
	.s-img{
		width: 110px;
		height: 110px;
		margin-right: 10px;
		overflow: hidden;
		border-radius: 8px;
		image{
			width: 100%;
			height: 100%;
		}
	}
	.s-right{
		width: 65%;
	}
	.s-title{
		font-size: 18px;
		font-weight: bold;
		color: #333333;
	}
	.s-hui{
		font-size: 15px;
		font-weight: 400;
		color: #999999;
		margin: 10px auto;
	}
	.s-ju{
		font-size: 18px;
		font-weight: bold;
		color: #FF571A;
	}
	.d-bottom{
		width: 100%;
		box-sizing: border-box;
		padding-top: 10px;
		display: flex;
		align-items: center;
		justify-content: flex-end;
	}
	.bottom-box{
		width: 66px;
		height: 31px;
		background: #DAE1F8;
		display: flex;
		justify-content: center;
		align-items: center;
		border-radius: 50px;
		font-size: 15px;
		font-weight: 400;
		color: #0D2E8D;
		margin-left: 5px;
	}
	.lan{
		color: #0D2E8D !important;
	}
	.jsy{
		width: 100%;
		margin-top: 20px;
		text-align: center;
		color: #0D2E8D !important;
	}
</style>
