<template>
	<view :style="{ minHeight: sys.windowHeight + 'px' }" :class="[$tm.vx.state().tmVuetify.black ? 'black' : ' ']">
		<tm-menubars title="衣柜" :shadow="0" :showback="true"></tm-menubars>
		<view class="C1b1b1b">
			<view class="dingwei ml-20" v-if="itemuser!=0">
				<image class="touxiang" style="vertical-align: middle;" src="/static/img/41.png" mode="widthFix"></image>
				<text style="vertical-align: middle;" class="text-size-m mr-20">{{itemuser.username}}的衣橱</text>
				<!-- <image @click="qiehuanFun" style="vertical-align: middle;" src="/static/img/42.png" mode="widthFix"></image> -->
				<!-- <text @click="qiehuanFun" style="vertical-align: middle;" class="text-size-m">切换</text> -->
			</view>
			<view class="dingwei" v-if="itemuser==0">
				<text style="vertical-align: middle;" class="text-size-m mr-20 ml-20">暂无家庭成员去添加</text>
				<image @click="tianjia" style="vertical-align: middle;" src="/static/img/42.png" mode="widthFix"></image>
			</view>
		</view>
		<!-- 推荐 -->
		<view class="zhuti">
			<!-- 衣橱 -->
			<tm-sheet class="yichu" style="margin-bottom: 70px !important;">
				<tm-tabs class="C1b1b1b qiehuan" @change="fenleichangeFun" color="white"  align="left"  v-model="activeIndex" :list="list" range-key="title"></tm-tabs>
				<view style="position: relative;" class="yiguicla black pa-6 ma-4 fl" :class="item.off==1?'C0178FD':''" v-for="(item,index) in quanbuList" @click="yifu(item,index)">
					<image :src="item.image" mode="widthFix"></image>
					<view  class="text-align-center text-size-m mt-8">{{item.brand}}</view>
					<view :class="item.is_have==0?'text-gray':''" class="text-align-center text-size-m mt-6 mb-6">{{item.goods_name}}</view>
					<view v-if="item.is_have==0" class="hui"></view>
				</view>
				<tm-empty v-if="quanbuList.length ==0" label="暂无数据" color="white" icon="icon-paperplane-fill"></tm-empty>
				<view style="clear: both;"></view>
				<view v-if="quanbuList.length<total" class="more ma-30 pt-40" @click="gengmore()">
					<image src="/static/img/30.png" mode="widthFix"></image>
					<text class="text-size-s">下拉加载更多~</text>
				</view>
			</tm-sheet>
			<view class="anniu">
				<tm-button @click="quxiao1" :round="24" class="fl" theme="gray" size="n">取消</tm-button>
				<tm-button :round="24" @click="shanchu" class="fl" theme="red" size="n">删除</tm-button>
				<tm-button :round="24" @click="chuku" class="fl" theme="primary" size="n">出库</tm-button>
				<tm-button :round="24" @click="baocun" class="fl" theme="primary" size="n">保存</tm-button>
			</view>
			<tm-poup v-model="show_1" :position="pos" class="tcc">
				<view style="position: relative !important;" v-if="chukudata.length !=0">
					<view style="height: 10px;"></view>
					<tm-swiper @change="qiehuanLb" :current="current" :indicator-dots="false" :round="6" :ani3d="190"  :autoplay="false" :list="list1"></tm-swiper>
					<view class="text-white text-align-center mt-15">{{chukudata[current].brand}}{{chukudata[current].color}}{{chukudata[current].goods_name}}</view>
					<view class="text-white text-align-center mt-10 text-size-s">{{chukudata[current].description}}</view>
					<image class="guayi" :src="chukudata[current].ygimage" mode="widthFix"></image>
					<view class="text-white text-align-center mt-15">衣物位于 {{chukudata[current].ygposition}} {{chukudata[current].is_have}}号衣柜</view>
					<view class="text-white text-align-center mt-15">
						<image class="aniOn deng" src="/static/img/101.png" mode="widthFix"></image>
						<text style="vertical-align: middle;">指示灯已亮，请取出衣柜</text>
					</view>
					<view class="anniu">
						<tm-button @click="quxiao()" theme="gray" size="n">关闭弹框</tm-button>
						<tm-button @click="chuFun()" class="fr" theme="primary" size="n">取消出库</tm-button>
					</view>
				</view>
			</tm-poup>
			<!-- 弹出层消息 -->
			<tm-message ref="toast"></tm-message>
			<tm-dialog v-model="show" :content="content" @confirm="queren"></tm-dialog>
		</view>
	</view>
