<template>
	<!-- 订单发货 -->
	<!-- 快速发货 -->
	<!-- 发货 -->
	<view class="delivery fahuo yocode">
		<view class="fahuobox">
			<!-- <picker @change="bindPickerChange" :value="index" :range="logsitslist"> -->
				<view class="selectcell flex ali-c jus-b" @tap='pickerone'>
					<view class="flex ali-c">
						<image class="icons1" src="/static/news/fahuo.png" mode=""></image>
						<view class="names">{{chindtext==''?'选择快递公司':chindtext}}</view>
					</view>
					<image class="icons2" src="/static/news/xiala.png" mode=""></image>
				</view>
				<lb-picker ref="picker" :list="logsitslist" :value='chindtext' range-key="label" :props="myProps" @confirm='confirm'></lb-picker>
			<!-- </picker> -->
			
			<view class="selectcell flex ali-c jus-b">
				<view class="flex ali-c">					
					<image class="icons3" src="/static/news/dindhao.png" mode=""></image>
					<input  class="names" type="text" value="" v-model="logscode"  placeholder="输入快递单号" />
				</view>
				<view @tap="tosaoyisao"  class="tosaomaboxs">
					<image class="icons4" src="/static/news/saoma.png" mode=""></image>
				</view>
			</view>
			
			<view class="btnsbox flex ali-c jus-a">
				<view class="btns">取消</view>
				<view class="btns btns1" @tap="oneKeyShipmentsfun">确定发货</view>
			</view>
		</view>
	</view>
</template>

<script>
	import { oneKeyShipments,logisticsList  } from '@/utils/api/api.js';
	export default{
		data(){
			return{
				myProps: {
				      label: 'value',
				      value: 'cate_id',
				},
				vendor:'',
				logsitslist:[
					"圆通速递",
					"百世快递",
					"中通快递",
					"申通快递",
					"顺丰速运",
					"韵达速递",
					"邮政快递包裹",
					"EMS",
					"天天快递",
					"京东快递",
					"优速快递",
					"德邦快递",
					"宅急送",
					"TNT快递",
					"UPS",
					"DHL",
					"FEDEX联邦(国内件）",
					"FEDEX联邦(国际件）"
				],
				index:0,
				chindtext:"",
				logscode:"",
				order_id:"",//物流号
			}
		},
		onLoad(opdata) {
			this.order_id = opdata.order_id;
			this.vendor = opdata.vendor;
			this.logisticsListfun();
		},
		methods:{
			confirm(e){
				console.log(e)
				this.chindtext=e.value;
			},
			pickerone(){
				this.$refs.picker.show() // 显示
			},
			async logisticsListfun(){
				let res = await logisticsList({
					
				});
				
				if(res.code==0){
					this.logsitslist  =res.data;
				}else{
					this.$api.msg(res.msg);
				}
			},
			//快速发货 确认发货
			async oneKeyShipmentsfun(){
				if(this.chindtext==""){
					this.$api.msg("请选中快速公司");
					return false;
				}
				if(this.logscode==""){
					this.$api.msg("物流单号不能为空");
					return false;
				}
				let res = await oneKeyShipments({
					logisticCode:this.logscode,//物流好 快递单号 订单号
					shipperName:this.chindtext,//名称 快递公司编号 名称
					order_id:this.order_id,//订单id 订单id
					vendor_id:this.vendor,
				});
				if(res.code==0){
					uni.showModal({
					  title: '提示',
					  content: res.msg,
					  showCancel: false,
					  success(res) {
						uni.$emit("isDelorder",{action: 'oneKeyShipments'});
						uni.navigateBack({}); //返回上一页
					  }
					})
				}else{
					this.$api.msg(res.msg);
				}
			},
			//请求end
			bindPickerChange(e){
				console.log(e.detail.value,'哈哈哈');
				this.chindtext = this.logsitslist[e.detail.value];
			},
			//扫码方法
			tosaoyisao(){
				uni.scanCode({
				    success:  (res)=> {
				        console.log('条码类型：' + res.scanType);
				        console.log('条码内容：' + res.result);
						
						// let qrcodecon = 
						
						this.logscode = res.result;
				    }
				});
			}
		}
	}
</script>

<style lang="scss">
	@import  "./delivery.scss"
</style>
