<template>
    <view>
        <form @submit="sendSubmit">
            <view class="nickname">
                <view class="examineTitle">
                    选择发货方式
                </view>
                <view class="toExamine" v-if="send.sendWay[send.sendIndex]">
                    <picker mode="selector" :value="send.sendIndex" range-key="name" :range="send.sendWay" @change="wayChange">
                        <view>{{send.sendWay[send.sendIndex].name}}</view>
                    </picker> 
                    <image class="toExamine-row" src="/static/icon/goods_row.png" mode="aspectFill"></image>
                </view>
            </view>
            <view class="nickname" >
                <view class="examineTitle">
                    选择快递公司
                </view>
                <view class="toExamine" v-if="state.array[state.index]">
                    <picker mode="selector" :value="state.index" range-key="name" :range="state.array" @change="sexChange">
                        <view>{{state.array[state.index].name}}</view>
                    </picker> 
                    <image class="toExamine-row" src="/static/icons/goods_row.png" mode="aspectFill"></image>
                </view>
            </view>
            <view class="nickname">
                <view class="examineTitle">
                    填写快递单号
                </view>
                <input class="remarks" @blur="bindExpressNo" auto-height placeholder="请输入订单单号" />
            </view>
            

            <button class="submit" form-type="submit" type="default">提交</button>
        </form>
    </view>
</template>

<script>
    import { deliverpre,refundsDeliver } from '@/apis/interfaces/order.js'
	export default {
		data() {
			return {
                send          : {
                    sendWay   : [{
                        id    : 'post',
                        name  : '自行邮寄'
                    }],
                    sendIndex : 0,
                },
				state       : {
				    // 快递筛选
				    array   : [],
				    // 快递筛选默认下标
				    index   : 0,
				},
                expressNo      : '',
			}
		},
        onLoad() {
            deliverpre().then(res=>{
                console.log(res)
                this.state.array = res.expresses
            }).catch(err=>{
                console.log(err);
            })
        },
		methods: {
            // 选择发货方式
            wayChange(e) {
                this.send.sendIndex = e.detail.value
                this.expressNo = ''
                this.courierName = ''
                this.courierMobile = ''
            },
            
            // 筛选
            sexChange(e) {
                this.state.index = e.detail.value
            },
            
            // 快递单号
            bindExpressNo(val) {
                this.expressNo = val.detail.value
            },
            
            // 	送货人姓名
            bindCourierName(val) {
                this.courierName = val.detail.value
            },
            
            // 	送货人联系方式
            bindCourierMobile(val) {
                this.courierMobile = val.detail.value
            },
            
            // 提交表单
            sendSubmit() {
                refundsDeliver(this.$Route.query.id,{
                    company      :	this.state.array[this.state.index].name || '',
                    number       :	this.expressNo || '',
                }).then(res=>{
                   uni.showToast({
                       icon: 'none',
                       title: '发送成功',
                       mask:true,
                   })
                   setTimeout(()=>{
                       this.$Router.back()
                   },2002)
                })
                
                
            }
		}
	}
</script>

<style lang="scss" scoped>
    .nickname {
        background-color: #FFFFFF;
        padding: $padding;
        margin-bottom: $margin;
        display: flex;
        position: relative;
        font-size: $title-size-lg;
        border-bottom: solid 1rpx #f9f9f9;
        .examineTitle {
            width: 210rpx;
        }
        .remarks {
            width: calc(100% - 210rpx);
            font-size: $title-size-lg;
            color: $text-color;
            text-align: right;
        }
        .toExamine {
            position: absolute;
            top: $padding;
            right: $padding;
            display: flex;
            .toExamine-row {
                width: 32rpx;
                height: 32rpx;
                margin-top: 6rpx;
                filter: grayscale(100%);
            }
        }
    }
    .submit {
        background: #34ce98;
        color: white;
        border-color: #34ce98;
        margin: $margin*4 $margin 0;
    }
</style>
