<template>
	<view>
		<view style="height: 80rpx;line-height: 100rpx;padding-left: 20rpx;width: 95%;margin: 0 auto;">
			打印设置
		</view>
		<view style="width: 95%;margin: 0 auto;background: #fff;border-radius: 10px;padding: 15rpx;">
			<radio-group @change="radioChange" style="display: flex;">
				<label class="uni-list-cell uni-list-cell-pd" v-for="(item, index) in items" :key="item.value" style="flex: 1;">
					<view style="height: 100rpx;line-height: 100rpx;">
						<view style="height: 80rpx;line-height: 80rpx;">
							<radio :value="item.value" :checked="index === current" />
							{{item.name}}
						</view>
					</view>
				</label>
			</radio-group>
			<view style="display: flex;" v-if="current == 0">
				<view style="width: 40%;height: 80rpx;line-height: 80rpx;">选择打印纸张:</view>
				<view style="width: 60%;float: left;">
					<uni-data-select class="uni-data-select" :localdata="payTypeList"
						v-model="zhiType" placeholder="选择打印纸张" :clear="false"
						 style="width: 60%;">
					</uni-data-select>
				</view>
			</view>
			<view style="display: flex;">
				<view style="width: 40%;height: 80rpx;line-height: 80rpx;">打印份数:</view>
				<input type="number" placeholder="请输入物流单打印份数" v-model="wlNum"
					style="width: 60%;height: 80rpx;line-height: 80rpx;margin:0 10rpx;border: 1px solid #eee;padding-left: 20rpx;">
			</view>
		</view>
		<view style="height: 80rpx;line-height: 100rpx;padding-left: 20rpx;width: 95%;margin: 0 auto;">
			系统设置
		</view>
		<view style="width: 95%;margin: 0 auto;background: #fff;border-radius: 10px;padding: 15rpx;">
			<view style="display: flex;">
				<view style="width: 20%;height: 80rpx;line-height: 80rpx;">托运须知:</view>
				<textarea name="" id="" cols="30" rows="10" maxlength="-1" v-model="remark" style="width: 80%;line-height: 40rpx;margin:0 10rpx;border: 1px solid #eee;padding-left: 20rpx;"></textarea>
			</view>
		</view>
		<view style="width: 95%;margin: 0 auto;background: #fff;border-radius: 10px;padding: 15rpx;">
			<view style="display: flex;">
				<view style="width: 20%;height: 80rpx;line-height: 80rpx;">联系方式:</view>
				<textarea name="" id="" cols="30" rows="10" maxlength="-1" v-model="companyTel" style="width: 80%;line-height: 40rpx;margin:0 10rpx;border: 1px solid #eee;padding-left: 20rpx;"></textarea>
			</view>
		</view>
		<view style="background: #fff;width: 100%;height: 120rpx;position: fixed;bottom: 0;">
			<view @tap="editPrintWay" style="text-align: center;border-radius: 20rpx;font-size: 36rpx;width: 95%;margin: 15rpx auto 0;height: 90rpx;background: #088FEB;color: #fff;line-height: 90rpx;">
				修改
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				items: [{
					value: 'zwl',
					name: '只打印物流单',
					copies:1
				},
				{
					value: 'wlhxp',
					name: '打印物流单和小标签',
					WLcopies:1,
					XBQcopies:1,
					
				}],
				payTypeList: [{
					value: 0,
					text: "不干胶纸"
				}, {
					value: 1,
					text: "760mm热敏纸"
				}],
				zhiType:uni.getStorageSync('zhiType')?uni.getStorageSync('zhiType'):0,
				current: 0,
				wlNum:uni.getStorageSync('wlNum')?uni.getStorageSync('wlNum'):1,
				remark:uni.getStorageSync('remark')?uni.getStorageSync('remark'):"",
				companyTel:uni.getStorageSync('companyTel')?uni.getStorageSync('companyTel'):""
			}
		},
		onLoad(){
			if(uni.getStorageSync('wlNum') > 0 && uni.getStorageSync('xbqNum') > 0){
				//两个都打印
				this.current = 1
			}else{
				this.current = 0
			}
		},
		methods: {
			radioChange(evt) {
				for (let i = 0; i < this.items.length; i++) {
					if (this.items[i].value === evt.detail.value) {
						this.current = i;
						break;
					}
				}
			},
			editPrintWay(){
				
				let printMethod = {}
				if(this.current == 0){
					if(this.wlNum != '' && this.wlNum != 0){
						printMethod = {
							wlNum:this.wlNum,
							zhiType:this.zhiType
						}
						uni.setStorageSync('wlNum',this.wlNum)
						uni.removeStorageSync('xbqNum')
						uni.setStorageSync('zhiType',this.zhiType)
						
					}else{
						uni.showToast({
							title:'请输入打印份数'
						})
						return
					}
				}else{
					if(this.wlNum != '' && this.wlNum != 0){
						printMethod = {
							wlNum:this.wlNum,
							xbqNum:1,
							zhiType:this.zhiType
						}
						uni.setStorageSync('wlNum',this.wlNum)
						uni.setStorageSync('xbqNum',1)
						uni.setStorageSync('zhiType',this.zhiType)
					}else{
						uni.showToast({
							title:'请输入打印份数'
						})
						return
					}
				}
				uni.setStorageSync('remark',this.remark)
				uni.setStorageSync('companyTel',this.companyTel)
				uni.request({
					url: this.tui.interfaceUrl() + '/app/logitics/updateLogiticsCompany',
					data: {
						id:uni.getStorageSync('transCompany'),
						printMethod:JSON.stringify(printMethod),
						companyTel:this.companyTel,
						remark:this.remark
					},
					header: {
						'content-type': 'application/json',
						'appWLToken': this.tui.getToken()
					},
					method: 'POST', //'GET','POST'
					dataType: 'json',
					success: (res) => {
						if (res.data.code == 401) {
							uni.clearStorage()
							uni.navigateTo({
								url: '/package2/login/login'
							})
						}
						if (res.data.code == 200) {
							uni.showToast({
								title:'修改成功'
							})
							setTimeout(res=>{
								uni.navigateBack()
							},1000)
						}
					},
					fail: (res) => {
						this.tui.toast("网络不给力，请稍后再试~")
					}
				})
			}
		
		}
	}
</script>
<style lang="scss">
	page,
	.page1 {
		width: 100%;
	}
</style>