<template>
	<view style="margin: 25rpx 25rpx 75rpx 25rpx;">
		<uni-collapse>
			<u-form label-position = "left" label-width = "auto">
				<uni-collapse-item title="合同信息" :open="true" :showAnimation="true">
					<view style="background-color: #ffffff;padding: 0px 12px;">
						<u-form-item label="合同单号："><u-input v-model="paymentData.contractNo" /></u-form-item>
						<u-form-item label="客户名称："><u-input v-model="paymentData.buyName" /></u-form-item>
						<u-form-item label="贸易国："><u-input v-model="paymentData.mYCountryDesc" /></u-form-item>
						<u-form-item label="签订日期："><u-input v-model="paymentData.chooseTime" /></u-form-item>
						<u-form-item label="合同周期："><u-input v-model="paymentData.contractPeriod" /></u-form-item>
					</view>
				</uni-collapse-item>
				<uni-collapse-item title="付款信息" :open="true" :showAnimation="true">
					<view style="background-color: #ffffff;padding: 0px 12px;">
						<u-form-item label="类型："><u-input v-model="paymentData.priceType" /></u-form-item>
						<u-form-item label="付汇方式："><u-input v-model="paymentData.payTypeDesc" /></u-form-item>
						<u-form-item label="收款日期："><u-input v-model="paymentData.termsPayment" /></u-form-item>
						<u-form-item label="本币金额："><u-input v-model="paymentData.payPrice" /></u-form-item>
						<u-form-item label="备注："><u-input v-model="paymentData.remarks" /></u-form-item>
					</view>
					<view>
						<wyb-table :headers="headers" :contents="tableList" :width="tableWidth" :font-size="[20]" :default-col-width="120"></wyb-table>
					</view>
				</uni-collapse-item>
			</u-form>
		</uni-collapse>
	</view>
</template>

<script>
	import wybTable from '@/components/wyb-table/wyb-table.vue'
	export default {
		props: ['parentPaymentData'],
		components:{wybTable},
		data() {
			return {
				paymentData : {},
				tableList : [],
				headers: [{
							label: '商品名称',
							key: 'apiName'
						}, {
							label: '英文名',
							key: 'englishName'
						}, {
							label: '单位',
							key: 'apiUnit'
						}, {
							label: '规格',
							key: 'asrValue'
						}, {
							label: '总重量',
							key: 'weight'
						}, {
							label: '付款重量',
							key: 'paymentWeight'
						}, {
							label: '本币总金额',
							key: 'localAmount'
						}, {
							label: '备注',
							key: 'remarks'
						}],
				tableWidth : uni.getSystemInfoSync().screenWidth - 20 + 'px',
				form : {}
			}
		},
		beforeMount() {
			let self = this;
			this.paymentData = JSON.parse(JSON.stringify(this.parentPaymentData));
			this.priceTypeInit();
			this.payTypeInit();
			this.admRequest({
				action : 'ContractManageAction/selectContractInfo',
				data : {
					aciId : self.paymentData.contractId
				},
				success(res){
					let contractData = res.data.data[0];
					let chooseTime = contractData.chooseTime;
					let contractNo = contractData.contractNo;
					let contractPeriod = contractData.contractPeriod;
					let buyName = contractData.buyName;
					let mYCountryDesc = contractData.mYCountryDesc;
					
					// 合同金额 和 合同号
					self.paymentData.contractNo = contractNo;
					self.paymentData.chooseTime = chooseTime;
					self.paymentData.contractPeriod = contractPeriod;
					self.paymentData.buyName = buyName;
					self.paymentData.mYCountryDesc = mYCountryDesc;
					self.$forceUpdate();
				}
			}),
			this.admRequest({
				action : 'CollectPayManageAction/queryContractDetail',
				data : {
					aopId : self.paymentData.id, contractId : self.paymentData.contractId
				},
				success(res){
					self.tableList = res.data.data;
				}
			})
		},
		methods:{
			payTypeInit(){
				let self = this;
				let payTypeDesc = null;
				if (!!uni.getStorageSync('PAYMENT_METHOD_OUT')) {
					var payWayList = uni.getStorageSync('PAYMENT_METHOD_OUT');
					for (let p of payWayList) {
						if (self.paymentData.payType == p.value) {
							payTypeDesc = p.showmsg;
							self.paymentData.payTypeDesc = payTypeDesc;
							self.$forceUpdate();
						}
					}
				} else {
					self.admRequest({
						action : 'AppParamAction/getAppparList',
						data : {
							code : 'PAYMENT_METHOD_OUT'
						},
						success(r){
							var payWayList = r.data.data;
							if (!!payWayList) {
								uni.setStorageSync("PAYMENT_METHOD_OUT", payWayList);
							}
							for (let p of payWayList) {
								if (self.paymentData.payType == p.value) {
									payTypeDesc = p.showmsg;
									self.paymentData.payTypeDesc = payTypeDesc;
									self.$forceUpdate();
								}
							}
						}
					})
				}
				if (payTypeDesc == null) {
					if (!!uni.getStorageSync('PAYMENT_METHOD')) {
						var payWayList = uni.getStorageSync('PAYMENT_METHOD');
						for (let p of payWayList) {
							if (self.paymentData.payType == p.value) {
								payTypeDesc = p.showmsg;
								self.paymentData.payTypeDesc = payTypeDesc;
								self.$forceUpdate();
							}
						}
					} else {
						self.admRequest({
							action : 'AppParamAction/getAppparList',
							data : {
								code : 'PAYMENT_METHOD'
							},
							success(r){
								var payWayList = r.data.data;
								if (!!payWayList) {
									uni.setStorageSync("PAYMENT_METHOD", payWayList);
								}
								for (let p of payWayList) {
									if (self.paymentData.payType == p.value) {
										payTypeDesc = p.showmsg;
										self.paymentData.payTypeDesc = payTypeDesc;
										self.$forceUpdate();
									}
								}
							}
						})
					}
				}
			},
			priceTypeInit(){
				let self = this;
				if (!!uni.getStorageSync('AOP_PRICE_TYPE')) {
					let priceTypeInitList = uni.getStorageSync('AOP_PRICE_TYPE');
					for (let p of priceTypeInitList) {
						console.log(p)
						if (p.value == self.paymentData.priceType) {
							self.paymentData.priceType = p.showmsg;
							self.$forceUpdate();
							break;
						}
					}
				} else {
					this.admRequest({
						action : 'AppParamAction/getAppparList',
						data : {
							code : 'AOP_PRICE_TYPE'
						},
						success(r){
							var priceTypeInitList = r.data.data;
							if (!!priceTypeInitList) {
								uni.setStorageSync("AOP_PRICE_TYPE", priceTypeInitList);
							}
							for (let p of priceTypeInitList) {
								console.log(p)
								if (self.paymentData.priceType == p.value) {
									self.paymentData.priceType = p.showmsg;
									self.$forceUpdate();
									break;
								}
							}
						}
					})
				}
			}
		}
	}
</script>

<style>
</style>
