<template>
    <view class="page">
      <StickyNavBar>
        <NavBar :title="$t('进货单信息')" right="checkbox" @clickRight="submit"></NavBar>
		
      </StickyNavBar>
	  <u-form ref="form" :modelValue="form" :labelWidth="140" style="margin-left:20rpx;margin-right:20rpx;padding-bottom:0"> 
			<u-form-item prop="tg001" :label="$t('进货单别')">
				<input
				v-model="form.tg001"
				type="text"
				placeholder=""
				/>
			</u-form-item>
		</u-form>
		<view class="info">
			<view>
				<view style="width: 120rpx;">{{$t('到货单')}}</view>
				<view style="width: 120rpx;">{{$t('供应商')}}</view>
			</view>
			<view>
				<view>
					<text class="underline">{{ info.cc001 }}</text>
				</view>
				<view>
					<text class="underline">{{ info.cc005 }}</text>
				</view>
			</view>
			<view>
				<view>
					<text class="underline">{{ info.cc002 }}</text>
				</view>
				<view>
					<text class="underline">{{ info.cc012 }}</text>
				</view>
			</view>
		</view>
      <ContentLoadingMore class="cardbox" :list="chargaArr">
        <view class="cardContent" v-for="(item, index) in chargaArr" :key="index">
			<view class="cardItem" @click="editCard(item, index)" v-if="!item.batch">
				<view class="cardLeft">
					<view class="boxindex">{{index+1}}</view>
				</view>
				<view class="cardRight">
					<view class="itemtitle">
						<text>{{item.cd004}}</text>
						<view>
							<text style="color: #006400">{{item.th015}}</text>
							<text style="color: #8b008b; margin-left: 40rpx">{{item.th017}}</text>
						</view>
					</view>
					<view>
						<text>{{item.cd005}}</text>
						<text></text>
					</view>
					<view>
						<text>{{$t('仓库')}}</text>
						<text><text style="margin-right:20rpx">{{item.th009}}</text></text>
					</view>
					<view>
						<text>{{$t('库位')}}</text>
						<text><text>{{item.th072}}</text></text>
					</view>
					<view>
						<text>{{$t('进货数量')}}</text>
						<text><text>{{item.cd018}}</text><text style="margin-left:20rpx">{{item.cd015}}</text></text>
					</view>
					<view>
						<text>{{$t('入库数量')}}</text>
						<text><text>{{item.cd020}}</text><text style="margin-left:20rpx">{{item.cd007}}</text></text>
					</view>
					<view>
						<text>{{$t('采购单号')}}</text>
						<text>{{item.cd011}}</text>
					</view>
				</view>
			</view>
        </view>
      </ContentLoadingMore>
	  <button
		:loading="loading"
		size="medium"
		type="primary"
		style="width:98%;margin-top: 50rpx"
		@click="submit()"
	>
		<span>{{$t('确定')}}</span>
	</button>
    </view>
  </template>
  
  <script>
import i18n from '../../lang/index'

  import StickyNavBar from "@/components/StickyNavBar/index.vue";
  import ContentLoadingMore from "@/components/ContentLoadingMore/index.vue";
  export default {
    components: {
      StickyNavBar,
      ContentLoadingMore,
    },
	onLoad(option) {
		if (option.info) {
			let data = JSON.parse(decodeURIComponent(option.info));
			if(data.purths && data.purths.length > 0){
				data.purths.forEach(element => {
					if (!element['th015']) {
						element['th015'] = element['cd018'] - element.cd020
					}
					if (!element['th016']) {
						element['th016'] = element['cd018'] - element.cd020
					}
					if (!element['th017']) {
						element['th017'] = 0
					}
				});
			}
			this.chargaArr = data.purths
			this.info = data
		}
	},
    data() {
      return {
        chargaArr: [],
		form: {
			tg001: '3401'
		},
		loading: false,
		info: null
      };
    },
    created() {
    },
    methods: {
		getValue(data) {
			this.chargaArr = data.purths
			this.info = data
		},
		editCard(row, index) {
			uni.navigateTo({
              url: '/pages/forcreate/Edit?info=' + encodeURIComponent(JSON.stringify(this.info)) + '&index=' + index
            });
		},
		submit(){
			const purcdPrintParamsList = this.chargaArr.map(v => ({cd001: v.cd001, cd002: v.cd002, cd003: v.cd003, th009: v.th009, th010: v.th010, th015: v.th015, th016: v.th016, th017: v.th017, th072: v.th072}))
			this.$u.api.purtgcreate({
				cc001: this.info.cc001,
				cc002: this.info.cc002,
				tg001: this.form.tg001,
				purths: purcdPrintParamsList
			})
			.then(res => {
				if (res.success) {
					this.$u.toast(i18n.t('提交成功'));
					setTimeout(() => {
						uni.$emit('forcreateSubmitSuccess');
						this.goMypage('pages/forcreate/Main');
					}, 200);
				}
			})
		}
    },
  };
  </script>
  
  <style lang="scss" scoped>
  .page{
	background: #fff;
  }
  .cardbox {
    padding: 0rpx 20rpx;
  }
  .cardContent {
    background: #fff;
	padding: 10rpx 15rpx;
	.cardItem {
		display: flex;
	}
	.cardLeft{
		padding-right: 40rpx;
		padding-top: 40rpx;
		.boxindex {
			border: 1px solid #aaaaaa;
			padding: 15rpx 10rpx;
			font-size: 21px;
    		border-radius: 5px;
			color: #4a6865;
			background: #a1e3dc;
		}
	}
	.cardRight {
		color: #787878;
		font-size: 17px;
		width: 100%;
		border-bottom: 1px solid #f5f5f5;
		padding-bottom: 20rpx;
		padding-top: 10rpx;
		.itemtitle{
			font-weight: 600;
			font-size: 19px;
		}
		&>view{
			width: 100%;
			display: flex;
			justify-content: space-between;
		}
	}
  }
  ::v-deep .u-sticky {
    top: 0 !important;
    background: #fff;
  }
  .info {
	display: flex;
	line-height: 42px;
	padding: 20rpx 20rpx;
	padding-top: 0;
	padding-bottom: 0;
	font-size: 16px;
	border-bottom: 1px solid #f5f5f5;
	.underline {
		border-bottom: 1px solid #d5d5d5;
		padding-bottom: 0px;
    	line-height: 40px;
		font-weight: 500;
		margin-left: 20rpx;
		font-size: 18px;
	}
  }
  </style>
  