<template>
	<view>
		<view class="title-back" :style="{height:`${uni.getStorageSync('moveHeight')+40}px`}">
			<view class="left-father" @click="uni.navigateBack()">
				<image class="back-img" src="https://www.focusnu.com/media/directive/index/left.png" />
				<view style="font-size: 30rpx;">物料编辑</view>
			</view>
		</view>
		<view :style="{height:`${uni.getStorageSync('moveHeight') + 40}px`}"></view>
		<view class="box">
			<view class="cont">
				<view class="left">货品名称</view>
				<view class="cot">{{obj.materialName}}</view>
			</view>
			<view class="cont">
				<view class="left">规格型号</view>
				<view class="cot">{{obj.specificationModel}}</view>
			</view>
			<view class="cont">
				<view class="left">品牌型号</view>
				<view class="cot">{{obj.brandType}}</view>
			</view>
			<view class="cont">
				<view class="left">销售单价</view>
				<view class="cot"><input type="digit" maxlength="8" placeholder="请输入销售单价" v-model="obj.salesUnitPrice"></view>
				<image class="one-left-imge" src="https://www.focusnu.com/media/directive/index/canread.png" />
			</view>
			<view class="cont">
				<view class="left">销售单位</view>
				<view class="cot"><input type="text" maxlength="5" placeholder="请输入销售单位" v-model="obj.salesUnit"></view>
				<image class="one-left-imge" src="https://www.focusnu.com/media/directive/index/canread.png" />
			</view>
			<view class="queding" @click="config">
				确定
			</view>
		</view>
	</view>
</template>

<script setup lang="ts">
	 import {
	 	reactive,
	 	ref,
	 	onMounted,
	 	onUnmounted,
	 } from 'vue';
	 import {
	 	onLoad,
	 	onShow,
	 	onPullDownRefresh,
	 		onReachBottom
	 } from '@dcloudio/uni-app';
	 import {
	 	editSuppliersWlInfo,
	 } from './api.js'
	 const obj = ref({})
	 const dex = ref(0)
	 onLoad((e)=>{
		 obj.value = JSON.parse(e.obj);
		 dex.value = e.index
	 })
	 const config =()=>{
		 if(obj.value.salesUnitPrice==''){
			 uni.showToast({
			 	title:"请输入销售单价",
				icon:'none'
			 })
			 return
		 }
		 if(obj.value.salesUnit==''){
			 uni.showToast({
				title:"请输入销售单位",
				icon:'none'
			 })
			 return
		 }
		 let hom = {
			 id:obj.value.id,
			 salesUnitPrice:obj.value.salesUnitPrice,
			 salesUnit:obj.value.salesUnit
		 }
		 editSuppliersWlInfo(hom).then(res=>{
			 if(res.success){
				 let pages = getCurrentPages(); // 当前页面
				 let currentPage = pages[pages.length - 2]; // 上一页
				  if (currentPage ) {
				     currentPage.$vm.swih(obj.value, dex.value)
				   }
				   uni.showToast({
						title:"修改成功",
						icon:'none'
				   })
				setTimeout(()=>{
					uni.navigateBack()
				},800)
			 }else{
				 uni.showToast({
					title:res.message,
					icon:'none'
				 })
			 }
		 })
	 }
</script>

<style lang="less" scoped>
	.queding{
		width: 320rpx;
		height: 100rpx;
		border-radius: 28rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		background: linear-gradient(180deg, #E6F4FE,#CCE8FE,#CAE6FE);
		color: #0083FA;
		font-size: 36rpx;
		font-weight: 900;
		margin: 80rpx auto 30rpx;
	}
	.box{
		width: 700rpx;
		padding: 15rpx;
		margin: 40rpx auto;
		background: #fff;
		border-radius: 30rpx;
		.cont{
			width: 100%;
			height: 110rpx;
			display: flex;
			align-items: center;
			border-bottom: 1rpx solid #E5E5E5;
			font-size: 28rpx;
			position: relative;
			.one-left-imge {
				width: 35rpx;
				height: 35rpx;
				position: absolute;
				top: 50%;
				right: 8rpx;
				transform: translateY(-50%);
			}
			.left{
				width: 200rpx;
				color: #646464;
				padding-left: 15rpx;
			}
			.cot{
				color: #9E9E9E;
				max-width: 400rpx;
				input{
					max-width: 400rpx;
					color: #9E9E9E;
				}
			}
		}
	}

.title-back {
		background-color: #F7F7F7;
		width: 100%;
		height: 70rpx;
		display: flex;
		justify-content: space-between;
		align-items: flex-end;
		padding-bottom: 20rpx;
		border-bottom: 1rpx solid #cbd1d2;
		position: fixed;
		top: 0;
		left: 0;
		z-index: 9999;
	}

	.left-father {
		display: flex;
		align-items: center;
		z-index: 1;

		.back-img {
			width: 45rpx;
			height: 40rpx;
			margin-left: 40rpx;
			margin-right: 15rpx;
		}
	}
</style>
<style>
	page{
		background: RGBA(247, 247, 247, 1);
	}
</style>