<template>
	<view class="content">
		<view class="uni-status-height"></view>
		<view class="userData" v-if="userData">
			<view>{{userData.orgName||'用户名'}}</view>
			<view @click="toQuit">退出<u-icon name="arrow-right" color="#55aaff"></u-icon></view>
		</view>
		<view class="card-box">
			<view class="grid-box">
				 <view @click="toRuku">
					 <text class="iconfont icon-ruku"></text>
					 <text class="label">入库</text>
				 </view>
				 <view @click="toChuku">
					 <text class="iconfont icon-chukuguanli"></text>
					 <text class="label">出库</text>
				 </view>
			</view>
			<view class="grid-box">
				<view @click="toPandian">
					 <text class="iconfont icon-IMSpandianguanli"></text>
					 <text class="label">库存盘点</text>
				</view>
				 <view @click="toPandianRecord">
					 <text class="iconfont icon-pandianjilu"></text>
					 <text class="label">盘点记录</text>
				 </view>
			</view>
			<view class="grid-box">
				 <view @click="toEditCode">
					 <text class="iconfont icon-kucunchaxun"></text>
					 <text class="label">库存查询</text>
				 </view>
				 <view @click="torukurecord">
					 <text class="iconfont icon-churukujilu"></text>
					 <text class="label">入库记录</text>
				 </view>
			</view>
			<view class="grid-box">
				 <view @click="toEditCode">
					 <text class="iconfont icon-xiangmatiaomaluru"></text>
					 <text class="label">条码维护</text>
				 </view>
				 <view></view>
			</view>
		</view>
		<view class="copright">
			<view>系统版本：{{version}}</view>
			<view>Copyright © 2023 陕西山海高科信息技术有限公司</view>
		</view>
		<!-- 选择出库类型 -->
		<u-action-sheet
				:show="showOutType"
				:actions="outTypeList"
				title="请选择出库类型"
				@close="showOutType = false"
				@select="outTypeSelect"
		>
		</u-action-sheet>
	</view>
</template>

<script>
	import { supplierList, sparePartsPutTypeList, checkWarehouseList, warehouseCascadeList, logout } from '@/config/api.js'
	export default {
		data() {
			return {
				showOutType: false,
				outTypeList:[
					{
						name: "销售出库",
						value: 0
					},
					{
						name: "连锁调出",
						value: 1
					},
					{
						name: "店内调出",
						value: 2
					},
				],
				czCode: '',
				type: ''
			}
		},
		onLoad() {
			this.baseData()
		},
		computed: {
			userData() {
				return this.$store.state.vuex_user
			},
			version(){
				return getApp().globalData.version.version
			}
		},
		methods: {
			// 退出登录
			toQuit(){
				logout().then(res => {
					if(res.status == 200){
						this.$store.state.vuex_token = ''
						this.$store.state.vuex_user = ''
						uni.redirectTo({
							url: "/pages/login/index"
						})
					}
				})
			},
			// 同步基础数据
			async baseData(){
				// 供应商
				const supplier = await supplierList() 
				this.$store.state.vuex_supplierList = supplier.data || []
				// 入库类型
				const sparePartsPutType = await sparePartsPutTypeList()
				this.$store.state.vuex_sparePartsTypeList = sparePartsPutType.data || []
				// 盘点仓库列表
				const checkWarehouse = await checkWarehouseList()
				this.$store.state.vuex_checkWarehouseList = checkWarehouse.data || []
				// 仓库仓位列表
				const warehouse = await warehouseCascadeList()
				this.$store.state.vuex_warehouseList = warehouse.data || []
			},
			// 新建入库
			toRuku(){
				 uni.navigateTo({
				 	url: "/pages/stockIn/add"
				 })
			},
			torukurecord(){
				uni.navigateTo({
					url: "/pages/stockIn/list"
				})
			},
			// 出库
			toChuku(){
				this.showOutType = true
			},
			outTypeSelect(item){
				this.showOutType = false
				console.log(item)
				const url = ['/pages/stockOut/salesOut/list','/pages/stockOut/chainTransferOut/list','/pages/stockOut/storeTransferOut/list']
				uni.navigateTo({
					url: url[item.value]
				})
			},
			// 新建盘点
			toPandian(){
				uni.navigateTo({
					url: "/pages/stockPan/add"
				})
			},
			toPandianRecord(){
				uni.navigateTo({
					url: "/pages/stockPan/list"
				})
			},
			// 数据操作
			toRecord(){
				uni.navigateTo({
					url:"/pages/record/index"
				})
			},
			toEditCode(){
				uni.navigateTo({
					url:"/pages/codeBar/codeBar"
				})
			}
		}
	}
</script>

<style lang="scss">
	.content {
		height: 100vh;
		.userData{
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding: 30rpx;
			> view{
				display: flex;
				align-items: center;
				&:last-child{
					color: #55aaff;
				}
			}
		}
		.copright{
			text-align: center;
			color: $uni-text-color-grey;
			font-size: 20upx;
			position: fixed;
			left: 0;
			bottom: 30upx;
			width: 100%;
		}
		.card-box{
			border-radius: 20upx;
			margin: 20rpx 40rpx;
			background: #fff;
			border-right: 1px solid #eee;
			border-bottom: 1px solid #eee;
			overflow: hidden;
		}
		.grid-box{
			display: flex;
			justify-content: space-around;
			padding:0;
			> view{
				width: 50%;
				display: flex;
				flex-direction: column;
				align-items: center;
				border-left: 1px solid #eee;
				border-top: 1px solid #eee;
				.iconfont{
					font-size: 110upx;
					padding: 10upx 0;
				}
				.label{
					font-size: 32upx;
					text-align: center;
					padding: 0 0 24upx 0;
				}
				.icon-ruku{
					color: #ff0000;
				}
				.icon-churukujilu{
					color: #00aaff;
				}
				.icon-chukuguanli{
					color: #00aa00;
				}
				.icon-IMSpandianguanli{
					font-size: 105upx;
					color: #0055ff;
				}
				.icon-pandianjilu{
					font-size: 105upx;
					color: #55557f;
				}
				.icon-kucunchaxun{
					font-size: 108upx;
					color: #ffaa00;
				}
				.icon-xiangmatiaomaluru{
					font-size: 108upx;
					color: #aa55ff;
				}
				&:active{
					opacity: 0.8;
				}
			}
			.nob{
				border: 0;
				box-shadow:none;
			}
		}
		.uni-status-height{
			height: $uni-status-height;
		}
	}
</style>
