<template>
    <div>
        <div class="container">
            <form action="" v-if="isCombineVisible">
                <van-search @search="check" ref="searchRef" class="search" v-model="value" placeholder="请输入快递单号" />
                <img @click="onImg" src="@/assets/user/u4.png" alt="">
            </form>

            <Combine :signList="signList" @onIsCombine="isCombineChange" v-if="isSign"></Combine>
        </div>
    </div>
</template>

<script>
import { appFindYourShipmentList, appFindYourShipment } from '@/api/index'
import Combine from './combine.vue'
import { Toast } from 'vant'
import wx from "weixin-jsapi";
export default {
    name: 'Sign',
    components: {
        Combine
    },
    data() {
        return {
            value: '',//输入的值
            isSign: false,
            signList: [],
            isSearch: true,
            isCombineVisible: true
        };
    },
    mounted() {
        this.$nextTick(() => {
            if (this.$refs.searchRef) {
                const inputEle = this.$refs.searchRef.querySelector("input")
                inputEle.focus()
            }
        })
    },
    methods: {
        onImg() {
            wx.scanQRCode({
                needResult: 1, // 默认为0，扫描结果由微信处理，1则直接返回扫描结果，
                scanType: ["qrCode", "barCode"], // 可以指定扫二维码还是一维码，默认二者都有
                success: (res) => {
                    var result = res.resultStr; // 当needResult 为 1 时，扫码返回的结果
                    if (result.indexOf(",") != -1) {
                        let result1 = res.resultStr.split(",");
                        result = result1[result1.length - 1];
                    }
                    this.value = result
                    this.check()
                },
                error: function (res) {
                    console.log(res, 'error++++++++++');
                }
            });
        },

        // 查询
        async check() {
            if (this.value == '') {
                this.$toast('请输入快件单号或手机单号')
                return
            }

            const Shipment = await appFindYourShipment({ expressNo: this.value }, { emulateJSON: true, loading: true, message: '加载中...' })

            if (Shipment.data == null) {
                Toast('没有数据')
            }

            const res = await appFindYourShipmentList({ userId: Shipment.data.user_id }, { emulateJSON: true })
            if (res.code == '0') {
                this.isSign = true
                // res.data[1].expressStatus = "0"
                this.signList = res.data
                console.log(this.signList, '  this.signList')
            } else {
                Toast('快递单号不正确')
            }
        },
        isCombineChange(value) {
            this.isCombineVisible = value
        }
    }

};
</script>

<style lang="less" scoped>
.container {
    background-color: #fff;
    height: 100vh;

    img {
        position: fixed;
        height: 20px;
        width: 20px;
        right: 22px;
        top: 18px;
    }

    .search {
        /deep/ .van-icon-clear.van-field__clear {
            margin-right: 22px;
        }
    }
}
</style>