</template>	
<script>
import{myRequest} from '@/api/request.js'
export default {
	data() {
		return {
			itemuser:0,
			soso:'',
			activeIndex:0,
			list:[],
			list1:[],
			listlx:[],
			quanbuList:[],
			chooseindex:-1,
			pagesize:6,
			page:1,
			total:0,
			count:0,
			have:0,
			show:false,
			content:'',
			show_1:false,
			pos:'center',
			chukudata:[],
			ids:[],
			current:0
		};
	},
	onLoad() {
		console.log("111")
	},
	created() {
		this.sys = uni.getSystemInfoSync();
		console.log("222")
		this.getfenltext()
		this.fenleichange();
	},
	methods: {
		baocun(){
			var that=this;
			var arr=[],a=0;
			for(let i=0;i<this.quanbuList.length;i++){
				if(this.quanbuList[i].off){
					a=a+1;
					if(this.quanbuList[i].off){
						arr.push(this.quanbuList[i])
					}
				}
			}
			if(arr.length==0){
				that.$refs.toast.show({model:'error',label:'请选择在库衣物'})
				return
			}
			uni.setStorageSync("datalist",arr)
			uni.redirectTo({
				url: "/pages/baocun/index?type=1",
			})
		},
		shanchu(){
			var that=this,id=[];
			for(let i=0;i<this.quanbuList.length;i++){
				if(this.quanbuList[i].off){
					id.push(this.quanbuList[i].id)
				}
			}
			if(id.length==0){
				that.$refs.toast.show({model:'error',label:'请选择衣物'})
				return
			}
			myRequest({
				url: "/api/Goods/deleteGoods",
				method:'post',
				data:{ids:id}
			}).then(res => {
				console.log(res.data)
				if (res.data.code == 200) {
					that.quanbuList=[];
					this.fenleichange();
					that.$refs.toast.show({model:'success',label:res.data.msg})
				}else{
					that.$refs.toast.show({model:'error',label:res.data.msg})
				}
			})
		},
		qiehuanLb(e){
			var that=this;
			this.current=e;
			console.log(e)
		},
		queren(){
			var that=this;
			this.list1=[]
			myRequest({
				url: "/api/Goods/takeClothes",
				method:'post',
				data:{id:that.ids}
			}).then(res => {
				if (res.data.code == 200) {
					that.show_1=true;
					that.chukudata=res.data.data;
					for(let i=0;i<res.data.data.length;i++){
						that.list1.push(res.data.data[i].image)
					}
					that.$refs.toast.show({model:'success',label:'出库成功'})
				}else{
					that.$refs.toast.show({model:'error',label:res.data.msg})
				}
			})
		},
		quxiao1(){
			for(let i=0;i<this.quanbuList.length;i++){
				this.quanbuList[i].off=false;
				this.$forceUpdate()
			}
		},
		chuku(){
			var id=[],a=0;
			var that=this;
			// if(this.quanbuList.length==0){
			// 	that.$refs.toast.show({model:'error',label:'请选择衣物'})
			// 	return
			// }
			for(let i=0;i<this.quanbuList.length;i++){
				if(this.quanbuList[i].off){
					a=a+1;
					if(this.quanbuList[i].off && this.quanbuList[i].is_have !=0){
						id.push(this.quanbuList[i].id)
					}
				}
			}
			if(id.length==0){
				that.$refs.toast.show({model:'error',label:'请选择在库衣物'})
				return
			}
			this.content="有"+(a-id.length)+"衣物已经出库，在库衣物将添加至出库清单"
			this.ids=id;
			this.show=true;
		},
		sosoFun(){
			uni.navigateTo({
				url: "/pages/shopsoso/index",
			})
		},
		getfenltext(){
			var that=this;
			myRequest({
				url: "/api/Category/list",
				method:'post',
				data:{}
			}).then(res => {
				if (res.data.code == 200) {
					if(res.data.data.length != 0){
						that.list=['全部'];
						for(let i=0;i<res.data.data.length;i++){
							that.list.push(res.data.data[i].category_name)
						}
						that.listlx=res.data.data;
					}
				}else{
					that.list=[];
					that.listlx=[];
				}
			})
		},
		getList(){
			var that=this;
			myRequest({
				url: "/api/Goods/classificationData",
				method:'post',
				data:{role_id:that.itemuser.id,id:that.activeIndex,page:that.page,pagesize:that.pagesize}
			}).then(res => {
				if (res.data.code == 200) {
					if(res.data.data.length != 0){
						that.quanbuList=that.quanbuList.concat(res.data.data.data);
						for(let i=0;i<that.quanbuList.length;i++){
							that.quanbuList[i].off=false;
						}
						that.total=res.data.data.total;
						that.count=res.data.data.count;
						that.have=res.data.data.have;
					}
				}else{
					that.quanbuList=[];
				}
			})
		},
		fenleichangeFun(){
			this.page=1;
			this.quanbuList=[]
			this.getList()
		},
		fenleichange(){
			var that=this;
			myRequest({
				url: "/api/MemberInfo/getFamilyMember",
				method:'post',
				data:{family_id:uni.getStorageSync("family_id")}
			}).then(res => {
				console.log(res.data)
				if (res.data.code == 200) {
					if(res.data.data.length != 0){
						var wu=0;
						for(let i=0;i<res.data.data.length;i++){
							if(res.data.data[i].checked==1){
								wu=1;
								that.itemuser=res.data.data[i];
							}
						}
						if(wu==0){
							that.itemuser=res.data.data[0];
						}
						that.getList();
					}else{
						that.itemuser=0;
					}
				}else{
					that.itemuser=0;
				}
			})
		},
		yifu(item,index){
			item.off=!item.off;
			this.$forceUpdate()
		},
		qiehuanFun(){
			uni.navigateTo({
				url: "/pages/qiehuan/index",
			})
		},
		randouh(){
			let list2 = [],that=this;
			for(let i=0;i<6;i++){
				list2.push({
					src:'/static/img/47.png',
					text:'大号版型夹克',
					type:'新品',
					off:false
				})
			}
			this.quanbuList=this.quanbuList.concat(list2)
			console.log(this.quanbuList)
		},
		ruku(){
			uni.navigateTo({
				url: "/pages/putstorage/index",
			})
		},
		quxiao(){
			this.show_1=false;
		},
	},
}
</script>

