<template>
	<view class="center">
		<view class="introduce-section">
			<view class="informations"  v-for="(item , index) in procurementPlanInfos" :Key="index">
				<view @click="details(item)">
				<view class="labels">{{item.goodsName}}</view>
				<view class="labels">{{item.weight}}</view>
				<view class="labels">{{item.unitPrice}}</view>
				<view class="title">{{item.receivePrivate}}{{item.receiveCity}}{{item.receiveArea}}</view>
				</view>
				<view class='cu-tag radius line-pink'>编辑</view>
				<view class='cu-tag radius line-pink' @click="switch1(item)">显示/隐藏</view>
			    <view class='cu-tag radius line-pink' @click="deleteRelease(item)">删除</view>
				<view class='cu-tag radius line-pink put'>{{item.status}}</view>
			</view>
		</view>
		<view class="page-bottom">
			<view class="action-btn-group">
				<picker style='display:inline-block;' @change="releaseChange" :value="releases" :range="releaseType">
					<button  type="primary" class=" action-btn no-border add-cart-btn" >发布</button>
					<view class="picker">
						{{releases>-1?releaseType[releases]:''}}
					</view>
				</picker>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				releaseType:["我要卖粮","我要买粮"],
				release:'',
				releases:'',
				receivePrivate:'',
				procurementPlanInfo:{
					pageSize:10,
					currentPage:1
				},
				releaseIndex:"",
				pageSize:10,
				currentPage:1,
				procurementPlanInfos:[],
			}
		},
		onLoad(){
			this.getList()
		},
		methods: {
			switch1(item){
				if (!this.hasLogin) {
					uni.showModal({
						// title: '登录提示',
						content: '隐藏后该信息不再展示给其他用户，是否确定隐藏？',
						showCancel: true,
						confirmText: '确定',
						success: (e) => {
							this.$api.doRequest('post','/procurementPlanInfo/api/editStatus',{id:item.id,flag:0}).then(res => {		
								this.procurementPlanInfos = res.data.data.records
								if (res.errmsg == "Success") {
									this.$api.msg('隐藏成功！')
									return
								}
								
							})
							.catch(res => {
								uni.showToast({
									title: res.errmsg,
									icon:'none',
									duration: 2000
								})
							});
						},
						fail: () => {},
						complete: () => {}
					})
				}
			},
			
			
			deleteRelease(item){
				if (!this.hasLogin) {
					uni.showModal({
						// title: '登录提示',
						content: '确定删除该信息？',
						showCancel: true,
						confirmText: '确定',
						success: (e) => {
							this.$api.doRequest('post','/procurementPlanInfo/api/deleteProcurementPlan',{id:item.id}).then(res => {
								this.procurementPlanInfos = res.data.data.records
								if (res.errmsg == "Success") {
									this.$api.msg('删除成功！')
									return
								}
								
							})
							.catch(res => {
								uni.showToast({
									title: res.errmsg,
									icon:'none',
									duration: 2000
								})
							});
						},
						fail: () => {},
						complete: () => {}
					})
				}	
			},
			releaseChange(e){
				this.receivePrivate = e.detail.value
				this.release = this.releaseType[this.receivePrivate];
				this.pageSize = 1

				if(this.release == "我要卖粮"){
					uni.navigateTo({
						url: `/pageD/myRelease/sellGrain`
					})
				}else if(this.release == "我要买粮"){
					uni.navigateTo({
						url: `/pageD/myRelease/buyGrain`
					})
				}
			
			},
			details(item){
				uni.navigateTo({
					url: `/pageD/myRelease/buyDetails?id=${item.id}`
				})
			},
			getList(){
				
				this.$api.doRequest('get','/procurementPlanInfo/selectProcurementPlanInfo',this.procurementPlanInfo).then(res => {
					
					this.procurementPlanInfos = res.data.data.records
					console.log(this.procurementPlanInfos,"对象")
					
				})
				.catch(res => {
					uni.showToast({
						title: res.errmsg,
						icon:'none',
						duration: 2000
					})
				});
			}

		}
	}
</script>

<style>
	.center {
		padding: 10px 20px;
	}

	.informations {
		/* display: inline-flex; */
	}

	.labels {
		display: inline-flex;
		line-height: 20px;
		margin-right: 40px;
	}
	.put{
		float: right;
	}
	.fabuBut{
		margin-bottom: 0px;
	}


</style>
