<template>
	<view class="wrap">
		<view class='content1'>
			<view class='row content-item'>
				<view class="left" @click='show1=true'>
					<view>{{warehouseName}}</view>
					<u-icon name="arrow-right" color=""></u-icon>
					<u-picker @confirm="warehousechange" range-key='warehouseName' mode="selector" v-model="show1" :range="warehouseList"></u-picker>
				</view>
			</view>
			<view class="content-item">
				<view class="left">收购信息</view>
				<view class='row'>
				<textarea placeholder="请输入仓库信息" class="textarea" maxlength="2000" v-model="textareaValue"></textarea>
				<view class="textarea-bottom">{{textareaValue?textareaValue.length:'0'}}/2000字</view>
			</view>
			<view class='row row_css'>
				显示在易粮易运收购信息中
				<!-- <u-checkbox activeColor="#19be6b" v-model="value" @change="checkBoxChange">显示在易粮易运收购信息中</u-checkbox> -->
				<view class="right">
					<u-switch v-model="value" active-color="#19be6b" inactive-color="#eee" size='40' @change="checkBoxChange"></u-switch>
				</view>
			</view>
			</view>
			
		</view>
		<view class="bottom-btn">
			<u-button type="primary" class="submit" hover-class="none" @click="submit()">提交</u-button>
		</view>
		<u-toast ref="uToast" />
		<u-modal v-model="isShowAlert" :title-style="{fontSize: '18px',fontWeight:'500'}"
			:content-style="{fontSize: '14px',fontWeight:'400'}" confirm-color='#22C572' confirm-text='确定' title='登录提示'
			showCancelButton='false' :content="content" @confirm="alertBtn" @cancel="cancelClick"></u-modal>
		<u-modal v-model="isShowAlert1" :title-style="{fontSize: '18px',fontWeight:'500'}"
			:content-style="{fontSize: '14px',fontWeight:'400'}" confirm-color='#22C572' confirm-text='确定' title='收购信息'
			showCancelButton='false' :content="content1" @confirm="alertBtn1" @cancel="cancelClick"></u-modal>
	</view>
