<template>
    <div>
        <div class="container">
            <van-search @search="check" v-model="value" placeholder="请输入快件单号或手机单号" />
            <img @click="onImg" src="@/assets/user/u4.png" alt="">

            <!-- <van-button style="width: 200px; border-radius: 6px; margin-left: 10px;" type="info"
                @click="check">查询</van-button> -->
            <Combine :isSign="isSign" :signList="signList" @isSign="isCombine" 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 {
            titlename: "派件签收",
            value: '',
            isSign: true,
            signList: []
        };
    },
    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
                },
                error: function (res) {
                    console.log(res, 'error++++++++++');
                }
            });

        },
        // 查询
        async check() {
            if (this.value == '') {
                this.$toast('请输入快件单号或手机单号')
                return
            }
            const Shipment = await appFindYourShipment({ expressNo: this.value }, { emulateJSON: true })
            if (Shipment.data == null) {
                Toast('没有数据')
            }

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

};
</script>

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

    img {
        position: fixed;
        height: 20px;
        width: 20px;
        right: 22px;
        top: 18px;
    }
}
</style>