<style lang="scss">
	/deep/ uni-scroll-view{
		height: auto !important;
	}
	/deep/ .tm-menubars .body{
		background-color: #1b1b1b !important;
	}
	.shangright{
		padding: 10px;
	}
	// 
	.xiangji image{
		width: 30px;
		height: 22px;
	}
	.suosou image{
		width: 40px;
	}
	/deep/ .icon-search{
		font-size: 23px !important;
		color: #8E8E93 !important;
	}
	/deep/ .tm-search{
		width: 94%;
		margin: 0 auto;
		background-color: #414141 !important;
		border-radius: 10px;
	}
	/deep/ .tm-search .grey-darken-5{
		background-color: #414141 !important;
	}
	.dingwei{padding-bottom: 20px;}
	.dingwei image{width: 25px;margin-right: 10px;	}
	.dingwei .touxiang{width: 50px;margin-right: 3px;	}
	/deep/ .lunbo1{margin:0 !important;padding: 4px !important;margin-top: 5px !important;width: 46.6% !important;}
	.tuijiantp{width: 100%;}
	.tuijiantp image{width: 97% !important;}
	.yichu{margin:0 !important;padding: 4px !important;margin-top: 10px !important;}
	/deep/ .qiehuan .text-white{
		font-size: 14px;
		background: #303440;
		height: 28px;
		vertical-align: middle;
		line-height: 28px;
		border-radius: 20px;
		padding-left: 14px;
		padding-right: 14px;
		margin-top: 17%;
	}
	/deep/ .qiehuan .tm-tabs-con-item-border{display: none;}
	.yiguicla image{width: 95%;display: block;margin: 0 auto;margin-top: 5px;}
	.yiguicla{width: 30%;border-radius: 10px;}
	.more{text-align: center;}
	.more image{margin-right: 10px;vertical-align: middle;width: 30px;}
	.fudong{position:fixed;right:10px;bottom:150px;background: #303030;width: 130px;height: 60px;
	border-radius: 30px 0px 0px 30px;font-size: 14px;text-align: center;}
	.fudimg{width: 60px;height:60px}
	.anniu{width: 100%;margin: 0 auto;padding-bottom: 30px;text-align: center;}
	/deep/ .tm-button .tm-button-btn uni-button{min-width: 77px !important;}
	/deep/ .tm-button .red{color: white !important;}
	
	/deep/ .tcc .tm-poup-wk{width: 90% !important;position:relative;height: 580px !important;}
	/deep/ .tcc .uni-swiper-slides{width: 100%;}
	/deep/ .tcc uni-swiper{width: 100% !important;}
	/deep/ .uni-swiper-slides{width: 160px !important;}
	/deep/ .tcc uni-image{width: 160px !important;}
	.tcc .guayi{width: 70% !important;display: block;margin:0 auto;margin-top:15px !important;}
	.tcc .deng{width:25px !important;height:25px !important;vertical-align: middle;margin-right:8px;}
	.aniOn{
		animation:doudong 0.5s linear infinite;
		background:linear-gradient();
		background: -webkit-linear-gradient();
	}
	@keyframes doudong {
		0%{
			transform: rotate(-2deg) translateX(2rpx) translateY(2rpx);
		}
		25%{
			transform: rotate(0deg) translateX(-2rpx) translateY(-2rpx);
		}
		50%{
			transform: rotate(0deg) translateX(0rpx) translateY(-2rpx);
		}
		75%{
			transform: rotate(0deg) translateX(0rpx) translateY(2rpx);
		}
		100%{
			transform: rotate(-2deg) translateX(2rpx) translateY(2rpx);
		}
	}
	/deep/ .tcc .anniu .gray.bk{color: white !important;}
	.tcc .anniu{width: 88%;margin: 0 auto;margin-top: 20px;}
	/deep/ .hui{position: absolute;background: rgba(0,0,0,0.4);z-index: 1;top: 0;left: 0;width: 100%;height: 100%;}
</style>