</template>
<script>
	import {
		mapState
	} from 'vuex';

	export default {
		components: {

		},
		data() {
			return {
				isSHowBtn: true,
				isShowAlert: false,
				isShowAlert1: false,
				content: '当前登入信息验证失败，是否重新登录？',
				content1: '确定提交收购信息？',
				textareaValue: '',
				value: false,
				warehouseName: '暂无仓库',
				warehouseList: [],
				show1: false,
				status: "",
				isEdit: false,
				sgId: '',
				id: ''
			}
		},

		onLoad(options) {
			this.status = options.status
			this.sgId = options.id
		},
		// #ifndef MP
		onNavigationBarButtonTap(e) {
			const index = e.index;
			if (index === 0) {
				this.navTo('/pages/set/set');
			} else if (index === 1) {
				// #ifdef APP-PLUS
				const pages = getCurrentPages();
				const page = pages[pages.length - 1];
				const currentWebview = page.$getAppWebview();
				currentWebview.hideTitleNViewButtonRedDot({
					index
				});
				// #endif
				uni.navigateTo({
					url: '/pages/notice/notice'
				})
			}
		},
		// #endif
		computed: {
			...mapState(['hasLogin', 'userInfo']),
		},
		onShow() {
			uni.showLoading({
				title: "加载中...",
				mask: true
			})
			this.$api.doRequest('get', '/commonUser/api/checkSession').then(res => {
				console.log("checkSession", res)
				if (res.data.data == "INVALID") {
					this.isShowAlert = true;
					// uni.showModal({
					// 	title: '登录提示',
					// 	content: '当前登入信息验证失败，是否重新登录？',
					// 	showCancel: true,
					// 	confirmText: '登录',
					// 	success: (e) => {
					// 		if (e.confirm) {
					// 			uni.navigateTo({
					// 				url: '/pages/public/login'
					// 			})
					// 		}
					// 	},
					// 	fail: () => {},
					// 	complete: () => {}
					// })
				}
				this.init()
			})
			console.log("hasLogin", this.hasLogin)
		},
		methods: {
			init() {
				let _obj = {
					commonId: this.sgId,
					warehouseName:uni.getStorageSync("depotAcquisition_warehouseName")
				}
				this.$api.doRequest('get', '/acquisitionInfo/getInfo', _obj).then(res => {
					if (res.data.code == 200) {
						if (res.data.data) {
							this.isEdit = true
							this.value = res.data.data.checkFlag == '0' ? false : true
							console.log(this.value)
							this.warehouseName = res.data.data.warehouseName
							this.textareaValue = res.data.data.acquisitionInformation
							this.id = res.data.data.id
						} else {
							this.textareaValue = ''
							this.isEdit = false
							this.value = false
						}
					}
				})



				switch (this.status) {
					case '已隐藏':
						break;
					case '显示中':

						break;
				}
				this.$api.doRequest('get', '/warehouseBaseInfo/selectWarehouseSelfApp', {
					compId: uni.getStorageSync('pcUserInfo').compId,
				}).then(res => {
					if (res.data.data.length != 0) {
						uni.hideLoading()
						// let _showData = uni.getStorageSync("erpSelectWarehous")
						// let _showCWData = uni.getStorageSync("erpSelectWarehousCW")
						this.warehouseList = res.data.data
						let _storangewarehouseName = uni.getStorageSync("depotAcquisition_warehouseName")
						if (_storangewarehouseName) {
							this.warehouseName = _storangewarehouseName
						} else {
							this.warehouseName = res.data.data[0].warehouseName
						}
					} else {
						this.warehouseList = []
						this.warehouseName = '暂无仓库'
					}
				})
			},
			warehousechange(e) {
				this.warehouseName = this.warehouseList[e[0]].warehouseName
				this.warehouseId = this.warehouseList[e[0]].id
				uni.setStorageSync("depotAcquisition_warehouseName", this.warehouseName)
				this.init()
				
			},
			/**
			 * 统一跳转接口,拦截未登录路由
			 * navigator标签现在默认没有转场动画，所以用view
			 */
			navTo(url) {
				if (!this.hasLogin) {
					url = '/pages/public/login';
				}
				uni.navigateTo({
					url
				})
			},
			alertBtn() {
				uni.navigateTo({
					url: '/pages/public/login'
				})
			},
			alertBtn1() {
				uni.showLoading({
					title: "加载中...",
					mask: true
				})
				let _flag = ''
				console.log(this.value)
				if (this.value) {
					_flag = 1
				} else {
					_flag = 0
				}
				let _obj = {
					warehouseName: this.warehouseName,
					acquisitionInformation: this.textareaValue,
					checkFlag: _flag,
					followFlag: "0",
					commonId:uni.getStorageSync("userInfo").id

				}
				if (this.isEdit) {
					_obj.id = this.id
				}
				this.$api.doRequest('post', '/acquisitionInfo/api/addAcquisition', _obj).then(res => {
					if (res.data.code == 200) {
						uni.hideLoading()
						this.$api.msg('添加成功')
					uni.navigateBack()
					}
				})
			},
			cancelClick() {
				this.isShowAlert = false
			},
			checkBoxChange(e) {
				this.value = e
				// this.alertBtn1()
				// console.log("value----", this.value)
			},
			submit() {
				this.isShowAlert1 = true
				
				// this.$api.msg('提交成功')
				// this.$api.msg('提交失败')
			}
		}
	}
</script>
<style lang='scss' scoped>
	page {
		background: #F5F6FA;
	}

	.wrap {
		/* background: #fff; */
		margin: 10px;
		border-radius: 10px;
		/* padding: 10px; */
		height: calc(100vh - 55px);

	}
	
	.content-item{
		/* height: 104rpx; */
		border-radius: 14rpx;
		background: #fff;
		padding: 40rpx 30rpx;
		margin-bottom: 20rpx;
	}
	.left{
		align-items: center;
		color: #333333;
		font-size: 34rpx;
		font-weight: 600;
		}
	

	.row {
		display: flex;
		justify-content: space-between;
		position: relative;

		/* border-bottom: 1px solid #EEEEEE; */
		input {
			font-size: 28rpx;
			// color: #333333;
		}

		.left {
			display: flex;
			align-items: center;
			color: #333333;
			font-size: 34rpx;
			font-weight: 600;
		}
	}
	.row_css{
		font-size: 26rpx;
		color: #333333;
		margin-top: 60rpx;
		font-weight: 500;
	}

	.textarea {
		background: #F9F9FA;
		font-size: 28rpx;
		text-align: left;
		width: 100%;
		padding: 30rpx;
		border-radius: 5px;
		margin-top: 30rpx;
		height: 45vh;
		padding-bottom: 20rpx;
		color: #AFB3BF ;
	}

	.textarea-bottom {
		position: absolute;
		bottom: 20rpx;
		right: 20rpx;
		color: #606266;
	}

	.submit {
		/* width: 90%; */
		background: #22C572;
		border-radius: 50rpx;
	}

	.bottom-btn {
		position: fixed;
		bottom: 30rpx;
		width: 90%;
	}
</style>
